python-openstackclient 7.3.1__py3-none-any.whl → 8.0.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 (235) hide show
  1. openstackclient/common/availability_zone.py +3 -6
  2. openstackclient/common/clientmanager.py +2 -1
  3. openstackclient/common/envvars.py +57 -0
  4. openstackclient/common/extension.py +3 -11
  5. openstackclient/common/limits.py +1 -1
  6. openstackclient/common/project_cleanup.py +3 -2
  7. openstackclient/common/quota.py +54 -28
  8. openstackclient/compute/client.py +2 -5
  9. openstackclient/compute/v2/agent.py +5 -5
  10. openstackclient/compute/v2/aggregate.py +17 -15
  11. openstackclient/compute/v2/console.py +3 -4
  12. openstackclient/compute/v2/flavor.py +14 -18
  13. openstackclient/compute/v2/host.py +3 -3
  14. openstackclient/compute/v2/hypervisor.py +10 -4
  15. openstackclient/compute/v2/hypervisor_stats.py +1 -1
  16. openstackclient/compute/v2/keypair.py +8 -10
  17. openstackclient/compute/v2/server.py +70 -112
  18. openstackclient/compute/v2/server_backup.py +1 -1
  19. openstackclient/compute/v2/server_event.py +7 -16
  20. openstackclient/compute/v2/server_group.py +6 -6
  21. openstackclient/compute/v2/server_image.py +1 -1
  22. openstackclient/compute/v2/server_migration.py +6 -6
  23. openstackclient/compute/v2/server_volume.py +4 -4
  24. openstackclient/compute/v2/service.py +9 -13
  25. openstackclient/compute/v2/usage.py +4 -6
  26. openstackclient/identity/client.py +2 -4
  27. openstackclient/identity/common.py +16 -17
  28. openstackclient/identity/v2_0/ec2creds.py +4 -3
  29. openstackclient/identity/v2_0/endpoint.py +12 -10
  30. openstackclient/identity/v2_0/project.py +6 -6
  31. openstackclient/identity/v2_0/role.py +1 -1
  32. openstackclient/identity/v2_0/service.py +7 -7
  33. openstackclient/identity/v2_0/user.py +6 -21
  34. openstackclient/identity/v3/access_rule.py +2 -5
  35. openstackclient/identity/v3/consumer.py +4 -3
  36. openstackclient/identity/v3/credential.py +8 -9
  37. openstackclient/identity/v3/domain.py +1 -1
  38. openstackclient/identity/v3/ec2creds.py +4 -3
  39. openstackclient/identity/v3/endpoint.py +104 -88
  40. openstackclient/identity/v3/endpoint_group.py +1 -1
  41. openstackclient/identity/v3/group.py +3 -4
  42. openstackclient/identity/v3/identity_provider.py +1 -2
  43. openstackclient/identity/v3/limit.py +4 -9
  44. openstackclient/identity/v3/mapping.py +4 -3
  45. openstackclient/identity/v3/policy.py +5 -8
  46. openstackclient/identity/v3/project.py +6 -6
  47. openstackclient/identity/v3/region.py +2 -5
  48. openstackclient/identity/v3/registered_limit.py +4 -8
  49. openstackclient/identity/v3/role.py +15 -16
  50. openstackclient/identity/v3/service.py +8 -8
  51. openstackclient/identity/v3/service_provider.py +3 -6
  52. openstackclient/identity/v3/tag.py +2 -2
  53. openstackclient/identity/v3/token.py +1 -2
  54. openstackclient/identity/v3/trust.py +74 -25
  55. openstackclient/identity/v3/user.py +9 -6
  56. openstackclient/image/client.py +2 -5
  57. openstackclient/image/v1/image.py +11 -15
  58. openstackclient/image/v2/cache.py +2 -4
  59. openstackclient/image/v2/image.py +30 -37
  60. openstackclient/image/v2/metadef_namespaces.py +4 -3
  61. openstackclient/image/v2/metadef_resource_type_association.py +1 -2
  62. openstackclient/image/v2/metadef_resource_types.py +1 -2
  63. openstackclient/locale/tr_TR/LC_MESSAGES/openstackclient.po +9 -1370
  64. openstackclient/network/client.py +4 -10
  65. openstackclient/network/common.py +16 -12
  66. openstackclient/network/utils.py +3 -3
  67. openstackclient/network/v2/address_group.py +5 -9
  68. openstackclient/network/v2/address_scope.py +2 -3
  69. openstackclient/network/v2/default_security_group_rule.py +1 -2
  70. openstackclient/network/v2/floating_ip.py +14 -21
  71. openstackclient/network/v2/floating_ip_port_forwarding.py +7 -7
  72. openstackclient/network/v2/ip_availability.py +1 -2
  73. openstackclient/network/v2/l3_conntrack_helper.py +8 -12
  74. openstackclient/network/v2/local_ip.py +24 -26
  75. openstackclient/network/v2/local_ip_association.py +4 -5
  76. openstackclient/network/v2/ndp_proxy.py +9 -10
  77. openstackclient/network/v2/network.py +12 -16
  78. openstackclient/network/v2/network_agent.py +29 -37
  79. openstackclient/network/v2/network_auto_allocated_topology.py +4 -5
  80. openstackclient/network/v2/network_flavor.py +1 -1
  81. openstackclient/network/v2/network_flavor_profile.py +5 -5
  82. openstackclient/network/v2/network_meter.py +3 -3
  83. openstackclient/network/v2/network_meter_rule.py +5 -8
  84. openstackclient/network/v2/network_qos_policy.py +4 -4
  85. openstackclient/network/v2/network_qos_rule.py +4 -5
  86. openstackclient/network/v2/network_rbac.py +4 -4
  87. openstackclient/network/v2/network_segment.py +6 -7
  88. openstackclient/network/v2/network_segment_range.py +16 -20
  89. openstackclient/network/v2/network_trunk.py +24 -16
  90. openstackclient/network/v2/port.py +42 -31
  91. openstackclient/network/v2/router.py +55 -41
  92. openstackclient/network/v2/security_group.py +8 -15
  93. openstackclient/network/v2/security_group_rule.py +9 -10
  94. openstackclient/network/v2/subnet.py +31 -30
  95. openstackclient/network/v2/subnet_pool.py +4 -4
  96. openstackclient/object/client.py +2 -3
  97. openstackclient/object/v1/container.py +2 -3
  98. openstackclient/object/v1/object.py +2 -9
  99. openstackclient/shell.py +22 -5
  100. openstackclient/tests/functional/base.py +2 -2
  101. openstackclient/tests/functional/common/test_quota.py +3 -1
  102. openstackclient/tests/functional/compute/v2/common.py +12 -6
  103. openstackclient/tests/functional/compute/v2/test_server.py +2 -3
  104. openstackclient/tests/functional/compute/v2/test_server_event.py +1 -1
  105. openstackclient/tests/functional/identity/v2/test_user.py +1 -1
  106. openstackclient/tests/functional/identity/v3/common.py +3 -8
  107. openstackclient/tests/functional/identity/v3/test_application_credential.py +10 -10
  108. openstackclient/tests/functional/identity/v3/test_endpoint.py +3 -3
  109. openstackclient/tests/functional/identity/v3/test_group.py +3 -3
  110. openstackclient/tests/functional/identity/v3/test_idp.py +3 -7
  111. openstackclient/tests/functional/identity/v3/test_limit.py +4 -4
  112. openstackclient/tests/functional/identity/v3/test_project.py +5 -14
  113. openstackclient/tests/functional/identity/v3/test_region.py +1 -3
  114. openstackclient/tests/functional/identity/v3/test_registered_limit.py +3 -3
  115. openstackclient/tests/functional/identity/v3/test_role.py +1 -1
  116. openstackclient/tests/functional/identity/v3/test_role_assignment.py +13 -31
  117. openstackclient/tests/functional/identity/v3/test_service_provider.py +3 -7
  118. openstackclient/tests/functional/identity/v3/test_user.py +8 -8
  119. openstackclient/tests/functional/network/v2/common.py +7 -3
  120. openstackclient/tests/functional/network/v2/test_address_group.py +4 -0
  121. openstackclient/tests/functional/network/v2/test_l3_conntrack_helper.py +15 -11
  122. openstackclient/tests/functional/network/v2/test_local_ip.py +4 -0
  123. openstackclient/tests/functional/network/v2/test_network_meter_rule.py +2 -2
  124. openstackclient/tests/functional/network/v2/test_network_ndp_proxy.py +2 -3
  125. openstackclient/tests/functional/network/v2/test_network_rbac.py +2 -2
  126. openstackclient/tests/functional/network/v2/test_network_trunk.py +1 -1
  127. openstackclient/tests/functional/network/v2/test_port.py +17 -7
  128. openstackclient/tests/functional/network/v2/test_router.py +42 -0
  129. openstackclient/tests/functional/network/v2/test_subnet_pool.py +4 -0
  130. openstackclient/tests/unit/api/test_compute_v2.py +67 -87
  131. openstackclient/tests/unit/common/test_availability_zone.py +6 -14
  132. openstackclient/tests/unit/common/test_command.py +1 -1
  133. openstackclient/tests/unit/common/test_extension.py +5 -7
  134. openstackclient/tests/unit/common/test_limits.py +1 -1
  135. openstackclient/tests/unit/common/test_project_cleanup.py +5 -6
  136. openstackclient/tests/unit/common/test_quota.py +51 -28
  137. openstackclient/tests/unit/compute/v2/fakes.py +4 -10
  138. openstackclient/tests/unit/compute/v2/test_agent.py +16 -16
  139. openstackclient/tests/unit/compute/v2/test_aggregate.py +56 -60
  140. openstackclient/tests/unit/compute/v2/test_console.py +16 -16
  141. openstackclient/tests/unit/compute/v2/test_flavor.py +71 -71
  142. openstackclient/tests/unit/compute/v2/test_host.py +8 -8
  143. openstackclient/tests/unit/compute/v2/test_hypervisor.py +22 -30
  144. openstackclient/tests/unit/compute/v2/test_hypervisor_stats.py +2 -2
  145. openstackclient/tests/unit/compute/v2/test_keypair.py +24 -24
  146. openstackclient/tests/unit/compute/v2/test_server.py +524 -560
  147. openstackclient/tests/unit/compute/v2/test_server_backup.py +5 -7
  148. openstackclient/tests/unit/compute/v2/test_server_event.py +16 -18
  149. openstackclient/tests/unit/compute/v2/test_server_group.py +25 -31
  150. openstackclient/tests/unit/compute/v2/test_server_image.py +6 -8
  151. openstackclient/tests/unit/compute/v2/test_server_migration.py +37 -37
  152. openstackclient/tests/unit/compute/v2/test_server_volume.py +12 -12
  153. openstackclient/tests/unit/compute/v2/test_service.py +39 -45
  154. openstackclient/tests/unit/compute/v2/test_usage.py +5 -5
  155. openstackclient/tests/unit/identity/v2_0/fakes.py +1 -1
  156. openstackclient/tests/unit/identity/v3/test_access_rule.py +1 -3
  157. openstackclient/tests/unit/identity/v3/test_application_credential.py +1 -1
  158. openstackclient/tests/unit/identity/v3/test_credential.py +4 -4
  159. openstackclient/tests/unit/identity/v3/test_endpoint.py +167 -172
  160. openstackclient/tests/unit/identity/v3/test_mappings.py +2 -2
  161. openstackclient/tests/unit/identity/v3/test_trust.py +5 -2
  162. openstackclient/tests/unit/identity/v3/test_user.py +16 -0
  163. openstackclient/tests/unit/image/v1/fakes.py +2 -2
  164. openstackclient/tests/unit/image/v2/test_image.py +39 -1
  165. openstackclient/tests/unit/integ/cli/test_shell.py +1 -2
  166. openstackclient/tests/unit/network/test_common.py +2 -2
  167. openstackclient/tests/unit/network/v2/test_floating_ip_compute.py +8 -14
  168. openstackclient/tests/unit/network/v2/test_floating_ip_network.py +49 -35
  169. openstackclient/tests/unit/network/v2/test_floating_ip_pool_compute.py +1 -1
  170. openstackclient/tests/unit/network/v2/test_network_compute.py +11 -11
  171. openstackclient/tests/unit/network/v2/test_network_trunk.py +2 -2
  172. openstackclient/tests/unit/network/v2/test_port.py +33 -5
  173. openstackclient/tests/unit/network/v2/test_router.py +120 -7
  174. openstackclient/tests/unit/network/v2/test_security_group_compute.py +11 -19
  175. openstackclient/tests/unit/network/v2/test_security_group_rule_compute.py +14 -14
  176. openstackclient/tests/unit/object/v1/test_object_all.py +4 -3
  177. openstackclient/tests/unit/test_shell.py +16 -13
  178. openstackclient/tests/unit/volume/v2/test_volume.py +1 -1
  179. openstackclient/tests/unit/volume/v2/test_volume_transfer_request.py +1 -1
  180. openstackclient/tests/unit/volume/v3/fakes.py +2 -8
  181. openstackclient/tests/unit/volume/v3/test_volume.py +1 -1
  182. openstackclient/tests/unit/volume/v3/test_volume_attachment.py +3 -3
  183. openstackclient/tests/unit/volume/v3/test_volume_snapshot.py +1 -2
  184. openstackclient/tests/unit/volume/v3/test_volume_transfer_request.py +1 -1
  185. openstackclient/volume/client.py +1 -3
  186. openstackclient/volume/v2/consistency_group.py +4 -8
  187. openstackclient/volume/v2/consistency_group_snapshot.py +1 -2
  188. openstackclient/volume/v2/qos_specs.py +1 -2
  189. openstackclient/volume/v2/volume.py +8 -16
  190. openstackclient/volume/v2/volume_backup.py +6 -7
  191. openstackclient/volume/v2/volume_snapshot.py +8 -9
  192. openstackclient/volume/v2/volume_transfer_request.py +0 -3
  193. openstackclient/volume/v2/volume_type.py +10 -21
  194. openstackclient/volume/v3/block_storage_cluster.py +3 -3
  195. openstackclient/volume/v3/block_storage_manage.py +1 -3
  196. openstackclient/volume/v3/volume.py +18 -19
  197. openstackclient/volume/v3/volume_attachment.py +3 -2
  198. openstackclient/volume/v3/volume_backup.py +7 -8
  199. openstackclient/volume/v3/volume_group.py +2 -1
  200. openstackclient/volume/v3/volume_group_snapshot.py +2 -1
  201. openstackclient/volume/v3/volume_snapshot.py +4 -3
  202. openstackclient/volume/v3/volume_type.py +10 -21
  203. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/AUTHORS +4 -0
  204. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/METADATA +7 -13
  205. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/RECORD +210 -233
  206. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/WHEEL +1 -1
  207. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/entry_points.txt +0 -41
  208. python_openstackclient-8.0.0.dist-info/pbr.json +1 -0
  209. openstackclient/tests/functional/volume/v1/__init__.py +0 -0
  210. openstackclient/tests/functional/volume/v1/common.py +0 -35
  211. openstackclient/tests/functional/volume/v1/test_qos.py +0 -100
  212. openstackclient/tests/functional/volume/v1/test_service.py +0 -76
  213. openstackclient/tests/functional/volume/v1/test_snapshot.py +0 -232
  214. openstackclient/tests/functional/volume/v1/test_transfer_request.py +0 -111
  215. openstackclient/tests/functional/volume/v1/test_volume.py +0 -228
  216. openstackclient/tests/functional/volume/v1/test_volume_type.py +0 -213
  217. openstackclient/tests/unit/volume/v1/__init__.py +0 -0
  218. openstackclient/tests/unit/volume/v1/fakes.py +0 -615
  219. openstackclient/tests/unit/volume/v1/test_qos_specs.py +0 -471
  220. openstackclient/tests/unit/volume/v1/test_service.py +0 -295
  221. openstackclient/tests/unit/volume/v1/test_transfer_request.py +0 -380
  222. openstackclient/tests/unit/volume/v1/test_type.py +0 -633
  223. openstackclient/tests/unit/volume/v1/test_volume.py +0 -1447
  224. openstackclient/tests/unit/volume/v1/test_volume_backup.py +0 -435
  225. openstackclient/volume/v1/__init__.py +0 -0
  226. openstackclient/volume/v1/qos_specs.py +0 -377
  227. openstackclient/volume/v1/service.py +0 -136
  228. openstackclient/volume/v1/volume.py +0 -734
  229. openstackclient/volume/v1/volume_backup.py +0 -302
  230. openstackclient/volume/v1/volume_snapshot.py +0 -433
  231. openstackclient/volume/v1/volume_transfer_request.py +0 -200
  232. openstackclient/volume/v1/volume_type.py +0 -520
  233. python_openstackclient-7.3.1.dist-info/pbr.json +0 -1
  234. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/LICENSE +0 -0
  235. {python_openstackclient-7.3.1.dist-info → python_openstackclient-8.0.0.dist-info}/top_level.txt +0 -0
