Пример #1
0
 def test_utils_cmp_dicts_act_data_exception(self):
     self.assertEqual(
         utils.cmp_dicts({
             'k': 10,
             'c': 'abc',
             'f': 10
         }, {
             'k': 10,
             'd': -20,
             'c': 'abc',
             'f': 9
         },
                         exact=True), False)
     with self.assertRaises(Exception) as context:
         utils.cmp_dicts({'1': 1}, {})
     self.assertTrue("act_data is not defined" in str(context.exception))
Пример #2
0
 def test_utils_cmp_dicts_plain_no_tolerance(self):
     self.assertEqual(
         utils.cmp_dicts({
             'k': 10,
             'c': 'abc'
         }, {
             'k': 10,
             'd': -20,
             'c': 'abc'
         }), True)
Пример #3
0
 def test_utils_cmp_dicts_plain_no_tolerance_exact(self):
     self.assertEqual(
         utils.cmp_dicts({
             'k': 10,
             'c': 'abc'
         }, {
             'k': 10,
             'd': -20,
             'c': 'abc'
         },
                         exact=True), False)
Пример #4
0
    def verify_nat_pool(self, name, expected_output, **kwargs):
        """Verify NAT pool

        :param string name:
            **OPTIONAL** Name of NAT pool.

        :return: True if successful else False

        :rtype: bool

        Example::

            Python:
                hCgn.verify_nat_pool(name='nat_pool1', nat_type='source')

            Robot:
                hCgn.Verify NAT Rule   name=nat_pool1    nat_type=source
        """

        self.fn_checkin("Verifying NAT pool")
        result = True
        self.nat_type = kwargs.get('nat_type', self.nat_type)

        if self.nat_type == 'source':
            _xpath = '{}-nat-pool-detail-information/{}-nat-pool-info-entry'.format(self.nat_type, self.nat_type)
        elif self.nat_type == 'destination':
            _xpath = '{}-nat-pool-information/{}-nat-pool-entry'.format(self.nat_type, self.nat_type)

        cmd = 'show services nat {} pool {}'.format(self.nat_type, name)
        entry = self.get_xml_output(cmd, xpath=_xpath)

        nat_pool_dic = {}
        if 'interface-name' in expected_output:
            nat_pool_dic['interface-name'] = entry['interface-name']
        if 'service-set-name' in expected_output:
            nat_pool_dic['pool-name'] = entry['pool-name']
        if 'service-set-name' in expected_output:
            nat_pool_dic['service-set-name'] = entry['service-set-name']
        if 'address-range-high' in expected_output:
            range_name = 'source-pool-address-range' if self.nat_type == 'source' else 'pool-address-range'
            nat_pool_dic['address-range-high'] = entry[range_name]['address-range-high']
        if 'address-range-low' in expected_output:
            range_name = 'source-pool-address-range' if self.nat_type == 'source' else 'pool-address-range'
            nat_pool_dic['address-range-low'] = entry[range_name]['address-range-low']
        if 'total-pool-address' in expected_output:
            nat_pool_dic['total-pool-address'] = entry['total-pool-address']
        if utils.cmp_dicts(nat_pool_dic, expected_output):
            self.log('INFO', "Verification details for pool, {}, PASSED".format(name))
        else:
            self.log('INFO', "Verification for pool, {}, FAILED".format(name))
            result = False

        return self.fn_checkout(result)
Пример #5
0
    def verify_pcp_statistics(self, other_stats_zero=True, **kwargs):
        """Verify PCP statistics

        :param bool other_stats_zero:
            **OPTIONAL** Except for the stats passed, other stats will be default to 0.
                Default is False

        :return: True on successful verification else False

        :rtype: bool

        Example::

            Python:
                pcp.verify_pcp_statistics()
            Robot:
                pcp.Verify PCP Statistics
        """

        self.fn_checkin("Verifying PCP statistics")

        result = True

        self._get_tg_port_and_config_mapping(**kwargs)

        for spic in self.tg_sess_cnt:
            act_data = self.get_pcp_statistics(spic, **kwargs)
            exp_data = {}
            exp_data['map_req_rx'] = self.tg_sess_cnt[spic]['total_pcp_reqs']
            exp_data['pcp_success'] = self.tg_sess_cnt[spic]['total_pcp_reqs']
            for key in act_data:
                if key in kwargs:
                    exp_data[key] = kwargs[key]
                elif other_stats_zero:
                    exp_data[key] = 0
            result &= utils.cmp_dicts(exp_data=exp_data, act_data=act_data)

            result &= utils.cmp_dicts(exp_data=exp_data, act_data=act_data)

        return self.fn_checkout(result)
