Ejemplo n.º 1
0
 def test_source_openrc(self, mock_hierarchy, mock_setitem):
     mock_hierarchy.side_effect = [
         'username', 'password', 'project_name', 'external_network'
     ]
     Utils.source_openrc(None)
     self.assertEqual(mock_hierarchy.call_count, 4)
     self.assertEqual(mock_setitem.call_count, 4)
Ejemplo n.º 2
0
    def test_load_class_attribute_error(self):
        class Stateless():
            pass

        mock_module = mock.MagicMock(spec=Stateless)
        with mock.patch.dict('sys.modules', test_module=mock_module):
            with self.assertRaises(AttributeError):
                Utils.load_class('test_module.test_classname')
Ejemplo n.º 3
0
    def test_load_class_import_error(self):
        def throw(*args, **kwargs):
            # pylint: disable=unused-argument
            # These arguments are used by the call to __import__
            raise ImportError()

        with mock.patch('builtins.__import__', side_effect=throw):
            with self.assertRaises(ImportError):
                Utils.load_class('test.class.please.ignore')
Ejemplo n.º 4
0
    def create_image(self):
        # this has to run as root, in the container root is the default user
        LOG.info('Creating Yardstick image..')

        os.environ['YARD_IMG_ARCH'] = 'amd64'
        Utils.source_openrc(self)

        yrdstick_path = os.path.join(CONF.DEFAULT.files_dir,
                                     "frameworks/yardstick/")
        image_modify = yrdstick_path + 'tools/yardstick-img-modify'
        cloud_modify = yrdstick_path + 'tools/ubuntu-server-cloudimg-modify.sh'

        script_path = image_modify + " " + cloud_modify

        self._exec_cmd('apt update && ' + script_path)
Ejemplo n.º 5
0
def loader(name, framework, environment, options):
    # alter the name to correctly find the class e.g. go from shaker to Shaker
    class_name = name.title()
    cls = Utils.load_class('harbinger.executors.' + name + '.' + class_name +
                           'Executor')
    framework_executor = cls(framework, environment, options)
    framework_executor.setup()
Ejemplo n.º 6
0
    def create_cfg_file(self):
        if hasattr(self.framework, 'extras'):
            self.add_extras_options()

        username = Utils.hierarchy_lookup(self, 'username')
        password = Utils.hierarchy_lookup(self, 'password')
        project_name = Utils.hierarchy_lookup(self, 'project')
        flavor_name = Utils.hierarchy_lookup(self, 'flavor_name')
        image_name = Utils.hierarchy_lookup(self, 'image')
        output = self.results_json_path
        scenario = self.collect_scenario_tests()
        server_endpoint = Utils.hierarchy_lookup(self, 'server_endpoint')
        external_net = Utils.hierarchy_lookup(self, 'external_network')

        self.config.set("DEFAULT", "os_username", username)
        self.config.set("DEFAULT", "os_password", password)
        self.config.set("DEFAULT", "os_project_name", project_name)
        self.config.set("DEFAULT", "flavor_name", flavor_name)
        self.config.set("DEFAULT", "image_name", image_name)
        self.config.set("DEFAULT", "output", output)
        self.config.set("DEFAULT", "scenario", scenario)
        self.config.set("DEFAULT", "server_endpoint", server_endpoint)
        self.config.set("DEFAULT", "external_net", external_net)

        with open(self.cfg_full_path, 'wb') as configfile:
            self.config.write(configfile)
Ejemplo n.º 7
0
 def test_hierarchy_lookup_groupattr(self, mock_executor, mock_conf):
     mock_executor.options = mock.MagicMock(spec=dict)
     mock_executor.options.get = mock.MagicMock(
         return_value='test low priority')
     mock_executor.framework.required = mock.MagicMock(spec=dict)
     mock_executor.framework.required.get = mock.MagicMock(
         return_value='test high priority')
     self.assertEqual(Utils.hierarchy_lookup(mock_executor, 'test_key'),
                      'test high priority')
     self.assertEqual(mock_conf.call_count, 0)
