コード例 #1
0
    def testExecute(self, cache, split, eb):
        bi = buildinfo.BuildInfo()
        cache.side_effect = iter(['cmd.exe /c', 'explorer.exe'])
        eb.return_value = 0
        e = files.Execute([['cmd.exe /c', [0]], ['explorer.exe']], bi)
        e.Run()
        self.assertTrue(split.called)

        # success codes
        cache.side_effect = None
        cache.return_value = 'cmd.exe /c script.bat'
        e = files.Execute([['cmd.exe /c script.bat', [2, 4]]], bi)
        with self.assertRaises(files.ActionError):
            e.Run()
        eb.return_value = 4
        e.Run()

        # reboot codes - no retry
        e = files.Execute([['cmd.exe /c script.bat', [0], [2, 4]]], bi)
        with self.assertRaises(files.RestartEvent) as cm:
            e.Run()
        exception = cm.exception
        self.assertEqual(exception.retry_on_restart, False)

        # reboot codes -  retry
        e = files.Execute([['cmd.exe /c #script.bat', [0], [2, 4], True]], bi)
        with self.assertRaises(files.RestartEvent) as cm:
            e.Run()
        exception = cm.exception
        self.assertEqual(exception.retry_on_restart, True)
        cache.assert_called_with(mock.ANY, 'cmd.exe /c #script.bat', bi)

        # Shell
        files.Execute([['cmd.exe /c #script.bat', [4], [0], True, True]],
                      bi).Run()
        eb.assert_called_with(mock.ANY, mock.ANY, [4, 0], shell=True)

        # KeyboardInterrupt
        eb.side_effect = KeyboardInterrupt
        with self.assertRaises(files.ActionError):
            e.Run()

        # Execute Error
        eb.side_effect = files.execute.Error
        with self.assertRaises(files.ActionError):
            e.Run()

        # ValueError
        split.side_effect = ValueError
        with self.assertRaises(files.ActionError):
            e.Run()

        # Cache error
        cache.side_effect = files.cache.CacheError
        with self.assertRaises(files.ActionError):
            e.Run()
コード例 #2
0
    def testExecute(self, cache, sleep, mocked_popen):
        mocked_popen_instance = mocked_popen.return_value
        mocked_popen_instance.returncode = 0
        mocked_popen_instance.stdout = io.StringIO(u'Foo\n')
        bi = buildinfo.BuildInfo()
        cache.side_effect = iter(['cmd.exe /c', 'explorer.exe'])
        e = files.Execute([['cmd.exe /c', [0]], ['explorer.exe']], bi)
        e.Run()
        self.assertTrue(sleep.called)

        # success codes
        cache.side_effect = None
        cache.return_value = 'cmd.exe /c script.bat'
        e = files.Execute([['cmd.exe /c script.bat', [2, 4]]], bi)
        self.assertRaises(files.ActionError, e.Run)
        mocked_popen_instance.returncode = 4
        e.Run()

        # reboot codes - no retry
        e = files.Execute([['cmd.exe /c script.bat', [0], [2, 4]]], bi)
        with self.assertRaises(files.RestartEvent) as r_evt:
            e.Run()
            self.assertEqual(r_evt.retry_on_restart, False)

        # reboot codes -  retry
        e = files.Execute([['cmd.exe /c #script.bat', [0], [2, 4], True]], bi)
        with self.assertRaises(files.RestartEvent) as r_evt:
            e.Run()
            self.assertEqual(r_evt.retry_on_restart, True)
        cache.assert_called_with(mock.ANY, 'cmd.exe /c #script.bat', bi)
        self.assertTrue(sleep.called)

        # KeyboardInterrupt
        mocked_popen_instance.returncode = 0
        mocked_popen_instance.side_effect = KeyboardInterrupt
        e = files.Execute([['cmd.exe /c', [0]], ['explorer.exe']], bi)
        e.Run()

        # WindowsError
        files.WindowsError = Exception
        mocked_popen.return_value = files.WindowsError
        self.assertRaises(files.ActionError, e.Run)

        # Cache error
        mocked_popen_instance.return_value = None
        cache.side_effect = files.cache.CacheError
        self.assertRaises(files.ActionError, e.Run)
コード例 #3
0
    def testExecute(self, call, cache, sleep):
        bi = buildinfo.BuildInfo()
        cache.side_effect = iter(['cmd.exe /c', 'explorer.exe'])
        e = files.Execute([['cmd.exe /c', [0]], ['explorer.exe']], bi)
        call.return_value = 0
        e.Run()
        call.assert_has_calls([
            mock.call('cmd.exe /c', shell=True),
            mock.call('explorer.exe', shell=True)
        ])
        self.assertTrue(sleep.called)

        # success codes
        cache.side_effect = None
        cache.return_value = 'cmd.exe /c script.bat'
        e = files.Execute([['cmd.exe /c script.bat', [2, 4]]], bi)
        self.assertRaises(files.ActionError, e.Run)
        call.return_value = 4
        e.Run()

        # reboot codes - no retry
        e = files.Execute([['cmd.exe /c script.bat', [0], [2, 4]]], bi)
        with self.assertRaises(files.RestartEvent) as r_evt:
            e.Run()
            self.assertEqual(r_evt.retry_on_restart, False)

        # reboot codes -  retry
        e = files.Execute([['cmd.exe /c #script.bat', [0], [2, 4], True]], bi)
        with self.assertRaises(files.RestartEvent) as r_evt:
            e.Run()
            self.assertEqual(r_evt.retry_on_restart, True)
        cache.assert_called_with(mock.ANY, 'cmd.exe /c #script.bat', bi)
        call.assert_called_with('cmd.exe /c script.bat', shell=True)

        # WindowsError
        files.WindowsError = Exception
        call.side_effect = files.WindowsError
        self.assertRaises(files.ActionError, e.Run)
        # KeyboardInterrupt
        call.side_effect = KeyboardInterrupt
        e = files.Execute([['cmd.exe /c', [0]], ['explorer.exe']], bi)
        e.Run()
        # Cache error
        call.side_effect = None
        call.return_value = 0
        cache.side_effect = files.cache.CacheError
        self.assertRaises(files.ActionError, e.Run)
コード例 #4
0
 def testExecuteValidation(self):
   e = files.Execute([['cmd.exe', [0], [2], False], ['explorer.exe']], None)
   e.Validate()
   e = files.Execute([[]], None)
   self.assertRaises(files.ValidationError, e.Validate)
   e = files.Execute(['explorer.exe'], None)
   self.assertRaises(files.ValidationError, e.Validate)
   e = files.Execute('explorer.exe', None)
   self.assertRaises(files.ValidationError, e.Validate)
   e = files.Execute([['cmd.exe', [0]], ['explorer.exe', '0']], None)
   self.assertRaises(files.ValidationError, e.Validate)
   e = files.Execute([['cmd.exe', [0]], ['explorer.exe', ['0']]], None)
   self.assertRaises(files.ValidationError, e.Validate)
   e = files.Execute([['cmd.exe', [0], ['2']], ['explorer.exe']], None)
   self.assertRaises(files.ValidationError, e.Validate)
   e = files.Execute([['cmd.exe', [0], [2], 'True'], ['explorer.exe']], None)
   self.assertRaises(files.ValidationError, e.Validate)
   with self.assertRaises(files.ValidationError):
     files.Execute([['cmd.exe', [0], [2], False, 'True'], ['explorer.exe']],
                   None).Validate()