image: Ignore '--progress' if providing image data from stdin

You can provide data via stdin when creating an image. Using this with
'--progress' makes no sense and causes an error currently. Fix this.

Change-Id: I3c2d658b72a7c62931b779b0d19bb97f60a0c655
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
This commit is contained in:
Stephen Finucane 2022-10-21 16:40:36 +01:00
parent 31881c0b2b
commit bafece762a
2 changed files with 34 additions and 1 deletions

View File

@ -476,7 +476,9 @@ class CreateImage(command.ShowOne):
LOG.warning(_("Failed to get an image file."))
return {}, {}
if fp is not None and parsed_args.progress:
if parsed_args.progress and parsed_args.file:
# NOTE(stephenfin): we only show a progress bar if the user
# requested it *and* we're reading from a file (not stdin)
filesize = os.path.getsize(fname)
if filesize is not None:
kwargs['validate_checksum'] = False

View File

@ -252,6 +252,37 @@ class TestImageCreate(TestImage):
self.expected_data,
data)
@mock.patch('openstackclient.image.v2.image.get_data_file')
def test_image_create__progress_ignore_with_stdin(
self, mock_get_data_file,
):
fake_stdin = io.StringIO('fake-image-data')
mock_get_data_file.return_value = (fake_stdin, None)
arglist = [
'--progress',
self.new_image.name,
]
verifylist = [
('progress', True),
('name', self.new_image.name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
self.client.create_image.assert_called_with(
name=self.new_image.name,
allow_duplicates=True,
container_format=image.DEFAULT_CONTAINER_FORMAT,
disk_format=image.DEFAULT_DISK_FORMAT,
data=fake_stdin,
validate_checksum=False,
)
self.assertEqual(self.expected_columns, columns)
self.assertCountEqual(self.expected_data, data)
def test_image_create_dead_options(self):
arglist = [