Ejemplo n.º 1
0
    def __init__(self, test_cfg):
        """Pull out fields from test config

        :param test_cfg: A dictionary of string-value pairs describing the test
            configuration. Both the key and values strings use well-known
            values.
        :param results_dir: Where the csv formatted results are written.
        """
        # make a local copy of test configuration to avoid modification of
        # original content used in vsperf main script
        cfg = copy.deepcopy(test_cfg)

        self._testcase_start_time = time.time()
        self._testcase_stop_time = self._testcase_start_time
        self._hugepages_mounted = False
        self._traffic_ctl = None
        self._vnf_ctl = None
        self._pod_ctl = None
        self._vswitch_ctl = None
        self._collector = None
        self._loadgen = None
        self._output_file = None
        self._tc_results = None
        self._settings_paths_modified = False
        self._testcast_run_time = None
        self._versions = []
        self._k8s = False
        # initialization of step driven specific members
        self._step_check = False  # by default don't check result for step driven testcases
        self._step_vnf_list = {}
        self._step_result = []
        self._step_result_mapping = {}
        self._step_status = None
        self._step_send_traffic = False  # indication if send_traffic was called within test steps
        self._vnf_list = []
        self._testcase_run_time = None

        S.setValue('VSWITCH', cfg.get('vSwitch', S.getValue('VSWITCH')))
        S.setValue('VNF', cfg.get('VNF', S.getValue('VNF')))
        S.setValue('TRAFFICGEN', cfg.get('Trafficgen',
                                         S.getValue('TRAFFICGEN')))
        S.setValue('TUNNEL_TYPE',
                   cfg.get('Tunnel Type', S.getValue('TUNNEL_TYPE')))
        test_params = copy.deepcopy(S.getValue('TEST_PARAMS'))
        tc_test_params = cfg.get('Parameters', S.getValue('TEST_PARAMS'))
        test_params = merge_spec(test_params, tc_test_params)

        # ensure that parameters from TC definition have the highest priority, see MAPPING_TC_CFG2CONF
        for (cfg_param, param) in MAPPING_TC_CFG2CONF.items():
            if cfg_param in cfg and param in test_params:
                del test_params[param]

        S.setValue('TEST_PARAMS', test_params)
        S.check_test_params()

        # override all redefined GUEST_ values to have them expanded correctly
        tmp_test_params = copy.deepcopy(S.getValue('TEST_PARAMS'))
        for key in tmp_test_params:
            if key.startswith('GUEST_'):
                S.setValue(key, S.getValue(key))
                S.getValue('TEST_PARAMS').pop(key)

        # update global settings
        functions.settings_update_paths()

        # set test parameters; CLI options take precedence to testcase settings
        self._logger = logging.getLogger(__name__)
        self.name = cfg['Name']
        self.desc = cfg.get('Description', 'No description given.')
        self.test = cfg.get('TestSteps', None)

        # log testcase name and details
        tmp_desc = functions.format_description(self.desc, 50)
        self._logger.info(
            '############################################################')
        self._logger.info('# Test:    %s', self.name)
        self._logger.info('# Details: %s', tmp_desc[0])
        for i in range(1, len(tmp_desc)):
            self._logger.info('#          %s', tmp_desc[i])
        self._logger.info(
            '############################################################')

        bidirectional = S.getValue('TRAFFIC')['bidir']
        if not isinstance(S.getValue('TRAFFIC')['bidir'], str):
            raise TypeError('Bi-dir value must be of type string')
        bidirectional = bidirectional.title()  # Keep things consistent

        self.deployment = cfg['Deployment']
        self._frame_mod = cfg.get('Frame Modification', None)

        self._tunnel_operation = cfg.get('Tunnel Operation', None)

        # check if test requires background load and which generator it uses
        self._load_cfg = cfg.get('Load', None)

        if self._frame_mod:
            self._frame_mod = self._frame_mod.lower()
        self._results_dir = S.getValue('RESULTS_PATH')

        # set traffic details, so they can be passed to vswitch and traffic ctls
        self._traffic = copy.deepcopy(S.getValue('TRAFFIC'))
        self._traffic.update({'bidir': bidirectional})

        # Packet Forwarding mode
        self._vswitch_none = str(
            S.getValue('VSWITCH')).strip().lower() == 'none'

        # trafficgen configuration required for tests of tunneling protocols
        if self._tunnel_operation:
            self._traffic.update({'tunnel_type': S.getValue('TUNNEL_TYPE')})
            self._traffic['l2'].update({
                'srcmac':
                S.getValue('TRAFFICGEN_PORT1_MAC'),
                'dstmac':
                S.getValue('TRAFFICGEN_PORT2_MAC')
            })

            self._traffic['l3'].update({
                'srcip':
                S.getValue('TRAFFICGEN_PORT1_IP'),
                'dstip':
                S.getValue('TRAFFICGEN_PORT2_IP')
            })

            if self._tunnel_operation == "decapsulation":
                self._traffic['l2'].update(
                    S.getValue(
                        S.getValue('TUNNEL_TYPE').upper() + '_FRAME_L2'))
                self._traffic['l3'].update(
                    S.getValue(
                        S.getValue('TUNNEL_TYPE').upper() + '_FRAME_L3'))
                self._traffic['l4'].update(
                    S.getValue(
                        S.getValue('TUNNEL_TYPE').upper() + '_FRAME_L4'))
                self._traffic['l2']['dstmac'] = S.getValue('NICS')[1]['mac']
        elif len(S.getValue('NICS')) >= 2 and \
             (S.getValue('NICS')[0]['type'] == 'vf' or
              S.getValue('NICS')[1]['type'] == 'vf'):
            mac1 = S.getValue('NICS')[0]['mac']
            mac2 = S.getValue('NICS')[1]['mac']
            if mac1 and mac2:
                self._traffic['l2'].update({'srcmac': mac2, 'dstmac': mac1})
            else:
                self._logger.debug("MAC addresses can not be read")

        self._traffic = functions.check_traffic(self._traffic)

        # count how many VNFs are involved in TestSteps
        if self.test:
            for step in self.test:
                if step[0].startswith('vnf'):
                    self._step_vnf_list[step[0]] = None

        # if llc allocation is required, initialize it.
        if S.getValue('LLC_ALLOCATION'):
            self._rmd = rmd.CacheAllocator()
