python-openstackclient 10.0.0__py3-none-any.whl → 10.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. openstackclient/common/availability_zone.py +1 -1
  2. openstackclient/common/module.py +21 -27
  3. openstackclient/common/pagination.py +42 -4
  4. openstackclient/common/project_cleanup.py +1 -2
  5. openstackclient/common/quota.py +9 -5
  6. openstackclient/compute/v2/flavor.py +3 -1
  7. openstackclient/compute/v2/hypervisor.py +2 -0
  8. openstackclient/compute/v2/keypair.py +6 -2
  9. openstackclient/compute/v2/server.py +21 -12
  10. openstackclient/compute/v2/server_event.py +8 -1
  11. openstackclient/compute/v2/server_group.py +2 -0
  12. openstackclient/compute/v2/server_migration.py +3 -0
  13. openstackclient/compute/v2/server_volume.py +3 -1
  14. openstackclient/compute/v2/service.py +3 -1
  15. openstackclient/compute/v2/usage.py +2 -2
  16. openstackclient/identity/common.py +5 -1
  17. openstackclient/identity/v3/access_rule.py +6 -0
  18. openstackclient/identity/v3/application_credential.py +10 -3
  19. openstackclient/identity/v3/credential.py +4 -2
  20. openstackclient/identity/v3/domain.py +4 -2
  21. openstackclient/identity/v3/endpoint.py +57 -45
  22. openstackclient/identity/v3/federation_protocol.py +7 -5
  23. openstackclient/identity/v3/group.py +11 -10
  24. openstackclient/identity/v3/identity_provider.py +4 -1
  25. openstackclient/identity/v3/limit.py +5 -2
  26. openstackclient/identity/v3/mapping.py +36 -19
  27. openstackclient/identity/v3/project.py +18 -5
  28. openstackclient/identity/v3/region.py +4 -2
  29. openstackclient/identity/v3/registered_limit.py +3 -2
  30. openstackclient/identity/v3/role.py +2 -1
  31. openstackclient/identity/v3/role_assignment.py +3 -2
  32. openstackclient/identity/v3/service.py +4 -2
  33. openstackclient/identity/v3/service_provider.py +4 -2
  34. openstackclient/identity/v3/trust.py +8 -5
  35. openstackclient/identity/v3/user.py +38 -11
  36. openstackclient/image/v2/cache.py +2 -2
  37. openstackclient/image/v2/image.py +15 -9
  38. openstackclient/image/v2/metadef_namespaces.py +11 -10
  39. openstackclient/image/v2/metadef_objects.py +5 -5
  40. openstackclient/image/v2/metadef_properties.py +7 -4
  41. openstackclient/image/v2/task.py +11 -22
  42. openstackclient/network/utils.py +0 -41
  43. openstackclient/network/v2/address_group.py +13 -1
  44. openstackclient/network/v2/address_scope.py +13 -8
  45. openstackclient/network/v2/bgpvpn/bgpvpn.py +33 -19
  46. openstackclient/network/v2/bgpvpn/network_association.py +25 -13
  47. openstackclient/network/v2/bgpvpn/port_association.py +35 -21
  48. openstackclient/network/v2/bgpvpn/router_association.py +27 -14
  49. openstackclient/network/v2/default_security_group_rule.py +14 -6
  50. openstackclient/network/v2/floating_ip.py +12 -4
  51. openstackclient/network/v2/floating_ip_port_forwarding.py +12 -2
  52. openstackclient/network/v2/fwaas/group.py +34 -1
  53. openstackclient/network/v2/fwaas/rule.py +39 -3
  54. openstackclient/network/v2/ip_availability.py +13 -4
  55. openstackclient/network/v2/l3_conntrack_helper.py +14 -1
  56. openstackclient/network/v2/local_ip.py +4 -1
  57. openstackclient/network/v2/local_ip_association.py +4 -1
  58. openstackclient/network/v2/ndp_proxy.py +4 -1
  59. openstackclient/network/v2/network.py +87 -20
  60. openstackclient/network/v2/network_agent.py +32 -10
  61. openstackclient/network/v2/network_auto_allocated_topology.py +6 -5
  62. openstackclient/network/v2/network_flavor.py +19 -6
  63. openstackclient/network/v2/network_flavor_profile.py +20 -6
  64. openstackclient/network/v2/network_meter.py +19 -6
  65. openstackclient/network/v2/network_meter_rule.py +20 -2
  66. openstackclient/network/v2/network_qos_policy.py +15 -7
  67. openstackclient/network/v2/network_qos_rule.py +16 -1
  68. openstackclient/network/v2/network_qos_rule_type.py +16 -5
  69. openstackclient/network/v2/network_rbac.py +12 -5
  70. openstackclient/network/v2/network_segment.py +13 -1
  71. openstackclient/network/v2/network_segment_range.py +15 -3
  72. openstackclient/network/v2/network_trunk.py +4 -1
  73. openstackclient/network/v2/port.py +88 -12
  74. openstackclient/network/v2/router.py +27 -16
  75. openstackclient/network/v2/security_group.py +18 -49
  76. openstackclient/network/v2/security_group_rule.py +18 -5
  77. openstackclient/network/v2/subnet.py +15 -7
  78. openstackclient/network/v2/subnet_pool.py +13 -8
  79. openstackclient/network/v2/taas/tap_flow.py +13 -3
  80. openstackclient/network/v2/taas/tap_mirror.py +7 -4
  81. openstackclient/network/v2/taas/tap_service.py +4 -1
  82. openstackclient/object/v1/container.py +3 -1
  83. openstackclient/object/v1/object.py +3 -1
  84. openstackclient/tests/functional/identity/v3/common.py +34 -0
  85. openstackclient/tests/functional/identity/v3/test_application_credential.py +1 -1
  86. openstackclient/tests/functional/identity/v3/test_mapping.py +81 -0
  87. openstackclient/tests/functional/volume/v3/test_volume_group.py +163 -0
  88. openstackclient/tests/unit/common/test_limits.py +1 -1
  89. openstackclient/tests/unit/common/test_module.py +77 -44
  90. openstackclient/tests/unit/common/test_quota.py +9 -0
  91. openstackclient/tests/unit/compute/v2/fakes.py +1 -57
  92. openstackclient/tests/unit/compute/v2/test_agent.py +4 -4
  93. openstackclient/tests/unit/compute/v2/test_aggregate.py +1 -1
  94. openstackclient/tests/unit/compute/v2/test_console.py +2 -2
  95. openstackclient/tests/unit/compute/v2/test_console_connection.py +1 -1
  96. openstackclient/tests/unit/compute/v2/test_flavor.py +1 -1
  97. openstackclient/tests/unit/compute/v2/test_host.py +3 -3
  98. openstackclient/tests/unit/compute/v2/test_hypervisor.py +2 -2
  99. openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +1 -1
  100. openstackclient/tests/unit/compute/v2/test_keypair.py +1 -1
  101. openstackclient/tests/unit/compute/v2/test_server.py +15 -15
  102. openstackclient/tests/unit/compute/v2/test_server_backup.py +1 -1
  103. openstackclient/tests/unit/compute/v2/test_server_event.py +2 -2
  104. openstackclient/tests/unit/compute/v2/test_server_group.py +1 -1
  105. openstackclient/tests/unit/compute/v2/test_server_image.py +1 -1
  106. openstackclient/tests/unit/compute/v2/test_server_migration.py +4 -4
  107. openstackclient/tests/unit/compute/v2/test_server_share.py +4 -4
  108. openstackclient/tests/unit/compute/v2/test_server_volume.py +2 -2
  109. openstackclient/tests/unit/compute/v2/test_service.py +3 -3
  110. openstackclient/tests/unit/compute/v2/test_usage.py +1 -1
  111. openstackclient/tests/unit/identity/v2_0/fakes.py +3 -7
  112. openstackclient/tests/unit/identity/v2_0/test_endpoint.py +1 -1
  113. openstackclient/tests/unit/identity/v2_0/test_project.py +1 -1
  114. openstackclient/tests/unit/identity/v2_0/test_role.py +1 -1
  115. openstackclient/tests/unit/identity/v2_0/test_role_assignment.py +1 -1
  116. openstackclient/tests/unit/identity/v2_0/test_service.py +1 -1
  117. openstackclient/tests/unit/identity/v2_0/test_token.py +2 -2
  118. openstackclient/tests/unit/identity/v2_0/test_user.py +1 -1
  119. openstackclient/tests/unit/identity/v3/fakes.py +5 -38
  120. openstackclient/tests/unit/identity/v3/test_access_rule.py +3 -3
  121. openstackclient/tests/unit/identity/v3/test_application_credential.py +4 -4
  122. openstackclient/tests/unit/identity/v3/test_credential.py +5 -5
  123. openstackclient/tests/unit/identity/v3/test_domain.py +5 -5
  124. openstackclient/tests/unit/identity/v3/test_endpoint.py +6 -6
  125. openstackclient/tests/unit/identity/v3/test_endpoint_group.py +1 -1
  126. openstackclient/tests/unit/identity/v3/test_group.py +8 -8
  127. openstackclient/tests/unit/identity/v3/test_implied_role.py +1 -1
  128. openstackclient/tests/unit/identity/v3/test_limit.py +5 -5
  129. openstackclient/tests/unit/identity/v3/test_mappings.py +163 -79
  130. openstackclient/tests/unit/identity/v3/test_project.py +28 -5
  131. openstackclient/tests/unit/identity/v3/test_protocol.py +3 -3
  132. openstackclient/tests/unit/identity/v3/test_region.py +5 -5
  133. openstackclient/tests/unit/identity/v3/test_registered_limit.py +5 -5
  134. openstackclient/tests/unit/identity/v3/test_role.py +8 -8
  135. openstackclient/tests/unit/identity/v3/test_role_assignment.py +1 -1
  136. openstackclient/tests/unit/identity/v3/test_service.py +5 -5
  137. openstackclient/tests/unit/identity/v3/test_token.py +2 -2
  138. openstackclient/tests/unit/identity/v3/test_trust.py +4 -4
  139. openstackclient/tests/unit/identity/v3/test_user.py +73 -6
  140. openstackclient/tests/unit/network/v2/fakes.py +5 -77
  141. openstackclient/tests/unit/network/v2/fwaas/test_group.py +28 -2
  142. openstackclient/tests/unit/network/v2/fwaas/test_rule.py +28 -3
  143. openstackclient/tests/unit/network/v2/test_address_group.py +24 -0
  144. openstackclient/tests/unit/network/v2/test_address_scope.py +24 -0
  145. openstackclient/tests/unit/network/v2/test_floating_ip.py +24 -0
  146. openstackclient/tests/unit/network/v2/test_floating_ip_port_forwarding.py +24 -0
  147. openstackclient/tests/unit/network/v2/test_ip_availability.py +25 -0
  148. openstackclient/tests/unit/network/v2/test_l3_conntrack_helper.py +29 -3
  149. openstackclient/tests/unit/network/v2/test_network.py +74 -12
  150. openstackclient/tests/unit/network/v2/test_network_agent.py +50 -1
  151. openstackclient/tests/unit/network/v2/test_network_flavor.py +24 -0
  152. openstackclient/tests/unit/network/v2/test_network_flavor_profile.py +24 -0
  153. openstackclient/tests/unit/network/v2/test_network_meter.py +24 -0
  154. openstackclient/tests/unit/network/v2/test_network_qos_policy.py +24 -0
  155. openstackclient/tests/unit/network/v2/test_network_qos_rule_type.py +24 -0
  156. openstackclient/tests/unit/network/v2/test_network_rbac.py +24 -0
  157. openstackclient/tests/unit/network/v2/test_network_segment.py +24 -0
  158. openstackclient/tests/unit/network/v2/test_network_segment_range.py +24 -0
  159. openstackclient/tests/unit/network/v2/test_port.py +166 -0
  160. openstackclient/tests/unit/network/v2/test_router.py +28 -7
  161. openstackclient/tests/unit/network/v2/test_security_group.py +22 -0
  162. openstackclient/tests/unit/network/v2/test_security_group_rule.py +25 -0
  163. openstackclient/tests/unit/network/v2/test_subnet.py +28 -4
  164. openstackclient/tests/unit/network/v2/test_subnet_pool.py +24 -0
  165. openstackclient/tests/unit/volume/v2/fakes.py +20 -140
  166. openstackclient/tests/unit/volume/v2/test_volume_backup.py +5 -9
  167. openstackclient/tests/unit/volume/v2/test_volume_snapshot.py +6 -0
  168. openstackclient/tests/unit/volume/v3/fakes.py +204 -100
  169. openstackclient/tests/unit/volume/v3/test_backup_record.py +114 -0
  170. openstackclient/tests/unit/volume/v3/test_consistency_group.py +720 -0
  171. openstackclient/tests/unit/volume/v3/test_consistency_group_snapshot.py +354 -0
  172. openstackclient/tests/unit/volume/v3/test_qos_specs.py +455 -0
  173. openstackclient/tests/unit/volume/v3/test_volume_attachment.py +2 -0
  174. openstackclient/tests/unit/volume/v3/test_volume_backend.py +158 -0
  175. openstackclient/tests/unit/volume/v3/test_volume_backup.py +5 -9
  176. openstackclient/tests/unit/volume/v3/test_volume_group_type.py +65 -0
  177. openstackclient/tests/unit/volume/v3/test_volume_host.py +115 -0
  178. openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +6 -0
  179. openstackclient/volume/v2/volume.py +4 -2
  180. openstackclient/volume/v2/volume_backup.py +2 -3
  181. openstackclient/volume/v2/volume_snapshot.py +3 -4
  182. openstackclient/volume/v3/backup_record.py +94 -0
  183. openstackclient/volume/v3/consistency_group.py +400 -0
  184. openstackclient/volume/v3/consistency_group_snapshot.py +225 -0
  185. openstackclient/volume/v3/qos_specs.py +389 -0
  186. openstackclient/volume/v3/volume.py +4 -2
  187. openstackclient/volume/v3/volume_attachment.py +5 -1
  188. openstackclient/volume/v3/volume_backend.py +130 -0
  189. openstackclient/volume/v3/volume_backup.py +2 -3
  190. openstackclient/volume/v3/volume_group_snapshot.py +4 -6
  191. openstackclient/volume/v3/volume_group_type.py +1 -1
  192. openstackclient/volume/v3/volume_host.py +74 -0
  193. openstackclient/volume/v3/volume_message.py +3 -1
  194. openstackclient/volume/v3/volume_snapshot.py +2 -1
  195. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/METADATA +3 -4
  196. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/RECORD +202 -188
  197. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/entry_points.txt +24 -24
  198. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/licenses/AUTHORS +5 -0
  199. python_openstackclient-10.1.0.dist-info/pbr.json +1 -0
  200. python_openstackclient-10.0.0.dist-info/pbr.json +0 -1
  201. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/WHEEL +0 -0
  202. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/licenses/LICENSE +0 -0
  203. {python_openstackclient-10.0.0.dist-info → python_openstackclient-10.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,720 @@
1
+ #
2
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
3
+ # not use this file except in compliance with the License. You may obtain
4
+ # a copy of the License at
5
+ #
6
+ # http://www.apache.org/licenses/LICENSE-2.0
7
+ #
8
+ # Unless required by applicable law or agreed to in writing, software
9
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11
+ # License for the specific language governing permissions and limitations
12
+ # under the License.
13
+
14
+ from unittest import mock
15
+ from unittest.mock import call
16
+
17
+ from osc_lib.cli import format_columns
18
+ from osc_lib import exceptions
19
+ from osc_lib import utils
20
+
21
+ from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
22
+ from openstackclient.volume.v3 import consistency_group
23
+
24
+
25
+ class TestConsistencyGroup(volume_fakes.TestVolume):
26
+ def setUp(self):
27
+ super().setUp()
28
+
29
+ # Get a shortcut to the TransferManager Mock
30
+ self.consistencygroups_mock = self.volume_client.consistencygroups
31
+ self.consistencygroups_mock.reset_mock()
32
+
33
+ self.cgsnapshots_mock = self.volume_client.cgsnapshots
34
+ self.cgsnapshots_mock.reset_mock()
35
+
36
+ self.volumes_mock = self.volume_client.volumes
37
+ self.volumes_mock.reset_mock()
38
+
39
+ self.types_mock = self.volume_client.volume_types
40
+ self.types_mock.reset_mock()
41
+
42
+
43
+ class TestConsistencyGroupAddVolume(TestConsistencyGroup):
44
+ _consistency_group = volume_fakes.create_one_consistency_group()
45
+
46
+ def setUp(self):
47
+ super().setUp()
48
+
49
+ self.consistencygroups_mock.get.return_value = self._consistency_group
50
+ # Get the command object to test
51
+ self.cmd = consistency_group.AddVolumeToConsistencyGroup(
52
+ self.app, None
53
+ )
54
+
55
+ def test_add_one_volume_to_consistency_group(self):
56
+ volume = volume_fakes.create_one_volume()
57
+ self.volumes_mock.get.return_value = volume
58
+ arglist = [
59
+ self._consistency_group.id,
60
+ volume.id,
61
+ ]
62
+ verifylist = [
63
+ ('consistency_group', self._consistency_group.id),
64
+ ('volumes', [volume.id]),
65
+ ]
66
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
67
+
68
+ result = self.cmd.take_action(parsed_args)
69
+
70
+ # Set expected values
71
+ kwargs = {
72
+ 'add_volumes': volume.id,
73
+ }
74
+ self.consistencygroups_mock.update.assert_called_once_with(
75
+ self._consistency_group.id, **kwargs
76
+ )
77
+ self.assertIsNone(result)
78
+
79
+ def test_add_multiple_volumes_to_consistency_group(self):
80
+ volumes = volume_fakes.create_volumes(count=2)
81
+ self.volumes_mock.get = volume_fakes.get_volumes(volumes)
82
+ arglist = [
83
+ self._consistency_group.id,
84
+ volumes[0].id,
85
+ volumes[1].id,
86
+ ]
87
+ verifylist = [
88
+ ('consistency_group', self._consistency_group.id),
89
+ ('volumes', [volumes[0].id, volumes[1].id]),
90
+ ]
91
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
92
+
93
+ result = self.cmd.take_action(parsed_args)
94
+
95
+ # Set expected values
96
+ kwargs = {
97
+ 'add_volumes': volumes[0].id + ',' + volumes[1].id,
98
+ }
99
+ self.consistencygroups_mock.update.assert_called_once_with(
100
+ self._consistency_group.id, **kwargs
101
+ )
102
+ self.assertIsNone(result)
103
+
104
+ @mock.patch.object(consistency_group.LOG, 'error')
105
+ def test_add_multiple_volumes_to_consistency_group_with_exception(
106
+ self,
107
+ mock_error,
108
+ ):
109
+ volume = volume_fakes.create_one_volume()
110
+ arglist = [
111
+ self._consistency_group.id,
112
+ volume.id,
113
+ 'unexist_volume',
114
+ ]
115
+ verifylist = [
116
+ ('consistency_group', self._consistency_group.id),
117
+ ('volumes', [volume.id, 'unexist_volume']),
118
+ ]
119
+
120
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
121
+
122
+ find_mock_result = [
123
+ volume,
124
+ exceptions.CommandError,
125
+ self._consistency_group,
126
+ ]
127
+ with mock.patch.object(
128
+ utils, 'find_resource', side_effect=find_mock_result
129
+ ) as find_mock:
130
+ result = self.cmd.take_action(parsed_args)
131
+ mock_error.assert_called_with(
132
+ '%(result)s of %(total)s volumes failed to add.',
133
+ {'result': 1, 'total': 2},
134
+ )
135
+ self.assertIsNone(result)
136
+ find_mock.assert_any_call(
137
+ self.consistencygroups_mock, self._consistency_group.id
138
+ )
139
+ find_mock.assert_any_call(self.volumes_mock, volume.id)
140
+ find_mock.assert_any_call(self.volumes_mock, 'unexist_volume')
141
+ self.assertEqual(3, find_mock.call_count)
142
+ self.consistencygroups_mock.update.assert_called_once_with(
143
+ self._consistency_group.id, add_volumes=volume.id
144
+ )
145
+
146
+
147
+ class TestConsistencyGroupCreate(TestConsistencyGroup):
148
+ volume_type = volume_fakes.create_one_volume_type()
149
+ new_consistency_group = volume_fakes.create_one_consistency_group()
150
+ consistency_group_snapshot = (
151
+ volume_fakes.create_one_consistency_group_snapshot()
152
+ )
153
+
154
+ columns = (
155
+ 'availability_zone',
156
+ 'created_at',
157
+ 'description',
158
+ 'id',
159
+ 'name',
160
+ 'status',
161
+ 'volume_types',
162
+ )
163
+ data = (
164
+ new_consistency_group.availability_zone,
165
+ new_consistency_group.created_at,
166
+ new_consistency_group.description,
167
+ new_consistency_group.id,
168
+ new_consistency_group.name,
169
+ new_consistency_group.status,
170
+ new_consistency_group.volume_types,
171
+ )
172
+
173
+ def setUp(self):
174
+ super().setUp()
175
+ self.consistencygroups_mock.create.return_value = (
176
+ self.new_consistency_group
177
+ )
178
+ self.consistencygroups_mock.create_from_src.return_value = (
179
+ self.new_consistency_group
180
+ )
181
+ self.consistencygroups_mock.get.return_value = (
182
+ self.new_consistency_group
183
+ )
184
+ self.types_mock.get.return_value = self.volume_type
185
+ self.cgsnapshots_mock.get.return_value = (
186
+ self.consistency_group_snapshot
187
+ )
188
+
189
+ # Get the command object to test
190
+ self.cmd = consistency_group.CreateConsistencyGroup(self.app, None)
191
+
192
+ def test_consistency_group_create(self):
193
+ arglist = [
194
+ '--volume-type',
195
+ self.volume_type.id,
196
+ '--description',
197
+ self.new_consistency_group.description,
198
+ '--availability-zone',
199
+ self.new_consistency_group.availability_zone,
200
+ self.new_consistency_group.name,
201
+ ]
202
+ verifylist = [
203
+ ('volume_type', self.volume_type.id),
204
+ ('description', self.new_consistency_group.description),
205
+ (
206
+ 'availability_zone',
207
+ self.new_consistency_group.availability_zone,
208
+ ),
209
+ ('name', self.new_consistency_group.name),
210
+ ]
211
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
212
+
213
+ columns, data = self.cmd.take_action(parsed_args)
214
+
215
+ self.types_mock.get.assert_called_once_with(self.volume_type.id)
216
+ self.consistencygroups_mock.get.assert_not_called()
217
+ self.consistencygroups_mock.create.assert_called_once_with(
218
+ self.volume_type.id,
219
+ name=self.new_consistency_group.name,
220
+ description=self.new_consistency_group.description,
221
+ availability_zone=self.new_consistency_group.availability_zone,
222
+ )
223
+
224
+ self.assertEqual(self.columns, columns)
225
+ self.assertEqual(self.data, data)
226
+
227
+ def test_consistency_group_create_without_name(self):
228
+ arglist = [
229
+ '--volume-type',
230
+ self.volume_type.id,
231
+ '--description',
232
+ self.new_consistency_group.description,
233
+ '--availability-zone',
234
+ self.new_consistency_group.availability_zone,
235
+ ]
236
+ verifylist = [
237
+ ('volume_type', self.volume_type.id),
238
+ ('description', self.new_consistency_group.description),
239
+ (
240
+ 'availability_zone',
241
+ self.new_consistency_group.availability_zone,
242
+ ),
243
+ ]
244
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
245
+
246
+ columns, data = self.cmd.take_action(parsed_args)
247
+
248
+ self.types_mock.get.assert_called_once_with(self.volume_type.id)
249
+ self.consistencygroups_mock.get.assert_not_called()
250
+ self.consistencygroups_mock.create.assert_called_once_with(
251
+ self.volume_type.id,
252
+ name=None,
253
+ description=self.new_consistency_group.description,
254
+ availability_zone=self.new_consistency_group.availability_zone,
255
+ )
256
+
257
+ self.assertEqual(self.columns, columns)
258
+ self.assertCountEqual(self.data, data)
259
+
260
+ def test_consistency_group_create_from_source(self):
261
+ arglist = [
262
+ '--consistency-group-source',
263
+ self.new_consistency_group.id,
264
+ '--description',
265
+ self.new_consistency_group.description,
266
+ self.new_consistency_group.name,
267
+ ]
268
+ verifylist = [
269
+ ('source', self.new_consistency_group.id),
270
+ ('description', self.new_consistency_group.description),
271
+ ('name', self.new_consistency_group.name),
272
+ ]
273
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
274
+
275
+ columns, data = self.cmd.take_action(parsed_args)
276
+
277
+ self.types_mock.get.assert_not_called()
278
+ self.consistencygroups_mock.get.assert_called_once_with(
279
+ self.new_consistency_group.id
280
+ )
281
+ self.consistencygroups_mock.create_from_src.assert_called_with(
282
+ None,
283
+ self.new_consistency_group.id,
284
+ name=self.new_consistency_group.name,
285
+ description=self.new_consistency_group.description,
286
+ )
287
+
288
+ self.assertEqual(self.columns, columns)
289
+ self.assertCountEqual(self.data, data)
290
+
291
+ def test_consistency_group_create_from_snapshot(self):
292
+ arglist = [
293
+ '--consistency-group-snapshot',
294
+ self.consistency_group_snapshot.id,
295
+ '--description',
296
+ self.new_consistency_group.description,
297
+ self.new_consistency_group.name,
298
+ ]
299
+ verifylist = [
300
+ ('snapshot', self.consistency_group_snapshot.id),
301
+ ('description', self.new_consistency_group.description),
302
+ ('name', self.new_consistency_group.name),
303
+ ]
304
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
305
+
306
+ columns, data = self.cmd.take_action(parsed_args)
307
+
308
+ self.types_mock.get.assert_not_called()
309
+ self.cgsnapshots_mock.get.assert_called_once_with(
310
+ self.consistency_group_snapshot.id
311
+ )
312
+ self.consistencygroups_mock.create_from_src.assert_called_with(
313
+ self.consistency_group_snapshot.id,
314
+ None,
315
+ name=self.new_consistency_group.name,
316
+ description=self.new_consistency_group.description,
317
+ )
318
+
319
+ self.assertEqual(self.columns, columns)
320
+ self.assertCountEqual(self.data, data)
321
+
322
+
323
+ class TestConsistencyGroupDelete(TestConsistencyGroup):
324
+ consistency_groups = volume_fakes.create_consistency_groups(count=2)
325
+
326
+ def setUp(self):
327
+ super().setUp()
328
+
329
+ self.consistencygroups_mock.get = volume_fakes.get_consistency_groups(
330
+ self.consistency_groups,
331
+ )
332
+ self.consistencygroups_mock.delete.return_value = None
333
+
334
+ # Get the command object to mock
335
+ self.cmd = consistency_group.DeleteConsistencyGroup(self.app, None)
336
+
337
+ def test_consistency_group_delete(self):
338
+ arglist = [self.consistency_groups[0].id]
339
+ verifylist = [("consistency_groups", [self.consistency_groups[0].id])]
340
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
341
+
342
+ result = self.cmd.take_action(parsed_args)
343
+
344
+ self.consistencygroups_mock.delete.assert_called_with(
345
+ self.consistency_groups[0].id, False
346
+ )
347
+ self.assertIsNone(result)
348
+
349
+ def test_consistency_group_delete_with_force(self):
350
+ arglist = [
351
+ '--force',
352
+ self.consistency_groups[0].id,
353
+ ]
354
+ verifylist = [
355
+ ('force', True),
356
+ ("consistency_groups", [self.consistency_groups[0].id]),
357
+ ]
358
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
359
+
360
+ result = self.cmd.take_action(parsed_args)
361
+
362
+ self.consistencygroups_mock.delete.assert_called_with(
363
+ self.consistency_groups[0].id, True
364
+ )
365
+ self.assertIsNone(result)
366
+
367
+ def test_delete_multiple_consistency_groups(self):
368
+ arglist = []
369
+ for b in self.consistency_groups:
370
+ arglist.append(b.id)
371
+ verifylist = [
372
+ ('consistency_groups', arglist),
373
+ ]
374
+
375
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
376
+ result = self.cmd.take_action(parsed_args)
377
+
378
+ calls = []
379
+ for b in self.consistency_groups:
380
+ calls.append(call(b.id, False))
381
+ self.consistencygroups_mock.delete.assert_has_calls(calls)
382
+ self.assertIsNone(result)
383
+
384
+ def test_delete_multiple_consistency_groups_with_exception(self):
385
+ arglist = [
386
+ self.consistency_groups[0].id,
387
+ 'unexist_consistency_group',
388
+ ]
389
+ verifylist = [
390
+ ('consistency_groups', arglist),
391
+ ]
392
+
393
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
394
+
395
+ find_mock_result = [
396
+ self.consistency_groups[0],
397
+ exceptions.CommandError,
398
+ ]
399
+ with mock.patch.object(
400
+ utils, 'find_resource', side_effect=find_mock_result
401
+ ) as find_mock:
402
+ try:
403
+ self.cmd.take_action(parsed_args)
404
+ self.fail('CommandError should be raised.')
405
+ except exceptions.CommandError as e:
406
+ self.assertEqual(
407
+ '1 of 2 consistency groups failed to delete.', str(e)
408
+ )
409
+
410
+ find_mock.assert_any_call(
411
+ self.consistencygroups_mock, self.consistency_groups[0].id
412
+ )
413
+ find_mock.assert_any_call(
414
+ self.consistencygroups_mock, 'unexist_consistency_group'
415
+ )
416
+
417
+ self.assertEqual(2, find_mock.call_count)
418
+ self.consistencygroups_mock.delete.assert_called_once_with(
419
+ self.consistency_groups[0].id, False
420
+ )
421
+
422
+
423
+ class TestConsistencyGroupList(TestConsistencyGroup):
424
+ consistency_groups = volume_fakes.create_consistency_groups(count=2)
425
+
426
+ columns = [
427
+ 'ID',
428
+ 'Status',
429
+ 'Name',
430
+ ]
431
+ columns_long = [
432
+ 'ID',
433
+ 'Status',
434
+ 'Availability Zone',
435
+ 'Name',
436
+ 'Description',
437
+ 'Volume Types',
438
+ ]
439
+ data = []
440
+ for c in consistency_groups:
441
+ data.append(
442
+ (
443
+ c.id,
444
+ c.status,
445
+ c.name,
446
+ )
447
+ )
448
+ data_long = []
449
+ for c in consistency_groups:
450
+ data_long.append(
451
+ (
452
+ c.id,
453
+ c.status,
454
+ c.availability_zone,
455
+ c.name,
456
+ c.description,
457
+ format_columns.ListColumn(c.volume_types),
458
+ )
459
+ )
460
+
461
+ def setUp(self):
462
+ super().setUp()
463
+
464
+ self.consistencygroups_mock.list.return_value = self.consistency_groups
465
+ # Get the command to test
466
+ self.cmd = consistency_group.ListConsistencyGroup(self.app, None)
467
+
468
+ def test_consistency_group_list_without_options(self):
469
+ arglist = []
470
+ verifylist = [
471
+ ("all_projects", False),
472
+ ("long", False),
473
+ ]
474
+
475
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
476
+ columns, data = self.cmd.take_action(parsed_args)
477
+
478
+ self.consistencygroups_mock.list.assert_called_once_with(
479
+ detailed=True, search_opts={'all_tenants': False}
480
+ )
481
+ self.assertEqual(self.columns, columns)
482
+ self.assertCountEqual(self.data, list(data))
483
+
484
+ def test_consistency_group_list_with_all_project(self):
485
+ arglist = ["--all-projects"]
486
+ verifylist = [
487
+ ("all_projects", True),
488
+ ("long", False),
489
+ ]
490
+
491
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
492
+ columns, data = self.cmd.take_action(parsed_args)
493
+
494
+ self.consistencygroups_mock.list.assert_called_once_with(
495
+ detailed=True, search_opts={'all_tenants': True}
496
+ )
497
+ self.assertEqual(self.columns, columns)
498
+ self.assertCountEqual(self.data, list(data))
499
+
500
+ def test_consistency_group_list_with_long(self):
501
+ arglist = [
502
+ "--long",
503
+ ]
504
+ verifylist = [
505
+ ("all_projects", False),
506
+ ("long", True),
507
+ ]
508
+
509
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
510
+ columns, data = self.cmd.take_action(parsed_args)
511
+
512
+ self.consistencygroups_mock.list.assert_called_once_with(
513
+ detailed=True, search_opts={'all_tenants': False}
514
+ )
515
+ self.assertEqual(self.columns_long, columns)
516
+ self.assertCountEqual(self.data_long, list(data))
517
+
518
+
519
+ class TestConsistencyGroupRemoveVolume(TestConsistencyGroup):
520
+ _consistency_group = volume_fakes.create_one_consistency_group()
521
+
522
+ def setUp(self):
523
+ super().setUp()
524
+
525
+ self.consistencygroups_mock.get.return_value = self._consistency_group
526
+ # Get the command object to test
527
+ self.cmd = consistency_group.RemoveVolumeFromConsistencyGroup(
528
+ self.app, None
529
+ )
530
+
531
+ def test_remove_one_volume_from_consistency_group(self):
532
+ volume = volume_fakes.create_one_volume()
533
+ self.volumes_mock.get.return_value = volume
534
+ arglist = [
535
+ self._consistency_group.id,
536
+ volume.id,
537
+ ]
538
+ verifylist = [
539
+ ('consistency_group', self._consistency_group.id),
540
+ ('volumes', [volume.id]),
541
+ ]
542
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
543
+
544
+ result = self.cmd.take_action(parsed_args)
545
+
546
+ # Set expected values
547
+ kwargs = {
548
+ 'remove_volumes': volume.id,
549
+ }
550
+ self.consistencygroups_mock.update.assert_called_once_with(
551
+ self._consistency_group.id, **kwargs
552
+ )
553
+ self.assertIsNone(result)
554
+
555
+ def test_remove_multi_volumes_from_consistency_group(self):
556
+ volumes = volume_fakes.create_volumes(count=2)
557
+ self.volumes_mock.get = volume_fakes.get_volumes(volumes)
558
+ arglist = [
559
+ self._consistency_group.id,
560
+ volumes[0].id,
561
+ volumes[1].id,
562
+ ]
563
+ verifylist = [
564
+ ('consistency_group', self._consistency_group.id),
565
+ ('volumes', [volumes[0].id, volumes[1].id]),
566
+ ]
567
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
568
+
569
+ result = self.cmd.take_action(parsed_args)
570
+
571
+ # Set expected values
572
+ kwargs = {
573
+ 'remove_volumes': volumes[0].id + ',' + volumes[1].id,
574
+ }
575
+ self.consistencygroups_mock.update.assert_called_once_with(
576
+ self._consistency_group.id, **kwargs
577
+ )
578
+ self.assertIsNone(result)
579
+
580
+ @mock.patch.object(consistency_group.LOG, 'error')
581
+ def test_remove_multiple_volumes_from_consistency_group_with_exception(
582
+ self,
583
+ mock_error,
584
+ ):
585
+ volume = volume_fakes.create_one_volume()
586
+ arglist = [
587
+ self._consistency_group.id,
588
+ volume.id,
589
+ 'unexist_volume',
590
+ ]
591
+ verifylist = [
592
+ ('consistency_group', self._consistency_group.id),
593
+ ('volumes', [volume.id, 'unexist_volume']),
594
+ ]
595
+
596
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
597
+
598
+ find_mock_result = [
599
+ volume,
600
+ exceptions.CommandError,
601
+ self._consistency_group,
602
+ ]
603
+ with mock.patch.object(
604
+ utils, 'find_resource', side_effect=find_mock_result
605
+ ) as find_mock:
606
+ result = self.cmd.take_action(parsed_args)
607
+ mock_error.assert_called_with(
608
+ '%(result)s of %(total)s volumes failed to remove.',
609
+ {'result': 1, 'total': 2},
610
+ )
611
+ self.assertIsNone(result)
612
+ find_mock.assert_any_call(
613
+ self.consistencygroups_mock, self._consistency_group.id
614
+ )
615
+ find_mock.assert_any_call(self.volumes_mock, volume.id)
616
+ find_mock.assert_any_call(self.volumes_mock, 'unexist_volume')
617
+ self.assertEqual(3, find_mock.call_count)
618
+ self.consistencygroups_mock.update.assert_called_once_with(
619
+ self._consistency_group.id, remove_volumes=volume.id
620
+ )
621
+
622
+
623
+ class TestConsistencyGroupSet(TestConsistencyGroup):
624
+ consistency_group = volume_fakes.create_one_consistency_group()
625
+
626
+ def setUp(self):
627
+ super().setUp()
628
+
629
+ self.consistencygroups_mock.get.return_value = self.consistency_group
630
+ # Get the command object to test
631
+ self.cmd = consistency_group.SetConsistencyGroup(self.app, None)
632
+
633
+ def test_consistency_group_set_name(self):
634
+ new_name = 'new_name'
635
+ arglist = [
636
+ '--name',
637
+ new_name,
638
+ self.consistency_group.id,
639
+ ]
640
+ verifylist = [
641
+ ('name', new_name),
642
+ ('description', None),
643
+ ('consistency_group', self.consistency_group.id),
644
+ ]
645
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
646
+
647
+ result = self.cmd.take_action(parsed_args)
648
+
649
+ # Set expected values
650
+ kwargs = {
651
+ 'name': new_name,
652
+ }
653
+ self.consistencygroups_mock.update.assert_called_once_with(
654
+ self.consistency_group.id, **kwargs
655
+ )
656
+ self.assertIsNone(result)
657
+
658
+ def test_consistency_group_set_description(self):
659
+ new_description = 'new_description'
660
+ arglist = [
661
+ '--description',
662
+ new_description,
663
+ self.consistency_group.id,
664
+ ]
665
+ verifylist = [
666
+ ('name', None),
667
+ ('description', new_description),
668
+ ('consistency_group', self.consistency_group.id),
669
+ ]
670
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
671
+
672
+ result = self.cmd.take_action(parsed_args)
673
+
674
+ # Set expected values
675
+ kwargs = {
676
+ 'description': new_description,
677
+ }
678
+ self.consistencygroups_mock.update.assert_called_once_with(
679
+ self.consistency_group.id, **kwargs
680
+ )
681
+ self.assertIsNone(result)
682
+
683
+
684
+ class TestConsistencyGroupShow(TestConsistencyGroup):
685
+ columns = (
686
+ 'availability_zone',
687
+ 'created_at',
688
+ 'description',
689
+ 'id',
690
+ 'name',
691
+ 'status',
692
+ 'volume_types',
693
+ )
694
+
695
+ def setUp(self):
696
+ super().setUp()
697
+
698
+ self.consistency_group = volume_fakes.create_one_consistency_group()
699
+ self.data = (
700
+ self.consistency_group.availability_zone,
701
+ self.consistency_group.created_at,
702
+ self.consistency_group.description,
703
+ self.consistency_group.id,
704
+ self.consistency_group.name,
705
+ self.consistency_group.status,
706
+ self.consistency_group.volume_types,
707
+ )
708
+ self.consistencygroups_mock.get.return_value = self.consistency_group
709
+ self.cmd = consistency_group.ShowConsistencyGroup(self.app, None)
710
+
711
+ def test_consistency_group_show(self):
712
+ arglist = [self.consistency_group.id]
713
+ verifylist = [("consistency_group", self.consistency_group.id)]
714
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
715
+ columns, data = self.cmd.take_action(parsed_args)
716
+ self.consistencygroups_mock.get.assert_called_once_with(
717
+ self.consistency_group.id
718
+ )
719
+ self.assertEqual(self.columns, columns)
720
+ self.assertCountEqual(self.data, data)