Example #1
0
def main(args):
    """Main function for the `run` command"""
    if not data.Base.is_dir_valid(args.db):
        raise Exception("\"{}\" is not a database directory".format(args.db))
    database = data.Base(args.db)
    if args.action == 'generate':
        if args.tree not in database.trees:
            raise Exception("Tree \"{}\" not found".format(args.tree))
        src_files = get_src_files(args.mboxes, args.pw_cookie)
        baserun = run.Base(database, src_files)
        content = baserun.generate(description=args.description,
                                   tree_name=args.tree,
                                   arch_name=args.arch,
                                   kernel_location=args.kernel,
                                   lint=not args.no_lint)
        if not args.output:
            sys.stdout.write(content)
        else:
            with open(args.output, 'w') as file_handler:
                file_handler.write(content)
    elif args.action == 'print-test-cases':
        src_files = get_src_files(args.patches, args.pw_cookie)
        case_name_list = sorted(
            [case.name for case in database.match_case_list(src_files)])
        for case_name in case_name_list:
            print(case_name)
    else:
        misc.raise_action_not_found(args.action, args.command)
Example #2
0
    def test_generate(self):
        """
        Check the success case, if it raises the proper exception when
        the type is not found and if it saves the output in a file instead
        printing it on stdout.
        """
        template_params = {
            'DESCRIPTION': 'Foo',
            'KURL': 'bar',
            'ARCH': 'baz',
        }
        dbdir = os.path.join(os.path.dirname(__file__), 'assets')
        database = data.Base(dbdir)
        template = utils.get_jinja_template('rhel7', dbdir)
        with mock.patch('sys.stdout') as mock_stdout:
            run.generate(template, template_params, [], database, None)
        with open(os.path.join(dbdir, 'rhel7_rendered.xml')) as file_handler:
            content_expected = file_handler.read()
        self.assertEqual(
            mock.call(content_expected),
            mock_stdout.write.call_args_list[0],
        )

        tmpfile = tempfile.mktemp()
        run.generate(template, template_params, [], database, tmpfile)
        with open(tmpfile) as tmp_handler:
            content = tmp_handler.read()
        self.assertEqual(
            content_expected,
            content,
        )
        os.remove(tmpfile)
Example #3
0
    def test_invalid_schema(self):
        """
        Check that Object raiser Invalid exception if the schema doesn't match.
        """
        with open(os.path.join(self.tmpdir, 'index.yaml'), 'w') as fhandle:
            fhandle.write('')

        with self.assertRaises(data.Invalid):
            data.Base(self.tmpdir)
Example #4
0
def main(args):
    """Main function for the `tree` command"""
    if not data.Base.is_dir_valid(args.db):
        raise Exception("\"{}\" is not a database directory".format(args.db))
    database = data.Base(args.db)
    if args.action == 'list':
        for tree in sorted(database.trees.keys()):
            print(tree)
    else:
        misc.raise_action_not_found(args.action, args.command)
Example #5
0
 def test_generate(self):
     """
     Check the success case.
     """
     database = data.Base(self.dbdir)
     target = data.Target(arches='baz', trees='rhel7', sources=set())
     baserun = run.Base(database, target)
     content = baserun.generate(description='Foo', kernel_location='bar',
                                lint=True)
     with open(os.path.join(self.dbdir, 'rhel7_rendered.xml')) as fhandle:
         content_expected = fhandle.read()
     self.assertEqual(content_expected, content)
Example #6
0
def main(args):
    """Main function for the `run` command"""
    if not data.Base.is_dir_valid(args.db):
        raise Exception("\"{}\" is not a database directory".format(args.db))
    database = data.Base(args.db)
    if args.action == 'generate':
        if args.arch not in database.arches:
            raise Exception("Architecture \"{}\" not found".format(args.arch))
        if args.tree not in database.trees:
            raise Exception("Tree \"{}\" not found".format(args.tree))
        if args.type == "auto":
            loc_type = loc.type_detect(args.kernel)
            if loc_type is None:
                raise \
                    Exception(
                        "Cannot determine the type of kernel location \"{}\". "
                        "Expecting a path to/URL of a .tar.gz/.rpm file or "
                        "a YUM/DNF repo. "
                        "Use --type <TYPE> to force a specific type.".
                        format(args.kernel))
        else:
            loc_type = args.type
        assert loc.type_is_valid(loc_type)

        src_files = get_src_files(args.mboxes, args.pw_cookie)
        target = data.Target(trees=args.tree,
                             arches=args.arch,
                             sources=src_files,
                             location_types=loc_type)
        baserun = run.Base(database, target)
        content = baserun.generate(description=args.description,
                                   kernel_location=args.kernel,
                                   lint=not args.no_lint)
        if not args.output:
            sys.stdout.write(content)
        else:
            with open(args.output, 'w') as file_handler:
                file_handler.write(content)
    elif args.action == 'print-test-cases':
        src_files = get_src_files(args.patches, args.pw_cookie)
        target = data.Target(sources=src_files)
        baserun = run.Base(database, target)
        case_name_list = []
        for recipeset in baserun.recipesets_of_hosts:
            for host in recipeset:
                for suite in host.suites:
                    for case in suite.cases:
                        case_name_list.append(case.name)
        for case_name in sorted(case_name_list):
            print(case_name)
    else:
        misc.raise_action_not_found(args.action, args.command)
