blob: c5e80124cf7b74054a4c83d3552a8b518359a42f [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
Doug Hellmann583ce2c2015-03-11 14:55:46 +000016from oslo_log import log as logging
Matthew Treinish01472ff2015-02-20 17:26:52 -050017from tempest_lib.common.utils import data_utils
18
David Kranzafecec02015-03-23 14:27:15 -040019from tempest.common import credentials
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050020from tempest.common import tempest_fixtures as fixtures
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050021from tempest.scenario import manager
22from tempest import test
23
24
25LOG = logging.getLogger(__name__)
26
27
Masayuki Igawaccd66592014-07-17 00:42:42 +090028class TestAggregatesBasicOps(manager.ScenarioTest):
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050029 """
30 Creates an aggregate within an availability zone
31 Adds a host to the aggregate
32 Checks aggregate details
33 Updates aggregate's name
34 Removes host from aggregate
35 Deletes aggregate
36 """
37 @classmethod
David Kranzafecec02015-03-23 14:27:15 -040038 def skip_checks(cls):
39 super(TestAggregatesBasicOps, cls).skip_checks()
40 if not credentials.is_admin_available():
41 msg = ("Missing Identity Admin API credentials in configuration.")
42 raise cls.skipException(msg)
43
44 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000045 def setup_clients(cls):
46 super(TestAggregatesBasicOps, cls).setup_clients()
Masayuki Igawaccd66592014-07-17 00:42:42 +090047 cls.aggregates_client = cls.manager.aggregates_client
48 cls.hosts_client = cls.manager.hosts_client
49
50 @classmethod
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050051 def credentials(cls):
52 return cls.admin_credentials()
53
Yuiko Takadaf93d2482014-01-30 16:25:08 +000054 def _create_aggregate(self, **kwargs):
David Kranz0a735172015-01-16 10:51:18 -050055 aggregate = self.aggregates_client.create_aggregate(**kwargs)
Masayuki Igawaccd66592014-07-17 00:42:42 +090056 self.addCleanup(self._delete_aggregate, aggregate)
Yuiko Takadaf93d2482014-01-30 16:25:08 +000057 aggregate_name = kwargs['name']
58 availability_zone = kwargs['availability_zone']
Masayuki Igawaccd66592014-07-17 00:42:42 +090059 self.assertEqual(aggregate['name'], aggregate_name)
60 self.assertEqual(aggregate['availability_zone'], availability_zone)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050061 return aggregate
62
63 def _delete_aggregate(self, aggregate):
Masayuki Igawaccd66592014-07-17 00:42:42 +090064 self.aggregates_client.delete_aggregate(aggregate['id'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050065
66 def _get_host_name(self):
David Kranz0a735172015-01-16 10:51:18 -050067 hosts = self.hosts_client.list_hosts()
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050068 self.assertTrue(len(hosts) >= 1)
Masayuki Igawaccd66592014-07-17 00:42:42 +090069 computes = [x for x in hosts if x['service'] == 'compute']
70 return computes[0]['host_name']
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050071
Masayuki Igawaccd66592014-07-17 00:42:42 +090072 def _add_host(self, aggregate_id, host):
David Kranz0a735172015-01-16 10:51:18 -050073 aggregate = self.aggregates_client.add_host(aggregate_id, host)
Masayuki Igawaccd66592014-07-17 00:42:42 +090074 self.addCleanup(self._remove_host, aggregate['id'], host)
75 self.assertIn(host, aggregate['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050076
Masayuki Igawaccd66592014-07-17 00:42:42 +090077 def _remove_host(self, aggregate_id, host):
David Kranz0a735172015-01-16 10:51:18 -050078 aggregate = self.aggregates_client.remove_host(aggregate_id, host)
Masayuki Igawaccd66592014-07-17 00:42:42 +090079 self.assertNotIn(host, aggregate['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050080
81 def _check_aggregate_details(self, aggregate, aggregate_name, azone,
82 hosts, metadata):
David Kranz0a735172015-01-16 10:51:18 -050083 aggregate = self.aggregates_client.get_aggregate(aggregate['id'])
Masayuki Igawaccd66592014-07-17 00:42:42 +090084 self.assertEqual(aggregate_name, aggregate['name'])
85 self.assertEqual(azone, aggregate['availability_zone'])
86 self.assertEqual(hosts, aggregate['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050087 for meta_key in metadata.keys():
Masayuki Igawaccd66592014-07-17 00:42:42 +090088 self.assertIn(meta_key, aggregate['metadata'])
89 self.assertEqual(metadata[meta_key],
90 aggregate['metadata'][meta_key])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050091
92 def _set_aggregate_metadata(self, aggregate, meta):
David Kranz0a735172015-01-16 10:51:18 -050093 aggregate = self.aggregates_client.set_metadata(aggregate['id'],
94 meta)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050095
96 for key, value in meta.items():
Masayuki Igawaccd66592014-07-17 00:42:42 +090097 self.assertEqual(meta[key], aggregate['metadata'][key])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050098
99 def _update_aggregate(self, aggregate, aggregate_name,
100 availability_zone):
David Kranz0a735172015-01-16 10:51:18 -0500101 aggregate = self.aggregates_client.update_aggregate(
Masayuki Igawaccd66592014-07-17 00:42:42 +0900102 aggregate['id'], name=aggregate_name,
103 availability_zone=availability_zone)
104 self.assertEqual(aggregate['name'], aggregate_name)
105 self.assertEqual(aggregate['availability_zone'], availability_zone)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500106 return aggregate
107
Chris Hoge7579c1a2015-02-26 14:12:15 -0800108 @test.idempotent_id('cb2b4c4f-0c7c-4164-bdde-6285b302a081')
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500109 @test.services('compute')
110 def test_aggregate_basic_ops(self):
111 self.useFixture(fixtures.LockFixture('availability_zone'))
112 az = 'foo_zone'
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900113 aggregate_name = data_utils.rand_name('aggregate-scenario')
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000114 aggregate = self._create_aggregate(name=aggregate_name,
115 availability_zone=az)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500116
117 metadata = {'meta_key': 'meta_value'}
118 self._set_aggregate_metadata(aggregate, metadata)
119
120 host = self._get_host_name()
Masayuki Igawaccd66592014-07-17 00:42:42 +0900121 self._add_host(aggregate['id'], host)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500122 self._check_aggregate_details(aggregate, aggregate_name, az, [host],
123 metadata)
124
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900125 aggregate_name = data_utils.rand_name('renamed-aggregate-scenario')
Masayuki Igawaccd66592014-07-17 00:42:42 +0900126 # Updating the name alone. The az must be specified again otherwise
127 # the tempest client would send None in the put body
128 aggregate = self._update_aggregate(aggregate, aggregate_name, az)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500129
Masayuki Igawaccd66592014-07-17 00:42:42 +0900130 new_metadata = {'foo': 'bar'}
131 self._set_aggregate_metadata(aggregate, new_metadata)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500132
Masayuki Igawaccd66592014-07-17 00:42:42 +0900133 self._check_aggregate_details(aggregate, aggregate['name'], az,
134 [host], new_metadata)