Ejemplo n.º 2
0
    def __init__(self, test_cfg):
        """Pull out fields from test config

        :param test_cfg: A dictionary of string-value pairs describing the test
            configuration. Both the key and values strings use well-known
            values.
        :param results_dir: Where the csv formatted results are written.
        """
        # make a local copy of test configuration to avoid modification of
        # original content used in vsperf main script
        cfg = copy.deepcopy(test_cfg)

        self._testcase_start_time = time.time()
        self._hugepages_mounted = False
        self._traffic_ctl = None
        self._vnf_ctl = None
        self._vswitch_ctl = None
        self._collector = None
        self._loadgen = None
        self._output_file = None
        self._tc_results = None
        self._settings_original = {}
        self._settings_paths_modified = False
        self._testcast_run_time = None
        self._versions = []
        # initialization of step driven specific members
        self._step_check = False  # by default don't check result for step driven testcases
        self._step_vnf_list = {}
        self._step_result = []
        self._step_status = None
        self._testcase_run_time = None

        # store all GUEST_ specific settings to keep original values before their expansion
        for key in S.__dict__:
            if key.startswith('GUEST_'):
                self._settings_original[key] = S.getValue(key)

        self._update_settings('VSWITCH',
                              cfg.get('vSwitch', S.getValue('VSWITCH')))
        self._update_settings('VNF', cfg.get('VNF', S.getValue('VNF')))
        self._update_settings('TRAFFICGEN',
                              cfg.get('Trafficgen', S.getValue('TRAFFICGEN')))
        test_params = copy.deepcopy(S.getValue('TEST_PARAMS'))
        tc_test_params = cfg.get('Parameters', S.getValue('TEST_PARAMS'))
        test_params = merge_spec(test_params, tc_test_params)
        self._update_settings('TEST_PARAMS', test_params)
        S.check_test_params()

        # override all redefined GUEST_ values to have them expanded correctly
        tmp_test_params = copy.deepcopy(S.getValue('TEST_PARAMS'))
        for key in tmp_test_params:
            if key.startswith('GUEST_'):
                S.setValue(key, S.getValue(key))
                S.getValue('TEST_PARAMS').pop(key)

        # update global settings
        functions.settings_update_paths()

        # set test parameters; CLI options take precedence to testcase settings
        self._logger = logging.getLogger(__name__)
        self.name = cfg['Name']
        self.desc = cfg.get('Description', 'No description given.')
        self.test = cfg.get('TestSteps', None)

        bidirectional = S.getValue('TRAFFIC')['bidir']
        if not isinstance(S.getValue('TRAFFIC')['bidir'], str):
            raise TypeError('Bi-dir value must be of type string')
        bidirectional = bidirectional.title()  # Keep things consistent

        self.deployment = cfg['Deployment']
        self._frame_mod = cfg.get('Frame Modification', None)

        self._tunnel_type = None
        self._tunnel_operation = None

        if self.deployment == 'op2p':
            self._tunnel_operation = cfg['Tunnel Operation']

            if 'Tunnel Type' in cfg:
                self._tunnel_type = cfg['Tunnel Type']
                self._tunnel_type = get_test_param('TUNNEL_TYPE',
                                                   self._tunnel_type)

        # check if test requires background load and which generator it uses
        self._load_cfg = cfg.get('Load', None)
        if self._load_cfg and 'tool' in self._load_cfg:
            self._loadgen = self._load_cfg['tool']
        else:
            # background load is not requested, so use dummy implementation
            self._loadgen = "Dummy"

        if self._frame_mod:
            self._frame_mod = self._frame_mod.lower()
        self._results_dir = S.getValue('RESULTS_PATH')

        # set traffic details, so they can be passed to vswitch and traffic ctls
        self._traffic = copy.deepcopy(S.getValue('TRAFFIC'))
        self._traffic.update({
            'bidir': bidirectional,
            'tunnel_type': self._tunnel_type,
        })

        self._traffic = functions.check_traffic(self._traffic)

        # Packet Forwarding mode
        self._vswitch_none = str(
            S.getValue('VSWITCH')).strip().lower() == 'none'

        # trafficgen configuration required for tests of tunneling protocols
        if self.deployment == "op2p":
            self._traffic['l2'].update({
                'srcmac':
                S.getValue('TRAFFICGEN_PORT1_MAC'),
                'dstmac':
                S.getValue('TRAFFICGEN_PORT2_MAC')
            })

            self._traffic['l3'].update({
                'srcip':
                S.getValue('TRAFFICGEN_PORT1_IP'),
                'dstip':
                S.getValue('TRAFFICGEN_PORT2_IP')
            })

            if self._tunnel_operation == "decapsulation":
                self._traffic['l2'] = S.getValue(self._tunnel_type.upper() +
                                                 '_FRAME_L2')
                self._traffic['l3'] = S.getValue(self._tunnel_type.upper() +
                                                 '_FRAME_L3')
                self._traffic['l4'] = S.getValue(self._tunnel_type.upper() +
                                                 '_FRAME_L4')
        elif len(S.getValue('NICS')) and \
             (S.getValue('NICS')[0]['type'] == 'vf' or
              S.getValue('NICS')[1]['type'] == 'vf'):
            mac1 = S.getValue('NICS')[0]['mac']
            mac2 = S.getValue('NICS')[1]['mac']
            if mac1 and mac2:
                self._traffic['l2'].update({'srcmac': mac2, 'dstmac': mac1})
            else:
                self._logger.debug("MAC addresses can not be read")

        # count how many VNFs are involved in TestSteps
        if self.test:
            for step in self.test:
                if step[0].startswith('vnf'):
                    self._step_vnf_list[step[0]] = None