Exemple #1
0
 def test__default(self):
     mock_run_smartctl = self.patch(smartctl, 'run_smartctl')
     blockdevice = factory.make_name('blockdevice')
     test = factory.make_name('test')
     device = factory.make_name('device')
     smartctl.run_smartctl_selftest(blockdevice, test, device)
     self.assertThat(
         mock_run_smartctl,
         MockCalledOnceWith(blockdevice, ['-t', test],
                            device,
                            output=True,
                            stderr=DEVNULL))
Exemple #2
0
 def test_default(self):
     mock_run_smartctl = self.patch(smartctl, "run_smartctl")
     blockdevice = factory.make_name("blockdevice")
     test = factory.make_name("test")
     device = factory.make_name("device")
     smartctl.run_smartctl_selftest(blockdevice, test, device)
     self.assertThat(
         mock_run_smartctl,
         MockCalledOnceWith(blockdevice, ["-t", test],
                            device,
                            output=True,
                            stderr=DEVNULL),
     )
Exemple #3
0
    def test_run_smartctl_selftest_sets_failure_on_exec_fail_test_start(self):
        storage = factory.make_name('storage')
        test = factory.make_name('test')
        mock_check_call = self.patch(smartctl, 'check_call')
        mock_check_call.side_effect = CalledProcessError(1, 'smartctl')
        mock_check_output = self.patch(smartctl, 'check_output')

        self.assertFalse(smartctl.run_smartctl_selftest(storage, test))
        self.assertThat(
            mock_check_call,
            MockCalledOnceWith(
                ['sudo', '-n', 'smartctl', '-s', 'on', '-t', test, storage],
                timeout=smartctl.TIMEOUT,
                stdout=DEVNULL,
                stderr=DEVNULL))
        self.assertThat(mock_check_output, MockNotCalled())
Exemple #4
0
    def test_run_smartctl_selftest_sets_failure_on_timeout_status_check(self):
        storage = factory.make_name('storage')
        test = factory.make_name('test')
        mock_check_call = self.patch(smartctl, 'check_call')
        mock_check_output = self.patch(smartctl, 'check_output')
        mock_check_output.side_effect = TimeoutExpired('smartctl', 60)

        self.assertFalse(smartctl.run_smartctl_selftest(storage, test))
        self.assertThat(
            mock_check_call,
            MockCalledOnceWith(
                ['sudo', '-n', 'smartctl', '-s', 'on', '-t', test, storage],
                timeout=smartctl.TIMEOUT,
                stdout=DEVNULL,
                stderr=DEVNULL))
        self.assertThat(
            mock_check_output,
            MockCalledOnceWith(['sudo', '-n', 'smartctl', '-c', storage],
                               timeout=smartctl.TIMEOUT))
Exemple #5
0
    def test_run_smartctl_selftest(self):
        storage = factory.make_name('storage')
        test = factory.make_name('test')
        mock_check_call = self.patch(smartctl, "check_call")
        mock_check_output = self.patch(smartctl, "check_output")
        mock_check_output.return_value = (
            b'Self-test execution status:      (   0)')

        self.assertTrue(smartctl.run_smartctl_selftest(storage, test))
        self.assertThat(
            mock_check_call,
            MockCalledOnceWith(
                ['sudo', '-n', 'smartctl', '-s', 'on', '-t', test, storage],
                timeout=smartctl.TIMEOUT,
                stdout=DEVNULL,
                stderr=DEVNULL))
        self.assertThat(
            mock_check_output,
            MockCalledOnceWith(['sudo', '-n', 'smartctl', '-c', storage],
                               timeout=smartctl.TIMEOUT))
Exemple #6
0
    def test_run_smartctl_selftest_waits_for_finish(self):
        storage = factory.make_name('storage')
        test = factory.make_name('test')
        self.patch(smartctl, 'sleep')
        mock_check_call = self.patch(smartctl, "check_call")
        mock_check_output = self.patch(smartctl, "check_output")
        mock_check_output.side_effect = [
            b'Self-test execution status:      ( 249) ' +
            b'Self-test routine in progress...',
            b'Self-test execution status:      ( 249) ' +
            b'Self-test routine in progress...',
            b'Self-test execution status:      ( 249) ' +
            b'Self-test routine in progress...',
            b'Self-test execution status:      (  73) ' +
            b'The previous self-test completed having',
        ]

        self.assertTrue(smartctl.run_smartctl_selftest(storage, test))
        self.assertThat(
            mock_check_call,
            MockCalledOnceWith(
                ['sudo', '-n', 'smartctl', '-s', 'on', '-t', test, storage],
                timeout=smartctl.TIMEOUT,
                stdout=DEVNULL,
                stderr=DEVNULL))
        self.assertThat(
            mock_check_output,
            MockCallsMatch(
                call(['sudo', '-n', 'smartctl', '-c', storage],
                     timeout=smartctl.TIMEOUT),
                call(['sudo', '-n', 'smartctl', '-c', storage],
                     timeout=smartctl.TIMEOUT),
                call(['sudo', '-n', 'smartctl', '-c', storage],
                     timeout=smartctl.TIMEOUT),
                call(['sudo', '-n', 'smartctl', '-c', storage],
                     timeout=smartctl.TIMEOUT)))