Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 1 | # Copyright 2013 IBM Corp. |
| 2 | # All Rights Reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 | # not use this file except in compliance with the License. You may obtain |
| 6 | # a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | # License for the specific language governing permissions and limitations |
| 14 | # under the License. |
| 15 | |
Doug Hellmann | 583ce2c | 2015-03-11 14:55:46 +0000 | [diff] [blame] | 16 | from oslo_log import log as logging |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 17 | |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 18 | from tempest.common import tempest_fixtures as fixtures |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame^] | 19 | from tempest.common.utils import data_utils |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 20 | from tempest.scenario import manager |
| 21 | from tempest import test |
| 22 | |
| 23 | |
| 24 | LOG = logging.getLogger(__name__) |
| 25 | |
| 26 | |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 27 | class TestAggregatesBasicOps(manager.ScenarioTest): |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 28 | """ |
| 29 | Creates an aggregate within an availability zone |
| 30 | Adds a host to the aggregate |
| 31 | Checks aggregate details |
| 32 | Updates aggregate's name |
| 33 | Removes host from aggregate |
| 34 | Deletes aggregate |
| 35 | """ |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 36 | |
| 37 | credentials = ['primary', 'admin'] |
David Kranz | afecec0 | 2015-03-23 14:27:15 -0400 | [diff] [blame] | 38 | |
| 39 | @classmethod |
Emily Hugenbruch | 5e2d2a2 | 2015-02-25 21:35:45 +0000 | [diff] [blame] | 40 | def setup_clients(cls): |
| 41 | super(TestAggregatesBasicOps, cls).setup_clients() |
Andrea Frittoli | b21de6c | 2015-02-06 20:12:38 +0000 | [diff] [blame] | 42 | # Use admin client by default |
| 43 | cls.manager = cls.admin_manager |
| 44 | super(TestAggregatesBasicOps, cls).resource_setup() |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 45 | cls.aggregates_client = cls.manager.aggregates_client |
| 46 | cls.hosts_client = cls.manager.hosts_client |
| 47 | |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 48 | def _create_aggregate(self, **kwargs): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 49 | aggregate = self.aggregates_client.create_aggregate(**kwargs) |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 50 | self.addCleanup(self._delete_aggregate, aggregate) |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 51 | aggregate_name = kwargs['name'] |
| 52 | availability_zone = kwargs['availability_zone'] |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 53 | self.assertEqual(aggregate['name'], aggregate_name) |
| 54 | self.assertEqual(aggregate['availability_zone'], availability_zone) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 55 | return aggregate |
| 56 | |
| 57 | def _delete_aggregate(self, aggregate): |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 58 | self.aggregates_client.delete_aggregate(aggregate['id']) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 59 | |
| 60 | def _get_host_name(self): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 61 | hosts = self.hosts_client.list_hosts() |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 62 | self.assertTrue(len(hosts) >= 1) |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 63 | computes = [x for x in hosts if x['service'] == 'compute'] |
| 64 | return computes[0]['host_name'] |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 65 | |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 66 | def _add_host(self, aggregate_id, host): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 67 | aggregate = self.aggregates_client.add_host(aggregate_id, host) |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 68 | self.addCleanup(self._remove_host, aggregate['id'], host) |
| 69 | self.assertIn(host, aggregate['hosts']) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 70 | |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 71 | def _remove_host(self, aggregate_id, host): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 72 | aggregate = self.aggregates_client.remove_host(aggregate_id, host) |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 73 | self.assertNotIn(host, aggregate['hosts']) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 74 | |
| 75 | def _check_aggregate_details(self, aggregate, aggregate_name, azone, |
| 76 | hosts, metadata): |
Ken'ichi Ohmichi | 3de6d98 | 2015-04-13 00:20:41 +0000 | [diff] [blame] | 77 | aggregate = self.aggregates_client.show_aggregate(aggregate['id']) |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 78 | self.assertEqual(aggregate_name, aggregate['name']) |
| 79 | self.assertEqual(azone, aggregate['availability_zone']) |
| 80 | self.assertEqual(hosts, aggregate['hosts']) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 81 | for meta_key in metadata.keys(): |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 82 | self.assertIn(meta_key, aggregate['metadata']) |
| 83 | self.assertEqual(metadata[meta_key], |
| 84 | aggregate['metadata'][meta_key]) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 85 | |
| 86 | def _set_aggregate_metadata(self, aggregate, meta): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 87 | aggregate = self.aggregates_client.set_metadata(aggregate['id'], |
| 88 | meta) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 89 | |
| 90 | for key, value in meta.items(): |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 91 | self.assertEqual(meta[key], aggregate['metadata'][key]) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 92 | |
| 93 | def _update_aggregate(self, aggregate, aggregate_name, |
| 94 | availability_zone): |
David Kranz | 0a73517 | 2015-01-16 10:51:18 -0500 | [diff] [blame] | 95 | aggregate = self.aggregates_client.update_aggregate( |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 96 | aggregate['id'], name=aggregate_name, |
| 97 | availability_zone=availability_zone) |
| 98 | self.assertEqual(aggregate['name'], aggregate_name) |
| 99 | self.assertEqual(aggregate['availability_zone'], availability_zone) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 100 | return aggregate |
| 101 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 102 | @test.idempotent_id('cb2b4c4f-0c7c-4164-bdde-6285b302a081') |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 103 | @test.services('compute') |
| 104 | def test_aggregate_basic_ops(self): |
| 105 | self.useFixture(fixtures.LockFixture('availability_zone')) |
| 106 | az = 'foo_zone' |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 107 | aggregate_name = data_utils.rand_name('aggregate-scenario') |
Yuiko Takada | f93d248 | 2014-01-30 16:25:08 +0000 | [diff] [blame] | 108 | aggregate = self._create_aggregate(name=aggregate_name, |
| 109 | availability_zone=az) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 110 | |
| 111 | metadata = {'meta_key': 'meta_value'} |
| 112 | self._set_aggregate_metadata(aggregate, metadata) |
| 113 | |
| 114 | host = self._get_host_name() |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 115 | self._add_host(aggregate['id'], host) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 116 | self._check_aggregate_details(aggregate, aggregate_name, az, [host], |
| 117 | metadata) |
| 118 | |
Masayuki Igawa | 4ded9f0 | 2014-02-17 15:05:59 +0900 | [diff] [blame] | 119 | aggregate_name = data_utils.rand_name('renamed-aggregate-scenario') |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 120 | # Updating the name alone. The az must be specified again otherwise |
| 121 | # the tempest client would send None in the put body |
| 122 | aggregate = self._update_aggregate(aggregate, aggregate_name, az) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 123 | |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 124 | new_metadata = {'foo': 'bar'} |
| 125 | self._set_aggregate_metadata(aggregate, new_metadata) |
Mauro S. M. Rodrigues | 92ed9b8 | 2013-12-17 07:21:48 -0500 | [diff] [blame] | 126 | |
Masayuki Igawa | ccd6659 | 2014-07-17 00:42:42 +0900 | [diff] [blame] | 127 | self._check_aggregate_details(aggregate, aggregate['name'], az, |
| 128 | [host], new_metadata) |