summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2022-10-21 16:40:36 +0100
committerStephen Finucane <sfinucan@redhat.com>2022-11-09 16:51:54 +0000
commitbafece762a5d0b03e28f9d81c98ad46777f56a34 (patch)
tree88f0dc354190802b7875e8e4d969e56f080489f6 /openstackclient
parent31881c0b2b6581e16a1d802b01a52d2b2eefb750 (diff)
downloadpython-openstackclient-bafece762a5d0b03e28f9d81c98ad46777f56a34.tar.gz
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>
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/image/v2/image.py4
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py31
2 files changed, 34 insertions, 1 deletions
diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py
index 2342fd3e..1ff8ad3a 100644
--- a/openstackclient/image/v2/image.py
+++ b/openstackclient/image/v2/image.py
@@ -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
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index f2c11364..e17363a5 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -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 = [