Esempio n. 1
0
    def test_init(self):
        self.god.stub_function(local_host.platform, 'node')
        local_host.platform.node.expect_call().and_return('foo')

        # run the actual test
        host = local_host.LocalHost()
        self.assertEqual(host.hostname, 'foo')
        self.god.check_playback()

        host = local_host.LocalHost(hostname='bar')
        self.assertEqual(host.hostname, 'bar')
        self.god.check_playback()
Esempio n. 2
0
 def __init__(self, name, host=None):
     self._name = name
     if host is None:
         self.host = local_host.LocalHost()
     else:
         self.host = host
     self._run = self.host.run
Esempio n. 3
0
    def test_run_success(self, mock_run):
        result = local_host.utils.CmdResult(
                command='yes',
                stdout='y',
                stderr='',
                exit_status=0,
                duration=1,
        )
        mock_run.return_value = result

        host = local_host.LocalHost()
        got = host.run(
                'yes',
                timeout=123,
                ignore_status=True,
                stdout_tee=local_host.utils.TEE_TO_LOGS,
                stderr_tee=local_host.utils.TEE_TO_LOGS,
                stdin=None,
        )

        self.assertEqual(got, result)
        mock_run.assert_called_once_with(
                result.command,
                timeout=123,
                ignore_status=True,
                stdout_tee=local_host.utils.TEE_TO_LOGS,
                stderr_tee=local_host.utils.TEE_TO_LOGS,
                stdin=None,
                ignore_timeout=False,
                args=(),
        )
    def _post_record_init(self, control, options, drop_caches):
        """
        Perform job initialization not required by self.record().
        """
        self._init_drop_caches(drop_caches)

        self._init_packages()

        self.sysinfo = sysinfo.sysinfo(self.resultdir)
        self._load_sysinfo_state()

        if not options.cont:
            download = os.path.join(self.testdir, 'download')
            if not os.path.exists(download):
                os.mkdir(download)

            shutil.copyfile(self.control,
                            os.path.join(self.resultdir, 'control'))

        self.control = control

        self.logging = logging_manager.get_logging_manager(
                manage_stdout_and_stderr=True, redirect_fds=True)
        self.logging.start_logging()

        self.profilers = profilers.profilers(self)

        self.machines = [options.hostname]
        self.machine_dict_list = [{'hostname' : options.hostname}]
        # Client side tests should always run the same whether or not they are
        # running in the lab.
        self.in_lab = False
        self.hosts = set([local_host.LocalHost(hostname=options.hostname)])

        self.args = []
        if options.args:
            self.args = self._parse_args(options.args)

        if options.user:
            self.user = options.user
        else:
            self.user = getpass.getuser()

        self.sysinfo.log_per_reboot_data()

        if not options.cont:
            self.record('START', None, None)

        self.harness.run_start()

        if options.log:
            self.enable_external_logging()

        self.num_tests_run = None
        self.num_tests_failed = None

        self.warning_loggers = None
        self.warning_manager = None
Esempio n. 5
0
    def _setup_run(self, result):
        host = local_host.LocalHost()

        (local_host.utils.run.expect_call(result.command, timeout=123,
                ignore_status=True, stdout_tee=local_host.utils.TEE_TO_LOGS,
                stderr_tee=local_host.utils.TEE_TO_LOGS, stdin=None, args=())
                .and_return(result))

        return host
 def __init__(self, host=None, *args, **kwargs):
     self.args = args
     self.kwargs = kwargs
     self.gateway = None
     self.interface = None
     if host is not None:
         self.host = host
     else:
         self.host = local_host.LocalHost()
     self._run = self.host.run
Esempio n. 7
0
    def test_get_file(self):
        """Tests get_file() copying a regular file."""
        host = local_host.LocalHost()

        source_file = os.path.join(self.tmpdir.name, 'file')
        open(os.path.join(source_file), 'w').close()

        dest_file = os.path.join(self.tmpdir.name, 'dest')

        host.get_file(source_file, dest_file)
        self.assertTrue(os.path.isfile(dest_file))
Esempio n. 8
0
    def test_symlink_closure_adds_missing_files(self):
        host = local_host.LocalHost()

        # create a file and a symlink to it
        fname = os.path.join(self.tmpdir.name, 'file')
        sname = os.path.join(self.tmpdir.name, 'sym')
        open(fname, 'w').close()
        os.symlink(fname, sname)

        # test that when the symlinks point to unknown files they are added
        self.assertItemsEqual([fname, sname], host.symlink_closure([sname]))
Esempio n. 9
0
    def test_get_directory_into_new_directory(self):
        """Tests get_file() copying a directory into a new dir."""
        host = local_host.LocalHost()

        source_dir = os.path.join(self.tmpdir.name, 'dir')
        os.mkdir(source_dir)
        open(os.path.join(source_dir, 'file'), 'w').close()

        dest_dir = os.path.join(self.tmpdir.name, 'dest')

        host.get_file(source_dir, dest_dir)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'dir', 'file')))
Esempio n. 10
0
    def test_list_files_glob(self):
        host = local_host.LocalHost()

        files = (os.path.join(self.tmpdir.name, 'file1'),
                 os.path.join(self.tmpdir.name, 'file2'))

        # create some files in tmpdir
        open(files[0], 'w').close()
        open(files[1], 'w').close()

        self.assertItemsEqual(
                files,
                host.list_files_glob(os.path.join(self.tmpdir.name, '*')))
Esempio n. 11
0
    def test_symlink_closure_does_not_add_existent_file(self):
        host = local_host.LocalHost()

        # create a file and a symlink to it
        fname = os.path.join(self.tmpdir.name, 'file')
        sname = os.path.join(self.tmpdir.name, 'sym')
        open(fname, 'w').close()
        os.symlink(fname, sname)

        # test that when the symlinks point to already know files
        # nothing is added
        self.assertItemsEqual([fname, sname],
                              host.symlink_closure([fname, sname]))
