Fixes "stores" property added to the image

"stores" property gets added to the image when
`glance image-create-via-import` is called with --stores

Change-Id: I514e6e3ac2f3a1f56fb7883ed403a04b1e7f13b0
Closes-Bug: #1889666
This commit is contained in:
Erno Kuvaja 2020-07-30 18:39:31 +01:00
parent a29c6be97d
commit 77eab17cf9
3 changed files with 59 additions and 0 deletions

View File

@ -1557,6 +1557,56 @@ class ShellV2Test(testtools.TestCase):
'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd',
'container_format': 'bare', 'status': 'queued'})
@mock.patch('glanceclient.v2.shell.do_image_import')
@mock.patch('glanceclient.v2.shell.do_image_stage')
@mock.patch('sys.stdin', autospec=True)
def test_do_image_create_via_import_with_web_download_with_stores(
self, mock_stdin, mock_do_image_stage, mock_do_image_import):
temp_args = {'name': 'IMG-01',
'disk_format': 'vhd',
'container_format': 'bare',
'uri': 'http://example.com/image.qcow',
'import_method': 'web-download',
'progress': False,
'stores': 'file1,file2'}
tmp2_args = {'name': 'IMG-01',
'disk_format': 'vhd',
'container_format': 'bare',
'uri': 'http://example.com/image.qcow',
'import_method': 'web-download',
'progress': False}
args = self._make_args(temp_args)
with mock.patch.object(self.gc.images, 'create') as mocked_create:
with mock.patch.object(self.gc.images, 'get') as mocked_get:
with mock.patch.object(self.gc.images,
'get_import_info') as mocked_info:
with mock.patch.object(self.gc.images,
'get_stores_info') as m_stores_info:
ignore_fields = ['self', 'access', 'schema']
expect_image = dict([(field, field) for field in
ignore_fields])
expect_image['id'] = 'pass'
expect_image['name'] = 'IMG-01'
expect_image['disk_format'] = 'vhd'
expect_image['container_format'] = 'bare'
expect_image['status'] = 'queued'
mocked_create.return_value = expect_image
mocked_get.return_value = expect_image
mocked_info.return_value = self.import_info_response
m_stores_info.return_value = self.stores_info_response
mock_stdin.isatty = lambda: True
test_shell.do_image_create_via_import(self.gc, args)
mock_do_image_stage.assert_not_called()
mock_do_image_import.assert_called_once()
mocked_create.assert_called_once_with(**tmp2_args)
mocked_get.assert_called_with('pass')
utils.print_dict.assert_called_with({
'id': 'pass', 'name': 'IMG-01',
'disk_format': 'vhd',
'container_format': 'bare', 'status': 'queued'})
def test_do_image_update_no_user_props(self):
args = self._make_args({'id': 'pass', 'name': 'IMG-01',
'disk_format': 'vhd',

View File

@ -235,6 +235,9 @@ def do_image_create_via_import(gc, args):
# determine if backend is valid
_validate_backend(backend, gc)
elif stores:
# NOTE(jokke): Making sure here that we do not include the stores in
# the create call
fields.pop("stores")
stores = str(stores).split(',')
for store in stores:
# determine if backend is valid

View File

@ -0,0 +1,6 @@
---
fixes:
- |
Bug 1889666_: 'stores' property added when using image-create-via-import --stores <list>
.. _1889666: https://bugs.launchpad.net/glance/+bug/1889666