|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +from typing import ClassVar |
| 14 | +import uuid |
| 15 | + |
| 16 | +from openstackclient.tests.functional.volume.v3 import common |
| 17 | + |
| 18 | + |
| 19 | +class VolumeGroupTests(common.BaseVolumeTests): |
| 20 | + """Functional tests for volume group.""" |
| 21 | + |
| 22 | + API_VERSION = '3.13' |
| 23 | + GROUP_TYPE_NAME = uuid.uuid4().hex |
| 24 | + GROUP_TYPE_ID: ClassVar[str] |
| 25 | + VOLUME_TYPE_ID: ClassVar[str] |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def setUpClass(cls): |
| 29 | + super().setUpClass() |
| 30 | + cmd_output = cls.openstack( |
| 31 | + '--os-volume-api-version ' |
| 32 | + + cls.API_VERSION |
| 33 | + + ' volume group type create ' |
| 34 | + + cls.GROUP_TYPE_NAME, |
| 35 | + parse_output=True, |
| 36 | + ) |
| 37 | + cls.GROUP_TYPE_ID = cmd_output['ID'] |
| 38 | + |
| 39 | + volume_type_name = uuid.uuid4().hex |
| 40 | + cmd_output = cls.openstack( |
| 41 | + 'volume type create ' + volume_type_name, |
| 42 | + parse_output=True, |
| 43 | + ) |
| 44 | + cls.VOLUME_TYPE_ID = cmd_output['id'] |
| 45 | + |
| 46 | + @classmethod |
| 47 | + def tearDownClass(cls): |
| 48 | + try: |
| 49 | + raw_output = cls.openstack( |
| 50 | + 'volume type delete ' + cls.VOLUME_TYPE_ID |
| 51 | + ) |
| 52 | + cls.assertOutput('', raw_output) |
| 53 | + raw_output = cls.openstack( |
| 54 | + '--os-volume-api-version ' |
| 55 | + + cls.API_VERSION |
| 56 | + + ' volume group type delete ' |
| 57 | + + cls.GROUP_TYPE_NAME |
| 58 | + ) |
| 59 | + cls.assertOutput('', raw_output) |
| 60 | + finally: |
| 61 | + super().tearDownClass() |
| 62 | + |
| 63 | + def test_volume_group(self): |
| 64 | + # create volume group |
| 65 | + name = uuid.uuid4().hex |
| 66 | + description = 'description-' + uuid.uuid4().hex |
| 67 | + cmd_output = self.openstack( |
| 68 | + '--os-volume-api-version ' |
| 69 | + + self.API_VERSION |
| 70 | + + ' volume group create ' |
| 71 | + + '--volume-group-type ' |
| 72 | + + self.GROUP_TYPE_NAME |
| 73 | + + ' --volume-type ' |
| 74 | + + self.VOLUME_TYPE_ID |
| 75 | + + ' --name ' |
| 76 | + + name |
| 77 | + + ' --description ' |
| 78 | + + description, |
| 79 | + parse_output=True, |
| 80 | + ) |
| 81 | + group_id = cmd_output['ID'] |
| 82 | + self.addCleanup( |
| 83 | + self.wait_for_delete, |
| 84 | + '--os-volume-api-version ' + self.API_VERSION + ' volume group', |
| 85 | + group_id, |
| 86 | + name_field='ID', |
| 87 | + ) |
| 88 | + self.addCleanup( |
| 89 | + self.openstack, |
| 90 | + '--os-volume-api-version ' |
| 91 | + + self.API_VERSION |
| 92 | + + ' volume group delete ' |
| 93 | + + group_id, |
| 94 | + fail_ok=True, |
| 95 | + ) |
| 96 | + self.assertIsNotNone(group_id) |
| 97 | + self.assertEqual(name, cmd_output['Name']) |
| 98 | + self.assertEqual(description, cmd_output['Description']) |
| 99 | + self.assertEqual(self.GROUP_TYPE_ID, cmd_output['Group Type']) |
| 100 | + self.assertIn(self.VOLUME_TYPE_ID, cmd_output['Volume Types']) |
| 101 | + |
| 102 | + # show volume group |
| 103 | + cmd_output = self.openstack( |
| 104 | + '--os-volume-api-version ' |
| 105 | + + self.API_VERSION |
| 106 | + + ' volume group show ' |
| 107 | + + group_id, |
| 108 | + parse_output=True, |
| 109 | + ) |
| 110 | + self.assertEqual(group_id, cmd_output['ID']) |
| 111 | + self.assertEqual(name, cmd_output['Name']) |
| 112 | + self.assertEqual(description, cmd_output['Description']) |
| 113 | + |
| 114 | + # list volume group |
| 115 | + cmd_output = self.openstack( |
| 116 | + '--os-volume-api-version ' |
| 117 | + + self.API_VERSION |
| 118 | + + ' volume group list', |
| 119 | + parse_output=True, |
| 120 | + ) |
| 121 | + self.assertIn(group_id, [group['ID'] for group in cmd_output]) |
| 122 | + self.assertIn(name, [group['Name'] for group in cmd_output]) |
| 123 | + |
| 124 | + # set volume group |
| 125 | + new_name = uuid.uuid4().hex |
| 126 | + new_description = 'description-' + uuid.uuid4().hex |
| 127 | + self.openstack( |
| 128 | + '--os-volume-api-version ' |
| 129 | + + self.API_VERSION |
| 130 | + + ' volume group set ' |
| 131 | + + '--name ' |
| 132 | + + new_name |
| 133 | + + ' --description ' |
| 134 | + + new_description |
| 135 | + + ' ' |
| 136 | + + group_id, |
| 137 | + ) |
| 138 | + |
| 139 | + # show updated volume group |
| 140 | + cmd_output = self.openstack( |
| 141 | + '--os-volume-api-version ' |
| 142 | + + self.API_VERSION |
| 143 | + + ' volume group show ' |
| 144 | + + group_id, |
| 145 | + parse_output=True, |
| 146 | + ) |
| 147 | + self.assertEqual(group_id, cmd_output['ID']) |
| 148 | + self.assertEqual(new_name, cmd_output['Name']) |
| 149 | + self.assertEqual(new_description, cmd_output['Description']) |
| 150 | + |
| 151 | + # delete volume group |
| 152 | + raw_output = self.openstack( |
| 153 | + '--os-volume-api-version ' |
| 154 | + + self.API_VERSION |
| 155 | + + ' volume group delete ' |
| 156 | + + group_id, |
| 157 | + ) |
| 158 | + self.assertOutput('', raw_output) |
| 159 | + self.wait_for_delete( |
| 160 | + '--os-volume-api-version ' + self.API_VERSION + ' volume group', |
| 161 | + group_id, |
| 162 | + name_field='ID', |
| 163 | + ) |
0 commit comments