Ejemplo n.º 8
0
    def setup(self):
        super(ShakerExecutor, self).setup()

        image_name = Utils.hierarchy_lookup(self, 'image')
        image_exists = self.image.check_image(image_name)

        if image_exists is False:
            self.create_image()
            self.image.upload_image(image_name, 'qcow2', 'bare')

        self.create_cfg_file()
        self._exec_cmd("shaker --config-file " + self.cfg_full_path)
Ejemplo n.º 9
0
    def create_yardstick_conf(self):
        with open(self.conf_full_path, "wb") as configfile:
            if hasattr(self.framework, 'extras'):
                self.add_extras_options()

            debug = Utils.hierarchy_lookup(self, "debug")
            dispatcher = Utils.hierarchy_lookup(self, "dispatcher")
            dispatch_file = Utils.hierarchy_lookup(self,
                                                   "dispatcher_file_name")
            dispatch_file = os.path.join(self.outputs_dir, dispatch_file)

            self.config.set("DEFAULT", "debug", debug)
            self.config.set("DEFAULT", "dispatcher", dispatcher)

            self.config.add_section("dispatcher_file")
            self.config.set("dispatcher_file", "file_name", dispatch_file)

            self.config.set("DEFAULT", "debug",
                            Utils.hierarchy_lookup(self, "debug"))

            self.config.write(configfile)
Ejemplo n.º 10
0
    def setup(self):
        super(YardstickExecutor, self).setup()

        # check flavor
        flavor_name = Utils.hierarchy_lookup(self, 'flavor_name')
        flavor_exists = self.flavor.check_flavor(flavor_name)
        if flavor_exists is False:
            self.flavor.create_flavor(name=flavor_name,
                                      ram='512',
                                      vcpus='1',
                                      disk='3',
                                      swap='100')

        # check image
        image_name = Utils.hierarchy_lookup(self, 'image')
        image_exists = self.image.check_image(image_name)

        if image_exists is False:
            self.create_image()
            temp_dir = tempfile.gettempdir()
            self.image.upload_image(image_name, 'qcow2', 'bare',
                                    temp_dir + '/workspace/yardstick/')

        self.create_yardstick_conf()

        self.create_test_suite(self.formated_tests)

        # set additional environment variables necessary for openstack api
        Utils.source_openrc(self)

        run_command = "yardstick --config-file " + str(self.conf_full_path)
        run_command += " task start"
        run_command += " --output-file " + str(self.outputs_full_path)
        run_command += " --suite " + \
                       str(os.path.join(self.inputs_dir,
                                        self.test_suite_name))

        self._exec_cmd(run_command)
Ejemplo n.º 11
0
    def create_test_suite(self, test_list):
        test_suite_yaml = collections.OrderedDict()
        test_suite_yaml["schema"] = Utils.hierarchy_lookup(self, 'schema')
        test_suite_yaml["name"] = self.test_suite_name

        # Check if test_cases_dir is necessary

        if not any(self.test_paths[:-1] in test["file_name"]
                   for test in test_list):
            test_suite_yaml["test_cases_dir"] = self.test_paths
        else:
            test_suite_yaml["test_cases_dir"] = '/'

        test_suite_yaml["test_cases"] = test_list

        file_contents = yaml.dump(test_suite_yaml, default_flow_style=False)

        with open(os.path.join(self.inputs_dir, self.test_suite_name),
                  'w') as yaml_file:
            yaml_file.write(file_contents)
