Beispiel #1
0
 def setUp(self):
     Remote = flexmock()
     remote_remote = flexmock(avocado_runner_remote)
     (remote_remote.should_receive('Remote').with_args(
         hostname='hostname',
         username='******',
         password='******',
         key_filename=None,
         port=22,
         timeout=60,
         env_keep=None).once().ordered().and_return(Remote))
     Args = flexmock(
         test_result_total=1,
         reference=['/tests/sleeptest', '/tests/other/test', 'passtest'],
         remote_username='******',
         remote_hostname='hostname',
         remote_port=22,
         remote_password='******',
         remote_key_file=None,
         remote_timeout=60,
         show_job_log=False,
         env_keep=None)
     log = flexmock()
     log.should_receive("info")
     job = flexmock(args=Args, log=log)
     self.runner = avocado_runner_remote.RemoteTestRunner(job, None)
Beispiel #2
0
    def test_run_suite(self):
        """
        Test RemoteTestRunner.run_suite()

        The general idea of this test is to:

        1) Create the machinery necessary to get a RemoteTestRunner
           setup inside a job, or looking at it the other way around, to
           have a runner that is created with a valid job.

        2) Mock the interactions with a remote host.  This is done here
           basically by mocking 'Remote' and 'fabric' usage.

        3) Provide a polluted JSON to be parsed by the RemoteTestRunner

        4) Assert that those results are properly parsed into the
           job's result
        """
        job_args = argparse.Namespace(test_result_total=1,
                                      remote_username='******',
                                      remote_hostname='hostname',
                                      remote_port=22,
                                      remote_password='******',
                                      remote_key_file=None,
                                      remote_timeout=60,
                                      show_job_log=False,
                                      mux_yaml=[
                                          '~/avocado/tests/foo.yaml',
                                          '~/avocado/tests/bar/baz.yaml'
                                      ],
                                      dry_run=True,
                                      env_keep=None,
                                      reference=[
                                          '/tests/sleeptest.py',
                                          '/tests/other/test', 'passtest.py'
                                      ])

        job = None
        try:
            job = Job(job_args)
            job.setup()
            runner = avocado_runner_remote.RemoteTestRunner(job, job.result)
            return_value = (True, (version.MAJOR, version.MINOR))
            runner.check_remote_avocado = mock.Mock(return_value=return_value)

            # These are mocked at their source, and will prevent fabric from
            # trying to contact remote hosts
            with mock.patch('avocado_runner_remote.Remote'):
                runner.remote = avocado_runner_remote.Remote(
                    job_args.remote_hostname)

                # This is the result that the run_suite() will get from remote.run
                remote_run_result = process.CmdResult()
                remote_run_result.stdout = JSON_RESULTS
                remote_run_result.exit_status = 0
                runner.remote.run = mock.Mock(return_value=remote_run_result)

                # We have to fake the uncompressing and removal of the zip
                # archive that was never generated on the "remote" end
                # This test could be expand by mocking creating an actual
                # zip file instead, but it's really overkill
                with mock.patch('avocado_runner_remote.archive.uncompress'):
                    with mock.patch('avocado_runner_remote.os.remove'):
                        runner.run_suite(None, None, 61)

            # The job was created with dry_run so it should have a zeroed id
            self.assertEqual(job.result.job_unique_id, '0' * 40)
            self.assertEqual(job.result.tests_run, 1)
            self.assertEqual(job.result.passed, 1)
            cmd_line = ('avocado run --force-job-id '
                        '0000000000000000000000000000000000000000 --json - '
                        '--archive /tests/sleeptest.py /tests/other/test '
                        'passtest.py -m ~/avocado/tests/foo.yaml '
                        '~/avocado/tests/bar/baz.yaml --dry-run')
            runner.remote.run.assert_called_with(cmd_line,
                                                 ignore_status=True,
                                                 timeout=61)
        finally:
            if job:
                shutil.rmtree(job.args.base_logdir)
