Image upload: handle whole-disk image as default
For the image upload command, if overcloud-hardened-uefi-full.qcow2
file exists in the --image-path directory then this will be used as
the default value of --os-image-path.
If overcloud-hardened-uefi-full.qcow2 is the explicit or implicit
value of --os-image-path then --whole-disk will be implicitly set.
Otherwise the current default behaviour will continue (default image
overcloud-full.qcow2, whole-disk flag defaults to false)
With this change, the documentation can continue to call this command
without extra arguments whether uploading a whole-disk or partition
overcloud image.
Change-Id: I15e6148bafac05d8800665bf6b7268bec49dad6f
Blueprint: whole-disk-default
(cherry picked from commit 915ddcb615)
This commit is contained in:
@@ -282,3 +282,5 @@ KIND_TEMPLATES = {'roles': WD_DEFAULT_ROLES_FILE_NAME,
|
||||
'networks': WD_DEFAULT_NETWORKS_FILE_NAME,
|
||||
'baremetal': WD_DEFAULT_BAREMETAL_FILE_NAME,
|
||||
'vips': WD_DEFAULT_VIP_FILE_NAME}
|
||||
DEFAULT_PARTITION_IMAGE = 'overcloud-full.qcow2'
|
||||
DEFAULT_WHOLE_DISK_IMAGE = 'overcloud-hardened-uefi-full.qcow2'
|
||||
|
||||
@@ -519,6 +519,23 @@ class TestUploadOvercloudImage(TestPluginV1):
|
||||
'default-value',
|
||||
deprecated=['OLD_KEY']))
|
||||
|
||||
@mock.patch('os.path.exists')
|
||||
def test_get_image_filename(self, mock_exists):
|
||||
mock_exists.return_value = False
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, [], [])
|
||||
self.assertEqual('overcloud-full.qcow2',
|
||||
self.cmd._get_image_filename(parsed_args))
|
||||
|
||||
mock_exists.return_value = True
|
||||
self.assertEqual('overcloud-hardened-uefi-full.qcow2',
|
||||
self.cmd._get_image_filename(parsed_args))
|
||||
|
||||
parsed_args = self.check_parser(
|
||||
self.cmd, ['--os-image-name', 'overcloud-custom.qcow2'], [])
|
||||
self.assertEqual('overcloud-custom.qcow2',
|
||||
self.cmd._get_image_filename(parsed_args))
|
||||
|
||||
def test_platform_without_architecture_fail(self):
|
||||
parsed_args = self.check_parser(self.cmd, ['--platform', 'SNB'], [])
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
@@ -1220,6 +1237,43 @@ class TestUploadOnlyExisting(TestPluginV1):
|
||||
'./overcloud-full.raw'
|
||||
)
|
||||
|
||||
@mock.patch('subprocess.check_call', autospec=True)
|
||||
@mock.patch('os.path.isfile', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_image.'
|
||||
'GlanceClientAdapter._image_try_update', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_image.'
|
||||
'GlanceClientAdapter._image_changed', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_image.'
|
||||
'BaseClientAdapter._files_changed', autospec=True)
|
||||
def test_overcloud_upload_os_wholedisk_default(self,
|
||||
mock_files_changed,
|
||||
mock_image_changed,
|
||||
mock_image_try_update,
|
||||
mock_isfile_call,
|
||||
mock_subprocess_call):
|
||||
mock_image_changed.return_value = True
|
||||
mock_image_try_update.return_value = None
|
||||
|
||||
parsed_args = self.check_parser(
|
||||
self.cmd, ['--image-type=os',
|
||||
'--no-local',
|
||||
'--os-image-name',
|
||||
'overcloud-hardened-uefi-full.qcow2'], [])
|
||||
|
||||
mock_files_changed.return_value = True
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# ensure check_file_exists has been called just with ipa
|
||||
self.cmd.adapter.check_file_exists.assert_called_once_with(
|
||||
self.cmd.adapter, './overcloud-hardened-uefi-full.qcow2')
|
||||
|
||||
# ensure try_update has been called just with ipa
|
||||
mock_image_try_update.assert_called_once_with(
|
||||
self.cmd.adapter,
|
||||
'overcloud-hardened-uefi-full',
|
||||
'./overcloud-hardened-uefi-full.raw'
|
||||
)
|
||||
|
||||
@mock.patch('subprocess.check_call', autospec=True)
|
||||
@mock.patch('os.path.isfile', autospec=True)
|
||||
@mock.patch('tripleoclient.v1.overcloud_image.'
|
||||
|
||||
@@ -426,6 +426,14 @@ class UploadOvercloudImage(command.Command):
|
||||
return os.environ.get(env_key)
|
||||
return os.environ.get(envvar, default)
|
||||
|
||||
def _get_image_filename(self, parsed_args):
|
||||
if parsed_args.os_image_name:
|
||||
return parsed_args.os_image_name
|
||||
if os.path.exists(os.path.join(parsed_args.image_path,
|
||||
constants.DEFAULT_WHOLE_DISK_IMAGE)):
|
||||
return constants.DEFAULT_WHOLE_DISK_IMAGE
|
||||
return constants.DEFAULT_PARTITION_IMAGE
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UploadOvercloudImage, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
@@ -435,8 +443,7 @@ class UploadOvercloudImage(command.Command):
|
||||
)
|
||||
parser.add_argument(
|
||||
"--os-image-name",
|
||||
default=self._get_environment_var('OS_IMAGE_NAME',
|
||||
'overcloud-full.qcow2'),
|
||||
default=self._get_environment_var('OS_IMAGE_NAME', None),
|
||||
help=_("OpenStack disk image filename"),
|
||||
)
|
||||
parser.add_argument(
|
||||
@@ -537,21 +544,25 @@ class UploadOvercloudImage(command.Command):
|
||||
self.log.debug("checking if image files exist")
|
||||
|
||||
image_files = []
|
||||
image_filename = self._get_image_filename(parsed_args)
|
||||
image_name = os.path.splitext(image_filename)[0]
|
||||
|
||||
if image_filename == constants.DEFAULT_WHOLE_DISK_IMAGE:
|
||||
parsed_args.whole_disk = True
|
||||
|
||||
if parsed_args.image_type is None or \
|
||||
parsed_args.image_type == 'ironic-python-agent':
|
||||
image_files.append('%s.initramfs' % parsed_args.ipa_name)
|
||||
image_files.append('%s.kernel' % parsed_args.ipa_name)
|
||||
|
||||
if parsed_args.image_type is None or parsed_args.image_type == 'os':
|
||||
image_files.append(parsed_args.os_image_name)
|
||||
image_files.append(image_filename)
|
||||
|
||||
if parsed_args.whole_disk:
|
||||
overcloud_image_type = 'whole disk'
|
||||
else:
|
||||
overcloud_image_type = 'partition'
|
||||
|
||||
image_name = parsed_args.os_image_name.split('.')[0]
|
||||
|
||||
for image in image_files:
|
||||
extension = image.split('.')[-1]
|
||||
image_path = os.path.join(parsed_args.image_path, image)
|
||||
@@ -562,8 +573,6 @@ class UploadOvercloudImage(command.Command):
|
||||
image_path,
|
||||
os.path.join(parsed_args.image_path, image_name + '.raw'))
|
||||
|
||||
image_name = parsed_args.os_image_name.split('.')[0]
|
||||
|
||||
self.log.debug("uploading %s overcloud images " %
|
||||
overcloud_image_type)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user