check makefs.sh return code
This commit is contained in:
parent
078ff09e94
commit
dac1996eb4
teeth_agent
@ -84,3 +84,15 @@ class ImageChecksumError(errors.RESTError):
|
||||
details = details.format(image_id)
|
||||
super(ImageChecksumError, self).__init__()
|
||||
self.details = details
|
||||
|
||||
|
||||
class ImageWriteError(errors.RESTError):
|
||||
"""Error raised when an image cannot be written to a device."""
|
||||
|
||||
message = 'Error writing image to device.'
|
||||
|
||||
def __init__(self, exit_code, device):
|
||||
details = 'Writing image to device {} failed with exit code {}.'
|
||||
details = details.format(device, exit_code)
|
||||
super(ImageWriteError, self).__init__()
|
||||
self.details = details
|
||||
|
@ -40,13 +40,15 @@ def _write_local_config_drive(location, data):
|
||||
|
||||
|
||||
def _write_image(image_info, configdrive_dir, device):
|
||||
# TODO(jimrollenhagen) don't hardcode these kwargs
|
||||
image = _image_location(image_info)
|
||||
|
||||
cwd = os.path.dirname(os.path.realpath(__file__))
|
||||
script = os.path.join(cwd, 'shell/makefs.sh')
|
||||
command = ['/bin/bash', script, configdrive_dir, image, device]
|
||||
return subprocess.call(command)
|
||||
|
||||
exit_code = subprocess.call(command)
|
||||
if exit_code != 0:
|
||||
raise errors.ImageWriteError(exit_code, device)
|
||||
|
||||
|
||||
def _request_url(image_info, url):
|
||||
|
@ -86,7 +86,7 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
|
||||
@mock.patch('__builtin__.open', autospec=True)
|
||||
@mock.patch('subprocess.call', autospec=True)
|
||||
def test_write_image(self, call_mock, open_mock):
|
||||
def test_write_image_success(self, call_mock, open_mock):
|
||||
image_info = self._build_fake_image_info()
|
||||
configdrive = 'configdrive'
|
||||
device = '/dev/sda'
|
||||
@ -94,10 +94,31 @@ class TestBaseTeethAgent(unittest.TestCase):
|
||||
standby_dir = os.path.dirname(os.path.realpath(standby.__file__))
|
||||
script = os.path.join(standby_dir, 'shell/makefs.sh')
|
||||
command = ['/bin/bash', script, configdrive, location, device]
|
||||
call_mock.return_value = 0
|
||||
|
||||
standby._write_image(image_info,
|
||||
configdrive=configdrive,
|
||||
device=device)
|
||||
configdrive,
|
||||
device)
|
||||
call_mock.assert_called_once_with(command)
|
||||
|
||||
@mock.patch('__builtin__.open', autospec=True)
|
||||
@mock.patch('subprocess.call', autospec=True)
|
||||
def test_write_image_failure(self, call_mock, open_mock):
|
||||
image_info = self._build_fake_image_info()
|
||||
configdrive = 'configdrive'
|
||||
device = '/dev/sda'
|
||||
location = standby._image_location(image_info)
|
||||
standby_dir = os.path.dirname(os.path.realpath(standby.__file__))
|
||||
script = os.path.join(standby_dir, 'shell/makefs.sh')
|
||||
command = ['/bin/bash', script, configdrive, location, device]
|
||||
call_mock.return_value = 1
|
||||
|
||||
self.assertRaises(errors.ImageWriteError,
|
||||
standby._write_image,
|
||||
image_info,
|
||||
configdrive,
|
||||
device)
|
||||
|
||||
call_mock.assert_called_once_with(command)
|
||||
|
||||
@mock.patch('__builtin__.open', autospec=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user