Beispiel #3
0
    def setUp(self):
        Args = flexmock(test_result_total=1,
                        remote_username='******',
                        remote_hostname='hostname',
                        remote_port=22,
                        remote_password='******',
                        remote_key_file=None,
                        remote_timeout=60,
                        show_job_log=False,
                        mux_yaml=[
                            '~/avocado/tests/foo.yaml',
                            '~/avocado/tests/bar/baz.yaml'
                        ],
                        dry_run=True,
                        env_keep=None)
        log = flexmock()
        log.should_receive("info")
        result_dispatcher = flexmock()
        result_dispatcher.should_receive("map_method")
        job = flexmock(
            args=Args,
            log=log,
            references=['/tests/sleeptest', '/tests/other/test', 'passtest'],
            unique_id='1-sleeptest;0',
            logdir="/local/path",
            _result_events_dispatcher=result_dispatcher)

        flexmock(
            avocado_runner_remote.RemoteTestRunner).should_receive('__init__')
        self.runner = avocado_runner_remote.RemoteTestRunner(job, None)
        self.runner.job = job

        filehandler = logging.StreamHandler()
        flexmock(logging).should_receive("FileHandler").and_return(filehandler)

        test_results = flexmock(stdout=JSON_RESULTS, exit_status=0)
        stream = flexmock(job_unique_id='1-sleeptest;0',
                          debuglog='/local/path/dirname')
        Remote = flexmock()
        Remoter = flexmock(avocado_runner_remote.Remote)
        Remoter.new_instances(Remote)
        args_version = 'avocado -v'
        version_result = flexmock(stderr='Avocado 1.2', exit_status=0)
        args_env = 'env'
        env_result = flexmock(stdout='''XDG_SESSION_ID=20
HOSTNAME=rhel7.0
SELINUX_ROLE_REQUESTED=
SHELL=/bin/bash
TERM=vt100
HISTSIZE=1000
SSH_CLIENT=192.168.124.1 52948 22
SELINUX_USE_CURRENT_RANGE=
SSH_TTY=/dev/pts/0
USER=root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
MAIL=/var/spool/mail/root
PWD=/root
LANG=en_US.UTF-8
SELINUX_LEVEL_REQUESTED=
HISTCONTROL=ignoredups
HOME=/root
SHLVL=2
LOGNAME=root
SSH_CONNECTION=192.168.124.1 52948 192.168.124.65 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
XDG_RUNTIME_DIR=/run/user/0
_=/usr/bin/env''',
                              exit_status=0)
        (Remote.should_receive('run').with_args(
            args_env, ignore_status=True,
            timeout=60).once().and_return(env_result))

        (Remote.should_receive('run').with_args(
            args_version, ignore_status=True,
            timeout=60).once().and_return(version_result))

        args = ("avocado run --force-job-id 1-sleeptest;0 "
                "--json - --archive /tests/sleeptest /tests/other/test "
                "passtest -m ~/avocado/tests/foo.yaml "
                "~/avocado/tests/bar/baz.yaml --dry-run")
        (Remote.should_receive('run').with_args(
            args, timeout=61,
            ignore_status=True).once().and_return(test_results))
        Result = flexmock(remote=Remote,
                          references=['sleeptest'],
                          stream=stream,
                          timeout=None,
                          args=flexmock(show_job_log=False,
                                        mux_yaml=['foo.yaml', 'bar/baz.yaml'],
                                        dry_run=True))
        args = {
            'name': '1-sleeptest;0',
            'time_end': 1.23,
            'status': u'PASS',
            'time_start': 0,
            'time_elapsed': 1.23,
            'job_unique_id': '',
            'fail_reason': u'None',
            'logdir': u'/local/path/test-results/1-sleeptest;0',
            'logfile': u'/local/path/test-results/1-sleeptest;0/debug.log',
            'job_logdir': u'/local/path'
        }
        Result.should_receive('start_test').once().with_args(args).ordered()
        Result.should_receive('check_test').once().with_args(args).ordered()
        (Remote.should_receive('receive_files').with_args(
            '/local/path', '/home/user/avocado/logs/run-2014-05-26-'
            '15.45.37.zip')).once().ordered()
        (flexmock(archive).should_receive('uncompress').with_args(
            '/local/path/run-2014-05-26-15.45.37.zip',
            '/local/path').once().ordered())
        (flexmock(os).should_receive('remove').with_args(
            '/local/path/run-2014-05-26-15.45.37.zip').once().ordered())
        Result.should_receive('end_tests').once().ordered()
        self.runner.result = Result
