diff options
author | Abhishek Kekane <akekane@redhat.com> | 2018-06-29 10:29:04 +0000 |
---|---|---|
committer | Brian Rosmaita <rosmaita.fossdev@gmail.com> | 2018-07-25 10:27:28 -0400 |
commit | d7fbd0a516596a56ce7728142621c9034e6c82b7 (patch) | |
tree | bd37124b7a37ca4a585a496a56ae4bf6a60d2056 /glanceclient/tests | |
parent | ccbd86ba131d319e512bf4855e9b3152cc073fee (diff) | |
download | python-glanceclient-d7fbd0a516596a56ce7728142621c9034e6c82b7.tar.gz |
Add support for hide old images
Added --hidden argument to list, create and
update call.
Related to blueprint hidden-images
Change-Id: I1f2dcaa545c9da883186b20a96a70c7df994b994
Diffstat (limited to 'glanceclient/tests')
-rw-r--r-- | glanceclient/tests/unit/v2/test_shell_v2.py | 131 |
1 files changed, 123 insertions, 8 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py index 83fa526..6eeca83 100644 --- a/glanceclient/tests/unit/v2/test_shell_v2.py +++ b/glanceclient/tests/unit/v2/test_shell_v2.py @@ -263,7 +263,8 @@ class ShellV2Test(testtools.TestCase): 'sort_key': ['name', 'id'], 'sort_dir': ['desc', 'asc'], 'sort': None, - 'verbose': False + 'verbose': False, + 'os_hidden': False } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -276,7 +277,44 @@ class ShellV2Test(testtools.TestCase): 'member_status': 'Fake', 'visibility': True, 'checksum': 'fake_checksum', - 'tag': 'fake tag' + 'tag': 'fake tag', + 'os_hidden': False + } + mocked_list.assert_called_once_with(page_size=18, + sort_key=['name', 'id'], + sort_dir=['desc', 'asc'], + filters=exp_img_filters) + utils.print_list.assert_called_once_with({}, ['ID', 'Name']) + + def test_do_image_list_with_hidden_true(self): + input = { + 'limit': None, + 'page_size': 18, + 'visibility': True, + 'member_status': 'Fake', + 'owner': 'test', + 'checksum': 'fake_checksum', + 'tag': 'fake tag', + 'properties': [], + 'sort_key': ['name', 'id'], + 'sort_dir': ['desc', 'asc'], + 'sort': None, + 'verbose': False, + 'os_hidden': True + } + args = self._make_args(input) + with mock.patch.object(self.gc.images, 'list') as mocked_list: + mocked_list.return_value = {} + + test_shell.do_image_list(self.gc, args) + + exp_img_filters = { + 'owner': 'test', + 'member_status': 'Fake', + 'visibility': True, + 'checksum': 'fake_checksum', + 'tag': 'fake tag', + 'os_hidden': True } mocked_list.assert_called_once_with(page_size=18, sort_key=['name', 'id'], @@ -297,7 +335,8 @@ class ShellV2Test(testtools.TestCase): 'sort_key': ['name'], 'sort_dir': ['desc'], 'sort': None, - 'verbose': False + 'verbose': False, + 'os_hidden': False } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -310,7 +349,8 @@ class ShellV2Test(testtools.TestCase): 'member_status': 'Fake', 'visibility': True, 'checksum': 'fake_checksum', - 'tag': 'fake tag' + 'tag': 'fake tag', + 'os_hidden': False } mocked_list.assert_called_once_with(page_size=18, sort_key=['name'], @@ -331,7 +371,8 @@ class ShellV2Test(testtools.TestCase): 'sort': 'name:desc,size:asc', 'sort_key': [], 'sort_dir': [], - 'verbose': False + 'verbose': False, + 'os_hidden': False } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -344,7 +385,8 @@ class ShellV2Test(testtools.TestCase): 'member_status': 'Fake', 'visibility': True, 'checksum': 'fake_checksum', - 'tag': 'fake tag' + 'tag': 'fake tag', + 'os_hidden': False } mocked_list.assert_called_once_with( page_size=18, @@ -365,7 +407,8 @@ class ShellV2Test(testtools.TestCase): 'sort_key': ['name'], 'sort_dir': ['desc'], 'sort': None, - 'verbose': False + 'verbose': False, + 'os_hidden': False } args = self._make_args(input) with mock.patch.object(self.gc.images, 'list') as mocked_list: @@ -380,7 +423,8 @@ class ShellV2Test(testtools.TestCase): 'checksum': 'fake_checksum', 'tag': 'fake tag', 'os_distro': 'NixOS', - 'architecture': 'x86_64' + 'architecture': 'x86_64', + 'os_hidden': False } mocked_list.assert_called_once_with(page_size=1, @@ -527,6 +571,35 @@ class ShellV2Test(testtools.TestCase): except Exception: pass + @mock.patch('sys.stdin', autospec=True) + def test_do_image_create_hidden_image(self, mock_stdin): + args = self._make_args({'name': 'IMG-01', 'disk_format': 'vhd', + 'container_format': 'bare', + 'file': None, + 'os_hidden': True}) + 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]) + expect_image['id'] = 'pass' + expect_image['name'] = 'IMG-01' + expect_image['disk_format'] = 'vhd' + expect_image['container_format'] = 'bare' + expect_image['os_hidden'] = True + 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', + disk_format='vhd', + container_format='bare', + os_hidden=True) + utils.print_dict.assert_called_once_with({ + 'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd', + 'container_format': 'bare', 'os_hidden': True}) + def test_do_image_create_with_file(self): self.mock_get_data_file.return_value = six.StringIO() try: @@ -1256,6 +1329,48 @@ class ShellV2Test(testtools.TestCase): 'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd', 'container_format': 'bare'}) + def test_do_image_update_hide_image(self): + args = self._make_args({'id': 'pass', 'os_hidden': 'true'}) + with mock.patch.object(self.gc.images, 'update') as mocked_update: + ignore_fields = ['self', 'access', 'file', '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['os_hidden'] = True + mocked_update.return_value = expect_image + + test_shell.do_image_update(self.gc, args) + + mocked_update.assert_called_once_with('pass', + None, + os_hidden='true') + utils.print_dict.assert_called_once_with({ + 'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd', + 'container_format': 'bare', 'os_hidden': True}) + + def test_do_image_update_revert_hide_image(self): + args = self._make_args({'id': 'pass', 'os_hidden': 'false'}) + with mock.patch.object(self.gc.images, 'update') as mocked_update: + ignore_fields = ['self', 'access', 'file', '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['os_hidden'] = False + mocked_update.return_value = expect_image + + test_shell.do_image_update(self.gc, args) + + mocked_update.assert_called_once_with('pass', + None, + os_hidden='false') + utils.print_dict.assert_called_once_with({ + 'id': 'pass', 'name': 'IMG-01', 'disk_format': 'vhd', + 'container_format': 'bare', 'os_hidden': False}) + def test_do_image_update_with_user_props(self): args = self._make_args({'id': 'pass', 'name': 'IMG-01', 'property': ['myprop=myval']}) |