Пример #6
0
 def test_utils_cmp_dicts_plain(self):
     self.assertEqual(
         utils.cmp_dicts({
             'k': 10,
             'c': 'abc',
             'f': 10,
             'd': None
         }, {
             'k': 10,
             'd': -20,
             'c': 'abc'
         },
                         tol_perc=1,
                         tol_val=1), False)
Пример #7
0
 def test_utils_cmp_dicts_ip(self, is_ip_patch, cmp_ip_patch):
     is_ip_patch.return_value = True
     cmp_ip_patch.return_value = True
     self.assertEqual(
         utils.cmp_dicts({
             'k': 10,
             'c': 'abc',
             'f': 10,
             'd': None
         }, {
             'k': 10,
             'd': -20,
             'c': 'abc'
         },
                         tol_perc=1,
                         tol_val=1), False)
Пример #8
0
 def test_utils_cmp_dicts_non_exact(self):
     self.assertEqual(
         utils.cmp_dicts(
             {
                 'min__a': 10,
                 'max__b': 10,
                 'neg__d': -10,
                 'c': 'abc',
                 'f': 10
             }, {
                 'a': 10,
                 'b': 20,
                 'd': -20,
                 'c': 'abc'
             },
             tol_perc=1,
             tol_val=1), False)
Пример #9
0
    def verify_pcp_debug_statistics(self, other_stats_zero=False, **kwargs):
        """Verify PCP Debug statistics

        :param bool other_stats_zero:
            **OPTIONAL** Except for the stats passed, Default other stats to 0.
            Default is False

        :return: True on successful verification else False

        :rtype: bool

        Example::

            Python:
                pcp.verify_pcp_debug_statistics()
            Robot:
                pcp.Verify PCP Debug Statistics
        """

        self.fn_checkin("Verifying PCP Debug statistics")

        result = True

        self._get_tg_port_and_config_mapping(**kwargs)

        for tg_if in self.tg_cfg_map:
            _cfg_map = self.tg_cfg_map[tg_if]
            act_data = self.get_pcp_debug_statistics(_cfg_map['spic'],
                                                     **kwargs)
            exp_data = {}
            for key in act_data:
                if key in kwargs:
                    exp_data[key] = kwargs[key]
                elif other_stats_zero:
                    exp_data[key] = 0

            result &= utils.cmp_dicts(exp_data=exp_data, act_data=act_data)

        return self.fn_checkout(result)
Пример #10
0
    def verify_pic_memory_snapshot(self, **kwargs):
        """Verify memory snapshot

        For a given memory snapshot taken before (ideally before the start of the testcase),
        this routine compares this with the current memory snapshot.

        :param dict before:
            **REQUIRED** Memory snapshot taken before, by calling get_pic_memory_snapshot

        :param list daemon_list:
            **OPTIONAL** List of Daemons for which memory leak has to be verified

        :param list ignore_list:
            **OPTIONAL** List of objs to be ignored while verifying the objs in use

        :param bool verify_shm:
            **OPTIONAL** Enable shm verification. Default is True

        :param bool verify_mum:
            **OPTIONAL** Enable mum verification. Default is True

        :param int tol_perc:
            **OPTIONAL** Tolerance percentage in verifying. Default is 1

        :param int tol_shm:
            **OPTIONAL** Tolerance value in verifying shm. Default is 0

        :return: Dictionary containing the memory snapshot

        :rtype: dict

        Example::

          Python:
            verify_pic_memory_snapshot()

          Robot:
            Verify Pic Memory Snapshot
        """

        this = utils.update_opts_from_args(kwargs,
                                           defaults={
                                               'daemon_list': [],
                                               'ignore_list': [],
                                               'verify_shm': True,
                                               'verify_mum': True,
                                               'tol_shm': 0,
                                               'tol_perc': 1,
                                           })

        before = kwargs.get('before', {})

        #options = {}
        #if this['daemon_list']:
        #options['daemon_list'] = this['daemon_list']

        #after = self.get_pic_memory_snapshot(**options)
        after = self.get_pic_memory_snapshot(**kwargs)

        result = True
        _cmp_msg = "Comparing before and current memory snapshots"
        if this['verify_shm']:
            self.log('INFO', "{} for shm".format(_cmp_msg))
            result &= utils.cmp_dicts(exp_data=before['shm'],
                                      act_data=after['shm'],
                                      tol_perc=this['tol_shm'])

        if this['ignore_list']:
            for obj in before['objcache']:
                _msg = "For obj, {}, Objs in use".format(obj)
                if obj in this['ignore_list']:
                    self.log(
                        'INFO',
                        "{}, Before : {}".format(_msg,
                                                 before['objcache'][obj]))
                    self.log(
                        'INFO',
                        "{}, Current : {}".format(_msg,
                                                  after['objcache'][obj]))
                _msg += " before and current memory snapshots"
                if before['objcache'][obj] < after['objcache'][obj]:
                    self.log('ERROR', "{} are **NOT** same".format(_msg))
                    result &= False
                else:
                    self.log('ERROR', "{} **ARE** same".format(_msg))
        else:
            result &= utils.cmp_dicts(exp_data=before['objcache'],
                                      act_data=after['objcache'],
                                      tol_perc=this['tol_perc'])

        if this['verify_mum']:
            self.log('INFO', "{} for mum".format(_cmp_msg))
            result &= utils.cmp_dicts(exp_data=before['mum'],
                                      act_data=after['mum'],
                                      tol_perc=this['tol_perc'])

        if this['daemon_list']:
            self.log(
                'INFO', "{} for daemons: {}".format(_cmp_msg,
                                                    this['daemon_list']))
            result &= utils.cmp_dicts(exp_data=before['daemon'],
                                      act_data=after['daemon'],
                                      tol_perc=this['tol_perc'])

        return result
