v2: Allow upload from stdin on image-create
For example: $ glance --os-image-api-version 2 image-create < /tmp/data This is consistent with v1. DocImpact Closes-bug: 1408033 Change-Id: Ifed4ece9e4e02a46d80b49a8e4fc372f1a304241
This commit is contained in:
@@ -43,7 +43,8 @@ def get_image_schema():
|
||||
' May be used multiple times.'))
|
||||
@utils.arg('--file', metavar='<FILE>',
|
||||
help='Local file that contains disk image to be uploaded '
|
||||
'during creation.')
|
||||
'during creation. Alternatively, images can be passed '
|
||||
'to the client via stdin.')
|
||||
@utils.arg('--progress', action='store_true', default=False,
|
||||
help='Show upload progress bar.')
|
||||
def do_image_create(gc, args):
|
||||
@@ -66,7 +67,7 @@ def do_image_create(gc, args):
|
||||
"privileges to it" % file_name)
|
||||
image = gc.images.create(**fields)
|
||||
try:
|
||||
if file_name is not None:
|
||||
if utils.get_data_file(args) is not None:
|
||||
args.id = image['id']
|
||||
args.size = None
|
||||
do_image_upload(gc, args)
|
||||
|
@@ -131,9 +131,11 @@ class ShellV2Test(testtools.TestCase):
|
||||
utils.print_dict.assert_called_once_with({'id': 'pass'},
|
||||
max_column_width=120)
|
||||
|
||||
def test_do_image_create_no_user_props(self):
|
||||
@mock.patch('sys.stdin', autospec=True)
|
||||
def test_do_image_create_no_user_props(self, mock_stdin):
|
||||
args = self._make_args({'name': 'IMG-01', 'disk_format': 'vhd',
|
||||
'container_format': 'bare'})
|
||||
'container_format': 'bare',
|
||||
'file': None})
|
||||
with mock.patch.object(self.gc.images, 'create') as mocked_create:
|
||||
ignore_fields = ['self', 'access', 'file', 'schema']
|
||||
expect_image = dict([(field, field) for field in ignore_fields])
|
||||
@@ -143,6 +145,9 @@ class ShellV2Test(testtools.TestCase):
|
||||
expect_image['container_format'] = 'bare'
|
||||
mocked_create.return_value = expect_image
|
||||
|
||||
# Ensure that the test stdin is not considered
|
||||
# to be supplying image data
|
||||
mock_stdin.isatty = lambda: True
|
||||
test_shell.do_image_create(self.gc, args)
|
||||
|
||||
mocked_create.assert_called_once_with(name='IMG-01',
|
||||
@@ -193,9 +198,11 @@ class ShellV2Test(testtools.TestCase):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def test_do_image_create_with_user_props(self):
|
||||
@mock.patch('sys.stdin', autospec=True)
|
||||
def test_do_image_create_with_user_props(self, mock_stdin):
|
||||
args = self._make_args({'name': 'IMG-01',
|
||||
'property': ['myprop=myval']})
|
||||
'property': ['myprop=myval'],
|
||||
'file': None})
|
||||
with mock.patch.object(self.gc.images, 'create') as mocked_create:
|
||||
ignore_fields = ['self', 'access', 'file', 'schema']
|
||||
expect_image = dict([(field, field) for field in ignore_fields])
|
||||
@@ -204,6 +211,9 @@ class ShellV2Test(testtools.TestCase):
|
||||
expect_image['myprop'] = 'myval'
|
||||
mocked_create.return_value = expect_image
|
||||
|
||||
# Ensure that the test stdin is not considered
|
||||
# to be supplying image data
|
||||
mock_stdin.isatty = lambda: True
|
||||
test_shell.do_image_create(self.gc, args)
|
||||
|
||||
mocked_create.assert_called_once_with(name='IMG-01',
|
||||
|
Reference in New Issue
Block a user