|
| 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 | +import time |
| 14 | +import uuid |
| 15 | + |
| 16 | +from openstackclient.tests.functional.volume.v1 import common |
| 17 | + |
| 18 | + |
| 19 | +class SnapshotTests(common.BaseVolumeTests): |
| 20 | + """Functional tests for snapshot. """ |
| 21 | + |
| 22 | + VOLLY = uuid.uuid4().hex |
| 23 | + NAME = uuid.uuid4().hex |
| 24 | + OTHER_NAME = uuid.uuid4().hex |
| 25 | + HEADERS = ['"Name"'] |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def wait_for_status(cls, command, status, tries): |
| 29 | + opts = cls.get_opts(['status']) |
| 30 | + for attempt in range(tries): |
| 31 | + time.sleep(1) |
| 32 | + raw_output = cls.openstack(command + opts) |
| 33 | + if (raw_output == status): |
| 34 | + return |
| 35 | + cls.assertOutput(status, raw_output) |
| 36 | + |
| 37 | + @classmethod |
| 38 | + def setUpClass(cls): |
| 39 | + super(SnapshotTests, cls).setUpClass() |
| 40 | + cls.openstack('volume create --size 1 ' + cls.VOLLY) |
| 41 | + cls.wait_for_status('volume show ' + cls.VOLLY, 'available\n', 3) |
| 42 | + opts = cls.get_opts(['status']) |
| 43 | + raw_output = cls.openstack('snapshot create --name ' + cls.NAME + |
| 44 | + ' ' + cls.VOLLY + opts) |
| 45 | + cls.assertOutput('creating\n', raw_output) |
| 46 | + cls.wait_for_status('snapshot show ' + cls.NAME, 'available\n', 3) |
| 47 | + |
| 48 | + @classmethod |
| 49 | + def tearDownClass(cls): |
| 50 | + # Rename test |
| 51 | + raw_output = cls.openstack( |
| 52 | + 'snapshot set --name ' + cls.OTHER_NAME + ' ' + cls.NAME) |
| 53 | + cls.assertOutput('', raw_output) |
| 54 | + # Delete test |
| 55 | + raw_output_snapshot = cls.openstack( |
| 56 | + 'snapshot delete ' + cls.OTHER_NAME) |
| 57 | + cls.wait_for_status('volume show ' + cls.VOLLY, 'available\n', 6) |
| 58 | + raw_output_volume = cls.openstack('volume delete --force ' + cls.VOLLY) |
| 59 | + cls.assertOutput('', raw_output_snapshot) |
| 60 | + cls.assertOutput('', raw_output_volume) |
| 61 | + |
| 62 | + def test_snapshot_list(self): |
| 63 | + opts = self.get_opts(self.HEADERS) |
| 64 | + raw_output = self.openstack('snapshot list' + opts) |
| 65 | + self.assertIn(self.NAME, raw_output) |
| 66 | + |
| 67 | + def test_snapshot_set_unset_properties(self): |
| 68 | + raw_output = self.openstack( |
| 69 | + 'snapshot set --property a=b --property c=d ' + self.NAME) |
| 70 | + self.assertEqual("", raw_output) |
| 71 | + opts = self.get_opts(["properties"]) |
| 72 | + raw_output = self.openstack('snapshot show ' + self.NAME + opts) |
| 73 | + self.assertEqual("a='b', c='d'\n", raw_output) |
| 74 | + |
| 75 | + raw_output = self.openstack('snapshot unset --property a ' + self.NAME) |
| 76 | + self.assertEqual("", raw_output) |
| 77 | + raw_output = self.openstack('snapshot show ' + self.NAME + opts) |
| 78 | + self.assertEqual("c='d'\n", raw_output) |
| 79 | + |
| 80 | + def test_snapshot_set_description(self): |
| 81 | + raw_output = self.openstack( |
| 82 | + 'snapshot set --description backup ' + self.NAME) |
| 83 | + self.assertEqual("", raw_output) |
| 84 | + opts = self.get_opts(["display_description", "display_name"]) |
| 85 | + raw_output = self.openstack('snapshot show ' + self.NAME + opts) |
| 86 | + self.assertEqual("backup\n" + self.NAME + "\n", raw_output) |
0 commit comments