コード例 #1
0
ファイル: test_utils.py プロジェクト: warmwm/yardstick-ha
    def test_(self, mock_open):
        mock_open.side_effect = IOError

        with self.assertRaises(IOError):
            utils.find_relative_file('my/path', 'task/path')

        self.assertEqual(mock_open.call_count, 2)
コード例 #2
0
 def _start_vnf(self):
     yang_model_path = utils.find_relative_file(
         self.scenario_helper.options['rules'],
         self.scenario_helper.task_path)
     yang_model = YangModel(yang_model_path)
     self.vfw_rules = yang_model.get_rules()
     super(FWApproxVnf, self)._start_vnf()
コード例 #3
0
    def build_config(self):
        vnf_cfg = self.scenario_helper.vnf_cfg
        task_path = self.scenario_helper.task_path

        config_file = vnf_cfg.get('file')
        lb_count = vnf_cfg.get('lb_count', 3)
        lb_config = vnf_cfg.get('lb_config', 'SW')
        worker_config = vnf_cfg.get('worker_config', '1C/1T')
        worker_threads = vnf_cfg.get('worker_threads', 3)

        traffic_type = self.scenario_helper.all_options.get('traffic_type', 4)
        traffic_options = {
            'traffic_type': traffic_type,
            'pkt_type': 'ipv%s' % traffic_type,
            'vnf_type': self.VNF_TYPE,
        }

        # read actions/rules from file
        acl_options = None
        acl_file_name = self.scenario_helper.options.get('rules')
        if acl_file_name:
            with utils.open_relative_file(acl_file_name, task_path) as infile:
                acl_options = yaml_loader.yaml_load(infile)

        config_tpl_cfg = utils.find_relative_file(self.DEFAULT_CONFIG_TPL_CFG,
                                                  task_path)
        config_basename = posixpath.basename(self.CFG_CONFIG)
        script_basename = posixpath.basename(self.CFG_SCRIPT)
        multiport = MultiPortConfig(self.scenario_helper.topology,
                                    config_tpl_cfg, config_basename,
                                    self.vnfd_helper, self.VNF_TYPE, lb_count,
                                    worker_threads, worker_config, lb_config,
                                    self.socket)

        multiport.generate_config()
        if config_file:
            with utils.open_relative_file(config_file, task_path) as infile:
                new_config = ['[EAL]']
                vpci = []
                for port in self.vnfd_helper.port_pairs.all_ports:
                    interface = self.vnfd_helper.find_interface(name=port)
                    vpci.append(interface['virtual-interface']["vpci"])
                new_config.extend('w = {0}'.format(item) for item in vpci)
                new_config = '\n'.join(new_config) + '\n' + infile.read()
        else:
            with open(self.CFG_CONFIG) as handle:
                new_config = handle.read()
            new_config = self._update_traffic_type(new_config, traffic_options)
            new_config = self._update_packet_type(new_config, traffic_options)
        self.ssh_helper.upload_config_file(config_basename, new_config)
        self.ssh_helper.upload_config_file(
            script_basename,
            multiport.generate_script(self.vnfd_helper,
                                      self.get_flows_config(acl_options)))

        LOG.info("Provision and start the %s", self.APP_NAME)
        self._build_pipeline_kwargs()
        return self.PIPELINE_COMMAND.format(**self.pipeline_kwargs)
コード例 #4
0
    def setup(self):
        # NOTE: fixup scenario_helper to hanlde ixia
        self.resource_file_name = \
            utils.find_relative_file(
                self.scenario_helper.scenario_cfg['ixia_profile'],
                self.scenario_helper.scenario_cfg["task_path"])
        utils.makedirs(self.RESULTS_MOUNT)
        cmd = MOUNT_CMD.format(self.vnfd_helper.mgmt_interface, self)
        LOG.debug(cmd)

        if not os.path.ismount(self.RESULTS_MOUNT):
            call(cmd, shell=True)

        shutil.rmtree(self.RESULTS_MOUNT, ignore_errors=True)
        utils.makedirs(self.RESULTS_MOUNT)
        shutil.copy(self.resource_file_name, self.RESULTS_MOUNT)
コード例 #5
0
    def run_traffic(self, traffic_profile):
        if self._terminated.value:
            return

        min_tol = self.rfc_helper.tolerance_low
        max_tol = self.rfc_helper.tolerance_high
        default = "00:00:00:00:00:00"

        self._build_ports()

        # we don't know client_file_name until runtime as instantiate
        client_file_name = \
            utils.find_relative_file(
                self.scenario_helper.scenario_cfg['ixia_profile'],
                self.scenario_helper.scenario_cfg["task_path"])
        self.client.ix_load_config(client_file_name)
        time.sleep(WAIT_AFTER_CFG_LOAD)

        self.client.ix_assign_ports()

        mac = {}
        for port_name in self.vnfd_helper.port_pairs.all_ports:
            intf = self.vnfd_helper.find_interface(name=port_name)
            virt_intf = intf["virtual-interface"]
            # we only know static traffic id by reading the json
            # this is used by _get_ixia_trafficrofile
            port_num = self.vnfd_helper.port_num(intf)
            mac["src_mac_{}".format(port_num)] = virt_intf.get(
                "local_mac", default)
            mac["dst_mac_{}".format(port_num)] = virt_intf.get(
                "dst_mac", default)

        samples = {}
        # Generate ixia traffic config...
        try:
            while not self._terminated.value:
                traffic_profile.execute_traffic(self, self.client, mac)
                self.client_started.value = 1
                time.sleep(WAIT_FOR_TRAFFIC)
                self.client.ix_stop_traffic()
                samples = self.generate_samples(traffic_profile.ports)
                self._queue.put(samples)
                status, samples = traffic_profile.get_drop_percentage(
                    samples, min_tol, max_tol, self.client, mac)

                current = samples['CurrentDropPercentage']
                if min_tol <= current <= max_tol or status == 'Completed':
                    self._terminated.value = 1

            self.client.ix_stop_traffic()
            self._queue.put(samples)

            if not self.rfc_helper.is_done():
                self._terminated.value = 1
                return

            traffic_profile.execute_traffic(self, self.client, mac)
            for _ in range(5):
                time.sleep(self.LATENCY_TIME_SLEEP)
                self.client.ix_stop_traffic()
                samples = self.generate_samples(traffic_profile.ports,
                                                'latency', {})
                self._queue.put(samples)
                traffic_profile.start_ixia_latency(self, self.client, mac)
                if self._terminated.value:
                    break

            self.client.ix_stop_traffic()
        except Exception:  # pylint: disable=broad-except
            LOG.exception("Run Traffic terminated")

        self._terminated.value = 1