Example #1
0
    def test_run_image(self, call_mock):
        script = standby._path_to_script('shell/reboot.sh')
        command = ['/bin/bash', script]
        call_mock.return_value = 0

        success_result = self.agent_mode.run_image('run_image')
        success_result.join()
        call_mock.assert_called_once_with(command)

        call_mock.reset_mock()
        call_mock.return_value = 1

        failed_result = self.agent_mode.run_image('run_image')
        failed_result.join()

        call_mock.assert_called_once_with(command)
        self.assertEqual('FAILED', failed_result.command_status)
Example #2
0
    def test_copy_configdrive_to_disk(self, call_mock, open_mock):
        device = '/dev/sda'
        configdrive = 'configdrive'
        script = standby._path_to_script('shell/copy_configdrive_to_disk.sh')
        command = ['/bin/bash', script, configdrive, device]
        call_mock.return_value = 0

        standby._copy_configdrive_to_disk(configdrive, device)
        call_mock.assert_called_once_with(command)

        call_mock.reset_mock()
        call_mock.return_value = 1

        self.assertRaises(errors.ConfigDriveWriteError,
                          standby._copy_configdrive_to_disk,
                          configdrive,
                          device)

        call_mock.assert_called_once_with(command)
Example #3
0
    def test_write_image(self, call_mock, open_mock):
        image_info = self._build_fake_image_info()
        device = '/dev/sda'
        location = standby._image_location(image_info)
        script = standby._path_to_script('shell/write_image.sh')
        command = ['/bin/bash', script, location, device]
        call_mock.return_value = 0

        standby._write_image(image_info, device)
        call_mock.assert_called_once_with(command)

        call_mock.reset_mock()
        call_mock.return_value = 1

        self.assertRaises(errors.ImageWriteError,
                          standby._write_image,
                          image_info,
                          device)

        call_mock.assert_called_once_with(command)