2016-02-17 15:16:33 +08:00
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License. You may obtain
|
|
|
|
# a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations
|
|
|
|
# under the License.
|
|
|
|
|
|
|
|
import uuid
|
|
|
|
|
2016-09-05 20:35:06 -07:00
|
|
|
from openstackclient.tests.functional import base
|
2016-02-17 15:16:33 +08:00
|
|
|
|
|
|
|
|
2016-09-05 20:35:06 -07:00
|
|
|
class AggregateTests(base.TestCase):
|
2017-05-01 14:36:19 -05:00
|
|
|
"""Functional tests for aggregate"""
|
2016-02-17 15:16:33 +08:00
|
|
|
|
2019-05-17 16:40:12 -05:00
|
|
|
def test_aggregate_crud(self):
|
2016-11-25 19:44:23 +08:00
|
|
|
"""Test create, delete multiple"""
|
|
|
|
name1 = uuid.uuid4().hex
|
2019-11-05 13:26:19 -06:00
|
|
|
self.addCleanup(
|
|
|
|
self.openstack,
|
|
|
|
'aggregate delete ' + name1,
|
|
|
|
fail_ok=True,
|
|
|
|
)
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate create ' + '--zone nova ' + '--property a=b ' + name1,
|
2022-11-08 10:56:26 +00:00
|
|
|
parse_output=True,
|
|
|
|
)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.assertEqual(name1, cmd_output['name'])
|
|
|
|
self.assertEqual('nova', cmd_output['availability_zone'])
|
|
|
|
self.assertIn('a', cmd_output['properties'])
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'aggregate show ' + name1,
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2019-11-05 13:26:19 -06:00
|
|
|
self.assertEqual(name1, cmd_output['name'])
|
|
|
|
|
|
|
|
name2 = uuid.uuid4().hex
|
2019-05-17 20:06:44 -05:00
|
|
|
self.addCleanup(
|
|
|
|
self.openstack,
|
2019-11-05 13:26:19 -06:00
|
|
|
'aggregate delete ' + name2,
|
2019-05-17 20:06:44 -05:00
|
|
|
fail_ok=True,
|
|
|
|
)
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate create ' + '--zone external ' + name2,
|
2022-11-08 10:56:26 +00:00
|
|
|
parse_output=True,
|
|
|
|
)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.assertEqual(name2, cmd_output['name'])
|
|
|
|
self.assertEqual('external', cmd_output['availability_zone'])
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'aggregate show ' + name2,
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2019-11-05 13:26:19 -06:00
|
|
|
self.assertEqual(name2, cmd_output['name'])
|
|
|
|
|
|
|
|
# Test aggregate set
|
|
|
|
name3 = uuid.uuid4().hex
|
2019-05-17 20:06:44 -05:00
|
|
|
self.addCleanup(
|
|
|
|
self.openstack,
|
2019-11-05 13:26:19 -06:00
|
|
|
'aggregate delete ' + name3,
|
2019-05-17 20:06:44 -05:00
|
|
|
fail_ok=True,
|
|
|
|
)
|
2016-02-17 15:16:33 +08:00
|
|
|
raw_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate set '
|
|
|
|
+ '--name '
|
|
|
|
+ name3
|
|
|
|
+ ' '
|
|
|
|
+ '--zone internal '
|
|
|
|
+ '--no-property '
|
|
|
|
+ '--property c=d '
|
|
|
|
+ name1
|
2016-02-17 15:16:33 +08:00
|
|
|
)
|
2016-11-25 19:44:23 +08:00
|
|
|
self.assertOutput('', raw_output)
|
2016-06-16 16:41:25 +08:00
|
|
|
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate show ' + name3,
|
2022-11-08 10:56:26 +00:00
|
|
|
parse_output=True,
|
|
|
|
)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.assertEqual(name3, cmd_output['name'])
|
|
|
|
self.assertEqual('internal', cmd_output['availability_zone'])
|
|
|
|
self.assertIn('c', cmd_output['properties'])
|
|
|
|
self.assertNotIn('a', cmd_output['properties'])
|
2016-11-22 02:19:12 +08:00
|
|
|
|
2019-05-17 16:40:12 -05:00
|
|
|
# Test aggregate list
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'aggregate list',
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2019-05-17 16:40:12 -05:00
|
|
|
names = [x['Name'] for x in cmd_output]
|
|
|
|
self.assertIn(name3, names)
|
|
|
|
self.assertIn(name2, names)
|
|
|
|
zones = [x['Availability Zone'] for x in cmd_output]
|
|
|
|
self.assertIn('external', zones)
|
|
|
|
self.assertIn('internal', zones)
|
|
|
|
|
|
|
|
# Test aggregate list --long
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'aggregate list --long',
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2019-05-17 16:40:12 -05:00
|
|
|
names = [x['Name'] for x in cmd_output]
|
|
|
|
self.assertIn(name3, names)
|
|
|
|
self.assertIn(name2, names)
|
|
|
|
zones = [x['Availability Zone'] for x in cmd_output]
|
|
|
|
self.assertIn('external', zones)
|
|
|
|
self.assertIn('internal', zones)
|
|
|
|
properties = [x['Properties'] for x in cmd_output]
|
|
|
|
self.assertNotIn({'a': 'b'}, properties)
|
|
|
|
self.assertIn({'c': 'd'}, properties)
|
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
# Test unset
|
2016-11-22 02:19:12 +08:00
|
|
|
raw_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate unset ' + '--property c ' + name3
|
2016-11-25 19:44:23 +08:00
|
|
|
)
|
|
|
|
self.assertOutput('', raw_output)
|
2016-11-22 02:19:12 +08:00
|
|
|
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate show ' + name3,
|
2022-11-08 10:56:26 +00:00
|
|
|
parse_output=True,
|
|
|
|
)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.assertNotIn("c='d'", cmd_output['properties'])
|
2016-11-22 02:19:12 +08:00
|
|
|
|
2019-05-17 16:40:12 -05:00
|
|
|
# test aggregate delete
|
2023-05-08 10:48:54 +01:00
|
|
|
del_output = self.openstack('aggregate delete ' + name3 + ' ' + name2)
|
2019-05-17 16:40:12 -05:00
|
|
|
self.assertOutput('', del_output)
|
|
|
|
|
2016-11-22 02:19:12 +08:00
|
|
|
def test_aggregate_add_and_remove_host(self):
|
2016-11-25 19:44:23 +08:00
|
|
|
"""Test aggregate add and remove host"""
|
|
|
|
# Get a host
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
|
|
|
'host list',
|
|
|
|
parse_output=True,
|
|
|
|
)
|
2016-11-25 19:44:23 +08:00
|
|
|
host_name = cmd_output[0]['Host Name']
|
|
|
|
|
2017-05-01 14:36:19 -05:00
|
|
|
# NOTE(dtroyer): Cells v1 is not operable with aggregates. Hostnames
|
|
|
|
# are returned as rrr@host or ccc!rrr@host.
|
|
|
|
if '@' in host_name:
|
|
|
|
self.skipTest("Skip aggregates in a Nova cells v1 configuration")
|
|
|
|
|
|
|
|
name = uuid.uuid4().hex
|
2019-11-05 13:26:19 -06:00
|
|
|
self.addCleanup(self.openstack, 'aggregate delete ' + name)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.openstack('aggregate create ' + name)
|
2017-05-01 14:36:19 -05:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
# Test add host
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate add host ' + name + ' ' + host_name,
|
2022-11-08 10:56:26 +00:00
|
|
|
parse_output=True,
|
|
|
|
)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.assertIn(host_name, cmd_output['hosts'])
|
2016-11-22 02:19:12 +08:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
# Test remove host
|
2022-11-08 10:56:26 +00:00
|
|
|
cmd_output = self.openstack(
|
2023-05-08 10:48:54 +01:00
|
|
|
'aggregate remove host ' + name + ' ' + host_name,
|
2022-11-08 10:56:26 +00:00
|
|
|
parse_output=True,
|
|
|
|
)
|
2023-05-08 10:48:54 +01:00
|
|
|
self.assertNotIn(host_name, cmd_output['hosts'])
|