diff options
Diffstat (limited to 'openstackclient/tests/unit')
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/fakes.py | 1 | ||||
| -rw-r--r-- | openstackclient/tests/unit/compute/v2/test_aggregate.py | 98 | ||||
| -rw-r--r-- | openstackclient/tests/unit/fakes.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_network_segment.py | 61 | ||||
| -rw-r--r-- | openstackclient/tests/unit/network/v2/test_subnet.py | 18 | ||||
| -rw-r--r-- | openstackclient/tests/unit/object/v1/fakes.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/unit/object/v1/test_object_all.py | 22 | ||||
| -rw-r--r-- | openstackclient/tests/unit/volume/v1/test_volume.py | 62 | ||||
| -rw-r--r-- | openstackclient/tests/unit/volume/v2/fakes.py | 55 | ||||
| -rw-r--r-- | openstackclient/tests/unit/volume/v2/test_consistency_group.py | 122 | ||||
| -rw-r--r-- | openstackclient/tests/unit/volume/v2/test_volume.py | 131 |
11 files changed, 474 insertions, 100 deletions
diff --git a/openstackclient/tests/unit/compute/v2/fakes.py b/openstackclient/tests/unit/compute/v2/fakes.py index 3c829773..985ce5e2 100644 --- a/openstackclient/tests/unit/compute/v2/fakes.py +++ b/openstackclient/tests/unit/compute/v2/fakes.py @@ -83,6 +83,7 @@ class FakeAggregate(object): "id": "aggregate-id-" + uuid.uuid4().hex, "metadata": { "availability_zone": "ag_zone", + "key1": "value1", } } diff --git a/openstackclient/tests/unit/compute/v2/test_aggregate.py b/openstackclient/tests/unit/compute/v2/test_aggregate.py index c636d3de..3efe0dbd 100644 --- a/openstackclient/tests/unit/compute/v2/test_aggregate.py +++ b/openstackclient/tests/unit/compute/v2/test_aggregate.py @@ -21,7 +21,6 @@ from osc_lib import utils from openstackclient.compute.v2 import aggregate from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes -from openstackclient.tests.unit import utils as tests_utils class TestAggregate(compute_fakes.TestComputev2): @@ -235,7 +234,8 @@ class TestAggregateList(TestAggregate): TestAggregate.fake_ag.id, TestAggregate.fake_ag.name, TestAggregate.fake_ag.availability_zone, - {}, + {key: value for key, value in TestAggregate.fake_ag.metadata.items() + if key != 'availability_zone'}, ), ) def setUp(self): @@ -371,6 +371,62 @@ class TestAggregateSet(TestAggregate): self.fake_ag, parsed_args.property) self.assertIsNone(result) + def test_aggregate_set_with_no_property_and_property(self): + arglist = [ + '--no-property', + '--property', 'key2=value2', + 'ag1', + ] + verifylist = [ + ('no_property', True), + ('property', {'key2': 'value2'}), + ('aggregate', 'ag1'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + self.aggregate_mock.get.assert_called_once_with(parsed_args.aggregate) + self.assertNotCalled(self.aggregate_mock.update) + self.aggregate_mock.set_metadata.assert_called_once_with( + self.fake_ag, {'key1': None, 'key2': 'value2'}) + self.assertIsNone(result) + + def test_aggregate_set_with_no_property(self): + arglist = [ + '--no-property', + 'ag1', + ] + verifylist = [ + ('no_property', True), + ('aggregate', 'ag1'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + self.aggregate_mock.get.assert_called_once_with(parsed_args.aggregate) + self.assertNotCalled(self.aggregate_mock.update) + self.aggregate_mock.set_metadata.assert_called_once_with( + self.fake_ag, {'key1': None}) + self.assertIsNone(result) + + def test_aggregate_set_with_zone_and_no_property(self): + arglist = [ + '--zone', 'new_zone', + '--no-property', + 'ag1', + ] + verifylist = [ + ('zone', 'new_zone'), + ('no_property', True), + ('aggregate', 'ag1'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + self.aggregate_mock.get.assert_called_once_with(parsed_args.aggregate) + self.aggregate_mock.update.assert_called_once_with( + self.fake_ag, {'availability_zone': parsed_args.zone}) + self.aggregate_mock.set_metadata.assert_called_once_with( + self.fake_ag, {'key1': None}) + self.assertIsNone(result) + class TestAggregateShow(TestAggregate): @@ -387,7 +443,10 @@ class TestAggregateShow(TestAggregate): TestAggregate.fake_ag.hosts, TestAggregate.fake_ag.id, TestAggregate.fake_ag.name, - '', + utils.format_dict( + {key: value + for key, value in TestAggregate.fake_ag.metadata.items() + if key != 'availability_zone'}), ) def setUp(self): @@ -435,13 +494,32 @@ class TestAggregateUnset(TestAggregate): self.fake_ag, {'unset_key': None}) self.assertIsNone(result) - def test_aggregate_unset_no_property(self): + def test_aggregate_unset_multiple_properties(self): arglist = [ + '--property', 'unset_key1', + '--property', 'unset_key2', 'ag1', ] - verifylist = None - self.assertRaises(tests_utils.ParserException, - self.check_parser, - self.cmd, - arglist, - verifylist) + verifylist = [ + ('property', ['unset_key1', 'unset_key2']), + ('aggregate', 'ag1'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + self.aggregate_mock.set_metadata.assert_called_once_with( + self.fake_ag, {'unset_key1': None, 'unset_key2': None}) + self.assertIsNone(result) + + def test_aggregate_unset_no_option(self): + arglist = [ + 'ag1', + ] + verifylist = [ + ('property', None), + ('aggregate', 'ag1'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + self.assertNotCalled(self.aggregate_mock.set_metadata) + self.assertIsNone(result) diff --git a/openstackclient/tests/unit/fakes.py b/openstackclient/tests/unit/fakes.py index f2598366..f7cb5676 100644 --- a/openstackclient/tests/unit/fakes.py +++ b/openstackclient/tests/unit/fakes.py @@ -38,7 +38,7 @@ _s.add_endpoint(AUTH_URL + ':5000/v2.0') _s = TEST_RESPONSE_DICT.add_service('network', name='neutron') _s.add_endpoint(AUTH_URL + ':9696') _s = TEST_RESPONSE_DICT.add_service('compute', name='nova') -_s.add_endpoint(AUTH_URL + ':8774/v2') +_s.add_endpoint(AUTH_URL + ':8774/v2.1') _s = TEST_RESPONSE_DICT.add_service('image', name='glance') _s.add_endpoint(AUTH_URL + ':9292') _s = TEST_RESPONSE_DICT.add_service('object', name='swift') diff --git a/openstackclient/tests/unit/network/v2/test_network_segment.py b/openstackclient/tests/unit/network/v2/test_network_segment.py index 7457a8c2..0639766d 100644 --- a/openstackclient/tests/unit/network/v2/test_network_segment.py +++ b/openstackclient/tests/unit/network/v2/test_network_segment.py @@ -26,9 +26,6 @@ class TestNetworkSegment(network_fakes.TestNetworkV2): def setUp(self): super(TestNetworkSegment, self).setUp() - # Enable beta commands. - self.app.options.os_beta_command = True - # Get a shortcut to the network client self.network = self.app.client_manager.network @@ -81,22 +78,6 @@ class TestCreateNetworkSegment(TestNetworkSegment): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_create_no_beta_commands(self): - arglist = [ - '--network', self._network_segment.network_id, - '--network-type', self._network_segment.network_type, - self._network_segment.name, - ] - verifylist = [ - ('network', self._network_segment.network_id), - ('network_type', self._network_segment.network_type), - ('name', self._network_segment.name), - ] - self.app.options.os_beta_command = False - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) - def test_create_invalid_network_type(self): arglist = [ '--network', self._network_segment.network_id, @@ -192,18 +173,6 @@ class TestDeleteNetworkSegment(TestNetworkSegment): self.namespace ) - def test_delete_no_beta_commands(self): - arglist = [ - self._network_segments[0].id, - ] - verifylist = [ - ('network_segment', [self._network_segments[0].id]), - ] - self.app.options.os_beta_command = False - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) - def test_delete(self): arglist = [ self._network_segments[0].id, @@ -330,12 +299,6 @@ class TestListNetworkSegment(TestNetworkSegment): self.assertEqual(self.columns, columns) self.assertEqual(self.data, list(data)) - def test_list_no_beta_commands(self): - self.app.options.os_beta_command = False - parsed_args = self.check_parser(self.cmd, [], []) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) - def test_list_long(self): arglist = [ '--long', @@ -391,18 +354,6 @@ class TestSetNetworkSegment(TestNetworkSegment): # Get the command object to test self.cmd = network_segment.SetNetworkSegment(self.app, self.namespace) - def test_set_no_beta_commands(self): - arglist = [ - self._network_segment.id, - ] - verifylist = [ - ('network_segment', self._network_segment.id), - ] - self.app.options.os_beta_command = False - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) - def test_set_no_options(self): arglist = [ self._network_segment.id, @@ -485,18 +436,6 @@ class TestShowNetworkSegment(TestNetworkSegment): self.assertRaises(tests_utils.ParserException, self.check_parser, self.cmd, [], []) - def test_show_no_beta_commands(self): - arglist = [ - self._network_segment.id, - ] - verifylist = [ - ('network_segment', self._network_segment.id), - ] - self.app.options.os_beta_command = False - parsed_args = self.check_parser(self.cmd, arglist, verifylist) - self.assertRaises(exceptions.CommandError, self.cmd.take_action, - parsed_args) - def test_show_all_options(self): arglist = [ self._network_segment.id, diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py index 9c468f39..2d51aa4a 100644 --- a/openstackclient/tests/unit/network/v2/test_subnet.py +++ b/openstackclient/tests/unit/network/v2/test_subnet.py @@ -379,23 +379,6 @@ class TestCreateSubnet(TestSubnet): self.assertEqual(self.columns, columns) self.assertEqual(self.data_ipv6, data) - def test_create_no_beta_command_options(self): - arglist = [ - "--subnet-range", self._subnet.cidr, - "--network-segment", self._network_segment.id, - "--network", self._subnet.network_id, - self._subnet.name, - ] - verifylist = [ - ('name', self._subnet.name), - ('subnet_range', self._subnet.cidr), - ('network-segment', self._network_segment.id), - ('network', self._subnet.network_id), - ] - self.app.options.os_beta_command = False - self.assertRaises(tests_utils.ParserException, - self.check_parser, self.cmd, arglist, verifylist) - def test_create_with_network_segment(self): # Mock SDK calls for this test. self.network.create_subnet = mock.Mock(return_value=self._subnet) @@ -417,7 +400,6 @@ class TestCreateSubnet(TestSubnet): ] - self.app.options.os_beta_command = True parsed_args = self.check_parser(self.cmd, arglist, verifylist) columns, data = self.cmd.take_action(parsed_args) diff --git a/openstackclient/tests/unit/object/v1/fakes.py b/openstackclient/tests/unit/object/v1/fakes.py index 0ff594bc..72646d25 100644 --- a/openstackclient/tests/unit/object/v1/fakes.py +++ b/openstackclient/tests/unit/object/v1/fakes.py @@ -75,6 +75,8 @@ OBJECT_2 = { 'last_modified': object_modified_2, } +object_upload_name = 'test-object-name' + class TestObjectv1(utils.TestCommand): diff --git a/openstackclient/tests/unit/object/v1/test_object_all.py b/openstackclient/tests/unit/object/v1/test_object_all.py index a0948b1b..f215836e 100644 --- a/openstackclient/tests/unit/object/v1/test_object_all.py +++ b/openstackclient/tests/unit/object/v1/test_object_all.py @@ -13,6 +13,7 @@ import copy +from osc_lib import exceptions from requests_mock.contrib import fixture from openstackclient.object.v1 import object as object_cmds @@ -35,6 +36,27 @@ class TestObjectCreate(TestObjectAll): # Get the command object to test self.cmd = object_cmds.CreateObject(self.app, None) + def test_multiple_object_create_with_object_name(self): + arglist = [ + object_fakes.container_name, + object_fakes.object_name_1, + object_fakes.object_name_2, + '--name', object_fakes.object_upload_name, + ] + + verifylist = [ + ('container', object_fakes.container_name), + ('objects', [object_fakes.object_name_1, + object_fakes.object_name_2]), + ('name', object_fakes.object_upload_name), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises(exceptions.CommandError, + self.cmd.take_action, + parsed_args) + class TestObjectList(TestObjectAll): diff --git a/openstackclient/tests/unit/volume/v1/test_volume.py b/openstackclient/tests/unit/volume/v1/test_volume.py index 895f1f87..73c00844 100644 --- a/openstackclient/tests/unit/volume/v1/test_volume.py +++ b/openstackclient/tests/unit/volume/v1/test_volume.py @@ -23,6 +23,7 @@ from osc_lib import utils from openstackclient.tests.unit import fakes from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes +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 @@ -411,6 +412,67 @@ class TestVolumeCreate(TestVolume): self.assertEqual(self.columns, columns) self.assertEqual(self.datalist, data) + def test_volume_create_with_source(self): + self.volumes_mock.get.return_value = self.new_volume + arglist = [ + '--source', self.new_volume.id, + self.new_volume.display_name, + ] + verifylist = [ + ('source', self.new_volume.id), + ('name', self.new_volume.display_name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + self.volumes_mock.create.assert_called_with( + None, + None, + self.new_volume.id, + self.new_volume.display_name, + None, + None, + None, + None, + None, + None, + None, + ) + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, data) + + def test_volume_create_without_size(self): + arglist = [ + self.new_volume.display_name, + ] + verifylist = [ + ('name', self.new_volume.display_name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises(exceptions.CommandError, self.cmd.take_action, + parsed_args) + + def test_volume_create_with_multi_source(self): + arglist = [ + '--image', 'source_image', + '--source', 'source_volume', + '--snapshot', 'source_snapshot', + '--size', str(self.new_volume.size), + self.new_volume.display_name, + ] + verifylist = [ + ('image', 'source_image'), + ('source', 'source_volume'), + ('snapshot', 'source_snapshot'), + ('size', self.new_volume.size), + ('name', self.new_volume.display_name), + ] + + self.assertRaises(tests_utils.ParserException, self.check_parser, + self.cmd, arglist, verifylist) + class TestVolumeDelete(TestVolume): diff --git a/openstackclient/tests/unit/volume/v2/fakes.py b/openstackclient/tests/unit/volume/v2/fakes.py index 2aeea60a..5e1d16e1 100644 --- a/openstackclient/tests/unit/volume/v2/fakes.py +++ b/openstackclient/tests/unit/volume/v2/fakes.py @@ -222,6 +222,8 @@ class FakeVolumeClient(object): self.quotas.resource_class = fakes.FakeResource(None, {}) self.quota_classes = mock.Mock() self.quota_classes.resource_class = fakes.FakeResource(None, {}) + self.consistencygroups = mock.Mock() + self.consistencygroups.resource_class = fakes.FakeResource(None, {}) self.auth_token = kwargs['token'] self.management_url = kwargs['endpoint'] @@ -493,6 +495,59 @@ class FakeBackup(object): return mock.Mock(side_effect=backups) +class FakeConsistencyGroup(object): + """Fake one or more consistency group.""" + + @staticmethod + def create_one_consistency_group(attrs=None): + """Create a fake consistency group. + + :param Dictionary attrs: + A dictionary with all attributes + :return: + A FakeResource object with id, name, description, etc. + """ + attrs = attrs or {} + + # Set default attributes. + consistency_group_info = { + "id": 'backup-id-' + uuid.uuid4().hex, + "name": 'backup-name-' + uuid.uuid4().hex, + "description": 'description-' + uuid.uuid4().hex, + "status": "error", + "availability_zone": 'zone' + uuid.uuid4().hex, + "created_at": 'time-' + uuid.uuid4().hex, + "volume_types": ['volume-type1'], + } + + # Overwrite default attributes. + consistency_group_info.update(attrs) + + consistency_group = fakes.FakeResource( + info=copy.deepcopy(consistency_group_info), + loaded=True) + return consistency_group + + @staticmethod + def create_consistency_groups(attrs=None, count=2): + """Create multiple fake consistency groups. + + :param Dictionary attrs: + A dictionary with all attributes + :param int count: + The number of consistency groups to fake + :return: + A list of FakeResource objects faking the consistency groups + """ + consistency_groups = [] + for i in range(0, count): + consistency_group = ( + FakeConsistencyGroup.create_one_consistency_group(attrs)) + consistency_groups.append(consistency_group) + + return consistency_groups + + class FakeExtension(object): """Fake one or more extension.""" diff --git a/openstackclient/tests/unit/volume/v2/test_consistency_group.py b/openstackclient/tests/unit/volume/v2/test_consistency_group.py new file mode 100644 index 00000000..00e1b60e --- /dev/null +++ b/openstackclient/tests/unit/volume/v2/test_consistency_group.py @@ -0,0 +1,122 @@ +# +# 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. +# + +from osc_lib import utils + +from openstackclient.tests.unit.volume.v2 import fakes as volume_fakes +from openstackclient.volume.v2 import consistency_group + + +class TestConsistencyGroup(volume_fakes.TestVolume): + + def setUp(self): + super(TestConsistencyGroup, self).setUp() + + # Get a shortcut to the TransferManager Mock + self.consistencygroups_mock = ( + self.app.client_manager.volume.consistencygroups) + self.consistencygroups_mock.reset_mock() + + +class TestConsistencyGroupList(TestConsistencyGroup): + + consistency_groups = ( + volume_fakes.FakeConsistencyGroup.create_consistency_groups(count=2)) + + columns = [ + 'ID', + 'Status', + 'Name', + ] + columns_long = [ + 'ID', + 'Status', + 'Availability Zone', + 'Name', + 'Description', + 'Volume Types', + ] + data = [] + for c in consistency_groups: + data.append(( + c.id, + c.status, + c.name, + )) + data_long = [] + for c in consistency_groups: + data_long.append(( + c.id, + c.status, + c.availability_zone, + c.name, + c.description, + utils.format_list(c.volume_types) + )) + + def setUp(self): + super(TestConsistencyGroupList, self).setUp() + + self.consistencygroups_mock.list.return_value = self.consistency_groups + # Get the command to test + self.cmd = consistency_group.ListConsistencyGroup(self.app, None) + + def test_consistency_group_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.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)) + + def test_consistency_group_list_with_all_project(self): + arglist = [ + "--all-projects" + ] + verifylist = [ + ("all_projects", True), + ("long", False), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + 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)) + + def test_consistency_group_list_with_long(self): + arglist = [ + "--long", + ] + verifylist = [ + ("all_projects", False), + ("long", True), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + columns, data = self.cmd.take_action(parsed_args) + + 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)) diff --git a/openstackclient/tests/unit/volume/v2/test_volume.py b/openstackclient/tests/unit/volume/v2/test_volume.py index 5bdde9de..f4a7c142 100644 --- a/openstackclient/tests/unit/volume/v2/test_volume.py +++ b/openstackclient/tests/unit/volume/v2/test_volume.py @@ -21,6 +21,7 @@ from osc_lib import utils from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes from openstackclient.tests.unit.image.v2 import fakes as image_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 @@ -45,6 +46,10 @@ class TestVolume(volume_fakes.TestVolume): self.snapshots_mock = self.app.client_manager.volume.volume_snapshots self.snapshots_mock.reset_mock() + self.consistencygroups_mock = ( + self.app.client_manager.volume.consistencygroups) + self.consistencygroups_mock.reset_mock() + def setup_volumes_mock(self, count): volumes = volume_fakes.FakeVolume.create_volumes(count=count) @@ -123,18 +128,28 @@ class TestVolumeCreate(TestVolume): availability_zone=None, metadata=None, imageRef=None, - source_volid=None + source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) self.assertEqual(self.datalist, data) def test_volume_create_options(self): + consistency_group = ( + volume_fakes.FakeConsistencyGroup.create_one_consistency_group()) + self.consistencygroups_mock.get.return_value = consistency_group arglist = [ '--size', str(self.new_volume.size), '--description', self.new_volume.description, '--type', self.new_volume.volume_type, '--availability-zone', self.new_volume.availability_zone, + '--consistency-group', consistency_group.id, + '--hint', 'k=v', + '--multi-attach', self.new_volume.name, ] verifylist = [ @@ -142,6 +157,9 @@ class TestVolumeCreate(TestVolume): ('description', self.new_volume.description), ('type', self.new_volume.volume_type), ('availability_zone', self.new_volume.availability_zone), + ('consistency_group', consistency_group.id), + ('hint', {'k': 'v'}), + ('multi_attach', True), ('name', self.new_volume.name), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -162,7 +180,11 @@ class TestVolumeCreate(TestVolume): availability_zone=self.new_volume.availability_zone, metadata=None, imageRef=None, - source_volid=None + source_volid=None, + consistencygroup_id=consistency_group.id, + source_replica=None, + multiattach=True, + scheduler_hints={'k': 'v'}, ) self.assertEqual(self.columns, columns) @@ -204,7 +226,11 @@ class TestVolumeCreate(TestVolume): availability_zone=None, metadata=None, imageRef=None, - source_volid=None + source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) @@ -246,7 +272,11 @@ class TestVolumeCreate(TestVolume): availability_zone=None, metadata=None, imageRef=None, - source_volid=None + source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) @@ -282,7 +312,11 @@ class TestVolumeCreate(TestVolume): availability_zone=None, metadata={'Alpha': 'a', 'Beta': 'b'}, imageRef=None, - source_volid=None + source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) @@ -321,6 +355,10 @@ class TestVolumeCreate(TestVolume): metadata=None, imageRef=image.id, source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) @@ -358,7 +396,11 @@ class TestVolumeCreate(TestVolume): availability_zone=None, metadata=None, imageRef=image.id, - source_volid=None + source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) @@ -368,12 +410,10 @@ class TestVolumeCreate(TestVolume): snapshot = volume_fakes.FakeSnapshot.create_one_snapshot() self.new_volume.snapshot_id = snapshot.id arglist = [ - '--size', str(self.new_volume.size), '--snapshot', self.new_volume.snapshot_id, self.new_volume.name, ] verifylist = [ - ('size', self.new_volume.size), ('snapshot', self.new_volume.snapshot_id), ('name', self.new_volume.name), ] @@ -387,7 +427,7 @@ class TestVolumeCreate(TestVolume): columns, data = self.cmd.take_action(parsed_args) self.volumes_mock.create.assert_called_once_with( - size=self.new_volume.size, + size=None, snapshot_id=snapshot.id, name=self.new_volume.name, description=None, @@ -397,12 +437,83 @@ class TestVolumeCreate(TestVolume): availability_zone=None, metadata=None, imageRef=None, - source_volid=None + source_volid=None, + consistencygroup_id=None, + source_replica=None, + multiattach=False, + scheduler_hints=None, ) self.assertEqual(self.columns, columns) self.assertEqual(self.datalist, data) + def test_volume_create_with_source_replicated(self): + self.volumes_mock.get.return_value = self.new_volume + arglist = [ + '--source-replicated', self.new_volume.id, + self.new_volume.name, + ] + verifylist = [ + ('source_replicated', self.new_volume.id), + ('name', self.new_volume.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + self.volumes_mock.create.assert_called_once_with( + size=None, + snapshot_id=None, + name=self.new_volume.name, + description=None, + volume_type=None, + user_id=None, + project_id=None, + availability_zone=None, + metadata=None, + imageRef=None, + source_volid=None, + consistencygroup_id=None, + source_replica=self.new_volume.id, + multiattach=False, + scheduler_hints=None, + ) + + self.assertEqual(self.columns, columns) + self.assertEqual(self.datalist, data) + + def test_volume_create_without_size(self): + arglist = [ + self.new_volume.name, + ] + verifylist = [ + ('name', self.new_volume.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.assertRaises(exceptions.CommandError, self.cmd.take_action, + parsed_args) + + def test_volume_create_with_multi_source(self): + arglist = [ + '--image', 'source_image', + '--source', 'source_volume', + '--snapshot', 'source_snapshot', + '--source-replicated', 'source_replicated_volume', + '--size', str(self.new_volume.size), + self.new_volume.name, + ] + verifylist = [ + ('image', 'source_image'), + ('source', 'source_volume'), + ('snapshot', 'source_snapshot'), + ('source-replicated', 'source_replicated_volume'), + ('size', self.new_volume.size), + ('name', self.new_volume.name), + ] + + self.assertRaises(tests_utils.ParserException, self.check_parser, + self.cmd, arglist, verifylist) + class TestVolumeDelete(TestVolume): |
