blob: 8de3561171ad4741cf210ac0e73e74a3dd96343f [file] [log] [blame]
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -05001# 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
16from tempest.common import tempest_fixtures as fixtures
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050018from tempest.scenario import manager
19from tempest import test
20
21
Masayuki Igawaccd66592014-07-17 00:42:42 +090022class TestAggregatesBasicOps(manager.ScenarioTest):
Ken'ichi Ohmichic4e4f1c2015-11-17 08:16:12 +000023 """Creates an aggregate within an availability zone
24
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050025 Adds a host to the aggregate
26 Checks aggregate details
27 Updates aggregate's name
28 Removes host from aggregate
29 Deletes aggregate
30 """
Andrea Frittolib21de6c2015-02-06 20:12:38 +000031
32 credentials = ['primary', 'admin']
David Kranzafecec02015-03-23 14:27:15 -040033
34 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000035 def setup_clients(cls):
36 super(TestAggregatesBasicOps, cls).setup_clients()
Andrea Frittolib21de6c2015-02-06 20:12:38 +000037 # Use admin client by default
38 cls.manager = cls.admin_manager
Masayuki Igawaccd66592014-07-17 00:42:42 +090039 cls.aggregates_client = cls.manager.aggregates_client
40 cls.hosts_client = cls.manager.hosts_client
41
Yuiko Takadaf93d2482014-01-30 16:25:08 +000042 def _create_aggregate(self, **kwargs):
ghanshyam2eb282d2015-08-04 15:05:19 +090043 aggregate = (self.aggregates_client.create_aggregate(**kwargs)
44 ['aggregate'])
Jordan Pittierbbb17122016-01-26 17:10:55 +010045 self.addCleanup(self.aggregates_client.delete_aggregate,
46 aggregate['id'])
Yuiko Takadaf93d2482014-01-30 16:25:08 +000047 aggregate_name = kwargs['name']
48 availability_zone = kwargs['availability_zone']
Masayuki Igawaccd66592014-07-17 00:42:42 +090049 self.assertEqual(aggregate['name'], aggregate_name)
50 self.assertEqual(aggregate['availability_zone'], availability_zone)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050051 return aggregate
52
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050053 def _get_host_name(self):
ghanshyame1bd29e2015-08-18 16:47:24 +090054 hosts = self.hosts_client.list_hosts()['hosts']
melissamlc9f38b82016-10-31 13:41:59 +080055 self.assertGreaterEqual(len(hosts), 1)
Masayuki Igawaccd66592014-07-17 00:42:42 +090056 computes = [x for x in hosts if x['service'] == 'compute']
57 return computes[0]['host_name']
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050058
Masayuki Igawaccd66592014-07-17 00:42:42 +090059 def _add_host(self, aggregate_id, host):
ghanshyam2eb282d2015-08-04 15:05:19 +090060 aggregate = (self.aggregates_client.add_host(aggregate_id, host=host)
61 ['aggregate'])
Masayuki Igawaccd66592014-07-17 00:42:42 +090062 self.addCleanup(self._remove_host, aggregate['id'], host)
63 self.assertIn(host, aggregate['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050064
Masayuki Igawaccd66592014-07-17 00:42:42 +090065 def _remove_host(self, aggregate_id, host):
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +000066 aggregate = self.aggregates_client.remove_host(aggregate_id, host=host)
ghanshyam2eb282d2015-08-04 15:05:19 +090067 self.assertNotIn(host, aggregate['aggregate']['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050068
69 def _check_aggregate_details(self, aggregate, aggregate_name, azone,
70 hosts, metadata):
ghanshyam2eb282d2015-08-04 15:05:19 +090071 aggregate = (self.aggregates_client.show_aggregate(aggregate['id'])
72 ['aggregate'])
Masayuki Igawaccd66592014-07-17 00:42:42 +090073 self.assertEqual(aggregate_name, aggregate['name'])
74 self.assertEqual(azone, aggregate['availability_zone'])
75 self.assertEqual(hosts, aggregate['hosts'])
Joe H. Rahmea72f2c62016-07-11 16:28:19 +020076 for meta_key in metadata:
Masayuki Igawaccd66592014-07-17 00:42:42 +090077 self.assertIn(meta_key, aggregate['metadata'])
78 self.assertEqual(metadata[meta_key],
79 aggregate['metadata'][meta_key])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050080
81 def _set_aggregate_metadata(self, aggregate, meta):
David Kranz0a735172015-01-16 10:51:18 -050082 aggregate = self.aggregates_client.set_metadata(aggregate['id'],
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +000083 metadata=meta)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050084
85 for key, value in meta.items():
ghanshyam2eb282d2015-08-04 15:05:19 +090086 self.assertEqual(meta[key],
87 aggregate['aggregate']['metadata'][key])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050088
89 def _update_aggregate(self, aggregate, aggregate_name,
90 availability_zone):
David Kranz0a735172015-01-16 10:51:18 -050091 aggregate = self.aggregates_client.update_aggregate(
Masayuki Igawaccd66592014-07-17 00:42:42 +090092 aggregate['id'], name=aggregate_name,
ghanshyam2eb282d2015-08-04 15:05:19 +090093 availability_zone=availability_zone)['aggregate']
Masayuki Igawaccd66592014-07-17 00:42:42 +090094 self.assertEqual(aggregate['name'], aggregate_name)
95 self.assertEqual(aggregate['availability_zone'], availability_zone)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050096 return aggregate
97
Chris Hoge7579c1a2015-02-26 14:12:15 -080098 @test.idempotent_id('cb2b4c4f-0c7c-4164-bdde-6285b302a081')
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050099 @test.services('compute')
100 def test_aggregate_basic_ops(self):
101 self.useFixture(fixtures.LockFixture('availability_zone'))
102 az = 'foo_zone'
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900103 aggregate_name = data_utils.rand_name('aggregate-scenario')
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000104 aggregate = self._create_aggregate(name=aggregate_name,
105 availability_zone=az)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500106
107 metadata = {'meta_key': 'meta_value'}
108 self._set_aggregate_metadata(aggregate, metadata)
109
110 host = self._get_host_name()
Masayuki Igawaccd66592014-07-17 00:42:42 +0900111 self._add_host(aggregate['id'], host)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500112 self._check_aggregate_details(aggregate, aggregate_name, az, [host],
113 metadata)
114
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900115 aggregate_name = data_utils.rand_name('renamed-aggregate-scenario')
Masayuki Igawaccd66592014-07-17 00:42:42 +0900116 # Updating the name alone. The az must be specified again otherwise
117 # the tempest client would send None in the put body
118 aggregate = self._update_aggregate(aggregate, aggregate_name, az)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500119
Masayuki Igawaccd66592014-07-17 00:42:42 +0900120 new_metadata = {'foo': 'bar'}
121 self._set_aggregate_metadata(aggregate, new_metadata)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500122
Masayuki Igawaccd66592014-07-17 00:42:42 +0900123 self._check_aggregate_details(aggregate, aggregate['name'], az,
124 [host], new_metadata)