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.
|
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
import json
|
2016-02-17 15:16:33 +08:00
|
|
|
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):
|
2016-06-24 14:45:19 +03:00
|
|
|
"""Functional tests for aggregate."""
|
2016-02-17 15:16:33 +08:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
def test_aggregate_create_and_delete(self):
|
|
|
|
"""Test create, delete multiple"""
|
|
|
|
name1 = uuid.uuid4().hex
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate create -f json ' +
|
|
|
|
'--zone nova ' +
|
|
|
|
name1))
|
|
|
|
self.assertEqual(
|
|
|
|
name1,
|
|
|
|
cmd_output['name']
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'nova',
|
|
|
|
cmd_output['availability_zone']
|
|
|
|
)
|
2016-02-17 15:16:33 +08:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
name2 = uuid.uuid4().hex
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate create -f json ' +
|
|
|
|
'--zone nova ' +
|
|
|
|
name2))
|
|
|
|
self.assertEqual(
|
|
|
|
name2,
|
|
|
|
cmd_output['name']
|
|
|
|
)
|
|
|
|
self.assertEqual(
|
|
|
|
'nova',
|
|
|
|
cmd_output['availability_zone']
|
2016-03-03 12:32:09 -06:00
|
|
|
)
|
2016-02-17 15:16:33 +08:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
del_output = self.openstack(
|
|
|
|
'aggregate delete ' + name1 + ' ' + name2)
|
|
|
|
self.assertOutput('', del_output)
|
2016-02-17 15:16:33 +08:00
|
|
|
|
|
|
|
def test_aggregate_list(self):
|
2016-11-25 19:44:23 +08:00
|
|
|
"""Test aggregate list"""
|
|
|
|
name1 = uuid.uuid4().hex
|
|
|
|
self.openstack(
|
|
|
|
'aggregate create ' +
|
|
|
|
'--zone nova ' +
|
|
|
|
'--property a=b ' +
|
|
|
|
name1)
|
|
|
|
self.addCleanup(self.openstack, 'aggregate delete ' + name1)
|
2016-02-17 15:16:33 +08:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
name2 = uuid.uuid4().hex
|
|
|
|
self.openstack(
|
|
|
|
'aggregate create ' +
|
|
|
|
'--zone internal ' +
|
|
|
|
'--property c=d ' +
|
|
|
|
name2)
|
|
|
|
self.addCleanup(self.openstack, 'aggregate delete ' + name2)
|
|
|
|
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate list -f json'))
|
|
|
|
names = [x['Name'] for x in cmd_output]
|
|
|
|
self.assertIn(name1, names)
|
|
|
|
self.assertIn(name2, names)
|
|
|
|
zones = [x['Availability Zone'] for x in cmd_output]
|
|
|
|
self.assertIn('nova', zones)
|
|
|
|
self.assertIn('internal', zones)
|
|
|
|
|
|
|
|
# Test aggregate list --long
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate list --long -f json'))
|
|
|
|
names = [x['Name'] for x in cmd_output]
|
|
|
|
self.assertIn(name1, names)
|
|
|
|
self.assertIn(name2, names)
|
|
|
|
zones = [x['Availability Zone'] for x in cmd_output]
|
|
|
|
self.assertIn('nova', zones)
|
|
|
|
self.assertIn('internal', zones)
|
|
|
|
properties = [x['Properties'] for x in cmd_output]
|
|
|
|
self.assertIn({'a': 'b'}, properties)
|
|
|
|
self.assertIn({'c': 'd'}, properties)
|
|
|
|
|
|
|
|
def test_aggregate_set_and_unset(self):
|
|
|
|
"""Test aggregate set, show and unset"""
|
|
|
|
name1 = uuid.uuid4().hex
|
|
|
|
name2 = uuid.uuid4().hex
|
|
|
|
self.openstack(
|
|
|
|
'aggregate create ' +
|
|
|
|
'--zone nova ' +
|
|
|
|
'--property a=b ' +
|
|
|
|
name1)
|
|
|
|
self.addCleanup(self.openstack, 'aggregate delete ' + name2)
|
2016-02-17 15:16:33 +08:00
|
|
|
|
|
|
|
raw_output = self.openstack(
|
2016-11-25 19:44:23 +08:00
|
|
|
'aggregate set --name ' +
|
|
|
|
name2 +
|
|
|
|
' --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
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate show -f json ' + name2))
|
|
|
|
self.assertEqual(
|
|
|
|
name2,
|
|
|
|
cmd_output['name']
|
2016-06-16 16:41:25 +08:00
|
|
|
)
|
2016-11-25 19:44:23 +08:00
|
|
|
self.assertEqual(
|
|
|
|
'internal',
|
|
|
|
cmd_output['availability_zone']
|
2016-11-22 02:19:12 +08:00
|
|
|
)
|
2016-11-25 19:44:23 +08:00
|
|
|
self.assertIn(
|
|
|
|
"c='d'",
|
|
|
|
cmd_output['properties']
|
|
|
|
)
|
|
|
|
self.assertNotIn(
|
|
|
|
"a='b'",
|
|
|
|
cmd_output['properties']
|
2016-11-22 02:19:12 +08:00
|
|
|
)
|
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
# Test unset
|
2016-11-22 02:19:12 +08:00
|
|
|
raw_output = self.openstack(
|
2016-11-25 19:44:23 +08:00
|
|
|
'aggregate unset --property c ' +
|
|
|
|
name2
|
|
|
|
)
|
|
|
|
self.assertOutput('', raw_output)
|
2016-11-22 02:19:12 +08:00
|
|
|
|
2016-11-25 19:44:23 +08:00
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate show -f json ' + name2))
|
|
|
|
self.assertNotIn(
|
|
|
|
"c='d'",
|
|
|
|
cmd_output['properties']
|
|
|
|
)
|
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"""
|
|
|
|
name = uuid.uuid4().hex
|
2016-11-22 02:19:12 +08:00
|
|
|
self.openstack(
|
2016-11-25 19:44:23 +08:00
|
|
|
'aggregate create ' + name)
|
|
|
|
self.addCleanup(self.openstack, 'aggregate delete ' + name)
|
|
|
|
|
|
|
|
# Get a host
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'host list -f json'))
|
|
|
|
host_name = cmd_output[0]['Host Name']
|
|
|
|
|
|
|
|
# Test add host
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate add host -f json ' +
|
|
|
|
name + ' ' +
|
|
|
|
host_name
|
|
|
|
))
|
|
|
|
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
|
|
|
|
cmd_output = json.loads(self.openstack(
|
|
|
|
'aggregate remove host -f json ' +
|
|
|
|
name + ' ' +
|
|
|
|
host_name
|
|
|
|
))
|
|
|
|
self.assertNotIn(
|
|
|
|
host_name,
|
|
|
|
cmd_output['hosts']
|
|
|
|
)
|