Exemple #1
0
 def test_server_response(self):
     # will require automatic test server to shutdown, for now, just to it by hand before running this test
     if not is_test_server_running():
         with self.assertRaises(ApiException):
             SquadApi.get('/api/groups')
     else:
         self.assertTrue(SquadApi.get('/api/groups') is not None)
Exemple #2
0
    def setUp(self):
        SquadApi.configure(url='http://localhost:%s' %
                           settings.DEFAULT_SQUAD_PORT,
                           token='193cd8bb41ab9217714515954e8724f651ef8601')

        self.project = first(Squad().projects(slug='my_project'))
        self.build = first(Squad().builds(version='my_build'))
        self.build2 = first(Squad().builds(version='my_build2'))
    def setUp(self):
        self.squad = Squad()
        SquadApi.configure(
            url="http://localhost:%s" % settings.DEFAULT_SQUAD_PORT,
            token="193cd8bb41ab9217714515954e8724f651ef8601",
        )

        self.group_slug = 'my_group'
    def setUp(self):
        self.squad = Squad()

        self.testing_server = 'http://localhost:%s' % settings.DEFAULT_SQUAD_PORT
        self.testing_token = '193cd8bb41ab9217714515954e8724f651ef8601'
        SquadApi.configure(self.testing_server, self.testing_token)

        self.group = 'my_group'
        self.slug = 'create-project-via-cmdline'
Exemple #5
0
    def setUp(self):
        self.squad = Squad()
        SquadApi.configure(url=self.testing_server, token=self.testing_token)

        self.root_dir = os.path.join("tests", "data", "submit_tuxbuild")
        self.assertTrue(os.path.exists(self.root_dir))

        self.build_dir = os.path.join(self.root_dir, "build-x86-gcc")
        self.assertTrue(os.path.exists(self.build_dir))

        self.buildset_dir = os.path.join(self.root_dir, "buildset-x86")
        self.assertTrue(os.path.exists(self.buildset_dir))
Exemple #6
0
    def test_unauthorized_access(self):
        with self.assertRaises(ApiException):
            SquadApi.get('/my_group/my_private_project')

        SquadApi.configure(url='http://localhost:%s' %
                           settings.DEFAULT_SQUAD_PORT,
                           token='193cd8bb41ab9217714515954e8724f651ef8601')
        response = SquadApi.get('/my_group/my_private_project')
        self.assertTrue(response.ok)

        # reset config
        self.setUp()
    def send_to_qa_reports(self):
        if None in (self.qa_reports_server, self.qa_reports_token, self.qa_reports_group, self.qa_reports_project, self.qa_reports_build_version, self.qa_reports_env):
            self.logger.warning("All parameters for qa reports are not set, results will not be pushed to qa reports")
            return

        SquadApi.configure(
            url=self.qa_reports_server, token=self.qa_reports_token
        )
        tests = {}
        metrics = {}
        for metric in self.metrics:
            if metric['measurement'] != "":
                metrics["{}/{}".format(self.test['test_name'], metric['test_case_id'])] = metric['measurement']
            else:
                tests["{}/{}".format(self.test['test_name'], metric['test_case_id'])] = metric['result']

        with open("{}/stdout.log".format(self.test['test_path']), "r") as logfile:
            log = logfile.read()

        metadata = {}
        if not self.qa_reports_disable_metadata:
            if self.qa_reports_metadata:
                metadata.update(self.qa_reports_metadata)
            if self.qa_reports_metadata_file:
                try:
                    with open(self.qa_reports_metadata_file, "r") as metadata_file:
                        loaded_metadata = yaml.load(metadata_file, Loader=yaml.SafeLoader)
                        # check if loaded metadata is key=value and both are strings
                        for key, value in loaded_metadata.items():
                            if type(key) == str and type(value) == str:
                                # only update metadata with simple keys
                                # ignore all other items in the dictionary
                                metadata.update({key: value})
                            else:
                                self.logger.warning("Ignoring key: %s" % key)
                except FileNotFoundError:
                    self.logger.warning("Metadata file not found")
                except PermissionError:
                    self.logger.warning("Insufficient permissions to open metadata file")
        if submit_results(
                group_project_slug="{}/{}".format(self.qa_reports_group, self.qa_reports_project),
                build_version=self.qa_reports_build_version,
                env_slug=self.qa_reports_env,
                tests=tests,
                metrics=metrics,
                log=log,
                metadata=metadata,
                attachments=None):
            self.logger.info("Results pushed to QA Reports")
        else:
            self.logger.warning("Results upload to QA Reports failed!")
