|
| 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 os |
| 14 | +import uuid |
| 15 | + |
| 16 | +from functional.common import test |
| 17 | + |
| 18 | + |
| 19 | +class VolumeTests(test.TestCase): |
| 20 | + """Functional tests for volume. """ |
| 21 | + |
| 22 | + NAME = uuid.uuid4().hex |
| 23 | + OTHER_NAME = uuid.uuid4().hex |
| 24 | + HEADERS = ['"Display Name"'] |
| 25 | + FIELDS = ['name'] |
| 26 | + |
| 27 | + @classmethod |
| 28 | + def setUpClass(cls): |
| 29 | + os.environ['OS_VOLUME_API_VERSION'] = '2' |
| 30 | + opts = cls.get_show_opts(cls.FIELDS) |
| 31 | + raw_output = cls.openstack('volume create --size 1 ' + cls.NAME + opts) |
| 32 | + expected = cls.NAME + '\n' |
| 33 | + cls.assertOutput(expected, raw_output) |
| 34 | + |
| 35 | + @classmethod |
| 36 | + def tearDownClass(cls): |
| 37 | + # Rename test |
| 38 | + raw_output = cls.openstack( |
| 39 | + 'volume set --name ' + cls.OTHER_NAME + ' ' + cls.NAME) |
| 40 | + cls.assertOutput('', raw_output) |
| 41 | + # Delete test |
| 42 | + raw_output = cls.openstack('volume delete ' + cls.OTHER_NAME) |
| 43 | + cls.assertOutput('', raw_output) |
| 44 | + |
| 45 | + def test_volume_list(self): |
| 46 | + opts = self.get_list_opts(self.HEADERS) |
| 47 | + raw_output = self.openstack('volume list' + opts) |
| 48 | + self.assertIn(self.NAME, raw_output) |
| 49 | + |
| 50 | + def test_volume_show(self): |
| 51 | + opts = self.get_show_opts(self.FIELDS) |
| 52 | + raw_output = self.openstack('volume show ' + self.NAME + opts) |
| 53 | + self.assertEqual(self.NAME + "\n", raw_output) |
| 54 | + |
| 55 | + def test_volume_properties(self): |
| 56 | + raw_output = self.openstack( |
| 57 | + 'volume set --property a=b --property c=d ' + self.NAME) |
| 58 | + self.assertEqual("", raw_output) |
| 59 | + opts = self.get_show_opts(["properties"]) |
| 60 | + raw_output = self.openstack('volume show ' + self.NAME + opts) |
| 61 | + self.assertEqual("a='b', c='d'\n", raw_output) |
| 62 | + |
| 63 | + raw_output = self.openstack('volume unset --property a ' + self.NAME) |
| 64 | + self.assertEqual("", raw_output) |
| 65 | + raw_output = self.openstack('volume show ' + self.NAME + opts) |
| 66 | + self.assertEqual("c='d'\n", raw_output) |
| 67 | + |
| 68 | + def test_volume_set(self): |
| 69 | + discription = uuid.uuid4().hex |
| 70 | + self.openstack('volume set --description ' + discription + ' ' + |
| 71 | + self.NAME) |
| 72 | + opts = self.get_show_opts(["description", "name"]) |
| 73 | + raw_output = self.openstack('volume show ' + self.NAME + opts) |
| 74 | + self.assertEqual(discription + "\n" + self.NAME + "\n", raw_output) |
| 75 | + |
| 76 | + def test_volume_set_size(self): |
| 77 | + self.openstack('volume set --size 2 ' + self.NAME) |
| 78 | + opts = self.get_show_opts(["name", "size"]) |
| 79 | + raw_output = self.openstack('volume show ' + self.NAME + opts) |
| 80 | + self.assertEqual(self.NAME + "\n2\n", raw_output) |
0 commit comments