Example #7
0
 def test_get_test_cases(self):
     """Check getting test cases according to sources given"""
     database = data.Base(self.db_dir)
     self.assertSequenceEqual(set({'fs/xfs', 'default/ltplite', 'fs/ext4'}),
                              targeted.get_test_cases([], database))
     src_files = {
         'fs/xfs/xfs_log.c',
     }
     self.assertSequenceEqual(set({'fs/xfs', 'default/ltplite'}),
                              targeted.get_test_cases(src_files, database))
     src_files.add('fs/ext4/ext4.h')
     self.assertSequenceEqual(set({'fs/xfs', 'default/ltplite', 'fs/ext4'}),
                              targeted.get_test_cases(src_files, database))
Example #8
0
 def test_get_property(self):
     """Check properties are returned by test name"""
     database = data.Base(self.db_dir)
     self.assertSequenceEqual({'fs/xml/xfstests-ext4-4k.xml'},
                              targeted.get_property('tasks', ['fs/ext4'],
                                                    database))
     self.assertSequenceEqual(
         {'default/xml/ltplite.xml', 'fs/xml/xfstests-ext4-4k.xml'},
         targeted.get_property('tasks', ['fs/ext4', 'default/ltplite'],
                               database))
     self.assertSequenceEqual({'fs/xml/partitions.xml'},
                              targeted.get_property('partitions',
                                                    ['fs/xfs'], database))
     self.assertSequenceEqual({},
                              targeted.get_property('tasks', [], database))
     self.assertSequenceEqual({},
                              targeted.get_property('unknown', ['fs/xfs'],
                                                    database))
Example #9
0
    def test_invalid_schema2(self):
        """
        Check that Object raiser Invalid exception if the schema doesn't match.
        """
        self.tmpdir = '/tmp/assets'
        path2assets = os.path.join(os.path.dirname(__file__),
                                   'assets/db/general')
        shutil.copytree(path2assets, self.tmpdir)

        suite = os.path.join(self.tmpdir, 'suites/default/index.yaml')

        with open(suite, 'r') as fhandle:
            mydata = fhandle.read()
            mydata = mydata.replace('pattern: .*', 'pattern: .*[')

            with open(suite, 'a+') as fhandle2:
                fhandle2.write(mydata)

        with self.assertRaises(data.Invalid):
            data.Base(self.tmpdir)
Example #10
0
def main(args):
    """Main function for the `run` command"""
    if not data.Base.is_dir_valid(args.db):
        raise Exception("\"{}\" is not a database directory".format(args.db))
    database = data.Base(args.db)
    if args.action == 'generate':
        template = utils.get_jinja_template(args.tree, args.db)
        template_params = {
            'DESCRIPTION': args.description,
            'ARCH': args.arch,
            'KURL': args.kernel,
            'TREE': args.tree,
            'getenv': os.getenv,
        }
        generate(template, template_params, args.mboxes, database, args.output,
                 args.pw_cookie)
    elif args.action == 'print-test-cases':
        print_test_cases(args.patches, database, args.pw_cookie)
    else:
        utils.raise_action_not_found(args.action, args.command)
Example #11
0
    def test_invalid_schema2(self):
        """
        Check that Object raiser Invalid exception if the schema doesn't match.
        """
        self.tmpdir = '/tmp/assets'
        path2assets = os.path.join(os.path.dirname(__file__),
                                   'assets/db/general')
        shutil.copytree(path2assets, self.tmpdir)

        suite = os.path.join(self.tmpdir, 'suites/default/index.yaml')

        with open(suite, 'r') as fhandle:
            mydata = fhandle.read()
            mydata = mydata.replace('maintainers:', 'maintainers: []')
            mydata = mydata.replace('- maint1', '')

            # overwrite the file, without required 'maintainers: field'
            with open(suite, 'w') as fhandle2:
                fhandle2.write(mydata)

        with self.assertRaises(data.Invalid):
            data.Base(self.tmpdir)