Exemple #8
0
 def generate(self):
     for report in self.reports:
         SquadApi.configure(self.squad_url, self.token)
         output = report.generate()
         if report.output is None:
             # print to stdout
             print(output)
         elif type(report.output) is StringIO:
             report.output.write(output)
         elif type(report.output) is str and path.isfile(report.output):
             with open(report.output, 'w') as f:
                 f.write(output)
         else:
             raise InvalidReportOutput('Report "%s" output configuration is neither None, a file or StringIO object' % report.name)
     return self.reports
Exemple #9
0
def main():
    parser = argparse.ArgumentParser(prog='./manage.py')
    parser.add_argument('--debug',
                        action='store_true',
                        help='display debug messages')
    parser.add_argument(
        '--squad-host',
        help='SQUAD host, example: https://qa-reports.linaro.org')
    parser.add_argument('--squad-token', help='SQUAD authentication token')
    parser.add_argument(
        '--cache',
        default=0,
        help='Cache API results for N number of seconds. Disabled by default.')
    subparser = parser.add_subparsers(help='available subcommands',
                                      dest='command')

    SquadClientCommand.add_commands(subparser)

    args = parser.parse_args()
    if args.command is None:
        parser.print_help()
        return -1

    if args.command != 'test':
        squad_host = args.squad_host or os.getenv('SQUAD_HOST')
        squad_token = args.squad_token or os.getenv('SQUAD_TOKEN')
        if squad_host is None:
            logger.error(
                'Either --squad-host or SQUAD_HOST env variable are required')
            return -1

        try:
            SquadApi.configure(squad_host, token=squad_token)
        except ApiException as e:
            logger.error('Failed to configure squad api: %s' % e)
            return -1

    if args.cache > 0:
        logger.debug(
            'Caching results in "squad_client_cache.sqlite" for %d seconds' %
            args.cache)
        requests_cache.install_cache('squad_client_cache',
                                     expire_after=args.cache)

    rc = SquadClientCommand.process(args)
    return 1 if rc is False else 0 if rc is True else -1
Exemple #10
0
def main(args):
    # Some configuration, might get parameterized later
    SquadApi.configure(args.get('squadapi_url', None))
    squad = Squad()
    getid = lambda s: int(re.search('\d+', s).group())
    group = squad.group(args.get('group', None))
    project = group.project(args.get('project', None))
    bad_suite = project.suite(args.get('suite', None))
    bad_test = args.get('test', None)
    bad_build = project.build(args.get('kernel_build', None))
    bad_env = project.environment(args.get('arch', None))

    # sh environment on build next-20201210
    #bad_build = project.build('next-20201210')
    #bad_env = project.environment('sh')

    # now with arm64 on build next-20201204
    #bad_build = project.build('next-20201204')
    #bad_env = project.environment('arm64')

    # now with parisc on build next-20201124 (it should not return anything)
    #bad_build = project.build('next-20201124')
    #bad_env = project.environment('parisc')

    print('Looking at the next good build in %s/%s for build %s' %
          (group.slug, project.slug, bad_build.version),
          flush=True)

    tests = squad.tests(build__created_at__lt=bad_build.created_at,
                        suite=bad_suite.id,
                        environment=bad_env.id,
                        metadata__name=bad_test,
                        ordering='-build_id',
                        result=True,
                        count=1)

    if len(tests):
        test = first(tests)
        build = Build(getid(test.build))
        print('%s: https://qa-reports.linaro.org/%s/%s/build/%s' %
              (build.version, group.slug, project.slug, build.version))
    else:
        print('No good build')
Exemple #11
0
def main():
    parser = argparse.ArgumentParser(prog='./manage.py')
    parser.add_argument('--debug', action='store_true', help='display debug messages')
    parser.add_argument('--squad-host', help='SQUAD host, example: https://qa-reports.linaro.org')
    parser.add_argument('--squad-token', help='SQUAD authentication token')
    parser.add_argument('--cache', default=0, help='Cache API results for N number of seconds. Disabled by default.')
    parser.add_argument('--version', action='store_true', help='Display versions of squad-client and server')
    subparser = parser.add_subparsers(help='available subcommands', dest='command')

    SquadClientCommand.add_commands(subparser)

    args = parser.parse_args()

    if args.debug:
        logging.setLevel(logging.DEBUG)

    if args.command not in ['test']:
        squad_host = args.squad_host or os.getenv('SQUAD_HOST')
        squad_token = args.squad_token or os.getenv('SQUAD_TOKEN')
        if squad_host is None:
            logger.error('Either --squad-host or SQUAD_HOST env variable are required')
            return -1

        try:
            SquadApi.configure(squad_host, token=squad_token, cache=args.cache)
        except ApiException as e:
            logger.error('Failed to configure squad api: %s' % e)
            return -1

    if args.version:
        print('squad-client: %s' % squad_client_version)
        print('squad server: %s' % SquadApi.version)
        return 0

    if args.command is None:
        parser.print_help()
        return -1

    rc = SquadClientCommand.process(args)
    return 1 if rc is False else 0 if rc is True else -1