Пример #11
0
    def verify_pcp_mappings(self, **kwargs):
        """Verify PCP mappings

        Fetches PCP data from the output by calling get_pcp_mappings.
        This data is verified against the data fetched from configuration and traffic generator.
        Number of mappings to be verified can be limited by 'limit' or 'limit_perc'.
        Random mappings, to be verified, are picked from sessions to be sent by TG.

        :param int limit:
            **OPTIONAL** Number of mappings to be verified.

        :param int limit_perc:
            **OPTIONAL** Percentage number of mappings to be verified. Default is 1

        :return: True on successful verification else False

        :rtype: bool

        Example::

            Python:
                pcp.verify_pcp_mappings()
            Robot:
                pcp.Verify PCP Mappings
        """

        self.fn_checkin("Verifying PCP mappings")

        result = True

        # Fetch PCP Mappings output as dictionary
        act_data = self.get_pcp_mappings()

        self._get_tg_port_and_config_mapping(**kwargs)

        for tg_if in self.tg_cfg_map:
            _cfg_map = self.tg_cfg_map[tg_if]
            # Iterate over list of random mappings indices
            for req_idx in _cfg_map['rand_reqs_idx_list']:
                # We need to verify if theres a mapping for this session on the router
                _tg_data = self.tg_sess[tg_if]['pcp_maps_list'][req_idx]
                ext_port = _tg_data['ext_port']

                flow = self._get_pcp_ip_port_flow_from_data(
                    _tg_data, _cfg_map, act_data)

                if flow is None or ('nat_ip' in flow
                                    and flow['nat_ip'] is None):
                    continue

                if not iputils.cmp_ip(_tg_data['ext_ip'], flow['nat_ip']):
                    result = False
                    continue

                result &= utils.cmp_dicts(exp_data={
                    'state': 'active',
                    'nat_port': ext_port
                },
                                          act_data=flow)

        return self.fn_checkout(result)
