summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/tests/unit')
-rw-r--r--openstackclient/tests/unit/api/test_object_store_v1.py2
-rw-r--r--openstackclient/tests/unit/api/test_utils.py115
-rw-r--r--openstackclient/tests/unit/common/test_commandmanager.py107
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server.py624
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server_backup.py9
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server_image.py9
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_role.py133
-rw-r--r--openstackclient/tests/unit/identity/v2_0/test_service.py45
-rw-r--r--openstackclient/tests/unit/identity/v3/fakes.py62
-rw-r--r--openstackclient/tests/unit/identity/v3/test_endpoint_group.py495
-rw-r--r--openstackclient/tests/unit/identity/v3/test_role.py232
-rw-r--r--openstackclient/tests/unit/image/v1/test_image.py24
-rw-r--r--openstackclient/tests/unit/image/v2/fakes.py6
-rw-r--r--openstackclient/tests/unit/image/v2/test_image.py80
-rw-r--r--openstackclient/tests/unit/integ/cli/test_shell.py19
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_router.py46
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py83
-rw-r--r--openstackclient/tests/unit/network/v2/test_security_group_rule_network.py36
-rw-r--r--openstackclient/tests/unit/test_shell.py37
-rw-r--r--openstackclient/tests/unit/volume/v1/test_qos_specs.py28
-rw-r--r--openstackclient/tests/unit/volume/v1/test_snapshot.py580
-rw-r--r--openstackclient/tests/unit/volume/v1/test_transfer_request.py20
-rw-r--r--openstackclient/tests/unit/volume/v1/test_type.py59
-rw-r--r--openstackclient/tests/unit/volume/v1/test_volume.py79
-rw-r--r--openstackclient/tests/unit/volume/v1/test_volume_backup.py (renamed from openstackclient/tests/unit/volume/v1/test_backup.py)24
-rw-r--r--openstackclient/tests/unit/volume/v2/fakes.py5
-rw-r--r--openstackclient/tests/unit/volume/v2/test_consistency_group.py17
-rw-r--r--openstackclient/tests/unit/volume/v2/test_qos_specs.py28
-rw-r--r--openstackclient/tests/unit/volume/v2/test_snapshot.py741
-rw-r--r--openstackclient/tests/unit/volume/v2/test_transfer_request.py30
-rw-r--r--openstackclient/tests/unit/volume/v2/test_type.py75
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume.py160
-rw-r--r--openstackclient/tests/unit/volume/v2/test_volume_backup.py (renamed from openstackclient/tests/unit/volume/v2/test_backup.py)20
34 files changed, 1567 insertions, 2465 deletions
diff --git a/openstackclient/tests/unit/api/test_object_store_v1.py b/openstackclient/tests/unit/api/test_object_store_v1.py
index acf95550..74b62493 100644
--- a/openstackclient/tests/unit/api/test_object_store_v1.py
+++ b/openstackclient/tests/unit/api/test_object_store_v1.py
@@ -184,7 +184,7 @@ class TestObject(TestObjectAPIv1):
}
# TODO(dtroyer): When requests_mock gains the ability to
# match against request.body add this check
- # https://review.openstack.org/127316
+ # https://review.opendev.org/127316
self.requests_mock.register_uri(
'PUT',
FAKE_URL + '/qaz/counter.txt',
diff --git a/openstackclient/tests/unit/api/test_utils.py b/openstackclient/tests/unit/api/test_utils.py
deleted file mode 100644
index 1f528558..00000000
--- a/openstackclient/tests/unit/api/test_utils.py
+++ /dev/null
@@ -1,115 +0,0 @@
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-"""API Utilities Library Tests"""
-
-import copy
-
-from openstackclient.api import api
-from openstackclient.api import utils as api_utils
-from openstackclient.tests.unit.api import fakes as api_fakes
-
-
-class TestBaseAPIFilter(api_fakes.TestSession):
- """The filters can be tested independently"""
-
- def setUp(self):
- super(TestBaseAPIFilter, self).setUp()
- self.api = api.BaseAPI(
- session=self.sess,
- endpoint=self.BASE_URL,
- )
-
- self.input_list = [
- api_fakes.RESP_ITEM_1,
- api_fakes.RESP_ITEM_2,
- api_fakes.RESP_ITEM_3,
- ]
-
- def test_simple_filter_none(self):
- output = api_utils.simple_filter(
- )
- self.assertIsNone(output)
-
- def test_simple_filter_no_attr(self):
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- )
- self.assertEqual(self.input_list, output)
-
- def test_simple_filter_attr_only(self):
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='status',
- )
- self.assertEqual(self.input_list, output)
-
- def test_simple_filter_attr_value(self):
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='status',
- value='',
- )
- self.assertEqual([], output)
-
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='status',
- value='UP',
- )
- self.assertEqual(
- [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_3],
- output,
- )
-
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='fred',
- value='UP',
- )
- self.assertEqual([], output)
-
- def test_simple_filter_prop_attr_only(self):
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='b',
- property_field='props',
- )
- self.assertEqual(self.input_list, output)
-
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='status',
- property_field='props',
- )
- self.assertEqual(self.input_list, output)
-
- def test_simple_filter_prop_attr_value(self):
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='b',
- value=2,
- property_field='props',
- )
- self.assertEqual(
- [api_fakes.RESP_ITEM_1, api_fakes.RESP_ITEM_2],
- output,
- )
-
- output = api_utils.simple_filter(
- copy.deepcopy(self.input_list),
- attr='b',
- value=9,
- property_field='props',
- )
- self.assertEqual([], output)
diff --git a/openstackclient/tests/unit/common/test_commandmanager.py b/openstackclient/tests/unit/common/test_commandmanager.py
deleted file mode 100644
index 0c6c99c0..00000000
--- a/openstackclient/tests/unit/common/test_commandmanager.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# Copyright 2012-2013 OpenStack Foundation
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-import mock
-
-from openstackclient.common import commandmanager
-from openstackclient.tests.unit import utils
-
-
-class FakeCommand(object):
-
- @classmethod
- def load(cls):
- return cls
-
- def __init__(self):
- return
-
-FAKE_CMD_ONE = FakeCommand
-FAKE_CMD_TWO = FakeCommand
-FAKE_CMD_ALPHA = FakeCommand
-FAKE_CMD_BETA = FakeCommand
-
-
-class FakeCommandManager(commandmanager.CommandManager):
- commands = {}
-
- def load_commands(self, namespace):
- if namespace == 'test':
- self.commands['one'] = FAKE_CMD_ONE
- self.commands['two'] = FAKE_CMD_TWO
- self.group_list.append(namespace)
- elif namespace == 'greek':
- self.commands['alpha'] = FAKE_CMD_ALPHA
- self.commands['beta'] = FAKE_CMD_BETA
- self.group_list.append(namespace)
-
-
-class TestCommandManager(utils.TestCase):
-
- def test_add_command_group(self):
- mgr = FakeCommandManager('test')
-
- # Make sure add_command() still functions
- mock_cmd_one = mock.Mock()
- mgr.add_command('mock', mock_cmd_one)
- cmd_mock, name, args = mgr.find_command(['mock'])
- self.assertEqual(mock_cmd_one, cmd_mock)
-
- # Find a command added in initialization
- cmd_one, name, args = mgr.find_command(['one'])
- self.assertEqual(FAKE_CMD_ONE, cmd_one)
-
- # Load another command group
- mgr.add_command_group('greek')
-
- # Find a new command
- cmd_alpha, name, args = mgr.find_command(['alpha'])
- self.assertEqual(FAKE_CMD_ALPHA, cmd_alpha)
-
- # Ensure that the original commands were not overwritten
- cmd_two, name, args = mgr.find_command(['two'])
- self.assertEqual(FAKE_CMD_TWO, cmd_two)
-
- def test_get_command_groups(self):
- mgr = FakeCommandManager('test')
-
- # Make sure add_command() still functions
- mock_cmd_one = mock.Mock()
- mgr.add_command('mock', mock_cmd_one)
- cmd_mock, name, args = mgr.find_command(['mock'])
- self.assertEqual(mock_cmd_one, cmd_mock)
-
- # Load another command group
- mgr.add_command_group('greek')
-
- gl = mgr.get_command_groups()
- self.assertEqual(['test', 'greek'], gl)
-
- def test_get_command_names(self):
- mock_cmd_one = mock.Mock()
- mock_cmd_one.name = 'one'
- mock_cmd_two = mock.Mock()
- mock_cmd_two.name = 'cmd two'
- mock_pkg_resources = mock.Mock(
- return_value=[mock_cmd_one, mock_cmd_two],
- )
- with mock.patch(
- 'pkg_resources.iter_entry_points',
- mock_pkg_resources,
- ) as iter_entry_points:
- mgr = commandmanager.CommandManager('test')
- iter_entry_points.assert_called_once_with('test')
- cmds = mgr.get_command_names('test')
- self.assertEqual(['one', 'cmd two'], cmds)
diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py
index c30af8fb..8ea59a38 100644
--- a/openstackclient/tests/unit/compute/v2/test_server.py
+++ b/openstackclient/tests/unit/compute/v2/test_server.py
@@ -23,6 +23,7 @@ from openstack import exceptions as sdk_exceptions
from osc_lib import exceptions
from osc_lib import utils as common_utils
from oslo_utils import timeutils
+import six
from openstackclient.compute.v2 import server
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
@@ -90,7 +91,14 @@ class TestServer(compute_fakes.TestComputev2):
for s in servers:
method = getattr(s, method_name)
- method.assert_called_with()
+ if method_name == 'lock':
+ version = self.app.client_manager.compute.api_version
+ if version >= api_versions.APIVersion('2.73'):
+ method.assert_called_with(reason=None)
+ else:
+ method.assert_called_with()
+ else:
+ method.assert_called_with()
self.assertIsNone(result)
@@ -1834,6 +1842,90 @@ class TestServerCreate(TestServer):
self.cmd.take_action,
parsed_args)
+ def test_server_create_with_description_api_newer(self):
+
+ # Description is supported for nova api version 2.19 or above
+ self.app.client_manager.compute.api_version = 2.19
+
+ arglist = [
+ '--image', 'image1',
+ '--flavor', 'flavor1',
+ '--description', 'description1',
+ self.new_server.name,
+ ]
+ verifylist = [
+ ('image', 'image1'),
+ ('flavor', 'flavor1'),
+ ('description', 'description1'),
+ ('config_drive', False),
+ ('server_name', self.new_server.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ # In base command class ShowOne in cliff, abstract method
+ # take_action() returns a two-part tuple with a tuple of
+ # column names and a tuple of data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = dict(
+ meta=None,
+ files={},
+ reservation_id=None,
+ min_count=1,
+ max_count=1,
+ security_groups=[],
+ userdata=None,
+ key_name=None,
+ availability_zone=None,
+ block_device_mapping_v2=[],
+ nics='auto',
+ scheduler_hints={},
+ config_drive=None,
+ description='description1',
+ )
+ # ServerManager.create(name, image, flavor, **kwargs)
+ self.servers_mock.create.assert_called_with(
+ self.new_server.name,
+ self.image,
+ self.flavor,
+ **kwargs
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist(), data)
+ self.assertFalse(self.images_mock.called)
+ self.assertFalse(self.flavors_mock.called)
+
+ def test_server_create_with_description_api_older(self):
+
+ # Description is not supported for nova api version below 2.19
+ self.app.client_manager.compute.api_version = 2.18
+
+ arglist = [
+ '--image', 'image1',
+ '--flavor', 'flavor1',
+ '--description', 'description1',
+ self.new_server.name,
+ ]
+ verifylist = [
+ ('image', 'image1'),
+ ('flavor', 'flavor1'),
+ ('description', 'description1'),
+ ('config_drive', False),
+ ('server_name', self.new_server.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
class TestServerDelete(TestServer):
@@ -1991,6 +2083,7 @@ class TestServerList(TestServer):
'user_id': None,
'deleted': False,
'changes-since': None,
+ 'changes-before': None,
}
# Default params of the core function of the command in the case of no
@@ -2210,6 +2303,80 @@ class TestServerList(TestServer):
self.assertEqual(self.columns, columns)
self.assertEqual(tuple(self.data), tuple(data))
+ def test_server_list_with_locked_pre_v273(self):
+
+ arglist = [
+ '--locked'
+ ]
+ verifylist = [
+ ('locked', True)
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ ex = self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args)
+ self.assertIn(
+ '--os-compute-api-version 2.73 or greater is required', str(ex))
+
+ def test_server_list_with_locked_v273(self):
+
+ self.app.client_manager.compute.api_version = \
+ api_versions.APIVersion('2.73')
+ arglist = [
+ '--locked'
+ ]
+ verifylist = [
+ ('locked', True)
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.search_opts['locked'] = True
+ self.servers_mock.list.assert_called_with(**self.kwargs)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(tuple(self.data), tuple(data))
+
+ def test_server_list_with_unlocked_v273(self):
+
+ self.app.client_manager.compute.api_version = \
+ api_versions.APIVersion('2.73')
+ arglist = [
+ '--unlocked'
+ ]
+ verifylist = [
+ ('unlocked', True)
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.search_opts['locked'] = False
+ self.servers_mock.list.assert_called_with(**self.kwargs)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(tuple(self.data), tuple(data))
+
+ def test_server_list_with_locked_and_unlocked_v273(self):
+
+ self.app.client_manager.compute.api_version = \
+ api_versions.APIVersion('2.73')
+ arglist = [
+ '--locked',
+ '--unlocked'
+ ]
+ verifylist = [
+ ('locked', True),
+ ('unlocked', True)
+ ]
+
+ ex = self.assertRaises(
+ utils.ParserException,
+ self.check_parser, self.cmd, arglist, verifylist)
+ self.assertIn('Argument parse failed', str(ex))
+
def test_server_list_with_flavor(self):
arglist = [
@@ -2272,6 +2439,71 @@ class TestServerList(TestServer):
'Invalid time value'
)
+ def test_server_list_v266_with_changes_before(self):
+ self.app.client_manager.compute.api_version = (
+ api_versions.APIVersion('2.66'))
+ arglist = [
+ '--changes-before', '2016-03-05T06:27:59Z',
+ '--deleted'
+ ]
+ verifylist = [
+ ('changes_before', '2016-03-05T06:27:59Z'),
+ ('deleted', True),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.search_opts['changes-before'] = '2016-03-05T06:27:59Z'
+ self.search_opts['deleted'] = True
+ self.servers_mock.list.assert_called_with(**self.kwargs)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(tuple(self.data), tuple(data))
+
+ @mock.patch.object(timeutils, 'parse_isotime', side_effect=ValueError)
+ def test_server_list_v266_with_invalid_changes_before(
+ self, mock_parse_isotime):
+ self.app.client_manager.compute.api_version = (
+ api_versions.APIVersion('2.66'))
+
+ arglist = [
+ '--changes-before', 'Invalid time value',
+ ]
+ verifylist = [
+ ('changes_before', 'Invalid time value'),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ try:
+ self.cmd.take_action(parsed_args)
+ self.fail('CommandError should be raised.')
+ except exceptions.CommandError as e:
+ self.assertEqual('Invalid changes-before value: Invalid time '
+ 'value', str(e))
+ mock_parse_isotime.assert_called_once_with(
+ 'Invalid time value'
+ )
+
+ def test_server_with_changes_before_older_version(self):
+ self.app.client_manager.compute.api_version = (
+ api_versions.APIVersion('2.65'))
+
+ arglist = [
+ '--changes-before', '2016-03-05T06:27:59Z',
+ '--deleted'
+ ]
+ verifylist = [
+ ('changes_before', '2016-03-05T06:27:59Z'),
+ ('deleted', True),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args)
+
def test_server_list_v269_with_partial_constructs(self):
self.app.client_manager.compute.api_version = \
api_versions.APIVersion('2.69')
@@ -2336,6 +2568,72 @@ class TestServerLock(TestServer):
def test_server_lock_multi_servers(self):
self.run_method_with_servers('lock', 3)
+ def test_server_lock_with_reason(self):
+ server = compute_fakes.FakeServer.create_one_server()
+ arglist = [
+ server.id,
+ '--reason', "blah",
+ ]
+ verifylist = [
+ ('reason', "blah"),
+ ('server', [server.id])
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ ex = self.assertRaises(exceptions.CommandError,
+ self.cmd.take_action,
+ parsed_args)
+ self.assertIn(
+ '--os-compute-api-version 2.73 or greater is required', str(ex))
+
+
+class TestServerLockV273(TestServerLock):
+
+ def setUp(self):
+ super(TestServerLockV273, self).setUp()
+
+ self.server = compute_fakes.FakeServer.create_one_server(
+ methods=self.methods)
+
+ # This is the return value for utils.find_resource()
+ self.servers_mock.get.return_value = self.server
+
+ self.app.client_manager.compute.api_version = \
+ api_versions.APIVersion('2.73')
+
+ # Get the command object to test
+ self.cmd = server.LockServer(self.app, None)
+
+ def test_server_lock_with_reason(self):
+ arglist = [
+ self.server.id,
+ '--reason', "blah",
+ ]
+ verifylist = [
+ ('reason', "blah"),
+ ('server', [self.server.id])
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.cmd.take_action(parsed_args)
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.server.lock.assert_called_with(reason="blah")
+
+ def test_server_lock_multi_servers_with_reason(self):
+ server2 = compute_fakes.FakeServer.create_one_server(
+ methods=self.methods)
+ arglist = [
+ self.server.id, server2.id,
+ '--reason', "choo..choo",
+ ]
+ verifylist = [
+ ('reason', "choo..choo"),
+ ('server', [self.server.id, server2.id])
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.cmd.take_action(parsed_args)
+ self.assertEqual(2, self.servers_mock.get.call_count)
+ self.server.lock.assert_called_with(reason="choo..choo")
+ self.assertEqual(2, self.server.lock.call_count)
+
class TestServerMigrate(TestServer):
@@ -2377,6 +2675,32 @@ class TestServerMigrate(TestServer):
self.assertNotCalled(self.servers_mock.live_migrate)
self.assertIsNone(result)
+ def test_server_migrate_with_host_2_56(self):
+ # Tests that --host is allowed for a cold migration
+ # for microversion 2.56 and greater.
+ arglist = [
+ '--host', 'fakehost', self.server.id,
+ ]
+ verifylist = [
+ ('live', None),
+ ('live_migration', False),
+ ('host', 'fakehost'),
+ ('block_migration', False),
+ ('disk_overcommit', False),
+ ('wait', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.app.client_manager.compute.api_version = \
+ api_versions.APIVersion('2.56')
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.server.migrate.assert_called_with(host='fakehost')
+ self.assertNotCalled(self.servers_mock.live_migrate)
+ self.assertIsNone(result)
+
def test_server_migrate_with_block_migration(self):
arglist = [
'--block-migration', self.server.id,
@@ -2415,12 +2739,42 @@ class TestServerMigrate(TestServer):
self.assertNotCalled(self.servers_mock.live_migrate)
self.assertNotCalled(self.servers_mock.migrate)
+ def test_server_migrate_with_host_pre_2_56(self):
+ # Tests that --host is not allowed for a cold migration
+ # before microversion 2.56 (the test defaults to 2.1).
+ arglist = [
+ '--host', 'fakehost', self.server.id,
+ ]
+ verifylist = [
+ ('live', None),
+ ('live_migration', False),
+ ('host', 'fakehost'),
+ ('block_migration', False),
+ ('disk_overcommit', False),
+ ('wait', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ ex = self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
+ # Make sure it's the error we expect.
+ self.assertIn('--os-compute-api-version 2.56 or greater is required '
+ 'to use --host without --live-migration.',
+ six.text_type(ex))
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.assertNotCalled(self.servers_mock.live_migrate)
+ self.assertNotCalled(self.servers_mock.migrate)
+
def test_server_live_migrate(self):
arglist = [
'--live', 'fakehost', self.server.id,
]
verifylist = [
('live', 'fakehost'),
+ ('live_migration', False),
+ ('host', None),
('block_migration', False),
('disk_overcommit', False),
('wait', False),
@@ -2430,7 +2784,8 @@ class TestServerMigrate(TestServer):
self.app.client_manager.compute.api_version = \
api_versions.APIVersion('2.24')
- result = self.cmd.take_action(parsed_args)
+ with mock.patch.object(self.cmd.log, 'warning') as mock_warning:
+ result = self.cmd.take_action(parsed_args)
self.servers_mock.get.assert_called_with(self.server.id)
self.server.live_migrate.assert_called_with(block_migration=False,
@@ -2438,6 +2793,132 @@ class TestServerMigrate(TestServer):
host='fakehost')
self.assertNotCalled(self.servers_mock.migrate)
self.assertIsNone(result)
+ # A warning should have been logged for using --live.
+ mock_warning.assert_called_once()
+ self.assertIn('The --live option has been deprecated.',
+ six.text_type(mock_warning.call_args[0][0]))
+
+ def test_server_live_migrate_host_pre_2_30(self):
+ # Tests that the --host option is not supported for --live-migration
+ # before microversion 2.30 (the test defaults to 2.1).
+ arglist = [
+ '--live-migration', '--host', 'fakehost', self.server.id,
+ ]
+ verifylist = [
+ ('live', None),
+ ('live_migration', True),
+ ('host', 'fakehost'),
+ ('block_migration', False),
+ ('disk_overcommit', False),
+ ('wait', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ ex = self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
+ # Make sure it's the error we expect.
+ self.assertIn('--os-compute-api-version 2.30 or greater is required '
+ 'when using --host', six.text_type(ex))
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.assertNotCalled(self.servers_mock.live_migrate)
+ self.assertNotCalled(self.servers_mock.migrate)
+
+ def test_server_live_migrate_no_host(self):
+ # Tests the --live-migration option without --host or --live.
+ arglist = [
+ '--live-migration', self.server.id,
+ ]
+ verifylist = [
+ ('live', None),
+ ('live_migration', True),
+ ('host', None),
+ ('block_migration', False),
+ ('disk_overcommit', False),
+ ('wait', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(self.cmd.log, 'warning') as mock_warning:
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.server.live_migrate.assert_called_with(block_migration=False,
+ disk_over_commit=False,
+ host=None)
+ self.assertNotCalled(self.servers_mock.migrate)
+ self.assertIsNone(result)
+ # Since --live wasn't used a warning shouldn't have been logged.
+ mock_warning.assert_not_called()
+
+ def test_server_live_migrate_with_host(self):
+ # Tests the --live-migration option with --host but no --live.
+ # This requires --os-compute-api-version >= 2.30 so the test uses 2.30.
+ arglist = [
+ '--live-migration', '--host', 'fakehost', self.server.id,
+ ]
+ verifylist = [
+ ('live', None),
+ ('live_migration', True),
+ ('host', 'fakehost'),
+ ('block_migration', False),
+ ('disk_overcommit', False),
+ ('wait', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ self.app.client_manager.compute.api_version = \
+ api_versions.APIVersion('2.30')
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ # No disk_overcommit with microversion >= 2.25.
+ self.server.live_migrate.assert_called_with(block_migration=False,
+ host='fakehost')
+ self.assertNotCalled(self.servers_mock.migrate)
+ self.assertIsNone(result)
+
+ def test_server_live_migrate_without_host_override_live(self):
+ # Tests the --live-migration option without --host and with --live.
+ # The --live-migration option will take precedence and a warning is
+ # logged for using --live.
+ arglist = [
+ '--live', 'fakehost', '--live-migration', self.server.id,
+ ]
+ verifylist = [
+ ('live', 'fakehost'),
+ ('live_migration', True),
+ ('host', None),
+ ('block_migration', False),
+ ('disk_overcommit', False),
+ ('wait', False),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(self.cmd.log, 'warning') as mock_warning:
+ result = self.cmd.take_action(parsed_args)
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.server.live_migrate.assert_called_with(block_migration=False,
+ disk_over_commit=False,
+ host=None)
+ self.assertNotCalled(self.servers_mock.migrate)
+ self.assertIsNone(result)
+ # A warning should have been logged for using --live.
+ mock_warning.assert_called_once()
+ self.assertIn('The --live option has been deprecated.',
+ six.text_type(mock_warning.call_args[0][0]))
+
+ def test_server_live_migrate_live_and_host_mutex(self):
+ # Tests specifying both the --live and --host options which are in a
+ # mutex group so argparse should fail.
+ arglist = [
+ '--live', 'fakehost', '--host', 'fakehost', self.server.id,
+ ]
+ self.assertRaises(utils.ParserException,
+ self.check_parser, self.cmd, arglist, verify_args=[])
def test_server_block_live_migrate(self):
arglist = [
@@ -2663,6 +3144,55 @@ class TestServerRebuild(TestServer):
self.images_mock.get.assert_called_with(self.image.id)
self.server.rebuild.assert_called_with(self.image, password)
+ def test_rebuild_with_description_api_older(self):
+
+ # Description is not supported for nova api version below 2.19
+ self.server.api_version = 2.18
+
+ description = 'description1'
+ arglist = [
+ self.server.id,
+ '--description', description
+ ]
+ verifylist = [
+ ('server', self.server.id),
+ ('description', description)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
+ def test_rebuild_with_description_api_newer(self):
+
+ # Description is supported for nova api version 2.19 or above
+ self.server.api_version = 2.19
+
+ description = 'description1'
+ arglist = [
+ self.server.id,
+ '--description', description
+ ]
+ verifylist = [
+ ('server', self.server.id),
+ ('description', description)
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ # Get the command object to test
+ self.cmd.take_action(parsed_args)
+
+ self.servers_mock.get.assert_called_with(self.server.id)
+ self.images_mock.get.assert_called_with(self.image.id)
+ self.server.rebuild.assert_called_with(self.image, None,
+ description=description)
+
@mock.patch.object(common_utils, 'wait_for_status', return_value=True)
def test_rebuild_with_wait_ok(self, mock_wait_for_status):
arglist = [
@@ -3400,6 +3930,10 @@ class TestServerSet(TestServer):
def setUp(self):
super(TestServerSet, self).setUp()
+ self.attrs = {
+ 'api_version': None,
+ }
+
self.methods = {
'update': None,
'reset_state': None,
@@ -3502,6 +4036,48 @@ class TestServerSet(TestServer):
mock.sentinel.fake_pass)
self.assertIsNone(result)
+ def test_server_set_with_description_api_newer(self):
+
+ # Description is supported for nova api version 2.19 or above
+ self.fake_servers[0].api_version = 2.19
+
+ arglist = [
+ '--description', 'foo_description',
+ 'foo_vm',
+ ]
+ verifylist = [
+ ('description', 'foo_description'),
+ ('server', 'foo_vm'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ result = self.cmd.take_action(parsed_args)
+ self.fake_servers[0].update.assert_called_once_with(
+ description='foo_description')
+ self.assertIsNone(result)
+
+ def test_server_set_with_description_api_older(self):
+
+ # Description is not supported for nova api version below 2.19
+ self.fake_servers[0].api_version = 2.18
+
+ arglist = [
+ '--description', 'foo_description',
+ 'foo_vm',
+ ]
+ verifylist = [
+ ('description', 'foo_description'),
+ ('server', 'foo_vm'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
class TestServerShelve(TestServer):
@@ -3783,6 +4359,50 @@ class TestServerUnset(TestServer):
self.fake_server, ['key1', 'key2'])
self.assertIsNone(result)
+ def test_server_unset_with_description_api_newer(self):
+
+ # Description is supported for nova api version 2.19 or above
+ self.app.client_manager.compute.api_version = 2.19
+
+ arglist = [
+ '--description',
+ 'foo_vm',
+ ]
+ verifylist = [
+ ('description', True),
+ ('server', 'foo_vm'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ result = self.cmd.take_action(parsed_args)
+ self.servers_mock.update.assert_called_once_with(
+ self.fake_server, description="")
+ self.assertIsNone(result)
+
+ def test_server_unset_with_description_api_older(self):
+
+ # Description is not supported for nova api version below 2.19
+ self.app.client_manager.compute.api_version = 2.18
+
+ arglist = [
+ '--description',
+ 'foo_vm',
+ ]
+ verifylist = [
+ ('description', True),
+ ('server', 'foo_vm'),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ with mock.patch.object(api_versions,
+ 'APIVersion',
+ return_value=2.19):
+ self.assertRaises(exceptions.CommandError, self.cmd.take_action,
+ parsed_args)
+
class TestServerUnshelve(TestServer):
diff --git a/openstackclient/tests/unit/compute/v2/test_server_backup.py b/openstackclient/tests/unit/compute/v2/test_server_backup.py
index 9a481e0a..24a94531 100644
--- a/openstackclient/tests/unit/compute/v2/test_server_backup.py
+++ b/openstackclient/tests/unit/compute/v2/test_server_backup.py
@@ -13,6 +13,7 @@
import mock
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils as common_utils
@@ -69,7 +70,7 @@ class TestServerBackupCreate(TestServerBackup):
image['owner'],
image['protected'],
'active',
- common_utils.format_list(image.get('tags')),
+ format_columns.ListColumn(image.get('tags')),
image['visibility'],
)
return datalist
@@ -134,7 +135,7 @@ class TestServerBackupCreate(TestServerBackup):
)
self.assertEqual(self.image_columns(images[0]), columns)
- self.assertEqual(self.image_data(images[0]), data)
+ self.assertItemEqual(self.image_data(images[0]), data)
def test_server_backup_create_options(self):
servers = self.setup_servers_mock(count=1)
@@ -168,7 +169,7 @@ class TestServerBackupCreate(TestServerBackup):
)
self.assertEqual(self.image_columns(images[0]), columns)
- self.assertEqual(self.image_data(images[0]), data)
+ self.assertItemEqual(self.image_data(images[0]), data)
@mock.patch.object(common_utils, 'wait_for_status', return_value=False)
def test_server_backup_wait_fail(self, mock_wait_for_status):
@@ -268,4 +269,4 @@ class TestServerBackupCreate(TestServerBackup):
)
self.assertEqual(self.image_columns(images[0]), columns)
- self.assertEqual(self.image_data(images[0]), data)
+ self.assertItemEqual(self.image_data(images[0]), data)
diff --git a/openstackclient/tests/unit/compute/v2/test_server_image.py b/openstackclient/tests/unit/compute/v2/test_server_image.py
index 47bd682f..02e43129 100644
--- a/openstackclient/tests/unit/compute/v2/test_server_image.py
+++ b/openstackclient/tests/unit/compute/v2/test_server_image.py
@@ -12,6 +12,7 @@
#
import mock
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils as common_utils
@@ -67,7 +68,7 @@ class TestServerImageCreate(TestServerImage):
image['owner'],
image['protected'],
'active',
- common_utils.format_list(image.get('tags')),
+ format_columns.ListColumn(image.get('tags')),
image['visibility'],
)
return datalist
@@ -129,7 +130,7 @@ class TestServerImageCreate(TestServerImage):
)
self.assertEqual(self.image_columns(images[0]), columns)
- self.assertEqual(self.image_data(images[0]), data)
+ self.assertItemEqual(self.image_data(images[0]), data)
def test_server_image_create_options(self):
servers = self.setup_servers_mock(count=1)
@@ -157,7 +158,7 @@ class TestServerImageCreate(TestServerImage):
)
self.assertEqual(self.image_columns(images[0]), columns)
- self.assertEqual(self.image_data(images[0]), data)
+ self.assertItemEqual(self.image_data(images[0]), data)
@mock.patch.object(common_utils, 'wait_for_status', return_value=False)
def test_server_create_image_wait_fail(self, mock_wait_for_status):
@@ -225,4 +226,4 @@ class TestServerImageCreate(TestServerImage):
)
self.assertEqual(self.image_columns(images[0]), columns)
- self.assertEqual(self.image_data(images[0]), data)
+ self.assertItemEqual(self.image_data(images[0]), data)
diff --git a/openstackclient/tests/unit/identity/v2_0/test_role.py b/openstackclient/tests/unit/identity/v2_0/test_role.py
index 684ce803..643d77f6 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_role.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_role.py
@@ -278,7 +278,7 @@ class TestRoleList(TestRole):
# Get the command object to test
self.cmd = role.ListRole(self.app, None)
- def test_role_list_no_options(self):
+ def test_role_list(self):
arglist = []
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -299,137 +299,6 @@ class TestRoleList(TestRole):
self.assertEqual(datalist, tuple(data))
-class TestUserRoleList(TestRole):
-
- columns = (
- 'ID',
- 'Name',
- 'Project',
- 'User'
- )
-
- def setUp(self):
- super(TestUserRoleList, self).setUp()
-
- self.projects_mock.get.return_value = self.fake_project
-
- self.users_mock.get.return_value = self.fake_user
-
- self.roles_mock.roles_for_user.return_value = [self.fake_role]
-
- # Get the command object to test
- self.cmd = role.ListUserRole(self.app, None)
-
- def test_user_role_list_no_options_unscoped_token(self):
- auth_ref = identity_fakes.fake_auth_ref(
- identity_fakes.UNSCOPED_TOKEN,
- fake_service=self.fake_service,
- )
- self.ar_mock = mock.PropertyMock(return_value=auth_ref)
- type(self.app.client_manager).auth_ref = self.ar_mock
-
- arglist = []
- verifylist = []
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # This argument combination should raise a CommandError
- self.assertRaises(
- exceptions.CommandError,
- self.cmd.take_action,
- parsed_args,
- )
-
- def test_user_role_list_no_options_scoped_token(self):
- arglist = []
- verifylist = []
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- self.roles_mock.roles_for_user.assert_called_with(
- self.fake_user.id,
- self.fake_project.id,
- )
-
- collist = ('ID', 'Name', 'Project', 'User')
- self.assertEqual(collist, columns)
- datalist = ((
- self.fake_role.id,
- self.fake_role.name,
- self.fake_project.name,
- self.fake_user.name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
- def test_user_role_list_project_unscoped_token(self):
- auth_ref = identity_fakes.fake_auth_ref(
- identity_fakes.UNSCOPED_TOKEN,
- fake_service=self.fake_service,
- )
- self.ar_mock = mock.PropertyMock(return_value=auth_ref)
- type(self.app.client_manager).auth_ref = self.ar_mock
-
- self.projects_mock.get.return_value = self.fake_project
- arglist = [
- '--project', self.fake_project.name,
- ]
- verifylist = [
- ('project', self.fake_project.name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- self.roles_mock.roles_for_user.assert_called_with(
- self.fake_user.id,
- self.fake_project.id,
- )
-
- self.assertEqual(columns, columns)
- datalist = ((
- self.fake_role.id,
- self.fake_role.name,
- self.fake_project.name,
- self.fake_user.name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
- def test_user_role_list_project_scoped_token(self):
- self.projects_mock.get.return_value = self.fake_project
- arglist = [
- '--project', self.fake_project.name,
- ]
- verifylist = [
- ('project', self.fake_project.name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- self.roles_mock.roles_for_user.assert_called_with(
- self.fake_user.id,
- self.fake_project.id,
- )
-
- self.assertEqual(columns, columns)
- datalist = ((
- self.fake_role.id,
- self.fake_role.name,
- self.fake_project.name,
- self.fake_user.name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
-
class TestRoleRemove(TestRole):
def setUp(self):
diff --git a/openstackclient/tests/unit/identity/v2_0/test_service.py b/openstackclient/tests/unit/identity/v2_0/test_service.py
index 1948bf4a..6c4374ef 100644
--- a/openstackclient/tests/unit/identity/v2_0/test_service.py
+++ b/openstackclient/tests/unit/identity/v2_0/test_service.py
@@ -55,43 +55,14 @@ class TestServiceCreate(TestService):
# Get the command object to test
self.cmd = service.CreateService(self.app, None)
- def test_service_create_with_type_positional(self):
+ def test_service_create(self):
arglist = [
self.fake_service_c.type,
]
verifylist = [
- ('type_or_name', self.fake_service_c.type),
- ('type', None),
- ('description', None),
- ('name', None),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class ShowOne in cliff, abstract method take_action()
- # returns a two-part tuple with a tuple of column names and a tuple of
- # data to be shown.
- columns, data = self.cmd.take_action(parsed_args)
-
- # ServiceManager.create(name, service_type, description)
- self.services_mock.create.assert_called_with(
- None,
- self.fake_service_c.type,
- None,
- )
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
-
- def test_service_create_with_type_option(self):
- arglist = [
- '--type', self.fake_service_c.type,
- self.fake_service_c.name,
- ]
- verifylist = [
- ('type_or_name', self.fake_service_c.name),
('type', self.fake_service_c.type),
- ('description', None),
('name', None),
+ ('description', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -102,7 +73,7 @@ class TestServiceCreate(TestService):
# ServiceManager.create(name, service_type, description)
self.services_mock.create.assert_called_with(
- self.fake_service_c.name,
+ None,
self.fake_service_c.type,
None,
)
@@ -116,10 +87,9 @@ class TestServiceCreate(TestService):
self.fake_service_c.type,
]
verifylist = [
- ('type_or_name', self.fake_service_c.type),
- ('type', None),
- ('description', None),
+ ('type', self.fake_service_c.type),
('name', self.fake_service_c.name),
+ ('description', None),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -145,10 +115,9 @@ class TestServiceCreate(TestService):
self.fake_service_c.type,
]
verifylist = [
- ('type_or_name', self.fake_service_c.type),
- ('type', None),
- ('description', self.fake_service_c.description),
+ ('type', self.fake_service_c.type),
('name', self.fake_service_c.name),
+ ('description', self.fake_service_c.description),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
diff --git a/openstackclient/tests/unit/identity/v3/fakes.py b/openstackclient/tests/unit/identity/v3/fakes.py
index 5caf156b..e9ff0689 100644
--- a/openstackclient/tests/unit/identity/v3/fakes.py
+++ b/openstackclient/tests/unit/identity/v3/fakes.py
@@ -236,6 +236,10 @@ endpoint_group_filters = {
'service_id': service_id,
'region_id': endpoint_region,
}
+endpoint_group_filters_2 = {
+ 'region_id': endpoint_region,
+}
+endpoint_group_file_path = '/tmp/path/to/file'
ENDPOINT_GROUP = {
'id': endpoint_group_id,
@@ -1045,6 +1049,64 @@ class FakeEndpoint(object):
return endpoint_filter
+class FakeEndpointGroup(object):
+ """Fake one or more endpoint group."""
+
+ @staticmethod
+ def create_one_endpointgroup(attrs=None):
+ """Create a fake endpoint group.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes
+ :return:
+ A FakeResource object, with id, url, and so on
+ """
+
+ attrs = attrs or {}
+
+ # set default attributes.
+ endpointgroup_info = {
+ 'id': 'endpoint-group-id-' + uuid.uuid4().hex,
+ 'name': 'endpoint-group-name-' + uuid.uuid4().hex,
+ 'filters': {
+ 'region': 'region-' + uuid.uuid4().hex,
+ 'service_id': 'service-id-' + uuid.uuid4().hex,
+ },
+ 'description': 'endpoint-group-description-' + uuid.uuid4().hex,
+ 'links': 'links-' + uuid.uuid4().hex,
+ }
+ endpointgroup_info.update(attrs)
+
+ endpoint = fakes.FakeResource(info=copy.deepcopy(endpointgroup_info),
+ loaded=True)
+ return endpoint
+
+ @staticmethod
+ def create_one_endpointgroup_filter(attrs=None):
+ """Create a fake endpoint project relationship.
+
+ :param Dictionary attrs:
+ A dictionary with all attributes of endpointgroup filter
+ :return:
+ A FakeResource object with project, endpointgroup and so on
+ """
+ attrs = attrs or {}
+
+ # Set default attribute
+ endpointgroup_filter_info = {
+ 'project': 'project-id-' + uuid.uuid4().hex,
+ 'endpointgroup': 'endpointgroup-id-' + uuid.uuid4().hex,
+ }
+
+ # Overwrite default attributes if there are some attributes set
+ endpointgroup_filter_info.update(attrs)
+
+ endpointgroup_filter = fakes.FakeModel(
+ copy.deepcopy(endpointgroup_filter_info))
+
+ return endpointgroup_filter
+
+
class FakeService(object):
"""Fake one or more service."""
diff --git a/openstackclient/tests/unit/identity/v3/test_endpoint_group.py b/openstackclient/tests/unit/identity/v3/test_endpoint_group.py
new file mode 100644
index 00000000..6e9da9c7
--- /dev/null
+++ b/openstackclient/tests/unit/identity/v3/test_endpoint_group.py
@@ -0,0 +1,495 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+
+import mock
+
+from openstackclient.identity.v3 import endpoint_group
+from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
+
+
+class TestEndpointGroup(identity_fakes.TestIdentityv3):
+
+ def setUp(self):
+ super(TestEndpointGroup, self).setUp()
+
+ # Get a shortcut to the EndpointManager Mock
+ self.endpoint_groups_mock = (
+ self.app.client_manager.identity.endpoint_groups
+ )
+ self.endpoint_groups_mock.reset_mock()
+ self.epf_mock = (
+ self.app.client_manager.identity.endpoint_filter
+ )
+ self.epf_mock.reset_mock()
+
+ # Get a shortcut to the ServiceManager Mock
+ self.services_mock = self.app.client_manager.identity.services
+ self.services_mock.reset_mock()
+
+ # Get a shortcut to the DomainManager Mock
+ self.domains_mock = self.app.client_manager.identity.domains
+ self.domains_mock.reset_mock()
+
+ # Get a shortcut to the ProjectManager Mock
+ self.projects_mock = self.app.client_manager.identity.projects
+ self.projects_mock.reset_mock()
+
+
+class TestEndpointGroupCreate(TestEndpointGroup):
+
+ columns = (
+ 'description',
+ 'filters',
+ 'id',
+ 'name',
+ )
+
+ def setUp(self):
+ super(TestEndpointGroupCreate, self).setUp()
+
+ self.endpoint_group = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup(
+ attrs={'filters': identity_fakes.endpoint_group_filters}))
+
+ self.endpoint_groups_mock.create.return_value = self.endpoint_group
+
+ # Get the command object to test
+ self.cmd = endpoint_group.CreateEndpointGroup(self.app, None)
+
+ def test_endpointgroup_create_no_options(self):
+ arglist = [
+ '--description', self.endpoint_group.description,
+ self.endpoint_group.name,
+ identity_fakes.endpoint_group_file_path,
+ ]
+ verifylist = [
+ ('name', self.endpoint_group.name),
+ ('filters', identity_fakes.endpoint_group_file_path),
+ ('description', self.endpoint_group.description),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ mocker = mock.Mock()
+ mocker.return_value = identity_fakes.endpoint_group_filters
+ with mock.patch("openstackclient.identity.v3.endpoint_group."
+ "CreateEndpointGroup._read_filters", mocker):
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': self.endpoint_group.name,
+ 'filters': identity_fakes.endpoint_group_filters,
+ 'description': self.endpoint_group.description,
+ }
+
+ self.endpoint_groups_mock.create.assert_called_with(
+ **kwargs
+ )
+
+ self.assertEqual(self.columns, columns)
+ datalist = (
+ self.endpoint_group.description,
+ identity_fakes.endpoint_group_filters,
+ self.endpoint_group.id,
+ self.endpoint_group.name,
+ )
+ self.assertEqual(datalist, data)
+
+
+class TestEndpointGroupDelete(TestEndpointGroup):
+
+ endpoint_group = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup())
+
+ def setUp(self):
+ super(TestEndpointGroupDelete, self).setUp()
+
+ # This is the return value for utils.find_resource(endpoint)
+ self.endpoint_groups_mock.get.return_value = self.endpoint_group
+ self.endpoint_groups_mock.delete.return_value = None
+
+ # Get the command object to test
+ self.cmd = endpoint_group.DeleteEndpointGroup(self.app, None)
+
+ def test_endpointgroup_delete(self):
+ arglist = [
+ self.endpoint_group.id,
+ ]
+ verifylist = [
+ ('endpointgroup', [self.endpoint_group.id]),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.endpoint_groups_mock.delete.assert_called_with(
+ self.endpoint_group.id,
+ )
+ self.assertIsNone(result)
+
+
+class TestEndpointGroupList(TestEndpointGroup):
+
+ endpoint_group = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup())
+ project = identity_fakes.FakeProject.create_one_project()
+ domain = identity_fakes.FakeDomain.create_one_domain()
+
+ columns = (
+ 'ID',
+ 'Name',
+ 'Description',
+ )
+
+ def setUp(self):
+ super(TestEndpointGroupList, self).setUp()
+
+ self.endpoint_groups_mock.list.return_value = [self.endpoint_group]
+ self.endpoint_groups_mock.get.return_value = self.endpoint_group
+ self.epf_mock.list_projects_for_endpoint_group.return_value = [
+ self.project]
+ self.epf_mock.list_endpoint_groups_for_project.return_value = [
+ self.endpoint_group]
+
+ # Get the command object to test
+ self.cmd = endpoint_group.ListEndpointGroup(self.app, None)
+
+ def test_endpoint_group_list_no_options(self):
+ arglist = []
+ verifylist = []
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+ self.endpoint_groups_mock.list.assert_called_with()
+
+ self.assertEqual(self.columns, columns)
+ datalist = (
+ (
+ self.endpoint_group.id,
+ self.endpoint_group.name,
+ self.endpoint_group.description,
+ ),
+ )
+ self.assertEqual(datalist, tuple(data))
+
+ def test_endpoint_group_list_projects_by_endpoint_group(self):
+ arglist = [
+ '--endpointgroup', self.endpoint_group.id,
+ ]
+ verifylist = [
+ ('endpointgroup', self.endpoint_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+ self.epf_mock.list_projects_for_endpoint_group.assert_called_with(
+ endpoint_group=self.endpoint_group.id
+ )
+
+ self.assertEqual(self.columns, columns)
+ datalist = (
+ (
+ self.project.id,
+ self.project.name,
+ self.project.description,
+ ),
+ )
+ self.assertEqual(datalist, tuple(data))
+
+ def test_endpoint_group_list_by_project(self):
+ self.epf_mock.list_endpoints_for_project.return_value = [
+ self.endpoint_group
+ ]
+ self.projects_mock.get.return_value = self.project
+
+ arglist = [
+ '--project', self.project.name,
+ '--domain', self.domain.name
+ ]
+ verifylist = [
+ ('project', self.project.name),
+ ('domain', self.domain.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class Lister in cliff, abstract method take_action()
+ # returns a tuple containing the column names and an iterable
+ # containing the data to be listed.
+ columns, data = self.cmd.take_action(parsed_args)
+ self.epf_mock.list_endpoint_groups_for_project.assert_called_with(
+ project=self.project.id
+ )
+
+ self.assertEqual(self.columns, columns)
+ datalist = (
+ (
+ self.endpoint_group.id,
+ self.endpoint_group.name,
+ self.endpoint_group.description,
+ ),
+ )
+ self.assertEqual(datalist, tuple(data))
+
+
+class TestEndpointGroupSet(TestEndpointGroup):
+
+ endpoint_group = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup())
+
+ def setUp(self):
+ super(TestEndpointGroupSet, self).setUp()
+
+ # This is the return value for utils.find_resource(endpoint)
+ self.endpoint_groups_mock.get.return_value = self.endpoint_group
+
+ self.endpoint_groups_mock.update.return_value = self.endpoint_group
+
+ # Get the command object to test
+ self.cmd = endpoint_group.SetEndpointGroup(self.app, None)
+
+ def test_endpoint_group_set_no_options(self):
+ arglist = [
+ self.endpoint_group.id,
+ ]
+ verifylist = [
+ ('endpointgroup', self.endpoint_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ kwargs = {
+ 'name': None,
+ 'filters': None,
+ 'description': ''
+ }
+ self.endpoint_groups_mock.update.assert_called_with(
+ self.endpoint_group.id,
+ **kwargs
+ )
+ self.assertIsNone(result)
+
+ def test_endpoint_group_set_name(self):
+ arglist = [
+ '--name', 'qwerty',
+ self.endpoint_group.id
+ ]
+ verifylist = [
+ ('name', 'qwerty'),
+ ('endpointgroup', self.endpoint_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': 'qwerty',
+ 'filters': None,
+ 'description': ''
+ }
+ self.endpoint_groups_mock.update.assert_called_with(
+ self.endpoint_group.id,
+ **kwargs
+ )
+ self.assertIsNone(result)
+
+ def test_endpoint_group_set_filters(self):
+ arglist = [
+ '--filters', identity_fakes.endpoint_group_file_path,
+ self.endpoint_group.id,
+ ]
+ verifylist = [
+ ('filters', identity_fakes.endpoint_group_file_path),
+ ('endpointgroup', self.endpoint_group.id),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ mocker = mock.Mock()
+ mocker.return_value = identity_fakes.endpoint_group_filters_2
+ with mock.patch("openstackclient.identity.v3.endpoint_group."
+ "SetEndpointGroup._read_filters", mocker):
+ result = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': None,
+ 'filters': identity_fakes.endpoint_group_filters_2,
+ 'description': '',
+ }
+
+ self.endpoint_groups_mock.update.assert_called_with(
+ self.endpoint_group.id,
+ **kwargs
+ )
+
+ self.assertIsNone(result)
+
+ def test_endpoint_group_set_description(self):
+ arglist = [
+ '--description', 'qwerty',
+ self.endpoint_group.id
+ ]
+ verifylist = [
+ ('description', 'qwerty'),
+ ('endpointgroup', self.endpoint_group.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': None,
+ 'filters': None,
+ 'description': 'qwerty',
+ }
+ self.endpoint_groups_mock.update.assert_called_with(
+ self.endpoint_group.id,
+ **kwargs
+ )
+ self.assertIsNone(result)
+
+
+class TestAddProjectToEndpointGroup(TestEndpointGroup):
+
+ project = identity_fakes.FakeProject.create_one_project()
+ domain = identity_fakes.FakeDomain.create_one_domain()
+ endpoint_group = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup())
+
+ new_ep_filter = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup_filter(
+ attrs={'endpointgroup': endpoint_group.id,
+ 'project': project.id}))
+
+ def setUp(self):
+ super(TestAddProjectToEndpointGroup, self).setUp()
+
+ # This is the return value for utils.find_resource()
+ self.endpoint_groups_mock.get.return_value = self.endpoint_group
+
+ # Update the image_id in the MEMBER dict
+ self.epf_mock.create.return_value = self.new_ep_filter
+ self.projects_mock.get.return_value = self.project
+ self.domains_mock.get.return_value = self.domain
+
+ # Get the command object to test
+ self.cmd = endpoint_group.AddProjectToEndpointGroup(self.app, None)
+
+ def test_add_project_to_endpoint_no_option(self):
+ arglist = [
+ self.endpoint_group.id,
+ self.project.id,
+ ]
+ verifylist = [
+ ('endpointgroup', self.endpoint_group.id),
+ ('project', self.project.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.epf_mock.add_endpoint_group_to_project.assert_called_with(
+ project=self.project.id,
+ endpoint_group=self.endpoint_group.id,
+ )
+ self.assertIsNone(result)
+
+ def test_add_project_to_endpoint_with_option(self):
+ arglist = [
+ self.endpoint_group.id,
+ self.project.id,
+ '--project-domain', self.domain.id,
+ ]
+ verifylist = [
+ ('endpointgroup', self.endpoint_group.id),
+ ('project', self.project.id),
+ ('project_domain', self.domain.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+ self.epf_mock.add_endpoint_group_to_project.assert_called_with(
+ project=self.project.id,
+ endpoint_group=self.endpoint_group.id,
+ )
+ self.assertIsNone(result)
+
+
+class TestRemoveProjectEndpointGroup(TestEndpointGroup):
+
+ project = identity_fakes.FakeProject.create_one_project()
+ domain = identity_fakes.FakeDomain.create_one_domain()
+ endpoint_group = (
+ identity_fakes.FakeEndpointGroup.create_one_endpointgroup())
+
+ def setUp(self):
+ super(TestRemoveProjectEndpointGroup, self).setUp()
+
+ # This is the return value for utils.find_resource()
+ self.endpoint_groups_mock.get.return_value = self.endpoint_group
+
+ self.projects_mock.get.return_value = self.project
+ self.domains_mock.get.return_value = self.domain
+ self.epf_mock.delete.return_value = None
+
+ # Get the command object to test
+ self.cmd = endpoint_group.RemoveProjectFromEndpointGroup(
+ self.app, None)
+
+ def test_remove_project_endpoint_no_options(self):
+ arglist = [
+ self.endpoint_group.id,
+ self.project.id,
+ ]
+ verifylist = [
+ ('endpointgroup', self.endpoint_group.id),
+ ('project', self.project.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.epf_mock.delete_endpoint_group_from_project.assert_called_with(
+ project=self.project.id,
+ endpoint_group=self.endpoint_group.id,
+ )
+ self.assertIsNone(result)
+
+ def test_remove_project_endpoint_with_options(self):
+ arglist = [
+ self.endpoint_group.id,
+ self.project.id,
+ '--project-domain', self.domain.id,
+ ]
+ verifylist = [
+ ('endpointgroup', self.endpoint_group.id),
+ ('project', self.project.id),
+ ('project_domain', self.domain.id),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ self.epf_mock.delete_endpoint_group_from_project.assert_called_with(
+ project=self.project.id,
+ endpoint_group=self.endpoint_group.id,
+ )
+ self.assertIsNone(result)
diff --git a/openstackclient/tests/unit/identity/v3/test_role.py b/openstackclient/tests/unit/identity/v3/test_role.py
index 281d530c..99f3a2de 100644
--- a/openstackclient/tests/unit/identity/v3/test_role.py
+++ b/openstackclient/tests/unit/identity/v3/test_role.py
@@ -508,21 +508,6 @@ class TestRoleList(TestRole):
copy.deepcopy(identity_fakes.DOMAIN),
loaded=True,
)
- self.projects_mock.get.return_value = fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.PROJECT),
- loaded=True,
- )
- self.users_mock.get.return_value = fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.USER),
- loaded=True,
- )
- self.groups_mock.get.return_value = fakes.FakeResource(
- None,
- copy.deepcopy(identity_fakes.GROUP),
- loaded=True,
- )
# Get the command object to test
self.cmd = role.ListRole(self.app, None)
@@ -542,212 +527,6 @@ class TestRoleList(TestRole):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, tuple(data))
- def test_user_list_inherited(self):
- arglist = [
- '--user', identity_fakes.user_id,
- '--inherited',
- ]
- verifylist = [
- ('user', identity_fakes.user_id),
- ('inherited', True),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # Set expected values
- kwargs = {
- 'domain': 'default',
- 'user': self.users_mock.get(),
- 'os_inherit_extension_inherited': True,
- }
- # RoleManager.list(user=, group=, domain=, project=, **kwargs)
- self.roles_mock.list.assert_called_with(
- **kwargs
- )
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
-
- def test_user_list_user(self):
- arglist = [
- '--user', identity_fakes.user_id,
- ]
- verifylist = [
- ('user', identity_fakes.user_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # Set expected values
- kwargs = {
- 'domain': 'default',
- 'user': self.users_mock.get(),
- 'os_inherit_extension_inherited': False
- }
- # RoleManager.list(user=, group=, domain=, project=, **kwargs)
- self.roles_mock.list.assert_called_with(
- **kwargs
- )
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
-
- def test_role_list_domain_user(self):
- arglist = [
- '--domain', identity_fakes.domain_name,
- '--user', identity_fakes.user_id,
- ]
- verifylist = [
- ('domain', identity_fakes.domain_name),
- ('user', identity_fakes.user_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # Set expected values
- kwargs = {
- 'domain': self.domains_mock.get(),
- 'user': self.users_mock.get(),
- 'os_inherit_extension_inherited': False
- }
- # RoleManager.list(user=, group=, domain=, project=, **kwargs)
- self.roles_mock.list.assert_called_with(
- **kwargs
- )
-
- collist = ('ID', 'Name', 'Domain', 'User')
- self.assertEqual(collist, columns)
- datalist = ((
- identity_fakes.role_id,
- identity_fakes.role_name,
- identity_fakes.domain_name,
- identity_fakes.user_name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
- def test_role_list_domain_group(self):
- arglist = [
- '--domain', identity_fakes.domain_name,
- '--group', identity_fakes.group_id,
- ]
- verifylist = [
- ('domain', identity_fakes.domain_name),
- ('group', identity_fakes.group_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # Set expected values
- kwargs = {
- 'domain': self.domains_mock.get(),
- 'group': self.groups_mock.get(),
- 'os_inherit_extension_inherited': False
- }
- # RoleManager.list(user=, group=, domain=, project=, **kwargs)
- self.roles_mock.list.assert_called_with(
- **kwargs
- )
-
- collist = ('ID', 'Name', 'Domain', 'Group')
- self.assertEqual(collist, columns)
- datalist = ((
- identity_fakes.role_id,
- identity_fakes.role_name,
- identity_fakes.domain_name,
- identity_fakes.group_name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
- def test_role_list_project_user(self):
- arglist = [
- '--project', identity_fakes.project_name,
- '--user', identity_fakes.user_id,
- ]
- verifylist = [
- ('project', identity_fakes.project_name),
- ('user', identity_fakes.user_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # Set expected values
- kwargs = {
- 'project': self.projects_mock.get(),
- 'user': self.users_mock.get(),
- 'os_inherit_extension_inherited': False
- }
- # RoleManager.list(user=, group=, domain=, project=, **kwargs)
- self.roles_mock.list.assert_called_with(
- **kwargs
- )
-
- collist = ('ID', 'Name', 'Project', 'User')
- self.assertEqual(collist, columns)
- datalist = ((
- identity_fakes.role_id,
- identity_fakes.role_name,
- identity_fakes.project_name,
- identity_fakes.user_name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
- def test_role_list_project_group(self):
- arglist = [
- '--project', identity_fakes.project_name,
- '--group', identity_fakes.group_id,
- ]
- verifylist = [
- ('project', identity_fakes.project_name),
- ('group', identity_fakes.group_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- # In base command class Lister in cliff, abstract method take_action()
- # returns a tuple containing the column names and an iterable
- # containing the data to be listed.
- columns, data = self.cmd.take_action(parsed_args)
-
- # Set expected values
- kwargs = {
- 'project': self.projects_mock.get(),
- 'group': self.groups_mock.get(),
- 'os_inherit_extension_inherited': False
- }
- # RoleManager.list(user=, group=, domain=, project=, **kwargs)
- self.roles_mock.list.assert_called_with(
- **kwargs
- )
-
- collist = ('ID', 'Name', 'Project', 'Group')
- self.assertEqual(collist, columns)
- datalist = ((
- identity_fakes.role_id,
- identity_fakes.role_name,
- identity_fakes.project_name,
- identity_fakes.group_name,
- ), )
- self.assertEqual(datalist, tuple(data))
-
def test_role_list_domain_role(self):
self.roles_mock.list.return_value = [
fakes.FakeResource(
@@ -787,17 +566,6 @@ class TestRoleList(TestRole):
), )
self.assertEqual(datalist, tuple(data))
- def test_role_list_group_with_error(self):
- arglist = [
- '--group', identity_fakes.group_id,
- ]
- verifylist = [
- ('group', identity_fakes.group_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- self.assertRaises(exceptions.CommandError,
- self.cmd.take_action, parsed_args)
-
class TestRoleRemove(TestRole):
diff --git a/openstackclient/tests/unit/image/v1/test_image.py b/openstackclient/tests/unit/image/v1/test_image.py
index ae578d91..0997d765 100644
--- a/openstackclient/tests/unit/image/v1/test_image.py
+++ b/openstackclient/tests/unit/image/v1/test_image.py
@@ -16,8 +16,9 @@
import copy
import mock
+
+from osc_lib.cli import format_columns
from osc_lib import exceptions
-from osc_lib import utils
from openstackclient.image.v1 import image
from openstackclient.tests.unit import fakes
@@ -58,7 +59,7 @@ class TestImageCreate(TestImage):
new_image.min_ram,
new_image.name,
new_image.owner,
- utils.format_dict(new_image.properties),
+ format_columns.DictColumn(new_image.properties),
new_image.protected,
)
@@ -106,7 +107,7 @@ class TestImageCreate(TestImage):
self.assertEqual(self.images_mock.update.call_args_list, [])
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_image_reserve_options(self):
mock_exception = {
@@ -160,7 +161,7 @@ class TestImageCreate(TestImage):
self.assertEqual(self.images_mock.update.call_args_list, [])
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
@mock.patch('openstackclient.image.v1.image.io.open', name='Open')
def test_image_create_file(self, mock_open):
@@ -224,7 +225,7 @@ class TestImageCreate(TestImage):
self.assertEqual(self.images_mock.update.call_args_list, [])
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
class TestImageDelete(TestImage):
@@ -410,14 +411,15 @@ class TestImageList(TestImage):
'',
'',
'',
- 'public',
+ image.VisibilityColumn(True),
False,
self._image.owner,
- "Alpha='a', Beta='b', Gamma='g'",
+ format_columns.DictColumn(
+ {'Alpha': 'a', 'Beta': 'b', 'Gamma': 'g'}),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
- @mock.patch('openstackclient.api.utils.simple_filter')
+ @mock.patch('osc_lib.api.utils.simple_filter')
def test_image_list_property_option(self, sf_mock):
sf_mock.side_effect = [
[self.image_info], [],
@@ -742,7 +744,7 @@ class TestImageShow(TestImage):
_image.min_ram,
_image.name,
_image.owner,
- utils.format_dict(_image.properties),
+ format_columns.DictColumn(_image.properties),
_image.protected,
_image.size,
)
@@ -773,7 +775,7 @@ class TestImageShow(TestImage):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_image_show_human_readable(self):
arglist = [
diff --git a/openstackclient/tests/unit/image/v2/fakes.py b/openstackclient/tests/unit/image/v2/fakes.py
index d82d8114..f69a2bc3 100644
--- a/openstackclient/tests/unit/image/v2/fakes.py
+++ b/openstackclient/tests/unit/image/v2/fakes.py
@@ -19,7 +19,7 @@ import uuid
from glanceclient.v2 import schemas
import mock
-from osc_lib import utils as common_utils
+from osc_lib.cli import format_columns
import warlock
from openstackclient.tests.unit import fakes
@@ -48,7 +48,7 @@ IMAGE_columns = tuple(sorted(IMAGE))
IMAGE_data = tuple((IMAGE[x] for x in sorted(IMAGE)))
IMAGE_SHOW = copy.copy(IMAGE)
-IMAGE_SHOW['tags'] = ''
+IMAGE_SHOW['tags'] = format_columns.ListColumn(IMAGE_SHOW['tags'])
IMAGE_SHOW_data = tuple((IMAGE_SHOW[x] for x in sorted(IMAGE_SHOW)))
# Just enough v2 schema to do some testing
@@ -281,7 +281,7 @@ class FakeImage(object):
if x == 'tags':
# The 'tags' should be format_list
data_list.append(
- common_utils.format_list(getattr(image, x)))
+ format_columns.ListColumn(getattr(image, x)))
else:
data_list.append(getattr(image, x))
return tuple(data_list)
diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py
index 16a393df..748a61aa 100644
--- a/openstackclient/tests/unit/image/v2/test_image.py
+++ b/openstackclient/tests/unit/image/v2/test_image.py
@@ -18,8 +18,8 @@ import copy
from glanceclient.common import utils as glanceclient_utils
from glanceclient.v2 import schemas
import mock
+from osc_lib.cli import format_columns
from osc_lib import exceptions
-from osc_lib import utils as common_utils
import warlock
from openstackclient.image.v2 import image
@@ -116,7 +116,7 @@ class TestImageCreate(TestImage):
self.assertEqual(
image_fakes.FakeImage.get_image_columns(self.new_image),
columns)
- self.assertEqual(
+ self.assertItemEqual(
image_fakes.FakeImage.get_image_data(self.new_image),
data)
@@ -184,44 +184,10 @@ class TestImageCreate(TestImage):
self.assertEqual(
image_fakes.FakeImage.get_image_columns(self.new_image),
columns)
- self.assertEqual(
+ self.assertItemEqual(
image_fakes.FakeImage.get_image_data(self.new_image),
data)
- def test_image_create_with_unexist_owner(self):
- self.project_mock.get.side_effect = exceptions.NotFound(None)
- self.project_mock.find.side_effect = exceptions.NotFound(None)
-
- arglist = [
- '--container-format', 'ovf',
- '--disk-format', 'ami',
- '--min-disk', '10',
- '--min-ram', '4',
- '--owner', 'unexist_owner',
- '--protected',
- '--private',
- image_fakes.image_name,
- ]
- verifylist = [
- ('container_format', 'ovf'),
- ('disk_format', 'ami'),
- ('min_disk', 10),
- ('min_ram', 4),
- ('owner', 'unexist_owner'),
- ('protected', True),
- ('unprotected', False),
- ('public', False),
- ('private', True),
- ('name', image_fakes.image_name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- self.assertRaises(
- exceptions.CommandError,
- self.cmd.take_action,
- parsed_args,
- )
-
def test_image_create_with_unexist_project(self):
self.project_mock.get.side_effect = exceptions.NotFound(None)
self.project_mock.find.side_effect = exceptions.NotFound(None)
@@ -318,7 +284,7 @@ class TestImageCreate(TestImage):
self.assertEqual(
image_fakes.FakeImage.get_image_columns(self.new_image),
columns)
- self.assertEqual(
+ self.assertItemEqual(
image_fakes.FakeImage.get_image_data(self.new_image),
data)
@@ -542,7 +508,7 @@ class TestImageList(TestImage):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_image_list_public_option(self):
arglist = [
@@ -567,7 +533,7 @@ class TestImageList(TestImage):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_image_list_private_option(self):
arglist = [
@@ -592,7 +558,7 @@ class TestImageList(TestImage):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_image_list_community_option(self):
arglist = [
@@ -642,7 +608,7 @@ class TestImageList(TestImage):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_image_list_shared_member_status_option(self):
arglist = [
@@ -730,11 +696,11 @@ class TestImageList(TestImage):
self._image.visibility,
self._image.protected,
self._image.owner,
- common_utils.format_list(self._image.tags),
+ format_columns.ListColumn(self._image.tags),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
- @mock.patch('openstackclient.api.utils.simple_filter')
+ @mock.patch('osc_lib.api.utils.simple_filter')
def test_image_list_property_option(self, sf_mock):
sf_mock.return_value = [copy.deepcopy(self._image)]
@@ -761,7 +727,7 @@ class TestImageList(TestImage):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
@mock.patch('osc_lib.utils.sort_items')
def test_image_list_sort_option(self, si_mock):
@@ -784,7 +750,7 @@ class TestImageList(TestImage):
str,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_image_list_limit_option(self):
ret_limit = 1
@@ -1146,24 +1112,6 @@ class TestImageSet(TestImage):
image_fakes.image_id, **kwargs)
self.assertIsNone(result)
- def test_image_set_with_unexist_owner(self):
- self.project_mock.get.side_effect = exceptions.NotFound(None)
- self.project_mock.find.side_effect = exceptions.NotFound(None)
-
- arglist = [
- '--owner', 'unexist_owner',
- image_fakes.image_id,
- ]
- verifylist = [
- ('owner', 'unexist_owner'),
- ('image', image_fakes.image_id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- self.assertRaises(
- exceptions.CommandError,
- self.cmd.take_action, parsed_args)
-
def test_image_set_with_unexist_project(self):
self.project_mock.get.side_effect = exceptions.NotFound(None)
self.project_mock.find.side_effect = exceptions.NotFound(None)
@@ -1512,7 +1460,7 @@ class TestImageShow(TestImage):
)
self.assertEqual(image_fakes.IMAGE_columns, columns)
- self.assertEqual(image_fakes.IMAGE_SHOW_data, data)
+ self.assertItemEqual(image_fakes.IMAGE_SHOW_data, data)
def test_image_show_human_readable(self):
self.images_mock.get.return_value = self.new_image
diff --git a/openstackclient/tests/unit/integ/cli/test_shell.py b/openstackclient/tests/unit/integ/cli/test_shell.py
index 70303be3..200f9b18 100644
--- a/openstackclient/tests/unit/integ/cli/test_shell.py
+++ b/openstackclient/tests/unit/integ/cli/test_shell.py
@@ -12,6 +12,7 @@
import copy
+import fixtures
import mock
from osc_lib.tests import utils as osc_lib_utils
@@ -399,6 +400,16 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
test_shell.PUBLIC_1['public-clouds']['megadodo']['auth']['auth_url'] \
= test_base.V3_AUTH_URL
+ def get_temp_file_path(self, filename):
+ """Returns an absolute path for a temporary file.
+
+ :param filename: filename
+ :type filename: string
+ :returns: absolute file path string
+ """
+ temp_dir = self.useFixture(fixtures.TempDir())
+ return temp_dir.join(filename)
+
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_vendor_file")
@mock.patch(CONFIG_MOCK_BASE + ".OpenStackConfig._load_config_file")
def test_shell_args_precedence_1(self, config_mock, vendor_mock):
@@ -408,7 +419,9 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
"""
def config_mock_return():
- return ('file.yaml', copy.deepcopy(test_shell.CLOUD_2))
+ log_file = self.get_temp_file_path('test_log_file')
+ cloud2 = test_shell.get_cloud(log_file)
+ return ('file.yaml', cloud2)
config_mock.side_effect = config_mock_return
def vendor_mock_return():
@@ -478,7 +491,9 @@ class TestIntegShellCliPrecedenceOCC(test_base.TestInteg):
"""
def config_mock_return():
- return ('file.yaml', copy.deepcopy(test_shell.CLOUD_2))
+ log_file = self.get_temp_file_path('test_log_file')
+ cloud2 = test_shell.get_cloud(log_file)
+ return ('file.yaml', cloud2)
config_mock.side_effect = config_mock_return
def vendor_mock_return():
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index 100ea2b1..e41621a4 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -1305,7 +1305,7 @@ class FakeSecurityGroupRule(object):
'id': 'security-group-rule-id-' + uuid.uuid4().hex,
'port_range_max': None,
'port_range_min': None,
- 'protocol': 'tcp',
+ 'protocol': None,
'remote_group_id': None,
'remote_ip_prefix': '0.0.0.0/0',
'security_group_id': 'security-group-id-' + uuid.uuid4().hex,
diff --git a/openstackclient/tests/unit/network/v2/test_router.py b/openstackclient/tests/unit/network/v2/test_router.py
index 3e5ceac4..079b9746 100644
--- a/openstackclient/tests/unit/network/v2/test_router.py
+++ b/openstackclient/tests/unit/network/v2/test_router.py
@@ -939,52 +939,6 @@ class TestSetRouter(TestRouter):
_testrouter, **attrs)
self.assertIsNone(result)
- def test_set_clear_routes(self):
- arglist = [
- self._router.name,
- '--clear-routes',
- ]
- verifylist = [
- ('router', self._router.name),
- ('clear_routes', True),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- attrs = {
- 'routes': [],
- }
- self.network.update_router.assert_called_once_with(
- self._router, **attrs)
- self.assertIsNone(result)
-
- def test_overwrite_route_clear_routes(self):
- _testrouter = network_fakes.FakeRouter.create_one_router(
- {'routes': [{"destination": "10.0.0.2",
- "nexthop": "1.1.1.1"}]})
- self.network.find_router = mock.Mock(return_value=_testrouter)
- arglist = [
- _testrouter.name,
- '--route', 'destination=10.20.30.0/24,gateway=10.20.30.1',
- '--clear-routes',
- ]
- verifylist = [
- ('router', _testrouter.name),
- ('routes', [{'destination': '10.20.30.0/24',
- 'gateway': '10.20.30.1'}]),
- ('clear_routes', True),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- result = self.cmd.take_action(parsed_args)
- attrs = {
- 'routes': [{'destination': '10.20.30.0/24',
- 'nexthop': '10.20.30.1'}]
- }
- self.network.update_router.assert_called_once_with(
- _testrouter, **attrs)
- self.assertIsNone(result)
-
def test_set_nothing(self):
arglist = [
self._router.name,
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py
index 5c1937e3..6814c197 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py
@@ -72,15 +72,6 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
self.assertRaises(tests_utils.ParserException,
self.check_parser, self.cmd, [], [])
- def test_security_group_rule_create_all_source_options(self, sgr_mock):
- arglist = [
- '--src-ip', '10.10.0.0/24',
- '--src-group', self._security_group['id'],
- self._security_group['id'],
- ]
- self.assertRaises(tests_utils.ParserException,
- self.check_parser, self.cmd, arglist, [])
-
def test_security_group_rule_create_all_remote_options(self, sgr_mock):
arglist = [
'--remote-ip', '10.10.0.0/24',
@@ -151,41 +142,6 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
self.assertEqual(expected_columns, columns)
self.assertEqual(expected_data, data)
- def test_security_group_rule_create_source_group(self, sgr_mock):
- expected_columns, expected_data = self._setup_security_group_rule({
- 'from_port': 22,
- 'to_port': 22,
- 'group': {'name': self._security_group['name']},
- })
- sgr_mock.return_value = self._security_group_rule
- arglist = [
- '--dst-port', str(self._security_group_rule['from_port']),
- '--src-group', self._security_group['name'],
- self._security_group['id'],
- ]
- verifylist = [
- ('dst_port', (self._security_group_rule['from_port'],
- self._security_group_rule['to_port'])),
- ('src_group', self._security_group['name']),
- ('group', self._security_group['id']),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- # TODO(dtroyer): save this for the security group rule changes
- # self.compute.api.security_group_rule_create.assert_called_once_with(
- sgr_mock.assert_called_once_with(
- security_group_id=self._security_group['id'],
- ip_protocol=self._security_group_rule['ip_protocol'],
- from_port=self._security_group_rule['from_port'],
- to_port=self._security_group_rule['to_port'],
- remote_ip=self._security_group_rule['ip_range']['cidr'],
- remote_group=self._security_group['id'],
- )
- self.assertEqual(expected_columns, columns)
- self.assertEqual(expected_data, data)
-
def test_security_group_rule_create_remote_group(self, sgr_mock):
expected_columns, expected_data = self._setup_security_group_rule({
'from_port': 22,
@@ -221,41 +177,6 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
self.assertEqual(expected_columns, columns)
self.assertEqual(expected_data, data)
- def test_security_group_rule_create_source_ip(self, sgr_mock):
- expected_columns, expected_data = self._setup_security_group_rule({
- 'ip_protocol': 'icmp',
- 'from_port': -1,
- 'to_port': -1,
- 'ip_range': {'cidr': '10.0.2.0/24'},
- })
- sgr_mock.return_value = self._security_group_rule
- arglist = [
- '--protocol', self._security_group_rule['ip_protocol'],
- '--src-ip', self._security_group_rule['ip_range']['cidr'],
- self._security_group['id'],
- ]
- verifylist = [
- ('protocol', self._security_group_rule['ip_protocol']),
- ('src_ip', self._security_group_rule['ip_range']['cidr']),
- ('group', self._security_group['id']),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- # TODO(dtroyer): save this for the security group rule changes
- # self.compute.api.security_group_rule_create.assert_called_once_with(
- sgr_mock.assert_called_once_with(
- security_group_id=self._security_group['id'],
- ip_protocol=self._security_group_rule['ip_protocol'],
- from_port=self._security_group_rule['from_port'],
- to_port=self._security_group_rule['to_port'],
- remote_ip=self._security_group_rule['ip_range']['cidr'],
- remote_group=None,
- )
- self.assertEqual(expected_columns, columns)
- self.assertEqual(expected_data, data)
-
def test_security_group_rule_create_remote_ip(self, sgr_mock):
expected_columns, expected_data = self._setup_security_group_rule({
'ip_protocol': 'icmp',
@@ -301,13 +222,13 @@ class TestCreateSecurityGroupRuleCompute(TestSecurityGroupRuleCompute):
sgr_mock.return_value = self._security_group_rule
arglist = [
'--proto', self._security_group_rule['ip_protocol'],
- '--src-ip', self._security_group_rule['ip_range']['cidr'],
+ '--remote-ip', self._security_group_rule['ip_range']['cidr'],
self._security_group['id'],
]
verifylist = [
('proto', self._security_group_rule['ip_protocol']),
('protocol', None),
- ('src_ip', self._security_group_rule['ip_range']['cidr']),
+ ('remote_ip', self._security_group_rule['ip_range']['cidr']),
('group', self._security_group['id']),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
diff --git a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py
index b070ab6a..eb0cf310 100644
--- a/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py
+++ b/openstackclient/tests/unit/network/v2/test_security_group_rule_network.py
@@ -99,15 +99,6 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
self.assertRaises(tests_utils.ParserException,
self.check_parser, self.cmd, [], [])
- def test_create_all_source_options(self):
- arglist = [
- '--src-ip', '10.10.0.0/24',
- '--src-group', self._security_group.id,
- self._security_group.id,
- ]
- self.assertRaises(tests_utils.ParserException,
- self.check_parser, self.cmd, arglist, [])
-
def test_create_all_remote_options(self):
arglist = [
'--remote-ip', '10.10.0.0/24',
@@ -177,10 +168,12 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
def test_create_default_rule(self):
self._setup_security_group_rule({
+ 'protocol': 'tcp',
'port_range_max': 443,
'port_range_min': 443,
})
arglist = [
+ '--protocol', 'tcp',
'--dst-port', str(self._security_group_rule.port_range_min),
self._security_group.id,
]
@@ -212,13 +205,13 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
})
arglist = [
'--proto', self._security_group_rule.protocol,
- '--src-ip', self._security_group_rule.remote_ip_prefix,
+ '--remote-ip', self._security_group_rule.remote_ip_prefix,
self._security_group.id,
]
verifylist = [
('proto', self._security_group_rule.protocol),
('protocol', None),
- ('src_ip', self._security_group_rule.remote_ip_prefix),
+ ('remote_ip', self._security_group_rule.remote_ip_prefix),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -242,13 +235,13 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
})
arglist = [
'--proto', 'any',
- '--src-ip', self._security_group_rule.remote_ip_prefix,
+ '--remote-ip', self._security_group_rule.remote_ip_prefix,
self._security_group.id,
]
verifylist = [
('proto', 'any'),
('protocol', None),
- ('src_ip', self._security_group_rule.remote_ip_prefix),
+ ('remote_ip', self._security_group_rule.remote_ip_prefix),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -267,21 +260,22 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
def test_create_remote_group(self):
self._setup_security_group_rule({
+ 'protocol': 'tcp',
'port_range_max': 22,
'port_range_min': 22,
- 'remote_group_id': self._security_group.id,
})
arglist = [
+ '--protocol', 'tcp',
'--dst-port', str(self._security_group_rule.port_range_min),
'--ingress',
- '--src-group', self._security_group.name,
+ '--remote-group', self._security_group.name,
self._security_group.id,
]
verifylist = [
('dst_port', (self._security_group_rule.port_range_min,
self._security_group_rule.port_range_max)),
('ingress', True),
- ('src_group', self._security_group.name),
+ ('remote_group', self._security_group.name),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -294,7 +288,7 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
'port_range_max': self._security_group_rule.port_range_max,
'port_range_min': self._security_group_rule.port_range_min,
'protocol': self._security_group_rule.protocol,
- 'remote_group_id': self._security_group_rule.remote_group_id,
+ 'remote_group_id': self._security_group.id,
'security_group_id': self._security_group.id,
})
self.assertEqual(self.expected_columns, columns)
@@ -306,12 +300,12 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
})
arglist = [
'--ingress',
- '--src-group', self._security_group.name,
+ '--remote-group', self._security_group.name,
self._security_group.id,
]
verifylist = [
('ingress', True),
- ('src_group', self._security_group.name),
+ ('remote_group', self._security_group.name),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
@@ -335,12 +329,12 @@ class TestCreateSecurityGroupRuleNetwork(TestSecurityGroupRuleNetwork):
})
arglist = [
'--protocol', self._security_group_rule.protocol,
- '--src-ip', self._security_group_rule.remote_ip_prefix,
+ '--remote-ip', self._security_group_rule.remote_ip_prefix,
self._security_group.id,
]
verifylist = [
('protocol', self._security_group_rule.protocol),
- ('src_ip', self._security_group_rule.remote_ip_prefix),
+ ('remote_ip', self._security_group_rule.remote_ip_prefix),
('group', self._security_group.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
diff --git a/openstackclient/tests/unit/test_shell.py b/openstackclient/tests/unit/test_shell.py
index dff37f10..5d413e7e 100644
--- a/openstackclient/tests/unit/test_shell.py
+++ b/openstackclient/tests/unit/test_shell.py
@@ -70,23 +70,6 @@ CLOUD_1 = {
}
}
-CLOUD_2 = {
- 'clouds': {
- 'megacloud': {
- 'cloud': 'megadodo',
- 'auth': {
- 'project_name': 'heart-o-gold',
- 'username': 'zaphod',
- },
- 'region_name': 'occ-cloud,krikkit,occ-env',
- 'log_file': '/tmp/test_log_file',
- 'log_level': 'debug',
- 'cert': 'mycert',
- 'key': 'mickey',
- }
- }
-}
-
PUBLIC_1 = {
'public-clouds': {
'megadodo': {
@@ -118,6 +101,26 @@ global_options = {
}
+def get_cloud(log_file):
+ CLOUD = {
+ 'clouds': {
+ 'megacloud': {
+ 'cloud': 'megadodo',
+ 'auth': {
+ 'project_name': 'heart-o-gold',
+ 'username': 'zaphod',
+ },
+ 'region_name': 'occ-cloud,krikkit,occ-env',
+ 'log_file': log_file,
+ 'log_level': 'debug',
+ 'cert': 'mycert',
+ 'key': 'mickey',
+ }
+ }
+ }
+ return CLOUD
+
+
# Wrap the osc_lib make_shell() function to set the shell class since
# osc-lib's TestShell class doesn't allow us to specify it yet.
# TODO(dtroyer): remove this once the shell_class_patch patch is released
diff --git a/openstackclient/tests/unit/volume/v1/test_qos_specs.py b/openstackclient/tests/unit/volume/v1/test_qos_specs.py
index 442840f9..11dc8084 100644
--- a/openstackclient/tests/unit/volume/v1/test_qos_specs.py
+++ b/openstackclient/tests/unit/volume/v1/test_qos_specs.py
@@ -17,6 +17,8 @@ import copy
import mock
from mock import call
+
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -85,7 +87,7 @@ class TestQosCreate(TestQos):
self.new_qos_spec.consumer,
self.new_qos_spec.id,
self.new_qos_spec.name,
- utils.format_dict(self.new_qos_spec.specs)
+ format_columns.DictColumn(self.new_qos_spec.specs)
)
self.qos_mock.create.return_value = self.new_qos_spec
# Get the command object to test
@@ -108,7 +110,7 @@ class TestQosCreate(TestQos):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_qos_create_with_consumer(self):
arglist = [
@@ -128,7 +130,7 @@ class TestQosCreate(TestQos):
{'consumer': self.new_qos_spec.consumer}
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_qos_create_with_properties(self):
arglist = [
@@ -154,7 +156,7 @@ class TestQosCreate(TestQos):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
class TestQosDelete(TestQos):
@@ -326,8 +328,8 @@ class TestQosList(TestQos):
q.id,
q.name,
q.consumer,
- qos_association.name,
- utils.format_dict(q.specs),
+ format_columns.ListColumn([qos_association.name]),
+ format_columns.DictColumn(q.specs),
))
def setUp(self):
@@ -349,7 +351,7 @@ class TestQosList(TestQos):
self.qos_mock.list.assert_called_with()
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_qos_list_no_association(self):
self.qos_mock.reset_mock()
@@ -373,10 +375,10 @@ class TestQosList(TestQos):
self.qos_specs[1].id,
self.qos_specs[1].name,
self.qos_specs[1].consumer,
- None,
- utils.format_dict(self.qos_specs[1].specs),
+ format_columns.ListColumn(None),
+ format_columns.DictColumn(self.qos_specs[1].specs),
)
- self.assertEqual(ex_data, list(data))
+ self.assertListItemEqual(ex_data, list(data))
class TestQosSet(TestQos):
@@ -447,13 +449,13 @@ class TestQosShow(TestQos):
)
self.assertEqual(collist, columns)
datalist = (
- self.qos_association.name,
+ format_columns.ListColumn([self.qos_association.name]),
self.qos_spec.consumer,
self.qos_spec.id,
self.qos_spec.name,
- utils.format_dict(self.qos_spec.specs),
+ format_columns.DictColumn(self.qos_spec.specs),
)
- self.assertEqual(datalist, tuple(data))
+ self.assertItemEqual(datalist, tuple(data))
class TestQosUnset(TestQos):
diff --git a/openstackclient/tests/unit/volume/v1/test_snapshot.py b/openstackclient/tests/unit/volume/v1/test_snapshot.py
deleted file mode 100644
index 70b55ce2..00000000
--- a/openstackclient/tests/unit/volume/v1/test_snapshot.py
+++ /dev/null
@@ -1,580 +0,0 @@
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-import mock
-from mock import call
-
-from osc_lib import exceptions
-from osc_lib import utils
-
-from openstackclient.tests.unit import utils as tests_utils
-from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
-from openstackclient.volume.v1 import volume_snapshot
-
-
-class TestSnapshot(volume_fakes.TestVolumev1):
-
- def setUp(self):
- super(TestSnapshot, self).setUp()
-
- self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
- self.snapshots_mock.reset_mock()
- self.volumes_mock = self.app.client_manager.volume.volumes
- self.volumes_mock.reset_mock()
-
-
-class TestSnapshotCreate(TestSnapshot):
-
- columns = (
- 'created_at',
- 'display_description',
- 'display_name',
- 'id',
- 'properties',
- 'size',
- 'status',
- 'volume_id',
- )
-
- def setUp(self):
- super(TestSnapshotCreate, self).setUp()
-
- self.volume = volume_fakes.FakeVolume.create_one_volume()
- self.new_snapshot = volume_fakes.FakeSnapshot.create_one_snapshot(
- attrs={'volume_id': self.volume.id})
-
- self.data = (
- self.new_snapshot.created_at,
- self.new_snapshot.display_description,
- self.new_snapshot.display_name,
- self.new_snapshot.id,
- utils.format_dict(self.new_snapshot.metadata),
- self.new_snapshot.size,
- self.new_snapshot.status,
- self.new_snapshot.volume_id,
- )
-
- self.volumes_mock.get.return_value = self.volume
- self.snapshots_mock.create.return_value = self.new_snapshot
- # Get the command object to test
- self.cmd = volume_snapshot.CreateVolumeSnapshot(self.app, None)
-
- def test_snapshot_create(self):
- arglist = [
- "--volume", self.new_snapshot.volume_id,
- "--description", self.new_snapshot.display_description,
- "--force",
- self.new_snapshot.display_name,
- ]
- verifylist = [
- ("volume", self.new_snapshot.volume_id),
- ("description", self.new_snapshot.display_description),
- ("force", True),
- ("snapshot_name", self.new_snapshot.display_name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.create.assert_called_with(
- self.new_snapshot.volume_id,
- True,
- self.new_snapshot.display_name,
- self.new_snapshot.display_description,
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
- def test_snapshot_create_without_name(self):
- arglist = [
- "--volume", self.new_snapshot.volume_id,
- ]
- verifylist = [
- ("volume", self.new_snapshot.volume_id),
- ]
- self.assertRaises(
- tests_utils.ParserException,
- self.check_parser,
- self.cmd,
- arglist,
- verifylist,
- )
-
- def test_snapshot_create_without_volume(self):
- arglist = [
- "--description", self.new_snapshot.display_description,
- "--force",
- self.new_snapshot.display_name
- ]
- verifylist = [
- ("description", self.new_snapshot.display_description),
- ("force", True),
- ("snapshot_name", self.new_snapshot.display_name)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.volumes_mock.get.assert_called_once_with(
- self.new_snapshot.display_name)
- self.snapshots_mock.create.assert_called_once_with(
- self.new_snapshot.volume_id,
- True,
- self.new_snapshot.display_name,
- self.new_snapshot.display_description,
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
-
-class TestSnapshotDelete(TestSnapshot):
-
- snapshots = volume_fakes.FakeSnapshot.create_snapshots(count=2)
-
- def setUp(self):
- super(TestSnapshotDelete, self).setUp()
-
- self.snapshots_mock.get = (
- volume_fakes.FakeSnapshot.get_snapshots(self.snapshots))
- self.snapshots_mock.delete.return_value = None
-
- # Get the command object to mock
- self.cmd = volume_snapshot.DeleteVolumeSnapshot(self.app, None)
-
- def test_snapshot_delete(self):
- arglist = [
- self.snapshots[0].id
- ]
- verifylist = [
- ("snapshots", [self.snapshots[0].id])
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.delete.assert_called_with(
- self.snapshots[0].id)
- self.assertIsNone(result)
-
- def test_delete_multiple_snapshots(self):
- arglist = []
- for s in self.snapshots:
- arglist.append(s.id)
- verifylist = [
- ('snapshots', arglist),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- result = self.cmd.take_action(parsed_args)
-
- calls = []
- for s in self.snapshots:
- calls.append(call(s.id))
- self.snapshots_mock.delete.assert_has_calls(calls)
- self.assertIsNone(result)
-
- def test_delete_multiple_snapshots_with_exception(self):
- arglist = [
- self.snapshots[0].id,
- 'unexist_snapshot',
- ]
- verifylist = [
- ('snapshots', arglist),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- find_mock_result = [self.snapshots[0], exceptions.CommandError]
- with mock.patch.object(utils, 'find_resource',
- side_effect=find_mock_result) as find_mock:
- try:
- self.cmd.take_action(parsed_args)
- self.fail('CommandError should be raised.')
- except exceptions.CommandError as e:
- self.assertEqual('1 of 2 snapshots failed to delete.',
- str(e))
-
- find_mock.assert_any_call(
- self.snapshots_mock, self.snapshots[0].id)
- find_mock.assert_any_call(self.snapshots_mock, 'unexist_snapshot')
-
- self.assertEqual(2, find_mock.call_count)
- self.snapshots_mock.delete.assert_called_once_with(
- self.snapshots[0].id
- )
-
-
-class TestSnapshotList(TestSnapshot):
-
- volume = volume_fakes.FakeVolume.create_one_volume()
- snapshots = volume_fakes.FakeSnapshot.create_snapshots(
- attrs={'volume_id': volume.display_name}, count=3)
-
- columns = [
- "ID",
- "Name",
- "Description",
- "Status",
- "Size"
- ]
- columns_long = columns + [
- "Created At",
- "Volume",
- "Properties"
- ]
-
- data = []
- for s in snapshots:
- data.append((
- s.id,
- s.display_name,
- s.display_description,
- s.status,
- s.size,
- ))
- data_long = []
- for s in snapshots:
- data_long.append((
- s.id,
- s.display_name,
- s.display_description,
- s.status,
- s.size,
- s.created_at,
- s.volume_id,
- utils.format_dict(s.metadata),
- ))
-
- def setUp(self):
- super(TestSnapshotList, self).setUp()
-
- self.volumes_mock.list.return_value = [self.volume]
- self.volumes_mock.get.return_value = self.volume
- self.snapshots_mock.list.return_value = self.snapshots
- # Get the command to test
- self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
-
- def test_snapshot_list_without_options(self):
- arglist = []
- verifylist = [
- ('all_projects', False),
- ("long", False)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- search_opts={
- 'all_tenants': False,
- 'display_name': None,
- 'status': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_with_long(self):
- arglist = [
- "--long",
- ]
- verifylist = [
- ("long", True),
- ('all_projects', False),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- search_opts={
- 'all_tenants': False,
- 'display_name': None,
- 'status': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
-
- def test_snapshot_list_name_option(self):
- arglist = [
- '--name', self.snapshots[0].display_name,
- ]
- verifylist = [
- ('all_projects', False),
- ('long', False),
- ('name', self.snapshots[0].display_name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- search_opts={
- 'all_tenants': False,
- 'display_name': self.snapshots[0].display_name,
- 'status': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_status_option(self):
- arglist = [
- '--status', self.snapshots[0].status,
- ]
- verifylist = [
- ('all_projects', False),
- ('long', False),
- ('status', self.snapshots[0].status),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- search_opts={
- 'all_tenants': False,
- 'display_name': None,
- 'status': self.snapshots[0].status,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_volumeid_option(self):
- arglist = [
- '--volume', self.volume.id,
- ]
- verifylist = [
- ('all_projects', False),
- ('long', False),
- ('volume', self.volume.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- search_opts={
- 'all_tenants': False,
- 'display_name': None,
- 'status': None,
- 'volume_id': self.volume.id
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_all_projects(self):
- arglist = [
- '--all-projects',
- ]
- verifylist = [
- ('long', False),
- ('all_projects', True)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- search_opts={
- 'all_tenants': True,
- 'display_name': None,
- 'status': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
-
-class TestSnapshotSet(TestSnapshot):
-
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
-
- def setUp(self):
- super(TestSnapshotSet, self).setUp()
-
- self.snapshots_mock.get.return_value = self.snapshot
- self.snapshots_mock.set_metadata.return_value = None
- # Get the command object to mock
- self.cmd = volume_snapshot.SetVolumeSnapshot(self.app, None)
-
- def test_snapshot_set_all(self):
- arglist = [
- "--name", "new_snapshot",
- "--description", "new_description",
- "--property", "foo_1=foo_1",
- "--property", "foo_2=foo_2",
- "--no-property",
- self.snapshot.id,
- ]
- new_property = {"foo_1": "foo_1", "foo_2": "foo_2"}
- verifylist = [
- ("name", "new_snapshot"),
- ("description", "new_description"),
- ("property", new_property),
- ("no_property", True),
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- kwargs = {
- "display_name": "new_snapshot",
- "display_description": "new_description",
- }
- self.snapshot.update.assert_called_with(**kwargs)
- self.snapshots_mock.delete_metadata.assert_called_with(
- self.snapshot.id, ["foo"]
- )
- self.snapshots_mock.set_metadata.assert_called_with(
- self.snapshot.id, {"foo_2": "foo_2", "foo_1": "foo_1"}
- )
- self.assertIsNone(result)
-
- def test_snapshot_set_nothing(self):
- arglist = [
- self.snapshot.id,
- ]
- verifylist = [
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
- self.assertIsNone(result)
-
- def test_snapshot_set_fail(self):
- self.snapshots_mock.set_metadata.side_effect = (
- exceptions.CommandError())
- arglist = [
- "--name", "new_snapshot",
- "--description", "new_description",
- "--property", "x=y",
- "--property", "foo=foo",
- self.snapshot.id,
- ]
- new_property = {"x": "y", "foo": "foo"}
- verifylist = [
- ("name", "new_snapshot"),
- ("description", "new_description"),
- ("property", new_property),
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- self.assertRaises(exceptions.CommandError,
- self.cmd.take_action, parsed_args)
-
-
-class TestSnapshotShow(TestSnapshot):
-
- columns = (
- 'created_at',
- 'display_description',
- 'display_name',
- 'id',
- 'properties',
- 'size',
- 'status',
- 'volume_id',
- )
-
- def setUp(self):
- super(TestSnapshotShow, self).setUp()
-
- self.snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
-
- self.data = (
- self.snapshot.created_at,
- self.snapshot.display_description,
- self.snapshot.display_name,
- self.snapshot.id,
- utils.format_dict(self.snapshot.metadata),
- self.snapshot.size,
- self.snapshot.status,
- self.snapshot.volume_id,
- )
-
- self.snapshots_mock.get.return_value = self.snapshot
- # Get the command object to test
- self.cmd = volume_snapshot.ShowVolumeSnapshot(self.app, None)
-
- def test_snapshot_show(self):
- arglist = [
- self.snapshot.id
- ]
- verifylist = [
- ("snapshot", self.snapshot.id)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
- self.snapshots_mock.get.assert_called_with(self.snapshot.id)
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
-
-class TestSnapshotUnset(TestSnapshot):
-
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
-
- def setUp(self):
- super(TestSnapshotUnset, self).setUp()
-
- self.snapshots_mock.get.return_value = self.snapshot
- self.snapshots_mock.delete_metadata.return_value = None
- # Get the command object to mock
- self.cmd = volume_snapshot.UnsetVolumeSnapshot(self.app, None)
-
- def test_snapshot_unset(self):
- arglist = [
- "--property", "foo",
- self.snapshot.id,
- ]
- verifylist = [
- ("property", ["foo"]),
- ("snapshot", self.snapshot.id),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.delete_metadata.assert_called_with(
- self.snapshot.id, ["foo"]
- )
- self.assertIsNone(result)
-
- def test_snapshot_unset_nothing(self):
- arglist = [
- self.snapshot.id,
- ]
- verifylist = [
- ("snapshot", self.snapshot.id),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
- self.assertIsNone(result)
diff --git a/openstackclient/tests/unit/volume/v1/test_transfer_request.py b/openstackclient/tests/unit/volume/v1/test_transfer_request.py
index 4c013dc0..680561d5 100644
--- a/openstackclient/tests/unit/volume/v1/test_transfer_request.py
+++ b/openstackclient/tests/unit/volume/v1/test_transfer_request.py
@@ -85,26 +85,6 @@ class TestTransferAccept(TestTransfer):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
- def test_transfer_accept_deprecated(self):
- arglist = [
- self.volume_transfer.id,
- 'key_value',
- ]
- verifylist = [
- ('transfer_request', self.volume_transfer.id),
- ('old_auth_key', 'key_value'),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.transfer_mock.accept.assert_called_once_with(
- self.volume_transfer.id,
- 'key_value',
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
def test_transfer_accept_no_option(self):
arglist = [
self.volume_transfer.id,
diff --git a/openstackclient/tests/unit/volume/v1/test_type.py b/openstackclient/tests/unit/volume/v1/test_type.py
index dcdd3d56..beff8336 100644
--- a/openstackclient/tests/unit/volume/v1/test_type.py
+++ b/openstackclient/tests/unit/volume/v1/test_type.py
@@ -15,6 +15,7 @@
import mock
from mock import call
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -77,7 +78,7 @@ class TestTypeCreate(TestType):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_type_create_with_encryption(self):
encryption_info = {
@@ -102,7 +103,7 @@ class TestTypeCreate(TestType):
)
encryption_data = (
self.new_volume_type.description,
- utils.format_dict(encryption_info),
+ format_columns.DictColumn(encryption_info),
self.new_volume_type.id,
True,
self.new_volume_type.name,
@@ -138,7 +139,7 @@ class TestTypeCreate(TestType):
body,
)
self.assertEqual(encryption_columns, columns)
- self.assertEqual(encryption_data, data)
+ self.assertItemEqual(encryption_data, data)
class TestTypeDelete(TestType):
@@ -246,7 +247,7 @@ class TestTypeList(TestType):
t.id,
t.name,
t.is_public,
- utils.format_dict(t.extra_specs),
+ format_columns.DictColumn(t.extra_specs),
))
def setUp(self):
@@ -269,7 +270,7 @@ class TestTypeList(TestType):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with()
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_type_list_with_options(self):
arglist = [
@@ -283,7 +284,7 @@ class TestTypeList(TestType):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with()
self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
+ self.assertListItemEqual(self.data_long, list(data))
def test_type_list_with_encryption(self):
encryption_type = volume_fakes.FakeType.create_one_encryption_type(
@@ -302,13 +303,16 @@ class TestTypeList(TestType):
self.volume_types[0].id,
self.volume_types[0].name,
self.volume_types[0].is_public,
- utils.format_dict(encryption_info),
+ volume_type.EncryptionInfoColumn(
+ self.volume_types[0].id,
+ {self.volume_types[0].id: encryption_info}),
))
encryption_data.append((
self.volume_types[1].id,
self.volume_types[1].name,
self.volume_types[1].is_public,
- '-',
+ volume_type.EncryptionInfoColumn(
+ self.volume_types[1].id, {}),
))
self.encryption_types_mock.list.return_value = [encryption_type]
@@ -324,7 +328,7 @@ class TestTypeList(TestType):
self.encryption_types_mock.list.assert_called_once_with()
self.types_mock.list.assert_called_once_with()
self.assertEqual(encryption_columns, columns)
- self.assertEqual(encryption_data, list(data))
+ self.assertListItemEqual(encryption_data, list(data))
class TestTypeSet(TestType):
@@ -443,7 +447,7 @@ class TestTypeShow(TestType):
self.volume_type.id,
True,
self.volume_type.name,
- utils.format_dict(self.volume_type.extra_specs)
+ format_columns.DictColumn(self.volume_type.extra_specs)
)
self.types_mock.get.return_value = self.volume_type
@@ -465,7 +469,7 @@ class TestTypeShow(TestType):
self.types_mock.get.assert_called_with(self.volume_type.id)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_type_show_with_encryption(self):
encryption_type = volume_fakes.FakeType.create_one_encryption_type()
@@ -489,11 +493,11 @@ class TestTypeShow(TestType):
)
encryption_data = (
self.volume_type.description,
- utils.format_dict(encryption_info),
+ format_columns.DictColumn(encryption_info),
self.volume_type.id,
True,
self.volume_type.name,
- utils.format_dict(self.volume_type.extra_specs)
+ format_columns.DictColumn(self.volume_type.extra_specs)
)
arglist = [
'--encryption-type',
@@ -509,7 +513,7 @@ class TestTypeShow(TestType):
self.types_mock.get.assert_called_with(self.volume_type.id)
self.encryption_types_mock.get.assert_called_with(self.volume_type.id)
self.assertEqual(encryption_columns, columns)
- self.assertEqual(encryption_data, data)
+ self.assertItemEqual(encryption_data, data)
class TestTypeUnset(TestType):
@@ -587,3 +591,30 @@ class TestTypeUnset(TestType):
result = self.cmd.take_action(parsed_args)
self.encryption_types_mock.delete.assert_called_with(self.volume_type)
self.assertIsNone(result)
+
+
+class TestColumns(TestType):
+
+ def test_encryption_info_column_with_info(self):
+ fake_volume_type = volume_fakes.FakeType.create_one_type()
+ type_id = fake_volume_type.id
+
+ encryption_info = {
+ 'provider': 'LuksEncryptor',
+ 'cipher': None,
+ 'key_size': None,
+ 'control_location': 'front-end',
+ }
+ col = volume_type.EncryptionInfoColumn(type_id,
+ {type_id: encryption_info})
+ self.assertEqual(utils.format_dict(encryption_info),
+ col.human_readable())
+ self.assertEqual(encryption_info, col.machine_readable())
+
+ def test_encryption_info_column_without_info(self):
+ fake_volume_type = volume_fakes.FakeType.create_one_type()
+ type_id = fake_volume_type.id
+
+ col = volume_type.EncryptionInfoColumn(type_id, {})
+ self.assertEqual('-', col.human_readable())
+ self.assertIsNone(col.machine_readable())
diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py
index eee5acd7..c4154555 100644
--- a/openstackclient/tests/unit/volume/v1/test_volume.py
+++ b/openstackclient/tests/unit/volume/v1/test_volume.py
@@ -17,6 +17,8 @@ import argparse
import mock
from mock import call
+
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -88,7 +90,7 @@ class TestVolumeCreate(TestVolume):
self.new_volume.display_description,
self.new_volume.id,
self.new_volume.display_name,
- utils.format_dict(self.new_volume.metadata),
+ format_columns.DictColumn(self.new_volume.metadata),
self.new_volume.size,
self.new_volume.snapshot_id,
self.new_volume.status,
@@ -134,7 +136,7 @@ class TestVolumeCreate(TestVolume):
None,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_options(self):
arglist = [
@@ -178,7 +180,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_user_project_id(self):
# Return a project
@@ -225,7 +227,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_user_project_name(self):
# Return a project
@@ -272,7 +274,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_properties(self):
arglist = [
@@ -313,7 +315,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_image_id(self):
image = image_fakes.FakeImage.create_one_image()
@@ -356,7 +358,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_image_name(self):
image = image_fakes.FakeImage.create_one_image()
@@ -399,7 +401,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_with_source(self):
self.volumes_mock.get.return_value = self.new_volume
@@ -429,7 +431,7 @@ class TestVolumeCreate(TestVolume):
None,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_with_bootable_and_readonly(self):
arglist = [
@@ -467,7 +469,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
self.volumes_mock.set_bootable.assert_called_with(
self.new_volume.id, True)
self.volumes_mock.update_readonly_flag.assert_called_with(
@@ -509,7 +511,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
self.volumes_mock.set_bootable.assert_called_with(
self.new_volume.id, False)
self.volumes_mock.update_readonly_flag.assert_called_with(
@@ -561,7 +563,7 @@ class TestVolumeCreate(TestVolume):
self.assertEqual(2, mock_error.call_count)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
self.volumes_mock.set_bootable.assert_called_with(
self.new_volume.id, True)
self.volumes_mock.update_readonly_flag.assert_called_with(
@@ -732,16 +734,13 @@ class TestVolumeList(TestVolume):
'Size',
'Attached to',
)
- server = _volume.attachments[0]['server_id']
- device = _volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = (
(
_volume.id,
_volume.display_name,
_volume.status,
_volume.size,
- msg,
+ volume.AttachmentsColumn(_volume.attachments),
),
)
@@ -767,7 +766,7 @@ class TestVolumeList(TestVolume):
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_volume_list_name(self):
arglist = [
@@ -784,7 +783,7 @@ class TestVolumeList(TestVolume):
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, tuple(columns))
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_volume_list_status(self):
arglist = [
@@ -801,7 +800,7 @@ class TestVolumeList(TestVolume):
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, tuple(columns))
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_volume_list_all_projects(self):
arglist = [
@@ -818,7 +817,7 @@ class TestVolumeList(TestVolume):
columns, data = self.cmd.take_action(parsed_args)
self.assertEqual(self.columns, tuple(columns))
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_volume_list_long(self):
arglist = [
@@ -855,10 +854,10 @@ class TestVolumeList(TestVolume):
self._volume.size,
self._volume.volume_type,
self._volume.bootable,
- self.msg,
- utils.format_dict(self._volume.metadata),
+ volume.AttachmentsColumn(self._volume.attachments),
+ format_columns.DictColumn(self._volume.metadata),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_with_limit(self):
arglist = [
@@ -883,7 +882,7 @@ class TestVolumeList(TestVolume):
'all_tenants': False, }
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, tuple(data))
+ self.assertListItemEqual(self.datalist, tuple(data))
def test_volume_list_negative_limit(self):
arglist = [
@@ -1251,7 +1250,7 @@ class TestVolumeShow(TestVolume):
self._volume.display_description,
self._volume.id,
self._volume.display_name,
- utils.format_dict(self._volume.metadata),
+ format_columns.DictColumn(self._volume.metadata),
self._volume.size,
self._volume.snapshot_id,
self._volume.status,
@@ -1274,7 +1273,7 @@ class TestVolumeShow(TestVolume):
self.volumes_mock.get.assert_called_with(self._volume.id)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_show_backward_compatibility(self):
arglist = [
@@ -1339,3 +1338,31 @@ class TestVolumeUnset(TestVolume):
self._volume.id, ['myprop']
)
self.assertIsNone(result)
+
+
+class TestColumns(TestVolume):
+
+ def test_attachments_column_without_server_cache(self):
+ _volume = volume_fakes.FakeVolume.create_one_volume()
+ server_id = _volume.attachments[0]['server_id']
+ device = _volume.attachments[0]['device']
+
+ col = volume.AttachmentsColumn(_volume.attachments, {})
+ self.assertEqual('Attached to %s on %s ' % (server_id, device),
+ col.human_readable())
+ self.assertEqual(_volume.attachments, col.machine_readable())
+
+ def test_attachments_column_with_server_cache(self):
+ _volume = volume_fakes.FakeVolume.create_one_volume()
+
+ server_id = _volume.attachments[0]['server_id']
+ device = _volume.attachments[0]['device']
+ fake_server = mock.Mock()
+ fake_server.name = 'fake-server-name'
+ server_cache = {server_id: fake_server}
+
+ col = volume.AttachmentsColumn(_volume.attachments, server_cache)
+ self.assertEqual(
+ 'Attached to %s on %s ' % ('fake-server-name', device),
+ col.human_readable())
+ self.assertEqual(_volume.attachments, col.machine_readable())
diff --git a/openstackclient/tests/unit/volume/v1/test_backup.py b/openstackclient/tests/unit/volume/v1/test_volume_backup.py
index 1097d3f1..20be6e46 100644
--- a/openstackclient/tests/unit/volume/v1/test_backup.py
+++ b/openstackclient/tests/unit/volume/v1/test_volume_backup.py
@@ -19,7 +19,7 @@ from osc_lib import exceptions
from osc_lib import utils
from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
-from openstackclient.volume.v1 import backup
+from openstackclient.volume.v1 import volume_backup
class TestBackup(volume_fakes.TestVolumev1):
@@ -74,7 +74,7 @@ class TestBackupCreate(TestBackup):
self.backups_mock.create.return_value = self.new_backup
# Get the command object to test
- self.cmd = backup.CreateVolumeBackup(self.app, None)
+ self.cmd = volume_backup.CreateVolumeBackup(self.app, None)
def test_backup_create(self):
arglist = [
@@ -100,7 +100,7 @@ class TestBackupCreate(TestBackup):
self.new_backup.description,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_backup_create_without_name(self):
arglist = [
@@ -124,7 +124,7 @@ class TestBackupCreate(TestBackup):
self.new_backup.description,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
class TestBackupDelete(TestBackup):
@@ -139,7 +139,7 @@ class TestBackupDelete(TestBackup):
self.backups_mock.delete.return_value = None
# Get the command object to mock
- self.cmd = backup.DeleteVolumeBackup(self.app, None)
+ self.cmd = volume_backup.DeleteVolumeBackup(self.app, None)
def test_backup_delete(self):
arglist = [
@@ -240,7 +240,7 @@ class TestBackupList(TestBackup):
b.status,
b.size,
b.availability_zone,
- b.volume_id,
+ volume_backup.VolumeIdColumn(b.volume_id),
b.container,
))
@@ -251,7 +251,7 @@ class TestBackupList(TestBackup):
self.backups_mock.list.return_value = self.backups
self.volumes_mock.get.return_value = self.volume
# Get the command to test
- self.cmd = backup.ListVolumeBackup(self.app, None)
+ self.cmd = volume_backup.ListVolumeBackup(self.app, None)
def test_backup_list_without_options(self):
arglist = []
@@ -277,7 +277,7 @@ class TestBackupList(TestBackup):
search_opts=search_opts,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_backup_list_with_options(self):
arglist = [
@@ -309,7 +309,7 @@ class TestBackupList(TestBackup):
search_opts=search_opts,
)
self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
+ self.assertListItemEqual(self.data_long, list(data))
class TestBackupRestore(TestBackup):
@@ -325,7 +325,7 @@ class TestBackupRestore(TestBackup):
self.volumes_mock.get.return_value = self.volume
self.restores_mock.restore.return_value = None
# Get the command object to mock
- self.cmd = backup.RestoreVolumeBackup(self.app, None)
+ self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
def test_backup_restore(self):
arglist = [
@@ -376,7 +376,7 @@ class TestBackupShow(TestBackup):
)
self.backups_mock.get.return_value = self.backup
# Get the command object to test
- self.cmd = backup.ShowVolumeBackup(self.app, None)
+ self.cmd = volume_backup.ShowVolumeBackup(self.app, None)
def test_backup_show(self):
arglist = [
@@ -391,4 +391,4 @@ class TestBackupShow(TestBackup):
self.backups_mock.get.assert_called_with(self.backup.id)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py
index c245cbf6..5f976b06 100644
--- a/openstackclient/tests/unit/volume/v2/fakes.py
+++ b/openstackclient/tests/unit/volume/v2/fakes.py
@@ -17,7 +17,8 @@ import random
import uuid
import mock
-from osc_lib import utils as common_utils
+
+from osc_lib.cli import format_columns
from openstackclient.tests.unit import fakes
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
@@ -468,7 +469,7 @@ class FakeVolume(object):
if x == 'tags':
# The 'tags' should be format_list
data_list.append(
- common_utils.format_list(volume.info.get(x)))
+ format_columns.ListColumn(volume.info.get(x)))
else:
data_list.append(volume.info.get(x))
return tuple(data_list)
diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group.py b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
index 6eeeae39..d2388182 100644
--- a/openstackclient/tests/unit/volume/v2/test_consistency_group.py
+++ b/openstackclient/tests/unit/volume/v2/test_consistency_group.py
@@ -15,6 +15,7 @@
import mock
from mock import call
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -250,7 +251,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_consistency_group_create_from_source(self):
arglist = [
@@ -278,7 +279,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_consistency_group_create_from_snapshot(self):
arglist = [
@@ -306,7 +307,7 @@ class TestConsistencyGroupCreate(TestConsistencyGroup):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
class TestConsistencyGroupDelete(TestConsistencyGroup):
@@ -439,7 +440,7 @@ class TestConsistencyGroupList(TestConsistencyGroup):
c.availability_zone,
c.name,
c.description,
- utils.format_list(c.volume_types)
+ format_columns.ListColumn(c.volume_types)
))
def setUp(self):
@@ -462,7 +463,7 @@ class TestConsistencyGroupList(TestConsistencyGroup):
self.consistencygroups_mock.list.assert_called_once_with(
detailed=True, search_opts={'all_tenants': False})
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_consistency_group_list_with_all_project(self):
arglist = [
@@ -479,7 +480,7 @@ class TestConsistencyGroupList(TestConsistencyGroup):
self.consistencygroups_mock.list.assert_called_once_with(
detailed=True, search_opts={'all_tenants': True})
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_consistency_group_list_with_long(self):
arglist = [
@@ -496,7 +497,7 @@ class TestConsistencyGroupList(TestConsistencyGroup):
self.consistencygroups_mock.list.assert_called_once_with(
detailed=True, search_opts={'all_tenants': False})
self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
+ self.assertListItemEqual(self.data_long, list(data))
class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
@@ -704,4 +705,4 @@ class TestConsistencyGroupShow(TestConsistencyGroup):
self.consistencygroups_mock.get.assert_called_once_with(
self.consistency_group.id)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
diff --git a/openstackclient/tests/unit/volume/v2/test_qos_specs.py b/openstackclient/tests/unit/volume/v2/test_qos_specs.py
index 2b935e20..454747f5 100644
--- a/openstackclient/tests/unit/volume/v2/test_qos_specs.py
+++ b/openstackclient/tests/unit/volume/v2/test_qos_specs.py
@@ -17,6 +17,8 @@ import copy
import mock
from mock import call
+
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -88,7 +90,7 @@ class TestQosCreate(TestQos):
self.new_qos_spec.consumer,
self.new_qos_spec.id,
self.new_qos_spec.name,
- utils.format_dict(self.new_qos_spec.specs)
+ format_columns.DictColumn(self.new_qos_spec.specs)
)
# Get the command object to test
@@ -111,7 +113,7 @@ class TestQosCreate(TestQos):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_qos_create_with_consumer(self):
arglist = [
@@ -132,7 +134,7 @@ class TestQosCreate(TestQos):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_qos_create_with_properties(self):
arglist = [
@@ -158,7 +160,7 @@ class TestQosCreate(TestQos):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
class TestQosDelete(TestQos):
@@ -318,8 +320,8 @@ class TestQosList(TestQos):
q.id,
q.name,
q.consumer,
- qos_association.name,
- utils.format_dict(q.specs),
+ format_columns.ListColumn([qos_association.name]),
+ format_columns.DictColumn(q.specs),
))
def setUp(self):
@@ -341,7 +343,7 @@ class TestQosList(TestQos):
self.qos_mock.list.assert_called_with()
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_qos_list_no_association(self):
self.qos_mock.reset_mock()
@@ -365,10 +367,10 @@ class TestQosList(TestQos):
self.qos_specs[1].id,
self.qos_specs[1].name,
self.qos_specs[1].consumer,
- None,
- utils.format_dict(self.qos_specs[1].specs),
+ format_columns.ListColumn(None),
+ format_columns.DictColumn(self.qos_specs[1].specs),
)
- self.assertEqual(ex_data, list(data))
+ self.assertListItemEqual(ex_data, list(data))
class TestQosSet(TestQos):
@@ -416,11 +418,11 @@ class TestQosShow(TestQos):
'properties'
)
data = (
- qos_association.name,
+ format_columns.ListColumn([qos_association.name]),
qos_spec.consumer,
qos_spec.id,
qos_spec.name,
- utils.format_dict(qos_spec.specs),
+ format_columns.DictColumn(qos_spec.specs),
)
def setUp(self):
@@ -448,7 +450,7 @@ class TestQosShow(TestQos):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, tuple(data))
+ self.assertItemEqual(self.data, tuple(data))
class TestQosUnset(TestQos):
diff --git a/openstackclient/tests/unit/volume/v2/test_snapshot.py b/openstackclient/tests/unit/volume/v2/test_snapshot.py
deleted file mode 100644
index e8f4ae5a..00000000
--- a/openstackclient/tests/unit/volume/v2/test_snapshot.py
+++ /dev/null
@@ -1,741 +0,0 @@
-#
-# Licensed under the Apache License, Version 2.0 (the "License"); you may
-# not use this file except in compliance with the License. You may obtain
-# a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
-# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
-# License for the specific language governing permissions and limitations
-# under the License.
-#
-
-import argparse
-
-import mock
-from mock import call
-from osc_lib import exceptions
-from osc_lib import utils
-
-from openstackclient.tests.unit.identity.v3 import fakes as project_fakes
-from openstackclient.tests.unit import utils as tests_utils
-from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
-from openstackclient.volume.v2 import volume_snapshot
-
-
-class TestSnapshot(volume_fakes.TestVolume):
-
- def setUp(self):
- super(TestSnapshot, self).setUp()
-
- self.snapshots_mock = self.app.client_manager.volume.volume_snapshots
- self.snapshots_mock.reset_mock()
- self.volumes_mock = self.app.client_manager.volume.volumes
- self.volumes_mock.reset_mock()
- self.project_mock = self.app.client_manager.identity.projects
- self.project_mock.reset_mock()
-
-
-class TestSnapshotCreate(TestSnapshot):
-
- columns = (
- 'created_at',
- 'description',
- 'id',
- 'name',
- 'properties',
- 'size',
- 'status',
- 'volume_id',
- )
-
- def setUp(self):
- super(TestSnapshotCreate, self).setUp()
-
- self.volume = volume_fakes.FakeVolume.create_one_volume()
- self.new_snapshot = volume_fakes.FakeSnapshot.create_one_snapshot(
- attrs={'volume_id': self.volume.id})
-
- self.data = (
- self.new_snapshot.created_at,
- self.new_snapshot.description,
- self.new_snapshot.id,
- self.new_snapshot.name,
- utils.format_dict(self.new_snapshot.metadata),
- self.new_snapshot.size,
- self.new_snapshot.status,
- self.new_snapshot.volume_id,
- )
-
- self.volumes_mock.get.return_value = self.volume
- self.snapshots_mock.create.return_value = self.new_snapshot
- self.snapshots_mock.manage.return_value = self.new_snapshot
- # Get the command object to test
- self.cmd = volume_snapshot.CreateVolumeSnapshot(self.app, None)
-
- def test_snapshot_create(self):
- arglist = [
- "--volume", self.new_snapshot.volume_id,
- "--description", self.new_snapshot.description,
- "--force",
- '--property', 'Alpha=a',
- '--property', 'Beta=b',
- self.new_snapshot.name,
- ]
- verifylist = [
- ("volume", self.new_snapshot.volume_id),
- ("description", self.new_snapshot.description),
- ("force", True),
- ('property', {'Alpha': 'a', 'Beta': 'b'}),
- ("snapshot_name", self.new_snapshot.name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.create.assert_called_with(
- self.new_snapshot.volume_id,
- force=True,
- name=self.new_snapshot.name,
- description=self.new_snapshot.description,
- metadata={'Alpha': 'a', 'Beta': 'b'},
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
- def test_snapshot_create_without_name(self):
- arglist = [
- "--volume", self.new_snapshot.volume_id,
- ]
- verifylist = [
- ("volume", self.new_snapshot.volume_id),
- ]
- self.assertRaises(
- tests_utils.ParserException,
- self.check_parser,
- self.cmd,
- arglist,
- verifylist,
- )
-
- def test_snapshot_create_without_volume(self):
- arglist = [
- "--description", self.new_snapshot.description,
- "--force",
- self.new_snapshot.name
- ]
- verifylist = [
- ("description", self.new_snapshot.description),
- ("force", True),
- ("snapshot_name", self.new_snapshot.name)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.volumes_mock.get.assert_called_once_with(
- self.new_snapshot.name)
- self.snapshots_mock.create.assert_called_once_with(
- self.new_snapshot.volume_id,
- force=True,
- name=self.new_snapshot.name,
- description=self.new_snapshot.description,
- metadata=None,
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
- def test_snapshot_create_with_remote_source(self):
- arglist = [
- '--remote-source', 'source-name=test_source_name',
- '--remote-source', 'source-id=test_source_id',
- '--volume', self.new_snapshot.volume_id,
- self.new_snapshot.name,
- ]
- ref_dict = {'source-name': 'test_source_name',
- 'source-id': 'test_source_id'}
- verifylist = [
- ('remote_source', ref_dict),
- ('volume', self.new_snapshot.volume_id),
- ("snapshot_name", self.new_snapshot.name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.manage.assert_called_with(
- volume_id=self.new_snapshot.volume_id,
- ref=ref_dict,
- name=self.new_snapshot.name,
- description=None,
- metadata=None,
- )
- self.snapshots_mock.create.assert_not_called()
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
-
-class TestSnapshotDelete(TestSnapshot):
-
- snapshots = volume_fakes.FakeSnapshot.create_snapshots(count=2)
-
- def setUp(self):
- super(TestSnapshotDelete, self).setUp()
-
- self.snapshots_mock.get = (
- volume_fakes.FakeSnapshot.get_snapshots(self.snapshots))
- self.snapshots_mock.delete.return_value = None
-
- # Get the command object to mock
- self.cmd = volume_snapshot.DeleteVolumeSnapshot(self.app, None)
-
- def test_snapshot_delete(self):
- arglist = [
- self.snapshots[0].id
- ]
- verifylist = [
- ("snapshots", [self.snapshots[0].id])
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.delete.assert_called_with(
- self.snapshots[0].id, False)
- self.assertIsNone(result)
-
- def test_snapshot_delete_with_force(self):
- arglist = [
- '--force',
- self.snapshots[0].id
- ]
- verifylist = [
- ('force', True),
- ("snapshots", [self.snapshots[0].id])
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.delete.assert_called_with(
- self.snapshots[0].id, True)
- self.assertIsNone(result)
-
- def test_delete_multiple_snapshots(self):
- arglist = []
- for s in self.snapshots:
- arglist.append(s.id)
- verifylist = [
- ('snapshots', arglist),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- result = self.cmd.take_action(parsed_args)
-
- calls = []
- for s in self.snapshots:
- calls.append(call(s.id, False))
- self.snapshots_mock.delete.assert_has_calls(calls)
- self.assertIsNone(result)
-
- def test_delete_multiple_snapshots_with_exception(self):
- arglist = [
- self.snapshots[0].id,
- 'unexist_snapshot',
- ]
- verifylist = [
- ('snapshots', arglist),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- find_mock_result = [self.snapshots[0], exceptions.CommandError]
- with mock.patch.object(utils, 'find_resource',
- side_effect=find_mock_result) as find_mock:
- try:
- self.cmd.take_action(parsed_args)
- self.fail('CommandError should be raised.')
- except exceptions.CommandError as e:
- self.assertEqual('1 of 2 snapshots failed to delete.',
- str(e))
-
- find_mock.assert_any_call(
- self.snapshots_mock, self.snapshots[0].id)
- find_mock.assert_any_call(self.snapshots_mock, 'unexist_snapshot')
-
- self.assertEqual(2, find_mock.call_count)
- self.snapshots_mock.delete.assert_called_once_with(
- self.snapshots[0].id, False
- )
-
-
-class TestSnapshotList(TestSnapshot):
-
- volume = volume_fakes.FakeVolume.create_one_volume()
- project = project_fakes.FakeProject.create_one_project()
- snapshots = volume_fakes.FakeSnapshot.create_snapshots(
- attrs={'volume_id': volume.name}, count=3)
-
- columns = [
- "ID",
- "Name",
- "Description",
- "Status",
- "Size"
- ]
- columns_long = columns + [
- "Created At",
- "Volume",
- "Properties"
- ]
-
- data = []
- for s in snapshots:
- data.append((
- s.id,
- s.name,
- s.description,
- s.status,
- s.size,
- ))
- data_long = []
- for s in snapshots:
- data_long.append((
- s.id,
- s.name,
- s.description,
- s.status,
- s.size,
- s.created_at,
- s.volume_id,
- utils.format_dict(s.metadata),
- ))
-
- def setUp(self):
- super(TestSnapshotList, self).setUp()
-
- self.volumes_mock.list.return_value = [self.volume]
- self.volumes_mock.get.return_value = self.volume
- self.project_mock.get.return_value = self.project
- self.snapshots_mock.list.return_value = self.snapshots
- # Get the command to test
- self.cmd = volume_snapshot.ListVolumeSnapshot(self.app, None)
-
- def test_snapshot_list_without_options(self):
- arglist = []
- verifylist = [
- ('all_projects', False),
- ('long', False)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None,
- search_opts={
- 'all_tenants': False,
- 'name': None,
- 'status': None,
- 'project_id': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_with_options(self):
- arglist = [
- "--long",
- "--limit", "2",
- "--project", self.project.id,
- "--marker", self.snapshots[0].id,
- ]
- verifylist = [
- ("long", True),
- ("limit", 2),
- ("project", self.project.id),
- ("marker", self.snapshots[0].id),
- ('all_projects', False),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- limit=2,
- marker=self.snapshots[0].id,
- search_opts={
- 'all_tenants': True,
- 'project_id': self.project.id,
- 'name': None,
- 'status': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
-
- def test_snapshot_list_all_projects(self):
- arglist = [
- '--all-projects',
- ]
- verifylist = [
- ('long', False),
- ('all_projects', True)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None,
- search_opts={
- 'all_tenants': True,
- 'name': None,
- 'status': None,
- 'project_id': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_name_option(self):
- arglist = [
- '--name', self.snapshots[0].name,
- ]
- verifylist = [
- ('all_projects', False),
- ('long', False),
- ('name', self.snapshots[0].name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None,
- search_opts={
- 'all_tenants': False,
- 'name': self.snapshots[0].name,
- 'status': None,
- 'project_id': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_status_option(self):
- arglist = [
- '--status', self.snapshots[0].status,
- ]
- verifylist = [
- ('all_projects', False),
- ('long', False),
- ('status', self.snapshots[0].status),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None,
- search_opts={
- 'all_tenants': False,
- 'name': None,
- 'status': self.snapshots[0].status,
- 'project_id': None,
- 'volume_id': None
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_volumeid_option(self):
- arglist = [
- '--volume', self.volume.id,
- ]
- verifylist = [
- ('all_projects', False),
- ('long', False),
- ('volume', self.volume.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.list.assert_called_once_with(
- limit=None, marker=None,
- search_opts={
- 'all_tenants': False,
- 'name': None,
- 'status': None,
- 'project_id': None,
- 'volume_id': self.volume.id
- }
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
-
- def test_snapshot_list_negative_limit(self):
- arglist = [
- "--limit", "-2",
- ]
- verifylist = [
- ("limit", -2),
- ]
- self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
- self.cmd, arglist, verifylist)
-
-
-class TestSnapshotSet(TestSnapshot):
-
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
-
- def setUp(self):
- super(TestSnapshotSet, self).setUp()
-
- self.snapshots_mock.get.return_value = self.snapshot
- self.snapshots_mock.set_metadata.return_value = None
- self.snapshots_mock.update.return_value = None
- # Get the command object to mock
- self.cmd = volume_snapshot.SetVolumeSnapshot(self.app, None)
-
- def test_snapshot_set_no_option(self):
- arglist = [
- self.snapshot.id,
- ]
- verifylist = [
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
- self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
- self.assertNotCalled(self.snapshots_mock.reset_state)
- self.assertNotCalled(self.snapshots_mock.update)
- self.assertNotCalled(self.snapshots_mock.set_metadata)
- self.assertIsNone(result)
-
- def test_snapshot_set_name_and_property(self):
- arglist = [
- "--name", "new_snapshot",
- "--property", "x=y",
- "--property", "foo=foo",
- self.snapshot.id,
- ]
- new_property = {"x": "y", "foo": "foo"}
- verifylist = [
- ("name", "new_snapshot"),
- ("property", new_property),
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- kwargs = {
- "name": "new_snapshot",
- }
- self.snapshots_mock.update.assert_called_with(
- self.snapshot.id, **kwargs)
- self.snapshots_mock.set_metadata.assert_called_with(
- self.snapshot.id, new_property
- )
- self.assertIsNone(result)
-
- def test_snapshot_set_with_no_property(self):
- arglist = [
- "--no-property",
- self.snapshot.id,
- ]
- verifylist = [
- ("no_property", True),
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
- self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
- self.assertNotCalled(self.snapshots_mock.reset_state)
- self.assertNotCalled(self.snapshots_mock.update)
- self.assertNotCalled(self.snapshots_mock.set_metadata)
- self.snapshots_mock.delete_metadata.assert_called_with(
- self.snapshot.id, ["foo"]
- )
- self.assertIsNone(result)
-
- def test_snapshot_set_with_no_property_and_property(self):
- arglist = [
- "--no-property",
- "--property", "foo_1=bar_1",
- self.snapshot.id,
- ]
- verifylist = [
- ("no_property", True),
- ("property", {"foo_1": "bar_1"}),
- ("snapshot", self.snapshot.id),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
- self.snapshots_mock.get.assert_called_once_with(parsed_args.snapshot)
- self.assertNotCalled(self.snapshots_mock.reset_state)
- self.assertNotCalled(self.snapshots_mock.update)
- self.snapshots_mock.delete_metadata.assert_called_with(
- self.snapshot.id, ["foo"]
- )
- self.snapshots_mock.set_metadata.assert_called_once_with(
- self.snapshot.id, {"foo_1": "bar_1"})
- self.assertIsNone(result)
-
- def test_snapshot_set_state_to_error(self):
- arglist = [
- "--state", "error",
- self.snapshot.id
- ]
- verifylist = [
- ("state", "error"),
- ("snapshot", self.snapshot.id)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.reset_state.assert_called_with(
- self.snapshot.id, "error")
- self.assertIsNone(result)
-
- def test_volume_set_state_failed(self):
- self.snapshots_mock.reset_state.side_effect = exceptions.CommandError()
- arglist = [
- '--state', 'error',
- self.snapshot.id
- ]
- verifylist = [
- ('state', 'error'),
- ('snapshot', self.snapshot.id)
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- try:
- self.cmd.take_action(parsed_args)
- self.fail('CommandError should be raised.')
- except exceptions.CommandError as e:
- self.assertEqual('One or more of the set operations failed',
- str(e))
- self.snapshots_mock.reset_state.assert_called_once_with(
- self.snapshot.id, 'error')
-
- def test_volume_set_name_and_state_failed(self):
- self.snapshots_mock.reset_state.side_effect = exceptions.CommandError()
- arglist = [
- '--state', 'error',
- "--name", "new_snapshot",
- self.snapshot.id
- ]
- verifylist = [
- ('state', 'error'),
- ("name", "new_snapshot"),
- ('snapshot', self.snapshot.id)
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
- try:
- self.cmd.take_action(parsed_args)
- self.fail('CommandError should be raised.')
- except exceptions.CommandError as e:
- self.assertEqual('One or more of the set operations failed',
- str(e))
- kwargs = {
- "name": "new_snapshot",
- }
- self.snapshots_mock.update.assert_called_once_with(
- self.snapshot.id, **kwargs)
- self.snapshots_mock.reset_state.assert_called_once_with(
- self.snapshot.id, 'error')
-
-
-class TestSnapshotShow(TestSnapshot):
-
- columns = (
- 'created_at',
- 'description',
- 'id',
- 'name',
- 'properties',
- 'size',
- 'status',
- 'volume_id',
- )
-
- def setUp(self):
- super(TestSnapshotShow, self).setUp()
-
- self.snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
-
- self.data = (
- self.snapshot.created_at,
- self.snapshot.description,
- self.snapshot.id,
- self.snapshot.name,
- utils.format_dict(self.snapshot.metadata),
- self.snapshot.size,
- self.snapshot.status,
- self.snapshot.volume_id,
- )
-
- self.snapshots_mock.get.return_value = self.snapshot
- # Get the command object to test
- self.cmd = volume_snapshot.ShowVolumeSnapshot(self.app, None)
-
- def test_snapshot_show(self):
- arglist = [
- self.snapshot.id
- ]
- verifylist = [
- ("snapshot", self.snapshot.id)
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
- self.snapshots_mock.get.assert_called_with(self.snapshot.id)
-
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
-
-class TestSnapshotUnset(TestSnapshot):
-
- snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
-
- def setUp(self):
- super(TestSnapshotUnset, self).setUp()
-
- self.snapshots_mock.get.return_value = self.snapshot
- self.snapshots_mock.delete_metadata.return_value = None
- # Get the command object to mock
- self.cmd = volume_snapshot.UnsetVolumeSnapshot(self.app, None)
-
- def test_snapshot_unset(self):
- arglist = [
- "--property", "foo",
- self.snapshot.id,
- ]
- verifylist = [
- ("property", ["foo"]),
- ("snapshot", self.snapshot.id),
- ]
-
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- result = self.cmd.take_action(parsed_args)
-
- self.snapshots_mock.delete_metadata.assert_called_with(
- self.snapshot.id, ["foo"]
- )
- self.assertIsNone(result)
diff --git a/openstackclient/tests/unit/volume/v2/test_transfer_request.py b/openstackclient/tests/unit/volume/v2/test_transfer_request.py
index 37eed11e..1ea6648f 100644
--- a/openstackclient/tests/unit/volume/v2/test_transfer_request.py
+++ b/openstackclient/tests/unit/volume/v2/test_transfer_request.py
@@ -18,6 +18,7 @@ from mock import call
from osc_lib import exceptions
from osc_lib import utils
+from openstackclient.tests.unit import utils as test_utils
from openstackclient.tests.unit.volume.v2 import fakes as transfer_fakes
from openstackclient.volume.v2 import volume_transfer_request
@@ -85,26 +86,6 @@ class TestTransferAccept(TestTransfer):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
- def test_transfer_accept_deprecated(self):
- arglist = [
- self.volume_transfer.id,
- 'key_value',
- ]
- verifylist = [
- ('transfer_request', self.volume_transfer.id),
- ('old_auth_key', 'key_value'),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- columns, data = self.cmd.take_action(parsed_args)
-
- self.transfer_mock.accept.assert_called_once_with(
- self.volume_transfer.id,
- 'key_value',
- )
- self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
-
def test_transfer_accept_no_option(self):
arglist = [
self.volume_transfer.id,
@@ -112,12 +93,13 @@ class TestTransferAccept(TestTransfer):
verifylist = [
('transfer_request', self.volume_transfer.id),
]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.assertRaises(
- exceptions.CommandError,
- self.cmd.take_action,
- parsed_args,
+ test_utils.ParserException,
+ self.check_parser,
+ self.cmd,
+ arglist,
+ verifylist,
)
diff --git a/openstackclient/tests/unit/volume/v2/test_type.py b/openstackclient/tests/unit/volume/v2/test_type.py
index 4023d55b..17915928 100644
--- a/openstackclient/tests/unit/volume/v2/test_type.py
+++ b/openstackclient/tests/unit/volume/v2/test_type.py
@@ -15,6 +15,7 @@
import mock
from mock import call
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -92,7 +93,7 @@ class TestTypeCreate(TestType):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_type_create_private(self):
arglist = [
@@ -118,7 +119,7 @@ class TestTypeCreate(TestType):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_public_type_create_with_project(self):
arglist = [
@@ -158,7 +159,7 @@ class TestTypeCreate(TestType):
)
encryption_data = (
self.new_volume_type.description,
- utils.format_dict(encryption_info),
+ format_columns.DictColumn(encryption_info),
self.new_volume_type.id,
True,
self.new_volume_type.name,
@@ -195,7 +196,7 @@ class TestTypeCreate(TestType):
body,
)
self.assertEqual(encryption_columns, columns)
- self.assertEqual(encryption_data, data)
+ self.assertItemEqual(encryption_data, data)
class TestTypeDelete(TestType):
@@ -305,7 +306,7 @@ class TestTypeList(TestType):
t.name,
t.is_public,
t.description,
- utils.format_dict(t.extra_specs),
+ format_columns.DictColumn(t.extra_specs),
))
def setUp(self):
@@ -329,7 +330,7 @@ class TestTypeList(TestType):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with(is_public=None)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_type_list_with_options(self):
arglist = [
@@ -347,7 +348,7 @@ class TestTypeList(TestType):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with(is_public=True)
self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
+ self.assertListItemEqual(self.data_long, list(data))
def test_type_list_with_private_option(self):
arglist = [
@@ -364,7 +365,7 @@ class TestTypeList(TestType):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.list.assert_called_once_with(is_public=False)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_type_list_with_default_option(self):
arglist = [
@@ -382,7 +383,7 @@ class TestTypeList(TestType):
columns, data = self.cmd.take_action(parsed_args)
self.types_mock.default.assert_called_once_with()
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data_with_default_type, list(data))
+ self.assertListItemEqual(self.data_with_default_type, list(data))
def test_type_list_with_encryption(self):
encryption_type = volume_fakes.FakeType.create_one_encryption_type(
@@ -401,13 +402,16 @@ class TestTypeList(TestType):
self.volume_types[0].id,
self.volume_types[0].name,
self.volume_types[0].is_public,
- utils.format_dict(encryption_info),
+ volume_type.EncryptionInfoColumn(
+ self.volume_types[0].id,
+ {self.volume_types[0].id: encryption_info}),
))
encryption_data.append((
self.volume_types[1].id,
self.volume_types[1].name,
self.volume_types[1].is_public,
- '-',
+ volume_type.EncryptionInfoColumn(
+ self.volume_types[1].id, {}),
))
self.encryption_types_mock.list.return_value = [encryption_type]
@@ -423,7 +427,7 @@ class TestTypeList(TestType):
self.encryption_types_mock.list.assert_called_once_with()
self.types_mock.list.assert_called_once_with(is_public=None)
self.assertEqual(encryption_columns, columns)
- self.assertEqual(encryption_data, list(data))
+ self.assertListItemEqual(encryption_data, list(data))
class TestTypeSet(TestType):
@@ -687,7 +691,7 @@ class TestTypeShow(TestType):
self.volume_type.id,
True,
self.volume_type.name,
- utils.format_dict(self.volume_type.extra_specs)
+ format_columns.DictColumn(self.volume_type.extra_specs)
)
self.types_mock.get.return_value = self.volume_type
@@ -709,7 +713,7 @@ class TestTypeShow(TestType):
self.types_mock.get.assert_called_with(self.volume_type.id)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, data)
+ self.assertItemEqual(self.data, data)
def test_type_show_with_access(self):
arglist = [
@@ -735,14 +739,14 @@ class TestTypeShow(TestType):
self.assertEqual(self.columns, columns)
private_type_data = (
- utils.format_list([type_access_list.project_id]),
+ format_columns.ListColumn([type_access_list.project_id]),
private_type.description,
private_type.id,
private_type.is_public,
private_type.name,
- utils.format_dict(private_type.extra_specs)
+ format_columns.DictColumn(private_type.extra_specs)
)
- self.assertEqual(private_type_data, data)
+ self.assertItemEqual(private_type_data, data)
def test_type_show_with_list_access_exec(self):
arglist = [
@@ -772,9 +776,9 @@ class TestTypeShow(TestType):
private_type.id,
private_type.is_public,
private_type.name,
- utils.format_dict(private_type.extra_specs)
+ format_columns.DictColumn(private_type.extra_specs)
)
- self.assertEqual(private_type_data, data)
+ self.assertItemEqual(private_type_data, data)
def test_type_show_with_encryption(self):
encryption_type = volume_fakes.FakeType.create_one_encryption_type()
@@ -800,11 +804,11 @@ class TestTypeShow(TestType):
encryption_data = (
None,
self.volume_type.description,
- utils.format_dict(encryption_info),
+ format_columns.DictColumn(encryption_info),
self.volume_type.id,
True,
self.volume_type.name,
- utils.format_dict(self.volume_type.extra_specs)
+ format_columns.DictColumn(self.volume_type.extra_specs)
)
arglist = [
'--encryption-type',
@@ -820,7 +824,7 @@ class TestTypeShow(TestType):
self.types_mock.get.assert_called_with(self.volume_type.id)
self.encryption_types_mock.get.assert_called_with(self.volume_type.id)
self.assertEqual(encryption_columns, columns)
- self.assertEqual(encryption_data, data)
+ self.assertItemEqual(encryption_data, data)
class TestTypeUnset(TestType):
@@ -923,3 +927,30 @@ class TestTypeUnset(TestType):
result = self.cmd.take_action(parsed_args)
self.encryption_types_mock.delete.assert_called_with(self.volume_type)
self.assertIsNone(result)
+
+
+class TestColumns(TestType):
+
+ def test_encryption_info_column_with_info(self):
+ fake_volume_type = volume_fakes.FakeType.create_one_type()
+ type_id = fake_volume_type.id
+
+ encryption_info = {
+ 'provider': 'LuksEncryptor',
+ 'cipher': None,
+ 'key_size': None,
+ 'control_location': 'front-end',
+ }
+ col = volume_type.EncryptionInfoColumn(type_id,
+ {type_id: encryption_info})
+ self.assertEqual(utils.format_dict(encryption_info),
+ col.human_readable())
+ self.assertEqual(encryption_info, col.machine_readable())
+
+ def test_encryption_info_column_without_info(self):
+ fake_volume_type = volume_fakes.FakeType.create_one_type()
+ type_id = fake_volume_type.id
+
+ col = volume_type.EncryptionInfoColumn(type_id, {})
+ self.assertEqual('-', col.human_readable())
+ self.assertIsNone(col.machine_readable())
diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py
index dbe69ea0..332b50a7 100644
--- a/openstackclient/tests/unit/volume/v2/test_volume.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume.py
@@ -16,6 +16,8 @@ import argparse
import mock
from mock import call
+
+from osc_lib.cli import format_columns
from osc_lib import exceptions
from osc_lib import utils
@@ -94,7 +96,7 @@ class TestVolumeCreate(TestVolume):
self.new_volume.description,
self.new_volume.id,
self.new_volume.name,
- utils.format_dict(self.new_volume.metadata),
+ format_columns.DictColumn(self.new_volume.metadata),
self.new_volume.size,
self.new_volume.snapshot_id,
self.new_volume.status,
@@ -135,7 +137,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_options(self):
consistency_group = (
@@ -181,41 +183,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
-
- def test_volume_create_user(self):
- arglist = [
- '--size', str(self.new_volume.size),
- '--user', self.user.id,
- self.new_volume.name,
- ]
- verifylist = [
- ('size', self.new_volume.size),
- ('user', self.user.id),
- ('name', self.new_volume.name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- self.assertRaises(exceptions.CommandError, self.cmd.take_action,
- parsed_args)
- self.volumes_mock.create.assert_not_called()
-
- def test_volume_create_project(self):
- arglist = [
- '--size', str(self.new_volume.size),
- '--project', self.project.id,
- self.new_volume.name,
- ]
- verifylist = [
- ('size', self.new_volume.size),
- ('project', self.project.id),
- ('name', self.new_volume.name),
- ]
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
-
- self.assertRaises(exceptions.CommandError, self.cmd.take_action,
- parsed_args)
- self.volumes_mock.create.assert_not_called()
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_properties(self):
arglist = [
@@ -251,7 +219,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_image_id(self):
image = image_fakes.FakeImage.create_one_image()
@@ -289,7 +257,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_image_name(self):
image = image_fakes.FakeImage.create_one_image()
@@ -327,7 +295,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_with_snapshot(self):
snapshot = volume_fakes.FakeSnapshot.create_one_snapshot()
@@ -364,7 +332,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
def test_volume_create_with_bootable_and_readonly(self):
arglist = [
@@ -402,7 +370,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
self.volumes_mock.set_bootable.assert_called_with(
self.new_volume.id, True)
self.volumes_mock.update_readonly_flag.assert_called_with(
@@ -444,7 +412,7 @@ class TestVolumeCreate(TestVolume):
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
self.volumes_mock.set_bootable.assert_called_with(
self.new_volume.id, False)
self.volumes_mock.update_readonly_flag.assert_called_with(
@@ -496,7 +464,7 @@ class TestVolumeCreate(TestVolume):
self.assertEqual(2, mock_error.call_count)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.datalist, data)
+ self.assertItemEqual(self.datalist, data)
self.volumes_mock.set_bootable.assert_called_with(
self.new_volume.id, True)
self.volumes_mock.update_readonly_flag.assert_called_with(
@@ -706,17 +674,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_project(self):
arglist = [
@@ -749,17 +714,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_project_domain(self):
arglist = [
@@ -794,17 +756,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_user(self):
arglist = [
@@ -834,19 +793,16 @@ class TestVolumeList(TestVolume):
marker=None,
limit=None,
)
-
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
+
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_user_domain(self):
arglist = [
@@ -881,17 +837,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_name(self):
arglist = [
@@ -924,17 +877,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_status(self):
arglist = [
@@ -967,17 +917,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_all_projects(self):
arglist = [
@@ -1010,17 +957,14 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_long(self):
arglist = [
@@ -1064,9 +1008,6 @@ class TestVolumeList(TestVolume):
]
self.assertEqual(collist, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
@@ -1074,10 +1015,10 @@ class TestVolumeList(TestVolume):
self.mock_volume.size,
self.mock_volume.volume_type,
self.mock_volume.bootable,
- msg,
- utils.format_dict(self.mock_volume.metadata),
+ volume.AttachmentsColumn(self.mock_volume.attachments),
+ format_columns.DictColumn(self.mock_volume.metadata),
), )
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_with_marker_and_limit(self):
arglist = [
@@ -1098,15 +1039,12 @@ class TestVolumeList(TestVolume):
self.assertEqual(self.columns, columns)
- server = self.mock_volume.attachments[0]['server_id']
- device = self.mock_volume.attachments[0]['device']
- msg = 'Attached to %s on %s ' % (server, device)
datalist = ((
self.mock_volume.id,
self.mock_volume.name,
self.mock_volume.status,
self.mock_volume.size,
- msg,
+ volume.AttachmentsColumn(self.mock_volume.attachments),
), )
self.volumes_mock.list.assert_called_once_with(
@@ -1119,7 +1057,7 @@ class TestVolumeList(TestVolume):
'name': None,
'all_tenants': False, }
)
- self.assertEqual(datalist, tuple(data))
+ self.assertListItemEqual(datalist, tuple(data))
def test_volume_list_negative_limit(self):
arglist = [
@@ -1513,7 +1451,7 @@ class TestVolumeShow(TestVolume):
volume_fakes.FakeVolume.get_volume_columns(self._volume),
columns)
- self.assertEqual(
+ self.assertItemEqual(
volume_fakes.FakeVolume.get_volume_data(self._volume),
data)
@@ -1596,3 +1534,31 @@ class TestVolumeUnset(TestVolume):
self.new_volume.id, parsed_args.image_property)
self.volumes_mock.delete_metadata.assert_called_with(
self.new_volume.id, parsed_args.property)
+
+
+class TestColumns(TestVolume):
+
+ def test_attachments_column_without_server_cache(self):
+ _volume = volume_fakes.FakeVolume.create_one_volume()
+ server_id = _volume.attachments[0]['server_id']
+ device = _volume.attachments[0]['device']
+
+ col = volume.AttachmentsColumn(_volume.attachments, {})
+ self.assertEqual('Attached to %s on %s ' % (server_id, device),
+ col.human_readable())
+ self.assertEqual(_volume.attachments, col.machine_readable())
+
+ def test_attachments_column_with_server_cache(self):
+ _volume = volume_fakes.FakeVolume.create_one_volume()
+
+ server_id = _volume.attachments[0]['server_id']
+ device = _volume.attachments[0]['device']
+ fake_server = mock.Mock()
+ fake_server.name = 'fake-server-name'
+ server_cache = {server_id: fake_server}
+
+ col = volume.AttachmentsColumn(_volume.attachments, server_cache)
+ self.assertEqual(
+ 'Attached to %s on %s ' % ('fake-server-name', device),
+ col.human_readable())
+ self.assertEqual(_volume.attachments, col.machine_readable())
diff --git a/openstackclient/tests/unit/volume/v2/test_backup.py b/openstackclient/tests/unit/volume/v2/test_volume_backup.py
index 9a2ce718..30c7915d 100644
--- a/openstackclient/tests/unit/volume/v2/test_backup.py
+++ b/openstackclient/tests/unit/volume/v2/test_volume_backup.py
@@ -19,7 +19,7 @@ from osc_lib import exceptions
from osc_lib import utils
from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes
-from openstackclient.volume.v2 import backup
+from openstackclient.volume.v2 import volume_backup
class TestBackup(volume_fakes.TestVolume):
@@ -77,7 +77,7 @@ class TestBackupCreate(TestBackup):
self.backups_mock.create.return_value = self.new_backup
# Get the command object to test
- self.cmd = backup.CreateVolumeBackup(self.app, None)
+ self.cmd = volume_backup.CreateVolumeBackup(self.app, None)
def test_backup_create(self):
arglist = [
@@ -154,7 +154,7 @@ class TestBackupDelete(TestBackup):
self.backups_mock.delete.return_value = None
# Get the command object to mock
- self.cmd = backup.DeleteVolumeBackup(self.app, None)
+ self.cmd = volume_backup.DeleteVolumeBackup(self.app, None)
def test_backup_delete(self):
arglist = [
@@ -271,7 +271,7 @@ class TestBackupList(TestBackup):
b.status,
b.size,
b.availability_zone,
- b.volume_id,
+ volume_backup.VolumeIdColumn(b.volume_id),
b.container,
))
@@ -283,7 +283,7 @@ class TestBackupList(TestBackup):
self.volumes_mock.get.return_value = self.volume
self.backups_mock.get.return_value = self.backups[0]
# Get the command to test
- self.cmd = backup.ListVolumeBackup(self.app, None)
+ self.cmd = volume_backup.ListVolumeBackup(self.app, None)
def test_backup_list_without_options(self):
arglist = []
@@ -314,7 +314,7 @@ class TestBackupList(TestBackup):
limit=None,
)
self.assertEqual(self.columns, columns)
- self.assertEqual(self.data, list(data))
+ self.assertListItemEqual(self.data, list(data))
def test_backup_list_with_options(self):
arglist = [
@@ -353,7 +353,7 @@ class TestBackupList(TestBackup):
limit=3,
)
self.assertEqual(self.columns_long, columns)
- self.assertEqual(self.data_long, list(data))
+ self.assertListItemEqual(self.data_long, list(data))
class TestBackupRestore(TestBackup):
@@ -371,7 +371,7 @@ class TestBackupRestore(TestBackup):
volume_fakes.FakeVolume.create_one_volume(
{'id': self.volume['id']}))
# Get the command object to mock
- self.cmd = backup.RestoreVolumeBackup(self.app, None)
+ self.cmd = volume_backup.RestoreVolumeBackup(self.app, None)
def test_backup_restore(self):
arglist = [
@@ -400,7 +400,7 @@ class TestBackupSet(TestBackup):
self.backups_mock.get.return_value = self.backup
# Get the command object to test
- self.cmd = backup.SetVolumeBackup(self.app, None)
+ self.cmd = volume_backup.SetVolumeBackup(self.app, None)
def test_backup_set_name(self):
arglist = [
@@ -517,7 +517,7 @@ class TestBackupShow(TestBackup):
self.backups_mock.get.return_value = self.backup
# Get the command object to test
- self.cmd = backup.ShowVolumeBackup(self.app, None)
+ self.cmd = volume_backup.ShowVolumeBackup(self.app, None)
def test_backup_show(self):
arglist = [