Exemple #12
0
    def setUp(self):
        SquadApi.configure(url='http://localhost:%s' %
                           settings.DEFAULT_SQUAD_PORT,
                           token='193cd8bb41ab9217714515954e8724f651ef8601')

        self.group = first(Squad().groups(slug='my_group'))
Exemple #13
0
 def setUp(self):
     self.squad = Squad()
     SquadApi.configure(url=self.testing_server, token=self.testing_token)
 def setUp(self):
     self.squad = Squad()
     SquadApi.configure(url="http://localhost:%s" %
                        settings.DEFAULT_SQUAD_PORT)
#!/usr/bin/env python3
import os
import jinja2
import sys


sys.path.append('..')


from squad_client.core.api import SquadApi
from squad_client.core.models import Squad


SquadApi.configure(url='https://qa-reports.linaro.org/', token=os.getenv('QA_REPORTS_TOKEN'))
group = Squad().group('schneider')
project = group.project('schneider')
build = project.build('184')
testruns = build.testruns(bucket_suites=True, completed=True).values()

templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "schneider_template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
outputText = template.render(group=group, project=project, build=build, testruns=testruns)
with open('schneider_generated_report.html', 'w') as reportFile:
    reportFile.write(outputText)
Exemple #16
0
 def setUp(self):
     SquadApi.configure(url='http://localhost:%s' %
                        settings.DEFAULT_SQUAD_PORT)
Exemple #17
0
 def test_malformed_url(self):
     with self.assertRaises(ApiException):
         SquadApi.configure('http:/malformed/url')
Exemple #18
0
 def test_out_of_domain_object_url(self):
     with self.assertRaises(ApiException):
         SquadApi.get('http://some.other.url')
Exemple #19
0
def main(args):

    global do_color

    do_color = args.color

    SquadApi.configure(args.squadapi_url)
    squad = Squad()
    print(f'I: Fetching group {args.group}')
    group = squad.group(args.group)
    print(f'I: Fetching project {args.project}')
    project = group.project(args.project)

    build_filters = {}
    if args.builds and len(args.builds):
        build_filters["version__in"] = join(args.builds)
    else:
        build_filters["count"] = args.n

    test_filters = {}
    if args.tests and len(args.tests):
        test_filters["metadata__name__in"] = join(args.tests)

    if args.suites and len(args.suites):
        print(
            f'I: Fetching {args.group}/{args.project} suites ({args.suites})')
        suites = project.suites(slug__in=join(args.suites))
        test_filters["suite__id__in"] = join(
            [str(_id) for _id in suites.keys()])
    else:
        print(f'I: Fetching {args.group}/{args.project} suites')
        suites = project.suites()

    if args.no_arch:
        envs = {}
    elif args.archs and len(args.archs):
        print(
            f'I: Fetching {args.group}/{args.project} environments ({args.archs})'
        )
        envs = project.environments(slug__in=join(args.archs))
        test_filters["environment__id__in"] = join(
            [str(_id) for _id in envs.keys()])
    else:
        print(f'I: Fetching {args.group}/{args.project} environments')
        envs = project.environments()

    tests = []
    print(f'I: Fetching {args.n} builds ({build_filters}):', flush=True)
    for build in project.builds(**build_filters).values():
        print(f'D: Fetching build {build.version} tests ({test_filters})',
              flush=True)
        num_tests = 0
        for test in build.tests(**test_filters).values():
            if test.name.startswith('linux-log-parser'):
                continue
            tests.append(test)
            if num_tests % 1000 == 0:
                print('.', end='', flush=True)
            num_tests += 1

        if num_tests:
            print()

    print('I: Finding stable tests')
    find_stable_tests(
        tests,
        envs=envs,
        suites=suites,
    )
Exemple #20
0
 def test_unconfigured(self):
     with self.assertRaises(ApiException):
         SquadApi.configure(None)
Exemple #21
0
    def setUp(self):
        self.squad = Squad()

        self.testing_server = 'http://localhost:%s' % settings.DEFAULT_SQUAD_PORT
        self.testing_token = '193cd8bb41ab9217714515954e8724f651ef8601'
        SquadApi.configure(self.testing_server, self.testing_token)
