コード例 #1
0
    def test_default_id_assignment(self):
        default_ids_agenda = yaml.load(default_ids_agenda_text)

        self.parser.load(self.config, default_ids_agenda, 'test2')
        workload_entries = self.config.jobs_config.root_node.workload_entries
        assert_equal(workload_entries[0].id, 'wk2')
        assert_equal(workload_entries[3].id, 'wk3')
コード例 #2
0
    def test_defaults(self):
        short_agenda = yaml.load(short_agenda_text)
        self.parser.load(self.config, short_agenda, 'test')

        workload_entries = self.config.jobs_config.root_node.workload_entries
        assert_equal(len(workload_entries), 3)
        assert_equal(workload_entries[0].config['workload_name'], 'antutu')
        assert_equal(workload_entries[0].id, 'wk1')
コード例 #3
0
    def test_yaml_missing_field(self):
        invalid_agenda = yaml.load(invalid_agenda_text)

        try:
            self.parser.load(self.config, invalid_agenda, 'test')
        except ConfigError as e:
            assert_in('workload name', e.message)
        else:
            raise Exception('ConfigError was not raised for an invalid agenda.')
コード例 #4
0
    def test_duplicate_id(self):
        duplicate_agenda = yaml.load(duplicate_agenda_text)

        try:
            self.parser.load(self.config, duplicate_agenda, 'test')
        except ConfigError as e:
            assert_in('duplicate', e.message.lower())  # pylint: disable=E1101
        else:
            raise Exception('ConfigError was not raised for an agenda with duplicate ids.')
コード例 #5
0
ファイル: create.py プロジェクト: lisatn/workload-automation
    def execute(self, state, args):  # pylint: disable=too-many-branches
        if not psycopg2:
            raise CommandError('The module psycopg2 is required for the wa ' +
                               'create database command.')
        self.get_schema(self.schemafilepath)

        # Display the version if needed and exit
        if args.schema_version:
            self.logger.info('The current schema version is {}'.format(
                self.schemaversion))
            return

        if args.dbname == 'postgres':
            raise ValueError('Databasename to create cannot be postgres.')

        # Open user configuration
        with open(args.config_file, 'r') as config_file:
            config = yaml.load(config_file)
            if 'postgres' in config and not args.force_update_config:
                raise CommandError(
                    "The entry 'postgres' already exists in the config file. "
                    + "Please specify the -F flag to force an update.")

        possible_connection_errors = [
            (re.compile('FATAL:  role ".*" does not exist'),
             'Username does not exist or password is incorrect'),
            (re.compile('FATAL:  password authentication failed for user'),
             'Password was incorrect'),
            (re.compile('fe_sendauth: no password supplied'),
             'Passwordless connection is not enabled. '
             'Please enable trust in pg_hba for this host '
             'or use a password'),
            (re.compile('FATAL:  no pg_hba.conf entry for'),
             'Host is not allowed to connect to the specified database '
             'using this user according to pg_hba.conf. Please change the '
             'rules in pg_hba or your connection method'),
            (re.compile('FATAL:  pg_hba.conf rejects connection'),
             'Connection was rejected by pg_hba.conf'),
        ]

        def predicate(error, handle):
            if handle[0].match(str(error)):
                raise CommandError(handle[1] + ': \n' + str(error))

        # Attempt to create database
        try:
            self.create_database(args)
        except OperationalError as e:
            for handle in possible_connection_errors:
                predicate(e, handle)
            raise e

        # Update the configuration file
        _update_configuration_file(args, config)
コード例 #6
0
ファイル: misc.py プロジェクト: bea-arm/lisa
def load_struct_from_yaml(filepath=None, text=None):
    """Parses a config structure from a .yaml file. The structure should be composed
    of basic Python types (strings, ints, lists, dicts, etc.)."""

    # Import here to avoid circular imports
    # pylint: disable=wrong-import-position,cyclic-import
    from wa.utils.serializer import yaml

    if not (filepath or text) or (filepath and text):
        raise ValueError('Exactly one of filepath or text must be specified.')
    try:
        if filepath:
            with open(filepath) as fh:
                return yaml.load(fh)
        else:
            return yaml.load(text)
    except yaml.YAMLError as e:
        lineno = None
        if hasattr(e, 'problem_mark'):
            lineno = e.problem_mark.line  # pylint: disable=no-member
        raise LoadSyntaxError(e.message, filepath=filepath, lineno=lineno)
