Skip to content

Commit bafece7

Browse files
committed
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>
1 parent 31881c0 commit bafece7

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

openstackclient/image/v2/image.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ def _take_action_image(self, parsed_args):
476476
LOG.warning(_("Failed to get an image file."))
477477
return {}, {}
478478

479-
if fp is not None and parsed_args.progress:
479+
if parsed_args.progress and parsed_args.file:
480+
# NOTE(stephenfin): we only show a progress bar if the user
481+
# requested it *and* we're reading from a file (not stdin)
480482
filesize = os.path.getsize(fname)
481483
if filesize is not None:
482484
kwargs['validate_checksum'] = False

openstackclient/tests/unit/image/v2/test_image.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,37 @@ def test_image_create_file(self):
252252
self.expected_data,
253253
data)
254254

255+
@mock.patch('openstackclient.image.v2.image.get_data_file')
256+
def test_image_create__progress_ignore_with_stdin(
257+
self, mock_get_data_file,
258+
):
259+
fake_stdin = io.StringIO('fake-image-data')
260+
mock_get_data_file.return_value = (fake_stdin, None)
261+
262+
arglist = [
263+
'--progress',
264+
self.new_image.name,
265+
]
266+
verifylist = [
267+
('progress', True),
268+
('name', self.new_image.name),
269+
]
270+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
271+
272+
columns, data = self.cmd.take_action(parsed_args)
273+
274+
self.client.create_image.assert_called_with(
275+
name=self.new_image.name,
276+
allow_duplicates=True,
277+
container_format=image.DEFAULT_CONTAINER_FORMAT,
278+
disk_format=image.DEFAULT_DISK_FORMAT,
279+
data=fake_stdin,
280+
validate_checksum=False,
281+
)
282+
283+
self.assertEqual(self.expected_columns, columns)
284+
self.assertCountEqual(self.expected_data, data)
285+
255286
def test_image_create_dead_options(self):
256287

257288
arglist = [

0 commit comments

Comments
 (0)