Esempio n. 1
0
    def build_config(self):
        vnf_cfg = self.scenario_helper.vnf_cfg
        task_path = self.scenario_helper.task_path
        action_bulk_file = vnf_cfg.get('action_bulk_file',
                                       '/tmp/action_bulk_512.txt')
        full_tm_profile_file = vnf_cfg.get('full_tm_profile_file',
                                           '/tmp/full_tm_profile_10G.cfg')
        config_file = vnf_cfg.get('file', '/tmp/vpe_config')
        script_file = vnf_cfg.get('script_file', None)
        vpe_vars = {
            "bin_path": self.ssh_helper.bin_path,
            "socket": self.socket,
        }
        self._build_vnf_ports()
        vpe_conf = ConfigCreate(self.vnfd_helper, self.socket)

        if script_file is None:
            # autogenerate vpe_script if not given
            vpe_script = vpe_conf.generate_vpe_script(
                self.vnfd_helper.interfaces)
            script_file = self.CFG_SCRIPT
        else:
            with utils.open_relative_file(script_file, task_path) as handle:
                vpe_script = handle.read()

        config_basename = posixpath.basename(config_file)
        script_basename = posixpath.basename(script_file)

        with utils.open_relative_file(action_bulk_file, task_path) as handle:
            action_bulk = handle.read()

        with utils.open_relative_file(full_tm_profile_file,
                                      task_path) as handle:
            full_tm_profile = handle.read()

        with utils.open_relative_file(config_file, task_path) as handle:
            vpe_config = handle.read()

        # upload the 4 config files to the target server
        self.ssh_helper.upload_config_file(config_basename,
                                           vpe_config.format(**vpe_vars))
        self.ssh_helper.upload_config_file(script_basename,
                                           vpe_script.format(**vpe_vars))
        self.ssh_helper.upload_config_file(
            posixpath.basename(action_bulk_file),
            action_bulk.format(**vpe_vars))
        self.ssh_helper.upload_config_file(
            posixpath.basename(full_tm_profile_file),
            full_tm_profile.format(**vpe_vars))

        LOG.info("Provision and start the %s", self.APP_NAME)
        LOG.info(config_file)
        LOG.info(self.CFG_SCRIPT)
        self._build_pipeline_kwargs(cfg_file='/tmp/' + config_basename,
                                    script='/tmp/' + script_basename)
        return self.PIPELINE_COMMAND.format(**self.pipeline_kwargs)
Esempio n. 2
0
    def test_open_relative_path(self, mock_open):
        mock_open_result = mock_open()
        mock_open_call_count = 1  # initial call to get result

        self.assertEqual(utils.open_relative_file('foo', 'bar'),
                         mock_open_result)

        mock_open_call_count += 1  # one more call expected
        self.assertEqual(mock_open.call_count, mock_open_call_count)
        self.assertIn('foo', mock_open.call_args_list[-1][0][0])
        self.assertNotIn('bar', mock_open.call_args_list[-1][0][0])

        def open_effect(*args, **kwargs):
            if kwargs.get('name', args[0]) == os.path.join('bar', 'foo'):
                return mock_open_result
            raise IOError(errno.ENOENT, 'not found')

        mock_open.side_effect = open_effect
        self.assertEqual(utils.open_relative_file('foo', 'bar'),
                         mock_open_result)

        mock_open_call_count += 2  # two more calls expected
        self.assertEqual(mock_open.call_count, mock_open_call_count)
        self.assertIn('foo', mock_open.call_args_list[-1][0][0])
        self.assertIn('bar', mock_open.call_args_list[-1][0][0])

        # test an IOError of type ENOENT
        mock_open.side_effect = IOError(errno.ENOENT, 'not found')
        with self.assertRaises(IOError):
            # the second call still raises
            utils.open_relative_file('foo', 'bar')

        mock_open_call_count += 2  # two more calls expected
        self.assertEqual(mock_open.call_count, mock_open_call_count)
        self.assertIn('foo', mock_open.call_args_list[-1][0][0])
        self.assertIn('bar', mock_open.call_args_list[-1][0][0])

        # test an IOError other than ENOENT
        mock_open.side_effect = IOError(errno.EBUSY, 'busy')
        with self.assertRaises(IOError):
            utils.open_relative_file('foo', 'bar')

        mock_open_call_count += 1  # one more call expected
        self.assertEqual(mock_open.call_count, mock_open_call_count)