コード例 #7
0
    def test_yaml_anchors(self):
        yaml_anchors_agenda = yaml.load(yaml_anchors_agenda_text)
        self.parser.load(self.config, yaml_anchors_agenda, 'test')

        workload_entries = self.config.jobs_config.root_node.workload_entries
        assert_equal(len(workload_entries), 2)
        assert_equal(workload_entries[0].config['workload_name'], 'dhrystone')
        assert_equal(workload_entries[0].config['workload_parameters']['threads'], 1)
        assert_equal(workload_entries[0].config['workload_parameters']['delay'], 3)
        assert_equal(workload_entries[1].config['workload_name'], 'dhrystone')
        assert_equal(workload_entries[1].config['workload_parameters']['threads'], 4)
        assert_equal(workload_entries[1].config['workload_parameters']['delay'], 3)
コード例 #8
0
    def test_sections(self):
        sectioned_agenda = yaml.load(sectioned_agenda_text)
        self.parser.load(self.config, sectioned_agenda, 'test')

        root_node_workload_entries = self.config.jobs_config.root_node.workload_entries
        leaves = list(self.config.jobs_config.root_node.leaves())
        section1_workload_entries = leaves[0].workload_entries
        section2_workload_entries = leaves[0].workload_entries

        assert_equal(root_node_workload_entries[0].config['workload_name'], 'memcpy')
        assert_true(section1_workload_entries[0].config['workload_parameters']['markers_enabled'])
        assert_equal(section2_workload_entries[0].config['workload_name'], 'antutu')
コード例 #9
0
    def update_output(self, context):
        with open(self.host_file_results, 'r') as stress_ng_results:
            results = yaml.load(stress_ng_results)

        try:
            metric = results['metrics'][0]['stressor']
            throughput = results['metrics'][0]['bogo-ops']
            context.add_metric(metric, throughput, 'ops')
        # For some stressors like vm, if test duration is too short, stress_ng
        # may not able to produce test throughput rate.
        except TypeError:
            msg = '{} test throughput rate not found. Please increase test duration and retry.'
            self.logger.warning(msg.format(self.stressor))
コード例 #10
0
ファイル: create.py プロジェクト: lisatn/workload-automation
    def execute(self, state, args):  # pylint: disable=too-many-branches
        if not psycopg2:
            raise CommandError(
                'The module psycopg2 is required for the wa ' +
                'create database command.')
        self.get_schema(self.schemafilepath)

        # Display the version if needed and exit
        if args.schema_version:
            self.logger.info(
                'The current schema version is {}'.format(self.schemaversion))
            return

        if args.dbname == 'postgres':
            raise ValueError('Databasename to create cannot be postgres.')

        # Open user configuration
        with open(args.config_file, 'r') as config_file:
            config = yaml.load(config_file)
            if 'postgres' in config and not args.force_update_config:
                raise CommandError(
                    "The entry 'postgres' already exists in the config file. " +
                    "Please specify the -F flag to force an update.")

        possible_connection_errors = [
            (
                re.compile('FATAL:  role ".*" does not exist'),
                'Username does not exist or password is incorrect'
            ),
            (
                re.compile('FATAL:  password authentication failed for user'),
                'Password was incorrect'
            ),
            (
                re.compile('fe_sendauth: no password supplied'),
                'Passwordless connection is not enabled. '
                'Please enable trust in pg_hba for this host '
                'or use a password'
            ),
            (
                re.compile('FATAL:  no pg_hba.conf entry for'),
                'Host is not allowed to connect to the specified database '
                'using this user according to pg_hba.conf. Please change the '
                'rules in pg_hba or your connection method'
            ),
            (
                re.compile('FATAL:  pg_hba.conf rejects connection'),
                'Connection was rejected by pg_hba.conf'
            ),
        ]

        def predicate(error, handle):
            if handle[0].match(str(error)):
                raise CommandError(handle[1] + ': \n' + str(error))

        # Attempt to create database
        try:
            self.create_database(args)
        except OperationalError as e:
            for handle in possible_connection_errors:
                predicate(e, handle)
            raise e

        # Update the configuration file
        _update_configuration_file(args, config)
コード例 #11
0
 def test_dup_sections(self):
     dup_sectioned_agenda = yaml.load(dup_sectioned_agenda_text)
     self.parser.load(self.config, dup_sectioned_agenda, 'test')