blob: 22d26030a581ed216fa22ffd59a2244bd0554899 [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 -050017
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050018from tempest.common import tempest_fixtures as fixtures
Fei Long Wangd39431f2015-05-14 11:30:48 +120019from tempest.common.utils import data_utils
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050020from tempest.scenario import manager
21from tempest import test
22
23
24LOG = logging.getLogger(__name__)
25
26
Masayuki Igawaccd66592014-07-17 00:42:42 +090027class TestAggregatesBasicOps(manager.ScenarioTest):
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050028 """
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 Frittolib21de6c2015-02-06 20:12:38 +000036
37 credentials = ['primary', 'admin']
David Kranzafecec02015-03-23 14:27:15 -040038
39 @classmethod
Emily Hugenbruch5e2d2a22015-02-25 21:35:45 +000040 def setup_clients(cls):
41 super(TestAggregatesBasicOps, cls).setup_clients()
Andrea Frittolib21de6c2015-02-06 20:12:38 +000042 # Use admin client by default
43 cls.manager = cls.admin_manager
44 super(TestAggregatesBasicOps, cls).resource_setup()
Masayuki Igawaccd66592014-07-17 00:42:42 +090045 cls.aggregates_client = cls.manager.aggregates_client
46 cls.hosts_client = cls.manager.hosts_client
47
Yuiko Takadaf93d2482014-01-30 16:25:08 +000048 def _create_aggregate(self, **kwargs):
ghanshyam2eb282d2015-08-04 15:05:19 +090049 aggregate = (self.aggregates_client.create_aggregate(**kwargs)
50 ['aggregate'])
Masayuki Igawaccd66592014-07-17 00:42:42 +090051 self.addCleanup(self._delete_aggregate, aggregate)
Yuiko Takadaf93d2482014-01-30 16:25:08 +000052 aggregate_name = kwargs['name']
53 availability_zone = kwargs['availability_zone']
Masayuki Igawaccd66592014-07-17 00:42:42 +090054 self.assertEqual(aggregate['name'], aggregate_name)
55 self.assertEqual(aggregate['availability_zone'], availability_zone)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050056 return aggregate
57
58 def _delete_aggregate(self, aggregate):
Masayuki Igawaccd66592014-07-17 00:42:42 +090059 self.aggregates_client.delete_aggregate(aggregate['id'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050060
61 def _get_host_name(self):
ghanshyame1bd29e2015-08-18 16:47:24 +090062 hosts = self.hosts_client.list_hosts()['hosts']
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050063 self.assertTrue(len(hosts) >= 1)
Masayuki Igawaccd66592014-07-17 00:42:42 +090064 computes = [x for x in hosts if x['service'] == 'compute']
65 return computes[0]['host_name']
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050066
Masayuki Igawaccd66592014-07-17 00:42:42 +090067 def _add_host(self, aggregate_id, host):
ghanshyam2eb282d2015-08-04 15:05:19 +090068 aggregate = (self.aggregates_client.add_host(aggregate_id, host=host)
69 ['aggregate'])
Masayuki Igawaccd66592014-07-17 00:42:42 +090070 self.addCleanup(self._remove_host, aggregate['id'], host)
71 self.assertIn(host, aggregate['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050072
Masayuki Igawaccd66592014-07-17 00:42:42 +090073 def _remove_host(self, aggregate_id, host):
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +000074 aggregate = self.aggregates_client.remove_host(aggregate_id, host=host)
ghanshyam2eb282d2015-08-04 15:05:19 +090075 self.assertNotIn(host, aggregate['aggregate']['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050076
77 def _check_aggregate_details(self, aggregate, aggregate_name, azone,
78 hosts, metadata):
ghanshyam2eb282d2015-08-04 15:05:19 +090079 aggregate = (self.aggregates_client.show_aggregate(aggregate['id'])
80 ['aggregate'])
Masayuki Igawaccd66592014-07-17 00:42:42 +090081 self.assertEqual(aggregate_name, aggregate['name'])
82 self.assertEqual(azone, aggregate['availability_zone'])
83 self.assertEqual(hosts, aggregate['hosts'])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050084 for meta_key in metadata.keys():
Masayuki Igawaccd66592014-07-17 00:42:42 +090085 self.assertIn(meta_key, aggregate['metadata'])
86 self.assertEqual(metadata[meta_key],
87 aggregate['metadata'][meta_key])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050088
89 def _set_aggregate_metadata(self, aggregate, meta):
David Kranz0a735172015-01-16 10:51:18 -050090 aggregate = self.aggregates_client.set_metadata(aggregate['id'],
Ken'ichi Ohmichiec452b82015-07-15 04:59:51 +000091 metadata=meta)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050092
93 for key, value in meta.items():
ghanshyam2eb282d2015-08-04 15:05:19 +090094 self.assertEqual(meta[key],
95 aggregate['aggregate']['metadata'][key])
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -050096
97 def _update_aggregate(self, aggregate, aggregate_name,
98 availability_zone):
David Kranz0a735172015-01-16 10:51:18 -050099 aggregate = self.aggregates_client.update_aggregate(
Masayuki Igawaccd66592014-07-17 00:42:42 +0900100 aggregate['id'], name=aggregate_name,
ghanshyam2eb282d2015-08-04 15:05:19 +0900101 availability_zone=availability_zone)['aggregate']
Masayuki Igawaccd66592014-07-17 00:42:42 +0900102 self.assertEqual(aggregate['name'], aggregate_name)
103 self.assertEqual(aggregate['availability_zone'], availability_zone)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500104 return aggregate
105
Chris Hoge7579c1a2015-02-26 14:12:15 -0800106 @test.idempotent_id('cb2b4c4f-0c7c-4164-bdde-6285b302a081')
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500107 @test.services('compute')
108 def test_aggregate_basic_ops(self):
109 self.useFixture(fixtures.LockFixture('availability_zone'))
110 az = 'foo_zone'
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900111 aggregate_name = data_utils.rand_name('aggregate-scenario')
Yuiko Takadaf93d2482014-01-30 16:25:08 +0000112 aggregate = self._create_aggregate(name=aggregate_name,
113 availability_zone=az)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500114
115 metadata = {'meta_key': 'meta_value'}
116 self._set_aggregate_metadata(aggregate, metadata)
117
118 host = self._get_host_name()
Masayuki Igawaccd66592014-07-17 00:42:42 +0900119 self._add_host(aggregate['id'], host)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500120 self._check_aggregate_details(aggregate, aggregate_name, az, [host],
121 metadata)
122
Masayuki Igawa4ded9f02014-02-17 15:05:59 +0900123 aggregate_name = data_utils.rand_name('renamed-aggregate-scenario')
Masayuki Igawaccd66592014-07-17 00:42:42 +0900124 # Updating the name alone. The az must be specified again otherwise
125 # the tempest client would send None in the put body
126 aggregate = self._update_aggregate(aggregate, aggregate_name, az)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500127
Masayuki Igawaccd66592014-07-17 00:42:42 +0900128 new_metadata = {'foo': 'bar'}
129 self._set_aggregate_metadata(aggregate, new_metadata)
Mauro S. M. Rodrigues92ed9b82013-12-17 07:21:48 -0500130
Masayuki Igawaccd66592014-07-17 00:42:42 +0900131 self._check_aggregate_details(aggregate, aggregate['name'], az,
132 [host], new_metadata)