summaryrefslogtreecommitdiff
path: root/glanceclient/tests/unit
diff options
context:
space:
mode:
authorErno Kuvaja <jokke@usr.fi>2019-12-18 10:30:54 +0000
committerAbhishek Kekane <akekane@redhat.com>2020-02-27 05:52:49 +0000
commitc23d86738fcfd55301471e8da2512642fd66eba3 (patch)
treef6b1c876f98393e1aa0746795c3205bddb41395d /glanceclient/tests/unit
parent23fb691dfb2e27f8fe76574899f6ca68e6602b18 (diff)
downloadpython-glanceclient-c23d86738fcfd55301471e8da2512642fd66eba3.tar.gz
Add support for multi-store import
This change adds support for providing multiple target stores where image can be imported. Co-authored-by: Erno Kuvaja <jokke@usr.fi> Co-authored-by: Abhishek Kekane <akekane@redhat.com> bp: import-multi-stores Change-Id: I8730364263f1afd5d11fd56939851bda73a892bb
Diffstat (limited to 'glanceclient/tests/unit')
-rw-r--r--glanceclient/tests/unit/v2/test_shell_v2.py170
1 files changed, 167 insertions, 3 deletions
diff --git a/glanceclient/tests/unit/v2/test_shell_v2.py b/glanceclient/tests/unit/v2/test_shell_v2.py
index eb37500..994993c 100644
--- a/glanceclient/tests/unit/v2/test_shell_v2.py
+++ b/glanceclient/tests/unit/v2/test_shell_v2.py
@@ -871,6 +871,90 @@ class ShellV2Test(testtools.TestCase):
mock_utils_exit.assert_called_once_with(expected_msg)
@mock.patch('glanceclient.common.utils.exit')
+ def test_neg_image_create_via_import_stores_all_stores_specified(
+ self, mock_utils_exit):
+ expected_msg = ('Only one of --store, --stores and --all-stores can '
+ 'be provided')
+ mock_utils_exit.side_effect = self._mock_utils_exit
+ my_args = self.base_args.copy()
+ my_args.update(
+ {'id': 'IMG-01', 'import_method': 'glance-direct',
+ 'stores': 'file1,file2', 'os_all_stores': True,
+ 'file': 'some.mufile',
+ 'disk_format': 'raw',
+ 'container_format': 'bare',
+ })
+ args = self._make_args(my_args)
+
+ with mock.patch.object(self.gc.images,
+ 'get_import_info') as mocked_info:
+ mocked_info.return_value = self.import_info_response
+ try:
+ test_shell.do_image_create_via_import(self.gc, args)
+ self.fail("utils.exit should have been called")
+ except SystemExit:
+ pass
+ mock_utils_exit.assert_called_once_with(expected_msg)
+
+ @mock.patch('glanceclient.common.utils.exit')
+ @mock.patch('sys.stdin', autospec=True)
+ def test_neg_image_create_via_import_stores_without_file(
+ self, mock_stdin, mock_utils_exit):
+ expected_msg = ('--stores option should only be provided with --file '
+ 'option or stdin for the glance-direct import method.')
+ mock_utils_exit.side_effect = self._mock_utils_exit
+ mock_stdin.isatty = lambda: True
+ my_args = self.base_args.copy()
+ my_args.update(
+ {'id': 'IMG-01', 'import_method': 'glance-direct',
+ 'stores': 'file1,file2',
+ 'disk_format': 'raw',
+ 'container_format': 'bare',
+ })
+ args = self._make_args(my_args)
+
+ with mock.patch.object(self.gc.images,
+ 'get_import_info') as mocked_info:
+ with mock.patch.object(self.gc.images,
+ 'get_stores_info') as mocked_stores_info:
+ mocked_stores_info.return_value = self.stores_info_response
+ mocked_info.return_value = self.import_info_response
+ try:
+ test_shell.do_image_create_via_import(self.gc, args)
+ self.fail("utils.exit should have been called")
+ except SystemExit:
+ pass
+ mock_utils_exit.assert_called_once_with(expected_msg)
+
+ @mock.patch('glanceclient.common.utils.exit')
+ @mock.patch('sys.stdin', autospec=True)
+ def test_neg_image_create_via_import_all_stores_without_file(
+ self, mock_stdin, mock_utils_exit):
+ expected_msg = ('--all-stores option should only be provided with '
+ '--file option or stdin for the glance-direct import '
+ 'method.')
+ mock_utils_exit.side_effect = self._mock_utils_exit
+ mock_stdin.isatty = lambda: True
+ my_args = self.base_args.copy()
+ my_args.update(
+ {'id': 'IMG-01', 'import_method': 'glance-direct',
+ 'os_all_stores': True,
+ 'disk_format': 'raw',
+ 'container_format': 'bare',
+ })
+ args = self._make_args(my_args)
+
+ with mock.patch.object(self.gc.images,
+ 'get_import_info') as mocked_info:
+ mocked_info.return_value = self.import_info_response
+ try:
+ test_shell.do_image_create_via_import(self.gc, args)
+ self.fail("utils.exit should have been called")
+ except SystemExit:
+ pass
+ mock_utils_exit.assert_called_once_with(expected_msg)
+
+ @mock.patch('glanceclient.common.utils.exit')
@mock.patch('os.access')
@mock.patch('sys.stdin', autospec=True)
def test_neg_image_create_via_import_no_file_and_stdin_with_store(
@@ -1084,6 +1168,60 @@ class ShellV2Test(testtools.TestCase):
mock_utils_exit.assert_called_once_with(expected_msg)
@mock.patch('glanceclient.common.utils.exit')
+ def test_neg_image_create_via_import_stores_without_uri(
+ self, mock_utils_exit):
+ expected_msg = ('--stores option should only be provided with --uri '
+ 'option for the web-download import method.')
+ mock_utils_exit.side_effect = self._mock_utils_exit
+ my_args = self.base_args.copy()
+ my_args.update(
+ {'id': 'IMG-01', 'import_method': 'web-download',
+ 'stores': 'file1,file2',
+ 'disk_format': 'raw',
+ 'container_format': 'bare',
+ })
+ args = self._make_args(my_args)
+
+ with mock.patch.object(self.gc.images,
+ 'get_import_info') as mocked_info:
+ with mock.patch.object(self.gc.images,
+ 'get_stores_info') as mocked_stores_info:
+ mocked_stores_info.return_value = self.stores_info_response
+ mocked_info.return_value = self.import_info_response
+ try:
+ test_shell.do_image_create_via_import(self.gc, args)
+ self.fail("utils.exit should have been called")
+ except SystemExit:
+ pass
+ mock_utils_exit.assert_called_once_with(expected_msg)
+
+ @mock.patch('glanceclient.common.utils.exit')
+ def test_neg_image_create_via_import_all_stores_without_uri(
+ self, mock_utils_exit):
+ expected_msg = ('--all-stores option should only be provided with '
+ '--uri option for the web-download import '
+ 'method.')
+ mock_utils_exit.side_effect = self._mock_utils_exit
+ my_args = self.base_args.copy()
+ my_args.update(
+ {'id': 'IMG-01', 'import_method': 'web-download',
+ 'os_all_stores': True,
+ 'disk_format': 'raw',
+ 'container_format': 'bare',
+ })
+ args = self._make_args(my_args)
+
+ with mock.patch.object(self.gc.images,
+ 'get_import_info') as mocked_info:
+ mocked_info.return_value = self.import_info_response
+ try:
+ test_shell.do_image_create_via_import(self.gc, args)
+ self.fail("utils.exit should have been called")
+ except SystemExit:
+ pass
+ mock_utils_exit.assert_called_once_with(expected_msg)
+
+ @mock.patch('glanceclient.common.utils.exit')
@mock.patch('sys.stdin', autospec=True)
def test_neg_image_create_via_import_web_download_no_uri_with_file(
self, mock_stdin, mock_utils_exit):
@@ -1785,7 +1923,8 @@ class ShellV2Test(testtools.TestCase):
mock_import.return_value = None
test_shell.do_image_import(self.gc, args)
mock_import.assert_called_once_with(
- 'IMG-01', 'glance-direct', None, backend=None)
+ 'IMG-01', 'glance-direct', None, backend=None,
+ all_stores=None, allow_failure=True, stores=None)
def test_image_import_web_download(self):
args = self._make_args(
@@ -1803,7 +1942,9 @@ class ShellV2Test(testtools.TestCase):
test_shell.do_image_import(self.gc, args)
mock_import.assert_called_once_with(
'IMG-01', 'web-download',
- 'http://example.com/image.qcow', backend=None)
+ 'http://example.com/image.qcow',
+ all_stores=None, allow_failure=True,
+ backend=None, stores=None)
@mock.patch('glanceclient.common.utils.print_image')
def test_image_import_no_print_image(self, mocked_utils_print_image):
@@ -1821,9 +1962,32 @@ class ShellV2Test(testtools.TestCase):
mock_import.return_value = None
test_shell.do_image_import(self.gc, args)
mock_import.assert_called_once_with(
- 'IMG-02', 'glance-direct', None, backend=None)
+ 'IMG-02', 'glance-direct', None, stores=None,
+ all_stores=None, allow_failure=True, backend=None)
mocked_utils_print_image.assert_not_called()
+ @mock.patch('glanceclient.common.utils.print_image')
+ @mock.patch('glanceclient.v2.shell._validate_backend')
+ def test_image_import_multiple_stores(self, mocked_utils_print_image,
+ msvb):
+ args = self._make_args(
+ {'id': 'IMG-02', 'uri': None, 'import_method': 'glance-direct',
+ 'from_create': False, 'stores': 'site1,site2'})
+ with mock.patch.object(self.gc.images, 'image_import') as mock_import:
+ with mock.patch.object(self.gc.images, 'get') as mocked_get:
+ with mock.patch.object(self.gc.images,
+ 'get_import_info') as mocked_info:
+ mocked_get.return_value = {'status': 'uploading',
+ 'container_format': 'bare',
+ 'disk_format': 'raw'}
+ mocked_info.return_value = self.import_info_response
+ mock_import.return_value = None
+ test_shell.do_image_import(self.gc, args)
+ mock_import.assert_called_once_with(
+ 'IMG-02', 'glance-direct', None, all_stores=None,
+ allow_failure=True, stores=['site1', 'site2'],
+ backend=None)
+
def test_image_download(self):
args = self._make_args(
{'id': 'IMG-01', 'file': 'test', 'progress': True,