Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 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 tempest.api.baremetal import base |
| 15 | from tempest.common.utils import data_utils |
| 16 | from tempest import exceptions as exc |
| 17 | from tempest import test |
| 18 | |
| 19 | |
| 20 | class TestChassis(base.BaseBaremetalTest): |
| 21 | """Tests for chassis.""" |
| 22 | |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 23 | @classmethod |
| 24 | def setUpClass(cls): |
| 25 | super(TestChassis, cls).setUpClass() |
| 26 | _, cls.chassis = cls.create_chassis() |
| 27 | |
| 28 | def _assertExpected(self, expected, actual): |
| 29 | # Check if not expected keys/values exists in actual response body |
| 30 | for key, value in expected.iteritems(): |
| 31 | if key not in ('created_at', 'updated_at'): |
| 32 | self.assertIn(key, actual) |
| 33 | self.assertEqual(value, actual[key]) |
| 34 | |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 35 | @test.attr(type='smoke') |
| 36 | def test_create_chassis(self): |
| 37 | descr = data_utils.rand_name('test-chassis-') |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 38 | resp, chassis = self.create_chassis(description=descr) |
| 39 | self.assertEqual('201', resp['status']) |
| 40 | self.assertEqual(chassis['description'], descr) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 41 | |
| 42 | @test.attr(type='smoke') |
| 43 | def test_create_chassis_unicode_description(self): |
| 44 | # Use a unicode string for testing: |
| 45 | # 'We ♡ OpenStack in Ukraine' |
| 46 | descr = u'В Україні ♡ OpenStack!' |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 47 | resp, chassis = self.create_chassis(description=descr) |
| 48 | self.assertEqual('201', resp['status']) |
| 49 | self.assertEqual(chassis['description'], descr) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 50 | |
| 51 | @test.attr(type='smoke') |
| 52 | def test_show_chassis(self): |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 53 | resp, chassis = self.client.show_chassis(self.chassis['uuid']) |
| 54 | self.assertEqual('200', resp['status']) |
| 55 | self._assertExpected(self.chassis, chassis) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 56 | |
| 57 | @test.attr(type="smoke") |
| 58 | def test_list_chassis(self): |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 59 | resp, body = self.client.list_chassis() |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 60 | self.assertEqual('200', resp['status']) |
| 61 | self.assertIn(self.chassis['uuid'], |
| 62 | [i['uuid'] for i in body['chassis']]) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 63 | |
| 64 | @test.attr(type='smoke') |
| 65 | def test_delete_chassis(self): |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 66 | resp, body = self.create_chassis() |
| 67 | uuid = body['uuid'] |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 68 | |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 69 | resp = self.delete_chassis(uuid) |
| 70 | self.assertEqual('204', resp['status']) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 71 | self.assertRaises(exc.NotFound, self.client.show_chassis, uuid) |
| 72 | |
| 73 | @test.attr(type='smoke') |
| 74 | def test_update_chassis(self): |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 75 | resp, body = self.create_chassis() |
| 76 | uuid = body['uuid'] |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 77 | |
| 78 | new_description = data_utils.rand_name('new-description-') |
Mh Raies | a9bb79d | 2014-04-17 16:20:17 +0530 | [diff] [blame] | 79 | resp, body = (self.client.update_chassis(uuid, |
| 80 | description=new_description)) |
| 81 | self.assertEqual('200', resp['status']) |
| 82 | resp, chassis = self.client.show_chassis(uuid) |
Roman Prykhodchenko | 62b1ed1 | 2013-10-16 21:51:47 +0300 | [diff] [blame] | 83 | self.assertEqual(chassis['description'], new_description) |