Beispiel #4
0
    def test_run_suite(self):
        """
        Test RemoteTestRunner.run_suite()

        The general idea of this test is to:

        1) Create the machinery necessary to get a RemoteTestRunner
           setup inside a job, or looking at it the other way around, to
           have a runner that is created with a valid job.

        2) Mock the interactions with a remote host.  This is done here
           basically by mocking 'Remote' and 'fabric' usage.

        3) Provide a polluted JSON to be parsed by the RemoteTestRunner

        4) Assert that those results are properly parsed into the
           job's result
        """
        job_args = {'test_result_total': 1,
                    'remote_username': '******',
                    'remote_hostname': 'hostname',
                    'remote_port': 22,
                    'remote_password': '******',
                    'remote_key_file': None,
                    'remote_timeout': 60,
                    'mux_yaml': ['~/avocado/tests/foo.yaml',
                                 '~/avocado/tests/bar/baz.yaml'],
                    'filter_by_tags': ["-foo", "-bar"],
                    'filter_by_tags_include_empty': False,
                    'env_keep': None,
                    'base_logdir': self.tmpdir.name,
                    'run.keep_tmp': 'on',
                    'run.store_logging_stream': [],
                    'run.dry_run.enabled': True,
                    'run.references': ['/tests/sleeptest.py',
                                       '/tests/other/test',
                                       'passtest.py'],
                    }

        with Job(job_args) as job:
            runner = avocado_runner_remote.RemoteTestRunner()
            return_value = (True, (version.MAJOR, version.MINOR))
            runner.check_remote_avocado = unittest.mock.Mock(return_value=return_value)

            # These are mocked at their source, and will prevent fabric from
            # trying to contact remote hosts
            with unittest.mock.patch('avocado_runner_remote.Remote'):
                remote_hostname = job_args.get('remote_hostname')
                runner.remote = avocado_runner_remote.Remote(remote_hostname)

                # This is the result that the run_suite() will get from remote.run
                remote_run_result = process.CmdResult()
                remote_run_result.stdout = JSON_RESULTS
                remote_run_result.exit_status = 0
                runner.remote.run = unittest.mock.Mock(return_value=remote_run_result)

                # We have to fake the uncompressing and removal of the zip
                # archive that was never generated on the "remote" end
                # This test could be expand by mocking creating an actual
                # zip file instead, but it's really overkill
                with unittest.mock.patch('avocado_runner_remote.archive.uncompress'):
                    with unittest.mock.patch('avocado_runner_remote.os.remove'):
                        runner.run_suite(job, job.result, None, None, 61)

        # The job was created with dry_run so it should have a zeroed id
        self.assertEqual(job.result.job_unique_id, '0' * 40)
        self.assertEqual(job.result.tests_run, 1)
        self.assertEqual(job.result.passed, 1)
        cmd_line = ('avocado run --force-job-id '
                    '0000000000000000000000000000000000000000 --json - '
                    '--archive /tests/sleeptest.py /tests/other/test '
                    'passtest.py --mux-yaml ~/avocado/tests/foo.yaml '
                    '~/avocado/tests/bar/baz.yaml --dry-run --filter-'
                    'by-tags -foo --filter-by-tags -bar')
        runner.remote.run.assert_called_with(cmd_line,
                                             ignore_status=True,
                                             timeout=61)