def _setup_test_check_diskspace(self, command, command_result,
                                 command_exit_status, directory,
                                 directory_exists):
     self.god.stub_function(os.path, 'isdir')
     self.god.stub_function(base_classes.Host, 'run')
     host = base_classes.Host()
     host.hostname = 'unittest-host'
     host.run.expect_call(
         'test -e "%s"' % directory, ignore_status=True).and_return(
             utils.CmdResult(exit_status=0 if directory_exists else 1))
     if directory_exists:
         fake_cmd_status = utils.CmdResult(exit_status=command_exit_status,
                                           stdout=command_result)
         host.run.expect_call(command).and_return(fake_cmd_status)
     return host
Beispiel #2
0
 def test_check_diskspace(self):
     self.god.stub_function(base_classes.Host, 'run')
     host = base_classes.Host()
     host.hostname = 'unittest-host'
     test_df_tail = ('/dev/sda1                    1061       939'
                     '       123      89% /')
     fake_cmd_status = utils.CmdResult(exit_status=0, stdout=test_df_tail)
     host.run.expect_call('df -PB 1000000 /foo | tail -1').and_return(
             fake_cmd_status)
     self.assertRaises(error.AutoservDiskFullHostError,
                       host.check_diskspace, '/foo', 0.2)
     host.run.expect_call('df -PB 1000000 /foo | tail -1').and_return(
             fake_cmd_status)
     host.check_diskspace('/foo', 0.1)
     self.god.check_playback()
 def test_run_output_notimplemented(self):
     host = base_classes.Host()
     self.assertRaises(NotImplementedError, host.run_output, "fake command")