Пример #12
0
    def verify_nat_rule(self, name, expected_output, **kwargs):
        """Verify NAT rule

        :param string name:
          **OPTIONAL** Name of NAT rule.

        :return: True if successful else False

        :rtype: bool

        Example::

            Python:
                hCgn.verify_nat_rule(name='nat_rule1', nat_type='source')

            Robot:
                hCgn.Verify NAT Rule   name=nat_rule1    nat_type=source
        """

        self.fn_checkin("Verifying NAT rule")

        self.nat_type = kwargs.get('nat_type', self.nat_type)

        if self.nat_type == 'source':
            _xpath = 'source-nat-rule-detail-information/source-nat-rule-entry'
        elif self.nat_type == 'destination':
            _xpath = 'destination-nat-rule-information/destination-nat-rule-entry'
        cmd = 'show services nat {} rule {}'.format(self.nat_type, name)
        entry = self.get_xml_output(cmd, xpath=_xpath)
        result = True

        entry = self.get_xml_output(cmd, xpath=_xpath)
        nat_rule_dic = {}
        if 'interface-name' in expected_output:
            nat_rule_dic['interface-name'] = entry['interface-name']
        if 'rule-set-name' in expected_output:
            nat_rule_dic['rule-set-name'] = entry['rule-set-name']
        if 'service-set-name' in expected_output:
            nat_rule_dic['service-set-name'] = entry['service-set-name']
        if 'rule-source-address-low-range' in expected_output:
            range_entry = "source-address-range-entry" if self.nat_type == 'source' else 'rule-source-address-range-entry'
            nat_rule_dic['rule-source-address-low-range'] = entry[range_entry]['rule-source-address-low-range']
        if 'rule-source-address-high-range' in expected_output:
            range_entry = "source-address-range-entry" if self.nat_type == 'source' else 'rule-source-address-range-entry'
            nat_rule_dic['rule-source-address-high-range'] = entry[range_entry]['rule-source-address-high-range']
        if 'rule-source-address' in expected_output:
            range_entry = "source-address-range-entry" if self.nat_type == 'source' else 'rule-source-address-range-entry'
            nat_rule_dic['rule-source-address'] = entry[range_entry]['rule-source-address']
        if 'rule-destination-address-low-range' in expected_output:
            range_entry = "destination-address-range-entry" if self.nat_type == 'source' else 'rule-destination-address-range-entry'
            nat_rule_dic['rule-destination-address-low-range'] = entry[range_entry]['rule-destination-address-low-range']
        if 'rule-destination-address' in expected_output:
            range_entry = "destination-address-range-entry" if self.nat_type == 'source' else 'rule-destination-address-range-entry'
            nat_rule_dic['rule-destination-address'] = entry[range_entry]['rule-destination-address']
        if 'rule-destination-address-high-range' in expected_output:
            range_entry = "destination-address-range-entry" if self.nat_type == 'source' else 'rule-destination-address-range-entry'
            nat_rule_dic['rule-destination-address-high-range'] = entry[range_entry]['rule-destination-address-high-range']

        if utils.cmp_dicts(nat_rule_dic, expected_output):
            self.log('INFO', "Verification details for rule, {}, PASSED".format(name))
        else:
            self.log('INFO', "Verification for rule, {}, FAILED".format(name))
            result = False

        return self.fn_checkout(result)
Пример #13
0
    def verify_usf_nat_rule(self, rs_name=None, r_name=None, **kwargs):
        """Verify NAT pool detail

        :param string name:
            **OPTIONAL** Name of NAT pool. If name is passed, details for that NAT Pool
            are verified, else details for all pools configured (saved in object)
            will be verified. Default is None

        :return: True if successful else False

        :rtype: bool

        Example::

            Python:
                hCgn.verify_nat_pool_detail(name='nat_pool1')
                hCgn.verify_nat_pool_detail()
            Robot:
                hCgn.Verify NAT Pool Detail   name=nat_pool1
                hCgn.Verify NAT Pool Detail
        """

        self.fn_checkin("Verifying NAT pool detail")

        self._get_tg_port_and_config_mapping(**kwargs)
        #self._get_ss_from_pool()

        self.get_usf_nat_rule(rs_name, r_name)

        result = True
        rs_names = [rs_name] if rs_name is not None else self.nat_rule_set.keys()
        r_names = [r_name] if r_name is not None else self.nat_rule_set[rs_name].keys()

        #import sys, pdb; pdb.Pdb(stdout=sys.__stdout__).set_trace()
        for rs_name in rs_names:
            for r_name in r_names:
                self.log('INFO', "Verifying details for Rule Set : {}, Rule, {}".format(rs_name, r_name))

                rule_data = self.data['nat_rule_set'][rs_name][r_name]

            exp_data = {
                'app': 'configured', 'per_nat_type': 'N/A',
                'per_map_type': 'address-port-mapping'
                }
            #iputils.iputils.get_network_address is not defined:
            #iputils.get_broadcast_address  is not defined:
            #verify later if this block is necessary