Esempio n. 12
0
    def test_get_directory_contents_into_new_directory(self):
        """Tests get_file() copying dir contents to a new dir."""
        host = local_host.LocalHost()

        source_dir = os.path.join(self.tmpdir.name, 'dir')
        os.mkdir(source_dir)
        open(os.path.join(source_dir, 'file'), 'w').close()

        dest_dir = os.path.join(self.tmpdir.name, 'dest')

        # End the source with '/' to copy the contents only.
        host.get_file(os.path.join(source_dir, ''), dest_dir)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'file')))
Esempio n. 13
0
    def test_get_directory_contents_delete_dest(self):
        """Tests get_file() replacing contents of a dir."""
        host = local_host.LocalHost()

        source_dir = os.path.join(self.tmpdir.name, 'dir')
        os.mkdir(source_dir)
        open(os.path.join(source_dir, 'file'), 'w').close()

        dest_dir = os.path.join(self.tmpdir.name, 'dest')
        os.mkdir(dest_dir)
        open(os.path.join(dest_dir, 'file2'), 'w').close()

        # End the source with '/' to copy the contents only.
        host.get_file(os.path.join(source_dir, ''), dest_dir, delete_dest=True)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'file')))
        self.assertFalse(os.path.isfile(os.path.join(dest_dir, 'file2')))
Esempio n. 14
0
    def test_get_directory_delete_dest(self):
        """Tests get_file() replacing a dir."""
        host = local_host.LocalHost()

        source_dir = os.path.join(self.tmpdir.name, 'dir')
        os.mkdir(source_dir)
        open(os.path.join(source_dir, 'file'), 'w').close()

        dest_dir = os.path.join(self.tmpdir.name, 'dest')
        os.mkdir(dest_dir)
        os.mkdir(os.path.join(dest_dir, 'dir'))
        open(os.path.join(dest_dir, 'dir', 'file2'), 'w').close()

        host.get_file(source_dir, dest_dir, delete_dest=True)

        self.assertTrue(os.path.isfile(os.path.join(dest_dir, 'dir', 'file')))
        self.assertFalse(os.path.isfile(os.path.join(dest_dir, 'dir', 'file2')))
Esempio n. 15
0
    def test_run_cmd_timeout_raised(self, mock_run):
        mock_result = mock.MagicMock()
        mock_run.side_effect = error.CmdTimeoutError('yes', mock_result)

        host = local_host.LocalHost()
        with self.assertRaises(error.AutotestHostRunTimeoutError) as exc_cm:
            host.run('yes', timeout=123)

        self.assertEqual(exc_cm.exception.result_obj, mock_result)
        mock_run.assert_called_once_with(
                'yes',
                timeout=123,
                ignore_status=False,
                stdout_tee=local_host.utils.TEE_TO_LOGS,
                stderr_tee=local_host.utils.TEE_TO_LOGS,
                stdin=None,
                ignore_timeout=False,
                args=(),
        )
Esempio n. 16
0
 def test_wait_up(self):
     # just test that wait_up always works
     host = local_host.LocalHost()
     host.wait_up(1)
Esempio n. 17
0
 def test_init_with_hostname(self, mock_node):
     mock_node.return_value = 'foo'
     host = local_host.LocalHost(hostname='bar')
     self.assertEqual(host.hostname, 'bar')
Esempio n. 18
0
 def test_init_default_hostname(self, mock_node):
     mock_node.return_value = 'foo'
     host = local_host.LocalHost()
     self.assertEqual(host.hostname, 'foo')
Esempio n. 19
0
 def __init__(self, timestamp_remote_calls=True):
     super(_LocalDrone,
           self).__init__(timestamp_remote_calls=timestamp_remote_calls)
     self.hostname = 'localhost'
     self._host = local_host.LocalHost()
     self._drone_utility = drone_utility.DroneUtility()
Esempio n. 20
0
 def test_wait_up(self):
     # just test that wait_up always works
     host = local_host.LocalHost()
     host.wait_up(1)
     self.god.check_playback()
Esempio n. 21
0
    def _post_record_init(self, control, options, drop_caches,
                          extra_copy_cmdline):
        """
        Perform job initialization not required by self.record().
        """
        self._init_drop_caches(drop_caches)

        self._init_packages()

        self.sysinfo = sysinfo.sysinfo(self.resultdir)
        self._load_sysinfo_state()

        if not options.cont:
            download = os.path.join(self.testdir, 'download')
            if not os.path.exists(download):
                os.mkdir(download)

            shutil.copyfile(self.control,
                            os.path.join(self.resultdir, 'control'))

        self.control = control

        self.logging = logging_manager.get_logging_manager(
            manage_stdout_and_stderr=True, redirect_fds=True)
        self.logging.start_logging()

        self._config = config.config(self)
        self.profilers = profilers.profilers(self)

        self._init_bootloader()

        self.machines = [options.hostname]
        self.hosts = set([
            local_host.LocalHost(hostname=options.hostname,
                                 bootloader=self.bootloader)
        ])

        self.args = []
        if options.args:
            self.args = self._parse_args(options.args)

        if options.user:
            self.user = options.user
        else:
            self.user = getpass.getuser()

        self.sysinfo.log_per_reboot_data()

        if not options.cont:
            self.record('START', None, None)

        self.harness.run_start()

        if options.log:
            self.enable_external_logging()

        self._init_cmdline(extra_copy_cmdline)

        self.num_tests_run = None
        self.num_tests_failed = None

        self.warning_loggers = None
        self.warning_manager = None