Ejemplo n.º 12
0
    def __init__(self, framework, environment, options):
        self.inputs_dir = os.path.join(CONF.DEFAULT.files_dir, "inputs")
        self.outputs_dir = os.path.join(CONF.DEFAULT.files_dir, "outputs")
        self.framework = framework
        self.environment = environment
        self.options = options
        self.relative_path = os.path.join(
            CONF.DEFAULT.files_dir, "frameworks", self.framework.name,
            Utils.hierarchy_lookup(self, "test_paths"))

        auth_url = self.environment.OS_AUTH_URL + \
            self.environment.OS_API_VERSION

        client_label = self.framework.name

        openstack_creds = {
            'auth_url':
            auth_url,
            'user_id':
            getattr(self.options, 'user_id', None),
            'username':
            getattr(self.options, 'username', None),
            'password':
            getattr(self.options, 'password', None),
            'user_domain_id':
            getattr(self.options, 'user_domain_id', None),
            'user_domain_name':
            getattr(self.options, 'user_domain_name', None),
            'project_id':
            getattr(self.options, 'project_id', None),
            'project_name':
            getattr(self.options, 'project_name', None),
            'project_domain_id':
            getattr(self.options, 'project_domain_id', None),
            'project_domain_name':
            getattr(self.options, 'project_domain_name', None)
        }

        self.image = ImageManager(client_label, **openstack_creds)
        self.flavor = FlavorManager(client_label, **openstack_creds)
Ejemplo n.º 13
0
 def test_hierarchy_lookup_priorty(self, mock_executor, mock_conf):
     mock_executor.options = mock.MagicMock(spec=cfg.ConfigOpts.GroupAttr)
     mock_executor.options.test_attr = 'test_val'
     self.assertEqual(Utils.hierarchy_lookup(mock_executor, 'test_attr'),
                      'test_val')
     self.assertEqual(mock_conf.call_count, 0)
Ejemplo n.º 14
0
 def test_load_class(self):
     mock_module = mock.MagicMock()
     mock_module.test_classname = "test_classname"
     with mock.patch.dict('sys.modules', test_module=mock_module):
         self.assertEqual('test_classname',
                          Utils.load_class('test_module.test_classname'))
Ejemplo n.º 15
0
 def test_get_supported_frameworks(self, mock_listdir, mock_dirname,
                                   mock_conf):
     self.assertEqual(['first', 'second'], Utils.get_supported_frameworks())
     self.assertEqual(mock_dirname.call_count, 2)
     self.assertEqual(mock_conf.call_count, 2)
     self.assertEqual(mock_listdir.call_count, 1)
Ejemplo n.º 16
0
 def test_get_supported_frameworks_nosuchopt(self, mock_listdir,
                                             mock_dirname):
     self.assertEqual([], Utils.get_supported_frameworks())
     self.assertEqual(mock_dirname.call_count, 2)
     self.assertEqual(mock_listdir.call_count, 1)
Ejemplo n.º 17
0
 def take_action(self, parsed_args):
     self.framework_tables = PrettyTable(["Frameworks"])
     self.supported_frameworks = Utils.get_supported_frameworks()
     self.log_frameworks(self.supported_frameworks)
Ejemplo n.º 18
0
 def test_hierarchy_lookup_dict(self, mock_executor, mock_conf):
     mock_executor.options = mock.MagicMock(spec=dict)
     mock_executor.options.get = mock.MagicMock(return_value='test_val')
     self.assertEqual(Utils.hierarchy_lookup(mock_executor, 'test_key'),
                      'test_val')
     self.assertEqual(mock_conf.call_count, 0)
Ejemplo n.º 19
0
 def create_image(self):
     Utils.source_openrc(self)
     self._exec_cmd("shaker-image-builder")
Ejemplo n.º 20
0
 def test_hierarchy_lookup_basefactory(self, mock_executor, mock_conf):
     mock_executor.options = mock.MagicMock(spec=BaseFactory)
     mock_executor.options.test_attr = 'test_val'
     self.assertEqual(Utils.hierarchy_lookup(mock_executor, 'test_attr'),
                      'test_val')
     self.assertEqual(mock_conf.call_count, 0)