#############
            #if 'src_addr' in self.nat_rule_set[rs_name][r_name]:
            #    src_addr = self.nat_rule_set[rs_name][r_name]['src_addr']
            #    exp_data['src_addr_range_low'] = iputils.get_network_address(src_addr)
            #    exp_data['src_addr_range_high'] = iputils.get_broadcast_address(src_addr)

            #if 'dst_addr' in self.nat_rule_set[rs_name][r_name]:
            #    dst_addr = self.nat_rule_set[rs_name][r_name]['dst_addr']
            #    exp_data['dst_addr_range_low'] = iputils.get_network_address(dst_addr)
            #    exp_data['dst_addr_range_high'] = iputils.get_broadcast_address(dst_addr)
            #exp_data['spic'] = self.ss_map['nat_rule_set']
#############
            exp_data['sset'] = self.ss_map['nat_rule_set'][rs_name]
            exp_data['rule'] = r_name
            exp_data['rule_set'] = rs_name

            for key in kwargs:
                if 'tg_sess' in key:
                    continue
                exp_data[key] = kwargs[key]

            self.log('INFO', "Verifying expected({}) and actual({}) data".format(exp_data,
                                                                                 rule_data))
            if utils.cmp_dicts(exp_data, rule_data):
                self.log('INFO', "Verification details for pool, {}, PASSED".format(r_name))
            else:
                self.log('INFO', "Verification for pool, {}, FAILED".format(r_name))
                result = False

        return self.fn_checkout(result)
Пример #14
0
    def verify_usf_nat_pool_detail(self, name=None, **kwargs):
        """Verify NAT pool detail

        :param string name:
            **OPTIONAL** Name of NAT pool. If name is passed, details for that NAT Pool
            are verified, else details for all pools configured (saved in object)
            will be verified. Default is None

        :return: True if successful else False

        :rtype: bool

        Example::

            Python:
                hCgn.verify_nat_pool_detail(name='nat_pool1')
                hCgn.verify_nat_pool_detail()
            Robot:
                hCgn.Verify NAT Pool Detail   name=nat_pool1
                hCgn.Verify NAT Pool Detail
        """

        self.fn_checkin("Verifying NAT pool detail")

        self._get_tg_port_and_config_mapping(**kwargs)
        self._get_ss_from_pool()

        self.get_usf_nat_pool_detail(name)

        result = True
        pool_names = [name] if name is not None else self.data['nat_pool'].keys()

        self.log('INFO', "Verifying details for pools: {}".format(pool_names))
        for pool_name in pool_names:
            # for tg_if in self.tg_cfg_map:
            #_cfg_map = self.tg_cfg_map[tg_if]
            self.log('INFO', "Verifying details for pool, {}".format(pool_name))

            #pool_data = self.data['nat_pool'][_cfg_map['nat_pool']]
            pool_data = self.data['nat_pool'][pool_name]
            #_pool_sess_cnt = self.tg_sess_cnt['nat_pool'][pool_name]['tot_sess']
            #sset = self.pool_map[pool_name]['sset']
            #spic = self.pool_map[pool_name]['spic']
            _pool_sess_cnt = self.pool_map[pool_name]['total_sess']
            exp_data = {
                'ri_name': 'default',
                'host_addr_base': '0.0.0.0', 'single_ports_in_use': _pool_sess_cnt,
                'tot_single_ports_in_use': _pool_sess_cnt, 'twin_ports_in_use':0,
                'ports_range': '[1024, 63487]', 'port_overloading_factor':1,
                'addr_assignment':'no-paired', 'twin_port_range': '[63488, 65535]'
            }
            #iputils.get_subnet_total_address is not defined: verify later if this block is necessary
            #if 'addr' in self.nat_pool[pool_name]:
            #    pool_addr = self.nat_pool[pool_name]['addr']
            #    addr_range = iputils.get_network_ip_range(pool_addr)
            #    exp_data['addr_range_low'], exp_data['addr_range_high'] = addr_range.split('-')
            #    exp_data['total_addr'] = iputils.get_subnet_total_address(pool_addr)
            if pool_name in self.pool_map:
                exp_data['spic'] = self.pool_map[pool_name]['spic']
                exp_data['sset'] = self.pool_map[pool_name]['sset']

            for key in kwargs:
                if 'tg_sess' in key:
                    continue
                exp_data[key] = kwargs[key]

            self.log('INFO', "Verifying expected({}) and actual({}) data".format(exp_data,
                                                                                 pool_data))
            if utils.cmp_dicts(exp_data, pool_data):
                self.log('INFO', "Verification details for pool, {}, PASSED".format(pool_name))
            else:
                self.log('INFO', "Verification for pool, {}, FAILED".format(pool_name))
                result = False

        return self.fn_checkout(result)