@@ -1,1447 +0,0 @@
1
- # Copyright 2013 Nebula Inc.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
- # not use this file except in compliance with the License. You may obtain
5
- # a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
- # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
- # License for the specific language governing permissions and limitations
13
- # under the License.
14
-
15
- from unittest import mock
16
- from unittest.mock import call
17
-
18
- from osc_lib.cli import format_columns
19
- from osc_lib import exceptions
20
- from osc_lib import utils
21
-
22
- from openstackclient.tests.unit.identity.v2_0 import fakes as identity_fakes
23
- from openstackclient.tests.unit.image.v1 import fakes as image_fakes
24
- from openstackclient.tests.unit import utils as test_utils
25
- from openstackclient.tests.unit.volume.v1 import fakes as volume_fakes
26
- from openstackclient.volume.v1 import volume
27
-
28
-
29
- class TestVolume(volume_fakes.TestVolumev1):
30
- def setUp(self):
31
- super().setUp()
32
-
33
- # Get a shortcut to the VolumeManager Mock
34
- self.volumes_mock = self.volume_client.volumes
35
- self.volumes_mock.reset_mock()
36
-
37
- # Get a shortcut to the TenantManager Mock
38
- self.projects_mock = self.identity_client.tenants
39
- self.projects_mock.reset_mock()
40
-
41
- # Get a shortcut to the UserManager Mock
42
- self.users_mock = self.identity_client.users
43
- self.users_mock.reset_mock()
44
-
45
- def setup_volumes_mock(self, count):
46
- volumes = volume_fakes.create_volumes(count=count)
47
-
48
- self.volumes_mock.get = volume_fakes.get_volumes(volumes, 0)
49
- return volumes
50
-
51
-
52
- class TestVolumeCreate(TestVolume):
53
- project = identity_fakes.FakeProject.create_one_project()
54
- user = identity_fakes.FakeUser.create_one_user()
55
-
56
- columns = (
57
- 'attachments',
58
- 'availability_zone',
59
- 'bootable',
60
- 'created_at',
61
- 'display_description',
62
- 'id',
63
- 'name',
64
- 'properties',
65
- 'size',
66
- 'snapshot_id',
67
- 'status',
68
- 'type',
69
- )
70
-
71
- def setUp(self):
72
- super().setUp()
73
- self.new_volume = volume_fakes.create_one_volume()
74
- self.datalist = (
75
- self.new_volume.attachments,
76
- self.new_volume.availability_zone,
77
- self.new_volume.bootable,
78
- self.new_volume.created_at,
79
- self.new_volume.display_description,
80
- self.new_volume.id,
81
- self.new_volume.display_name,
82
- format_columns.DictColumn(self.new_volume.metadata),
83
- self.new_volume.size,
84
- self.new_volume.snapshot_id,
85
- self.new_volume.status,
86
- self.new_volume.volume_type,
87
- )
88
- self.volumes_mock.create.return_value = self.new_volume
89
-
90
- # Get the command object to test
91
- self.cmd = volume.CreateVolume(self.app, None)
92
-
93
- def test_volume_create_min_options(self):
94
- arglist = [
95
- '--size',
96
- str(self.new_volume.size),
97
- self.new_volume.display_name,
98
- ]
99
- verifylist = [
100
- ('size', self.new_volume.size),
101
- ('name', self.new_volume.display_name),
102
- ]
103
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
104
-
105
- # In base command class ShowOne in cliff, abstract method take_action()
106
- # returns a two-part tuple with a tuple of column names and a tuple of
107
- # data to be shown.
108
- columns, data = self.cmd.take_action(parsed_args)
109
-
110
- # VolumeManager.create(size, snapshot_id=, source_volid=,
111
- # display_name=, display_description=,
112
- # volume_type=, user_id=,
113
- # project_id=, availability_zone=,
114
- # metadata=, imageRef=)
115
- self.volumes_mock.create.assert_called_with(
116
- self.new_volume.size,
117
- None,
118
- None,
119
- self.new_volume.display_name,
120
- None,
121
- None,
122
- None,
123
- None,
124
- None,
125
- None,
126
- None,
127
- )
128
- self.assertEqual(self.columns, columns)
129
- self.assertCountEqual(self.datalist, data)
130
-
131
- def test_volume_create_options(self):
132
- arglist = [
133
- '--size',
134
- str(self.new_volume.size),
135
- '--description',
136
- self.new_volume.display_description,
137
- '--type',
138
- self.new_volume.volume_type,
139
- '--availability-zone',
140
- self.new_volume.availability_zone,
141
- self.new_volume.display_name,
142
- ]
143
- verifylist = [
144
- ('size', self.new_volume.size),
145
- ('description', self.new_volume.display_description),
146
- ('type', self.new_volume.volume_type),
147
- ('availability_zone', self.new_volume.availability_zone),
148
- ('name', self.new_volume.display_name),
149
- ]
150
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
151
-
152
- # In base command class ShowOne in cliff, abstract method take_action()
153
- # returns a two-part tuple with a tuple of column names and a tuple of
154
- # data to be shown.
155
- columns, data = self.cmd.take_action(parsed_args)
156
-
157
- # VolumeManager.create(size, snapshot_id=, source_volid=,
158
- # display_name=, display_description=,
159
- # volume_type=, user_id=,
160
- # project_id=, availability_zone=,
161
- # metadata=, imageRef=)
162
- self.volumes_mock.create.assert_called_with(
163
- self.new_volume.size,
164
- None,
165
- None,
166
- self.new_volume.display_name,
167
- self.new_volume.display_description,
168
- self.new_volume.volume_type,
169
- None,
170
- None,
171
- self.new_volume.availability_zone,
172
- None,
173
- None,
174
- )
175
-
176
- self.assertEqual(self.columns, columns)
177
- self.assertCountEqual(self.datalist, data)
178
-
179
- def test_volume_create_user_project_id(self):
180
- # Return a project
181
- self.projects_mock.get.return_value = self.project
182
- # Return a user
183
- self.users_mock.get.return_value = self.user
184
-
185
- arglist = [
186
- '--size',
187
- str(self.new_volume.size),
188
- '--project',
189
- self.project.id,
190
- '--user',
191
- self.user.id,
192
- self.new_volume.display_name,
193
- ]
194
- verifylist = [
195
- ('size', self.new_volume.size),
196
- ('project', self.project.id),
197
- ('user', self.user.id),
198
- ('name', self.new_volume.display_name),
199
- ]
200
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
201
-
202
- # In base command class ShowOne in cliff, abstract method take_action()
203
- # returns a two-part tuple with a tuple of column names and a tuple of
204
- # data to be shown.
205
- columns, data = self.cmd.take_action(parsed_args)
206
-
207
- # VolumeManager.create(size, snapshot_id=, source_volid=,
208
- # display_name=, display_description=,
209
- # volume_type=, user_id=,
210
- # project_id=, availability_zone=,
211
- # metadata=, imageRef=)
212
- self.volumes_mock.create.assert_called_with(
213
- self.new_volume.size,
214
- None,
215
- None,
216
- self.new_volume.display_name,
217
- None,
218
- None,
219
- self.user.id,
220
- self.project.id,
221
- None,
222
- None,
223
- None,
224
- )
225
-
226
- self.assertEqual(self.columns, columns)
227
- self.assertCountEqual(self.datalist, data)
228
-
229
- def test_volume_create_user_project_name(self):
230
- # Return a project
231
- self.projects_mock.get.return_value = self.project
232
- # Return a user
233
- self.users_mock.get.return_value = self.user
234
-
235
- arglist = [
236
- '--size',
237
- str(self.new_volume.size),
238
- '--project',
239
- self.project.name,
240
- '--user',
241
- self.user.name,
242
- self.new_volume.display_name,
243
- ]
244
- verifylist = [
245
- ('size', self.new_volume.size),
246
- ('project', self.project.name),
247
- ('user', self.user.name),
248
- ('name', self.new_volume.display_name),
249
- ]
250
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
251
-
252
- # In base command class ShowOne in cliff, abstract method take_action()
253
- # returns a two-part tuple with a tuple of column names and a tuple of
254
- # data to be shown.
255
- columns, data = self.cmd.take_action(parsed_args)
256
-
257
- # VolumeManager.create(size, snapshot_id=, source_volid=,
258
- # display_name=, display_description=,
259
- # volume_type=, user_id=,
260
- # project_id=, availability_zone=,
261
- # metadata=, imageRef=)
262
- self.volumes_mock.create.assert_called_with(
263
- self.new_volume.size,
264
- None,
265
- None,
266
- self.new_volume.display_name,
267
- None,
268
- None,
269
- self.user.id,
270
- self.project.id,
271
- None,
272
- None,
273
- None,
274
- )
275
-
276
- self.assertEqual(self.columns, columns)
277
- self.assertCountEqual(self.datalist, data)
278
-
279
- def test_volume_create_properties(self):
280
- arglist = [
281
- '--property',
282
- 'Alpha=a',
283
- '--property',
284
- 'Beta=b',
285
- '--size',
286
- str(self.new_volume.size),
287
- self.new_volume.display_name,
288
- ]
289
- verifylist = [
290
- ('property', {'Alpha': 'a', 'Beta': 'b'}),
291
- ('size', self.new_volume.size),
292
- ('name', self.new_volume.display_name),
293
- ]
294
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
295
-
296
- # In base command class ShowOne in cliff, abstract method take_action()
297
- # returns a two-part tuple with a tuple of column names and a tuple of
298
- # data to be shown.
299
- columns, data = self.cmd.take_action(parsed_args)
300
-
301
- # VolumeManager.create(size, snapshot_id=, source_volid=,
302
- # display_name=, display_description=,
303
- # volume_type=, user_id=,
304
- # project_id=, availability_zone=,
305
- # metadata=, imageRef=)
306
- self.volumes_mock.create.assert_called_with(
307
- self.new_volume.size,
308
- None,
309
- None,
310
- self.new_volume.display_name,
311
- None,
312
- None,
313
- None,
314
- None,
315
- None,
316
- {'Alpha': 'a', 'Beta': 'b'},
317
- None,
318
- )
319
-
320
- self.assertEqual(self.columns, columns)
321
- self.assertCountEqual(self.datalist, data)
322
-
323
- def test_volume_create_image_id(self):
324
- image = image_fakes.create_one_image()
325
- self.image_client.find_image.return_value = image
326
-
327
- arglist = [
328
- '--image',
329
- image.id,
330
- '--size',
331
- str(self.new_volume.size),
332
- self.new_volume.display_name,
333
- ]
334
- verifylist = [
335
- ('image', image.id),
336
- ('size', self.new_volume.size),
337
- ('name', self.new_volume.display_name),
338
- ]
339
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
340
-
341
- # In base command class ShowOne in cliff, abstract method take_action()
342
- # returns a two-part tuple with a tuple of column names and a tuple of
343
- # data to be shown.
344
- columns, data = self.cmd.take_action(parsed_args)
345
-
346
- # VolumeManager.create(size, snapshot_id=, source_volid=,
347
- # display_name=, display_description=,
348
- # volume_type=, user_id=,
349
- # project_id=, availability_zone=,
350
- # metadata=, imageRef=)
351
- self.volumes_mock.create.assert_called_with(
352
- self.new_volume.size,
353
- None,
354
- None,
355
- self.new_volume.display_name,
356
- None,
357
- None,
358
- None,
359
- None,
360
- None,
361
- None,
362
- image.id,
363
- )
364
-
365
- self.assertEqual(self.columns, columns)
366
- self.assertCountEqual(self.datalist, data)
367
-
368
- def test_volume_create_image_name(self):
369
- image = image_fakes.create_one_image()
370
- self.image_client.find_image.return_value = image
371
-
372
- arglist = [
373
- '--image',
374
- image.name,
375
- '--size',
376
- str(self.new_volume.size),
377
- self.new_volume.display_name,
378
- ]
379
- verifylist = [
380
- ('image', image.name),
381
- ('size', self.new_volume.size),
382
- ('name', self.new_volume.display_name),
383
- ]
384
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
385
-
386
- # In base command class ShowOne in cliff, abstract method take_action()
387
- # returns a two-part tuple with a tuple of column names and a tuple of
388
- # data to be shown.
389
- columns, data = self.cmd.take_action(parsed_args)
390
-
391
- # VolumeManager.create(size, snapshot_id=, source_volid=,
392
- # display_name=, display_description=,
393
- # volume_type=, user_id=,
394
- # project_id=, availability_zone=,
395
- # metadata=, imageRef=)
396
- self.volumes_mock.create.assert_called_with(
397
- self.new_volume.size,
398
- None,
399
- None,
400
- self.new_volume.display_name,
401
- None,
402
- None,
403
- None,
404
- None,
405
- None,
406
- None,
407
- image.id,
408
- )
409
-
410
- self.assertEqual(self.columns, columns)
411
- self.assertCountEqual(self.datalist, data)
412
-
413
- def test_volume_create_with_source(self):
414
- self.volumes_mock.get.return_value = self.new_volume
415
- arglist = [
416
- '--source',
417
- self.new_volume.id,
418
- self.new_volume.display_name,
419
- ]
420
- verifylist = [
421
- ('source', self.new_volume.id),
422
- ('name', self.new_volume.display_name),
423
- ]
424
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
425
-
426
- columns, data = self.cmd.take_action(parsed_args)
427
-
428
- self.volumes_mock.create.assert_called_with(
429
- None,
430
- None,
431
- self.new_volume.id,
432
- self.new_volume.display_name,
433
- None,
434
- None,
435
- None,
436
- None,
437
- None,
438
- None,
439
- None,
440
- )
441
- self.assertEqual(self.columns, columns)
442
- self.assertCountEqual(self.datalist, data)
443
-
444
- @mock.patch.object(utils, 'wait_for_status', return_value=True)
445
- def test_volume_create_with_bootable_and_readonly(self, mock_wait):
446
- arglist = [
447
- '--bootable',
448
- '--read-only',
449
- '--size',
450
- str(self.new_volume.size),
451
- self.new_volume.display_name,
452
- ]
453
- verifylist = [
454
- ('bootable', True),
455
- ('non_bootable', False),
456
- ('read_only', True),
457
- ('read_write', False),
458
- ('size', self.new_volume.size),
459
- ('name', self.new_volume.display_name),
460
- ]
461
-
462
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
463
-
464
- columns, data = self.cmd.take_action(parsed_args)
465
-
466
- self.volumes_mock.create.assert_called_with(
467
- self.new_volume.size,
468
- None,
469
- None,
470
- self.new_volume.display_name,
471
- None,
472
- None,
473
- None,
474
- None,
475
- None,
476
- None,
477
- None,
478
- )
479
-
480
- self.assertEqual(self.columns, columns)
481
- self.assertCountEqual(self.datalist, data)
482
- self.volumes_mock.set_bootable.assert_called_with(
483
- self.new_volume.id, True
484
- )
485
- self.volumes_mock.update_readonly_flag.assert_called_with(
486
- self.new_volume.id, True
487
- )
488
-
489
- @mock.patch.object(utils, 'wait_for_status', return_value=True)
490
- def test_volume_create_with_nonbootable_and_readwrite(self, mock_wait):
491
- arglist = [
492
- '--non-bootable',
493
- '--read-write',
494
- '--size',
495
- str(self.new_volume.size),
496
- self.new_volume.display_name,
497
- ]
498
- verifylist = [
499
- ('bootable', False),
500
- ('non_bootable', True),
501
- ('read_only', False),
502
- ('read_write', True),
503
- ('size', self.new_volume.size),
504
- ('name', self.new_volume.display_name),
505
- ]
506
-
507
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
508
-
509
- columns, data = self.cmd.take_action(parsed_args)
510
-
511
- self.volumes_mock.create.assert_called_with(
512
- self.new_volume.size,
513
- None,
514
- None,
515
- self.new_volume.display_name,
516
- None,
517
- None,
518
- None,
519
- None,
520
- None,
521
- None,
522
- None,
523
- )
524
-
525
- self.assertEqual(self.columns, columns)
526
- self.assertCountEqual(self.datalist, data)
527
- self.volumes_mock.set_bootable.assert_called_with(
528
- self.new_volume.id, False
529
- )
530
- self.volumes_mock.update_readonly_flag.assert_called_with(
531
- self.new_volume.id, False
532
- )
533
-
534
- @mock.patch.object(volume.LOG, 'error')
535
- @mock.patch.object(utils, 'wait_for_status', return_value=True)
536
- def test_volume_create_with_bootable_and_readonly_fail(
537
- self, mock_wait, mock_error
538
- ):
539
- self.volumes_mock.set_bootable.side_effect = exceptions.CommandError()
540
-
541
- self.volumes_mock.update_readonly_flag.side_effect = (
542
- exceptions.CommandError()
543
- )
544
-
545
- arglist = [
546
- '--bootable',
547
- '--read-only',
548
- '--size',
549
- str(self.new_volume.size),
550
- self.new_volume.display_name,
551
- ]
552
- verifylist = [
553
- ('bootable', True),
554
- ('non_bootable', False),
555
- ('read_only', True),
556
- ('read_write', False),
557
- ('size', self.new_volume.size),
558
- ('name', self.new_volume.display_name),
559
- ]
560
-
561
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
562
-
563
- columns, data = self.cmd.take_action(parsed_args)
564
-
565
- self.volumes_mock.create.assert_called_with(
566
- self.new_volume.size,
567
- None,
568
- None,
569
- self.new_volume.display_name,
570
- None,
571
- None,
572
- None,
573
- None,
574
- None,
575
- None,
576
- None,
577
- )
578
-
579
- self.assertEqual(2, mock_error.call_count)
580
- self.assertEqual(self.columns, columns)
581
- self.assertCountEqual(self.datalist, data)
582
- self.volumes_mock.set_bootable.assert_called_with(
583
- self.new_volume.id, True
584
- )
585
- self.volumes_mock.update_readonly_flag.assert_called_with(
586
- self.new_volume.id, True
587
- )
588
-
589
- @mock.patch.object(volume.LOG, 'error')
590
- @mock.patch.object(utils, 'wait_for_status', return_value=False)
591
- def test_volume_create_non_available_with_readonly(
592
- self, mock_wait, mock_error
593
- ):
594
- arglist = [
595
- '--non-bootable',
596
- '--read-only',
597
- '--size',
598
- str(self.new_volume.size),
599
- self.new_volume.display_name,
600
- ]
601
- verifylist = [
602
- ('bootable', False),
603
- ('non_bootable', True),
604
- ('read_only', True),
605
- ('read_write', False),
606
- ('size', self.new_volume.size),
607
- ('name', self.new_volume.display_name),
608
- ]
609
-
610
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
611
-
612
- columns, data = self.cmd.take_action(parsed_args)
613
-
614
- self.volumes_mock.create.assert_called_with(
615
- self.new_volume.size,
616
- None,
617
- None,
618
- self.new_volume.display_name,
619
- None,
620
- None,
621
- None,
622
- None,
623
- None,
624
- None,
625
- None,
626
- )
627
-
628
- self.assertEqual(2, mock_error.call_count)
629
- self.assertEqual(self.columns, columns)
630
- self.assertCountEqual(self.datalist, data)
631
-
632
- def test_volume_create_without_size(self):
633
- arglist = [
634
- self.new_volume.display_name,
635
- ]
636
- verifylist = [
637
- ('name', self.new_volume.display_name),
638
- ]
639
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
640
-
641
- self.assertRaises(
642
- exceptions.CommandError, self.cmd.take_action, parsed_args
643
- )
644
-
645
- def test_volume_create_with_multi_source(self):
646
- arglist = [
647
- '--image',
648
- 'source_image',
649
- '--source',
650
- 'source_volume',
651
- '--snapshot',
652
- 'source_snapshot',
653
- '--size',
654
- str(self.new_volume.size),
655
- self.new_volume.display_name,
656
- ]
657
- verifylist = [
658
- ('image', 'source_image'),
659
- ('source', 'source_volume'),
660
- ('snapshot', 'source_snapshot'),
661
- ('size', self.new_volume.size),
662
- ('name', self.new_volume.display_name),
663
- ]
664
-
665
- self.assertRaises(
666
- test_utils.ParserException,
667
- self.check_parser,
668
- self.cmd,
669
- arglist,
670
- verifylist,
671
- )
672
-
673
- def test_volume_create_backward_compatibility(self):
674
- arglist = [
675
- '-c',
676
- 'display_name',
677
- '--size',
678
- str(self.new_volume.size),
679
- self.new_volume.display_name,
680
- ]
681
- verifylist = [
682
- ('columns', ['display_name']),
683
- ('size', self.new_volume.size),
684
- ('name', self.new_volume.display_name),
685
- ]
686
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
687
-
688
- columns, data = self.cmd.take_action(parsed_args)
689
-
690
- self.volumes_mock.create.assert_called_with(
691
- self.new_volume.size,
692
- None,
693
- None,
694
- self.new_volume.display_name,
695
- None,
696
- None,
697
- None,
698
- None,
699
- None,
700
- None,
701
- None,
702
- )
703
- self.assertIn('display_name', columns)
704
- self.assertNotIn('name', columns)
705
- self.assertIn(self.new_volume.display_name, data)
706
-
707
-
708
- class TestVolumeDelete(TestVolume):
709
- def setUp(self):
710
- super().setUp()
711
-
712
- self.volumes_mock.delete.return_value = None
713
-
714
- # Get the command object to mock
715
- self.cmd = volume.DeleteVolume(self.app, None)
716
-
717
- def test_volume_delete_one_volume(self):
718
- volumes = self.setup_volumes_mock(count=1)
719
-
720
- arglist = [volumes[0].id]
721
- verifylist = [
722
- ("force", False),
723
- ("volumes", [volumes[0].id]),
724
- ]
725
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
726
-
727
- result = self.cmd.take_action(parsed_args)
728
-
729
- self.volumes_mock.delete.assert_called_once_with(volumes[0].id)
730
- self.assertIsNone(result)
731
-
732
- def test_volume_delete_multi_volumes(self):
733
- volumes = self.setup_volumes_mock(count=3)
734
-
735
- arglist = [v.id for v in volumes]
736
- verifylist = [
737
- ('force', False),
738
- ('volumes', arglist),
739
- ]
740
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
741
-
742
- result = self.cmd.take_action(parsed_args)
743
-
744
- calls = [call(v.id) for v in volumes]
745
- self.volumes_mock.delete.assert_has_calls(calls)
746
- self.assertIsNone(result)
747
-
748
- def test_volume_delete_multi_volumes_with_exception(self):
749
- volumes = self.setup_volumes_mock(count=2)
750
-
751
- arglist = [
752
- volumes[0].id,
753
- 'unexist_volume',
754
- ]
755
- verifylist = [
756
- ('force', False),
757
- ('volumes', arglist),
758
- ]
759
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
760
-
761
- find_mock_result = [volumes[0], exceptions.CommandError]
762
- with mock.patch.object(
763
- utils, 'find_resource', side_effect=find_mock_result
764
- ) as find_mock:
765
- try:
766
- self.cmd.take_action(parsed_args)
767
- self.fail('CommandError should be raised.')
768
- except exceptions.CommandError as e:
769
- self.assertEqual('1 of 2 volumes failed to delete.', str(e))
770
-
771
- find_mock.assert_any_call(self.volumes_mock, volumes[0].id)
772
- find_mock.assert_any_call(self.volumes_mock, 'unexist_volume')
773
-
774
- self.assertEqual(2, find_mock.call_count)
775
- self.volumes_mock.delete.assert_called_once_with(volumes[0].id)
776
-
777
- def test_volume_delete_with_force(self):
778
- volumes = self.setup_volumes_mock(count=1)
779
-
780
- arglist = [
781
- '--force',
782
- volumes[0].id,
783
- ]
784
- verifylist = [
785
- ('force', True),
786
- ('volumes', [volumes[0].id]),
787
- ]
788
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
789
-
790
- result = self.cmd.take_action(parsed_args)
791
-
792
- self.volumes_mock.force_delete.assert_called_once_with(volumes[0].id)
793
- self.assertIsNone(result)
794
-
795
-
796
- class TestVolumeList(TestVolume):
797
- _volume = volume_fakes.create_one_volume()
798
- columns = (
799
- 'ID',
800
- 'Name',
801
- 'Status',
802
- 'Size',
803
- 'Attached to',
804
- )
805
- datalist = (
806
- (
807
- _volume.id,
808
- _volume.display_name,
809
- _volume.status,
810
- _volume.size,
811
- volume.AttachmentsColumn(_volume.attachments),
812
- ),
813
- )
814
-
815
- def setUp(self):
816
- super().setUp()
817
-
818
- self.volumes_mock.list.return_value = [self._volume]
819
-
820
- # Get the command object to test
821
- self.cmd = volume.ListVolume(self.app, None)
822
-
823
- def test_volume_list_no_options(self):
824
- arglist = []
825
- verifylist = [
826
- ('long', False),
827
- ('all_projects', False),
828
- ('name', None),
829
- ('status', None),
830
- ('limit', None),
831
- ]
832
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
833
-
834
- columns, data = self.cmd.take_action(parsed_args)
835
-
836
- self.assertEqual(self.columns, columns)
837
- self.assertCountEqual(self.datalist, tuple(data))
838
-
839
- def test_volume_list_name(self):
840
- arglist = [
841
- '--name',
842
- self._volume.display_name,
843
- ]
844
- verifylist = [
845
- ('long', False),
846
- ('all_projects', False),
847
- ('name', self._volume.display_name),
848
- ('status', None),
849
- ('limit', None),
850
- ]
851
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
852
-
853
- columns, data = self.cmd.take_action(parsed_args)
854
- self.assertEqual(self.columns, tuple(columns))
855
- self.assertCountEqual(self.datalist, tuple(data))
856
-
857
- def test_volume_list_status(self):
858
- arglist = [
859
- '--status',
860
- self._volume.status,
861
- ]
862
- verifylist = [
863
- ('long', False),
864
- ('all_projects', False),
865
- ('name', None),
866
- ('status', self._volume.status),
867
- ('limit', None),
868
- ]
869
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
870
-
871
- columns, data = self.cmd.take_action(parsed_args)
872
- self.assertEqual(self.columns, tuple(columns))
873
- self.assertCountEqual(self.datalist, tuple(data))
874
-
875
- def test_volume_list_all_projects(self):
876
- arglist = [
877
- '--all-projects',
878
- ]
879
- verifylist = [
880
- ('long', False),
881
- ('all_projects', True),
882
- ('name', None),
883
- ('status', None),
884
- ('limit', None),
885
- ]
886
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
887
-
888
- columns, data = self.cmd.take_action(parsed_args)
889
- self.assertEqual(self.columns, tuple(columns))
890
- self.assertCountEqual(self.datalist, tuple(data))
891
-
892
- def test_volume_list_long(self):
893
- arglist = [
894
- '--long',
895
- ]
896
- verifylist = [
897
- ('long', True),
898
- ('all_projects', False),
899
- ('name', None),
900
- ('status', None),
901
- ('limit', None),
902
- ]
903
-
904
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
905
-
906
- columns, data = self.cmd.take_action(parsed_args)
907
-
908
- collist = (
909
- 'ID',
910
- 'Name',
911
- 'Status',
912
- 'Size',
913
- 'Type',
914
- 'Bootable',
915
- 'Attached to',
916
- 'Properties',
917
- )
918
- self.assertEqual(collist, columns)
919
-
920
- datalist = (
921
- (
922
- self._volume.id,
923
- self._volume.display_name,
924
- self._volume.status,
925
- self._volume.size,
926
- self._volume.volume_type,
927
- self._volume.bootable,
928
- volume.AttachmentsColumn(self._volume.attachments),
929
- format_columns.DictColumn(self._volume.metadata),
930
- ),
931
- )
932
- self.assertCountEqual(datalist, tuple(data))
933
-
934
- def test_volume_list_with_limit_and_offset(self):
935
- arglist = [
936
- '--limit',
937
- '2',
938
- '--offset',
939
- '5',
940
- ]
941
- verifylist = [
942
- ('long', False),
943
- ('all_projects', False),
944
- ('name', None),
945
- ('status', None),
946
- ('limit', 2),
947
- ('offset', 5),
948
- ]
949
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
950
-
951
- columns, data = self.cmd.take_action(parsed_args)
952
-
953
- self.volumes_mock.list.assert_called_once_with(
954
- limit=2,
955
- search_opts={
956
- 'offset': 5,
957
- 'status': None,
958
- 'display_name': None,
959
- 'all_tenants': False,
960
- },
961
- )
962
- self.assertEqual(self.columns, columns)
963
- self.assertCountEqual(self.datalist, tuple(data))
964
-
965
- def test_volume_list_negative_limit(self):
966
- arglist = [
967
- "--limit",
968
- "-2",
969
- ]
970
- verifylist = [
971
- ("limit", -2),
972
- ]
973
- self.assertRaises(
974
- test_utils.ParserException,
975
- self.check_parser,
976
- self.cmd,
977
- arglist,
978
- verifylist,
979
- )
980
-
981
- def test_volume_list_backward_compatibility(self):
982
- arglist = [
983
- '-c',
984
- 'Display Name',
985
- ]
986
- verifylist = [
987
- ('columns', ['Display Name']),
988
- ('long', False),
989
- ('all_projects', False),
990
- ('name', None),
991
- ('status', None),
992
- ('limit', None),
993
- ]
994
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
995
-
996
- columns, data = self.cmd.take_action(parsed_args)
997
-
998
- self.assertIn('Display Name', columns)
999
- self.assertNotIn('Name', columns)
1000
- for each_volume in data:
1001
- self.assertIn(self._volume.display_name, each_volume)
1002
-
1003
-
1004
- class TestVolumeMigrate(TestVolume):
1005
- _volume = volume_fakes.create_one_volume()
1006
-
1007
- def setUp(self):
1008
- super().setUp()
1009
-
1010
- self.volumes_mock.get.return_value = self._volume
1011
- self.volumes_mock.migrate_volume.return_value = None
1012
- # Get the command object to test
1013
- self.cmd = volume.MigrateVolume(self.app, None)
1014
-
1015
- def test_volume_migrate(self):
1016
- arglist = [
1017
- "--host",
1018
- "host@backend-name#pool",
1019
- self._volume.id,
1020
- ]
1021
- verifylist = [
1022
- ("force_host_copy", False),
1023
- ("host", "host@backend-name#pool"),
1024
- ("volume", self._volume.id),
1025
- ]
1026
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1027
-
1028
- result = self.cmd.take_action(parsed_args)
1029
- self.volumes_mock.get.assert_called_once_with(self._volume.id)
1030
- self.volumes_mock.migrate_volume.assert_called_once_with(
1031
- self._volume.id, "host@backend-name#pool", False
1032
- )
1033
- self.assertIsNone(result)
1034
-
1035
- def test_volume_migrate_with_option(self):
1036
- arglist = [
1037
- "--force-host-copy",
1038
- "--host",
1039
- "host@backend-name#pool",
1040
- self._volume.id,
1041
- ]
1042
- verifylist = [
1043
- ("force_host_copy", True),
1044
- ("host", "host@backend-name#pool"),
1045
- ("volume", self._volume.id),
1046
- ]
1047
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1048
-
1049
- result = self.cmd.take_action(parsed_args)
1050
- self.volumes_mock.get.assert_called_once_with(self._volume.id)
1051
- self.volumes_mock.migrate_volume.assert_called_once_with(
1052
- self._volume.id, "host@backend-name#pool", True
1053
- )
1054
- self.assertIsNone(result)
1055
-
1056
- def test_volume_migrate_without_host(self):
1057
- arglist = [
1058
- self._volume.id,
1059
- ]
1060
- verifylist = [
1061
- ("force_host_copy", False),
1062
- ("volume", self._volume.id),
1063
- ]
1064
-
1065
- self.assertRaises(
1066
- test_utils.ParserException,
1067
- self.check_parser,
1068
- self.cmd,
1069
- arglist,
1070
- verifylist,
1071
- )
1072
-
1073
-
1074
- class TestVolumeSet(TestVolume):
1075
- _volume = volume_fakes.create_one_volume()
1076
-
1077
- def setUp(self):
1078
- super().setUp()
1079
-
1080
- self.volumes_mock.get.return_value = self._volume
1081
-
1082
- self.volumes_mock.update.return_value = self._volume
1083
- # Get the command object to test
1084
- self.cmd = volume.SetVolume(self.app, None)
1085
-
1086
- def test_volume_set_no_options(self):
1087
- arglist = [
1088
- self._volume.display_name,
1089
- ]
1090
- verifylist = [
1091
- ('name', None),
1092
- ('description', None),
1093
- ('size', None),
1094
- ('property', None),
1095
- ('volume', self._volume.display_name),
1096
- ]
1097
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1098
-
1099
- result = self.cmd.take_action(parsed_args)
1100
- self.assertIsNone(result)
1101
-
1102
- def test_volume_set_name(self):
1103
- arglist = [
1104
- '--name',
1105
- 'qwerty',
1106
- self._volume.display_name,
1107
- ]
1108
- verifylist = [
1109
- ('name', 'qwerty'),
1110
- ('description', None),
1111
- ('size', None),
1112
- ('property', None),
1113
- ('volume', self._volume.display_name),
1114
- ]
1115
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1116
-
1117
- result = self.cmd.take_action(parsed_args)
1118
-
1119
- # Set expected values
1120
- kwargs = {
1121
- 'display_name': 'qwerty',
1122
- }
1123
- self.volumes_mock.update.assert_called_with(self._volume.id, **kwargs)
1124
- self.assertIsNone(result)
1125
-
1126
- def test_volume_set_description(self):
1127
- arglist = [
1128
- '--description',
1129
- 'new desc',
1130
- self._volume.display_name,
1131
- ]
1132
- verifylist = [
1133
- ('name', None),
1134
- ('description', 'new desc'),
1135
- ('size', None),
1136
- ('property', None),
1137
- ('volume', self._volume.display_name),
1138
- ]
1139
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1140
-
1141
- result = self.cmd.take_action(parsed_args)
1142
-
1143
- # Set expected values
1144
- kwargs = {
1145
- 'display_description': 'new desc',
1146
- }
1147
- self.volumes_mock.update.assert_called_with(self._volume.id, **kwargs)
1148
- self.assertIsNone(result)
1149
-
1150
- def test_volume_set_size(self):
1151
- arglist = [
1152
- '--size',
1153
- '130',
1154
- self._volume.display_name,
1155
- ]
1156
- verifylist = [
1157
- ('name', None),
1158
- ('description', None),
1159
- ('size', 130),
1160
- ('property', None),
1161
- ('volume', self._volume.display_name),
1162
- ]
1163
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1164
-
1165
- result = self.cmd.take_action(parsed_args)
1166
-
1167
- # Set expected values
1168
- size = 130
1169
- self.volumes_mock.extend.assert_called_with(self._volume.id, size)
1170
- self.assertIsNone(result)
1171
-
1172
- def test_volume_set_size_smaller(self):
1173
- self._volume.status = 'available'
1174
- arglist = [
1175
- '--size',
1176
- '1',
1177
- self._volume.display_name,
1178
- ]
1179
- verifylist = [
1180
- ('name', None),
1181
- ('description', None),
1182
- ('size', 1),
1183
- ('property', None),
1184
- ('volume', self._volume.display_name),
1185
- ]
1186
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1187
-
1188
- self.assertRaises(
1189
- exceptions.CommandError, self.cmd.take_action, parsed_args
1190
- )
1191
-
1192
- def test_volume_set_size_not_available(self):
1193
- self._volume.status = 'error'
1194
- arglist = [
1195
- '--size',
1196
- '130',
1197
- self._volume.display_name,
1198
- ]
1199
- verifylist = [
1200
- ('name', None),
1201
- ('description', None),
1202
- ('size', 130),
1203
- ('property', None),
1204
- ('volume', self._volume.display_name),
1205
- ]
1206
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1207
-
1208
- self.assertRaises(
1209
- exceptions.CommandError, self.cmd.take_action, parsed_args
1210
- )
1211
-
1212
- def test_volume_set_property(self):
1213
- arglist = [
1214
- '--no-property',
1215
- '--property',
1216
- 'myprop=myvalue',
1217
- self._volume.display_name,
1218
- ]
1219
- verifylist = [
1220
- ('read_only', False),
1221
- ('read_write', False),
1222
- ('name', None),
1223
- ('description', None),
1224
- ('size', None),
1225
- ('no_property', True),
1226
- ('property', {'myprop': 'myvalue'}),
1227
- ('volume', self._volume.display_name),
1228
- ('bootable', False),
1229
- ('non_bootable', False),
1230
- ]
1231
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1232
-
1233
- result = self.cmd.take_action(parsed_args)
1234
-
1235
- # Set expected values
1236
- metadata = {'myprop': 'myvalue'}
1237
- self.volumes_mock.set_metadata.assert_called_with(
1238
- self._volume.id, metadata
1239
- )
1240
- self.volumes_mock.delete_metadata.assert_called_with(
1241
- self._volume.id, self._volume.metadata.keys()
1242
- )
1243
- self.volumes_mock.update_readonly_flag.assert_not_called()
1244
- self.assertIsNone(result)
1245
-
1246
- def test_volume_set_bootable(self):
1247
- arglist = [
1248
- ['--bootable', self._volume.id],
1249
- ['--non-bootable', self._volume.id],
1250
- ]
1251
- verifylist = [
1252
- [
1253
- ('bootable', True),
1254
- ('non_bootable', False),
1255
- ('volume', self._volume.id),
1256
- ],
1257
- [
1258
- ('bootable', False),
1259
- ('non_bootable', True),
1260
- ('volume', self._volume.id),
1261
- ],
1262
- ]
1263
- for index in range(len(arglist)):
1264
- parsed_args = self.check_parser(
1265
- self.cmd, arglist[index], verifylist[index]
1266
- )
1267
-
1268
- self.cmd.take_action(parsed_args)
1269
- self.volumes_mock.set_bootable.assert_called_with(
1270
- self._volume.id, verifylist[index][0][1]
1271
- )
1272
-
1273
- def test_volume_set_readonly(self):
1274
- arglist = ['--read-only', self._volume.id]
1275
- verifylist = [
1276
- ('read_only', True),
1277
- ('read_write', False),
1278
- ('volume', self._volume.id),
1279
- ]
1280
-
1281
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1282
-
1283
- result = self.cmd.take_action(parsed_args)
1284
- self.volumes_mock.update_readonly_flag.assert_called_once_with(
1285
- self._volume.id, True
1286
- )
1287
- self.assertIsNone(result)
1288
-
1289
- def test_volume_set_read_write(self):
1290
- arglist = ['--read-write', self._volume.id]
1291
- verifylist = [
1292
- ('read_only', False),
1293
- ('read_write', True),
1294
- ('volume', self._volume.id),
1295
- ]
1296
-
1297
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1298
-
1299
- result = self.cmd.take_action(parsed_args)
1300
- self.volumes_mock.update_readonly_flag.assert_called_once_with(
1301
- self._volume.id, False
1302
- )
1303
- self.assertIsNone(result)
1304
-
1305
-
1306
- class TestVolumeShow(TestVolume):
1307
- columns = (
1308
- 'attachments',
1309
- 'availability_zone',
1310
- 'bootable',
1311
- 'created_at',
1312
- 'display_description',
1313
- 'id',
1314
- 'name',
1315
- 'properties',
1316
- 'size',
1317
- 'snapshot_id',
1318
- 'status',
1319
- 'type',
1320
- )
1321
-
1322
- def setUp(self):
1323
- super().setUp()
1324
- self._volume = volume_fakes.create_one_volume()
1325
- self.datalist = (
1326
- self._volume.attachments,
1327
- self._volume.availability_zone,
1328
- self._volume.bootable,
1329
- self._volume.created_at,
1330
- self._volume.display_description,
1331
- self._volume.id,
1332
- self._volume.display_name,
1333
- format_columns.DictColumn(self._volume.metadata),
1334
- self._volume.size,
1335
- self._volume.snapshot_id,
1336
- self._volume.status,
1337
- self._volume.volume_type,
1338
- )
1339
- self.volumes_mock.get.return_value = self._volume
1340
- # Get the command object to test
1341
- self.cmd = volume.ShowVolume(self.app, None)
1342
-
1343
- def test_volume_show(self):
1344
- arglist = [self._volume.id]
1345
- verifylist = [("volume", self._volume.id)]
1346
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1347
-
1348
- columns, data = self.cmd.take_action(parsed_args)
1349
- self.volumes_mock.get.assert_called_with(self._volume.id)
1350
-
1351
- self.assertEqual(self.columns, columns)
1352
- self.assertCountEqual(self.datalist, data)
1353
-
1354
- def test_volume_show_backward_compatibility(self):
1355
- arglist = [
1356
- '-c',
1357
- 'display_name',
1358
- self._volume.id,
1359
- ]
1360
- verifylist = [
1361
- ('columns', ['display_name']),
1362
- ('volume', self._volume.id),
1363
- ]
1364
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1365
-
1366
- columns, data = self.cmd.take_action(parsed_args)
1367
-
1368
- self.volumes_mock.get.assert_called_with(self._volume.id)
1369
-
1370
- self.assertIn('display_name', columns)
1371
- self.assertNotIn('name', columns)
1372
- self.assertIn(self._volume.display_name, data)
1373
-
1374
-
1375
- class TestVolumeUnset(TestVolume):
1376
- _volume = volume_fakes.create_one_volume()
1377
-
1378
- def setUp(self):
1379
- super().setUp()
1380
-
1381
- self.volumes_mock.get.return_value = self._volume
1382
-
1383
- self.volumes_mock.delete_metadata.return_value = None
1384
- # Get the command object to test
1385
- self.cmd = volume.UnsetVolume(self.app, None)
1386
-
1387
- def test_volume_unset_no_options(self):
1388
- arglist = [
1389
- self._volume.display_name,
1390
- ]
1391
- verifylist = [
1392
- ('property', None),
1393
- ('volume', self._volume.display_name),
1394
- ]
1395
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1396
-
1397
- result = self.cmd.take_action(parsed_args)
1398
- self.assertIsNone(result)
1399
-
1400
- def test_volume_unset_property(self):
1401
- arglist = [
1402
- '--property',
1403
- 'myprop',
1404
- self._volume.display_name,
1405
- ]
1406
- verifylist = [
1407
- ('property', ['myprop']),
1408
- ('volume', self._volume.display_name),
1409
- ]
1410
- parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1411
-
1412
- result = self.cmd.take_action(parsed_args)
1413
-
1414
- self.volumes_mock.delete_metadata.assert_called_with(
1415
- self._volume.id, ['myprop']
1416
- )
1417
- self.assertIsNone(result)
1418
-
1419
-
1420
- class TestColumns(TestVolume):
1421
- def test_attachments_column_without_server_cache(self):
1422
- _volume = volume_fakes.create_one_volume()
1423
- server_id = _volume.attachments[0]['server_id']
1424
- device = _volume.attachments[0]['device']
1425
-
1426
- col = volume.AttachmentsColumn(_volume.attachments, {})
1427
- self.assertEqual(
1428
- f'Attached to {server_id} on {device} ',
1429
- col.human_readable(),
1430
- )
1431
- self.assertEqual(_volume.attachments, col.machine_readable())
1432
-
1433
- def test_attachments_column_with_server_cache(self):
1434
- _volume = volume_fakes.create_one_volume()
1435
-
1436
- server_id = _volume.attachments[0]['server_id']
1437
- device = _volume.attachments[0]['device']
1438
- fake_server = mock.Mock()
1439
- fake_server.name = 'fake-server-name'
1440
- server_cache = {server_id: fake_server}
1441
-
1442
- col = volume.AttachmentsColumn(_volume.attachments, server_cache)
1443
- self.assertEqual(
1444
- 'Attached to {} on {} '.format('fake-server-name', device),
1445
- col.human_readable(),
1446
- )
1447
- self.assertEqual(_volume.attachments, col.machine_readable())