Exemple #22
0
def main(args):
    # Some configuration, might get parameterized later
    group_slug = args.get('group', None)
    suite_slug = args.get('suite', None)
    SquadApi.configure(args.get('squadapi_url', None))
    number_of_builds = args.get('number', None)
    squad = Squad()
    getid = lambda s: int(re.search('\d+', s).group())

    # First we need to know which projects from the selected group
    # contain the specified suite.
    print('Fetching projects that contain "%s" suites for "%s" group' %
          (suite_slug, group_slug),
          flush=True)
    suites = squad.suites(slug=suite_slug, project__group__slug=group_slug)
    projects_ids = list(
        set([str(getid(suite.project)) for suite in suites.values()]))
    projects = squad.projects(id__in=','.join(projects_ids),
                              ordering='slug').values()

    # Env/arch cache
    environments = set()

    # Table will be layed out like below
    # table = {
    #     'kernelA': {
    #         'buildA': {
    #             'summary': {
    #                 'envA': {'pass': 1, 'fail': 2, 'skip': 3},
    #                 'envB': {'pass': 1, 'fail': 2, 'skip': 3},
    #             }
    #             'envA': [
    #                 {'kunit/test1': 'pass'}
    #                 {'kunit/test2': 'fail'}
    #             ]
    #         },
    #     }
    # }
    table = {}

    if number_of_builds == "0":
        for project in projects:
            print('- %s' % project.slug, flush=True)
        return

    for project in projects:
        print('- %s: fetching %s builds' % (project.slug, number_of_builds),
              flush=True)

        environments = project.environments(count=ALL)

        for build in project.builds(count=int(number_of_builds),
                                    ordering='-id').values():
            print('  - %s: fetching tests' % build.version, flush=True)
            results = {'summary': defaultdict(dict)}

            for test in build.tests(suite__slug=suite_slug).values():

                env = environments[getid(test.environment)].slug

                if test.status not in results['summary'][env]:
                    results['summary'][env][test.status] = 0
                results['summary'][env][test.status] += 1

                if env not in results:
                    results[env] = []
                results[env].append((test.name, test.status))

            if len(results['summary']):
                print('    - summary:', flush=True)
                summary = results.pop('summary')
                for env in sorted(summary.keys()):
                    print('      - %s: %s' % (env, summary[env]), flush=True)

                for env in sorted(results.keys()):
                    print('    - %s:' % env, flush=True)
                    for test in sorted(results[env], key=lambda d: d[0]):
                        print('      - %s: %s' % (test[0], test[1]),
                              flush=True)
Exemple #23
0
    dest='intro',
    required=False,
    default=None,
    help='Free form text or HTML to be added to template introduction')
parser.add_argument('--output',
                    dest='output',
                    required=True,
                    help='Output filename')
parser.add_argument('--squad-host',
                    dest='server',
                    default='https://qa-reports.linaro.org/',
                    help='SQUAD server')

args = parser.parse_args()

SquadApi.configure(url=args.server, token=args.token)


def getid(url):
    matches = re.search('^.*/(\d+)/$', url)
    try:
        _id = int(matches.group(1))
        return _id
    except ValueError:
        print('Could not get id for %s' % url)
        return -1


group = Squad().group(args.group)
project = group.project(args.project)
environments = project.environments(count=ALL)
Exemple #24
0
 def setUp(self):
     self.squad = Squad()
     SquadApi.configure(url='http://localhost:%s' %
                        settings.DEFAULT_SQUAD_PORT,
                        token='193cd8bb41ab9217714515954e8724f651ef8601')
Exemple #25
0
#!/usr/bin/env python3

import jinja2
import sys

sys.path.append('..')

from squad_client.core.api import SquadApi
from squad_client.core.models import Squad

# Configure SQUAD url
SquadApi.configure(url='https://qa-reports.linaro.org/')

# Generate a report with all groups
groups = Squad().groups()

templateLoader = jinja2.FileSystemLoader(searchpath="./")
templateEnv = jinja2.Environment(loader=templateLoader)
TEMPLATE_FILE = "example_template.html"
template = templateEnv.get_template(TEMPLATE_FILE)
outputText = template.render(groups=groups.values())
with open('generated_report.html', 'w') as reportFile:
    reportFile.write(outputText)
Exemple #26
0
import unittest

from squad_client.core.api import SquadApi
from squad_client.core.models import Squad, Group, Project, Build, TestJob, TestRun, Test, Suite, Environment, Backend, EmailTemplate, KnownIssue, SuiteMetadata, Annotation, MetricThreshold, Report
from squad_client.utils import first

SquadApi.configure(url='http://localhost:8000')


class SquadTest(unittest.TestCase):
    def setUp(self):
        self.squad = Squad()

    def test_groups(self):
        groups = self.squad.groups()
        self.assertTrue(True, len(groups))

    def test_not_found_groups(self):
        groups = self.squad.groups(name__startswith='no group with this name')
        self.assertEqual(0, len(groups))

    def test_groups_with_count(self):
        four_groups = self.squad.groups(count=4)
        self.assertEqual(4, len(four_groups))

    def test_not_found_group(self):
        not_found_group = self.squad.group('this-group-does-not-really-exist')
        self.assertEqual(None, not_found_group)

    def test_group(self):
        lkft_group = self.squad.group('lkft')
Exemple #27
0
 def setUp(self):
     SquadApi.configure('http://localhost:8000')