Functional tests for host APIs
This patch adds functional tests to check the behaviour of host APIs. Change-Id: Iea2769bce4ceaea34d6d52e97c7e29cb8606ca71
This commit is contained in:
parent
0fa59ab7ed
commit
1b04778308
|
@ -0,0 +1,168 @@
|
|||
# Copyright (C) 2019 NTT DATA
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# 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 ddt
|
||||
|
||||
from masakari.objects import fields
|
||||
from masakari.tests.functional import base
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestHosts(base.BaseFunctionalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestHosts, self).setUp()
|
||||
|
||||
if not self.hypervisors:
|
||||
self.skipTest("Skipped as there are no hypervisors "
|
||||
"configured in nova")
|
||||
|
||||
# Create segment
|
||||
self.segment = self.conn.ha.create_segment(
|
||||
name=self.getUniqueString(),
|
||||
recovery_method=fields.FailoverSegmentRecoveryMethod.AUTO,
|
||||
service_type='COMPUTE')
|
||||
|
||||
# Delete segment which deletes host/s associated with it
|
||||
self.addCleanup(self.conn.ha.delete_segment, self.segment.uuid)
|
||||
|
||||
def test_create_get(self):
|
||||
# This test is for testing hosts create/get
|
||||
# Create valid host
|
||||
host_name = self.hypervisors[0]['hypervisor_hostname']
|
||||
host_data = {'name': host_name,
|
||||
'type': 'COMPUTE',
|
||||
'on_maintenance': False,
|
||||
'reserved': False,
|
||||
'control_attributes': 'SSH'}
|
||||
|
||||
host = self.conn.ha.create_host(self.segment.uuid, **host_data)
|
||||
|
||||
self.assertDictContainsSubset(host_data, host)
|
||||
|
||||
result = self.conn.ha.get_host(host.uuid, self.segment.uuid)
|
||||
|
||||
self.assertEqual('COMPUTE', result.type)
|
||||
self.assertEqual(False, result.on_maintenance)
|
||||
self.assertEqual(False, result.reserved)
|
||||
self.assertEqual('SSH', result.control_attributes)
|
||||
|
||||
def test_list(self):
|
||||
# This test is for testing host/s creation and listing the same.
|
||||
|
||||
expected_hosts = []
|
||||
for host in self.hypervisors:
|
||||
host_obj = self.conn.ha.create_host(segment_id=self.segment.uuid,
|
||||
name=host.hypervisor_hostname,
|
||||
type='COMPUTE',
|
||||
on_maintenance=False,
|
||||
reserved=False,
|
||||
control_attributes='SSH')
|
||||
|
||||
# Deleting 'segment_id' as in GET list call of host 'segment_id'
|
||||
# is not there in response
|
||||
del host_obj['segment_id']
|
||||
expected_hosts.append(host_obj)
|
||||
|
||||
hosts = self.conn.ha.hosts(self.segment.uuid)
|
||||
self.assertItemsEqual(expected_hosts, hosts)
|
||||
|
||||
@ddt.data(
|
||||
{'on_maintenance': False, 'host_type': 'COMPUTE', 'reserved': False,
|
||||
'control_attributes': 'SSH'},
|
||||
{'on_maintenance': True, 'host_type': 'CONTROLLER', 'reserved': True,
|
||||
'control_attributes': 'TCP'}
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_create_list_with_filter(self, on_maintenance,
|
||||
host_type, reserved, control_attributes):
|
||||
# This test is for testing host/s creation and listing
|
||||
# the same based on filters.
|
||||
if len(self.hypervisors) == 1:
|
||||
self.skipTest("Skipped as there is only one hypervisor "
|
||||
"configured in nova")
|
||||
|
||||
host_data_1 = {'name': self.hypervisors[0].hypervisor_hostname,
|
||||
'type': 'COMPUTE',
|
||||
'on_maintenance': False,
|
||||
'reserved': False,
|
||||
'control_attributes': 'SSH'}
|
||||
|
||||
host_data_2 = {'name': self.hypervisors[1].hypervisor_hostname,
|
||||
'type': 'CONTROLLER',
|
||||
'on_maintenance': True,
|
||||
'reserved': True,
|
||||
'control_attributes': 'TCP'}
|
||||
|
||||
self.conn.ha.create_host(self.segment.uuid, **host_data_1)
|
||||
self.conn.ha.create_host(self.segment.uuid, **host_data_2)
|
||||
|
||||
expected_host_data = {'on_maintenance': on_maintenance,
|
||||
'type': host_type,
|
||||
'reserved': reserved,
|
||||
'control_attributes': control_attributes
|
||||
}
|
||||
|
||||
# Returns list of hosts based on filters
|
||||
for host in self.conn.ha.hosts(self.segment.uuid,
|
||||
on_maintenance=on_maintenance,
|
||||
type=host_type,
|
||||
reserved=reserved):
|
||||
|
||||
self.assertDictContainsSubset(expected_host_data, host)
|
||||
|
||||
def test_update_get_delete(self):
|
||||
# This test is for updating created host and deletion of same
|
||||
host_name = self.hypervisors[0]['hypervisor_hostname']
|
||||
|
||||
host = self.conn.ha.create_host(segment_id=self.segment.uuid,
|
||||
name=host_name,
|
||||
on_maintenance='False',
|
||||
reserved='False',
|
||||
type='COMPUTE',
|
||||
control_attributes='SSH')
|
||||
|
||||
self.conn.ha.update_host(host['uuid'],
|
||||
segment_id=self.segment.uuid,
|
||||
on_maintenance='True',
|
||||
control_attributes='TCP',
|
||||
reserved='True')
|
||||
|
||||
result = self.conn.ha.get_host(host.uuid,
|
||||
host.failover_segment_id)
|
||||
# Confirm host update
|
||||
self.assertEqual(True, result.on_maintenance)
|
||||
self.assertEqual(True, result.reserved)
|
||||
self.assertEqual('TCP', result.control_attributes)
|
||||
|
||||
def test_update_host_name(self):
|
||||
# This test is for updating host name
|
||||
if len(self.hypervisors) == 1:
|
||||
self.skipTest("Skipped as there is only one hypervisor "
|
||||
"configured in nova")
|
||||
|
||||
host = self.conn.ha.create_host(segment_id=self.segment.uuid,
|
||||
name=self.hypervisors[0]['hypervisor_hostname'],
|
||||
type='COMPUTE',
|
||||
control_attributes='SSH')
|
||||
|
||||
# Update host name
|
||||
updated_host = self.conn.ha.update_host(host['uuid'],
|
||||
segment_id=self.segment.uuid,
|
||||
name=self.hypervisors[1]['hypervisor_hostname'])
|
||||
|
||||
result = self.conn.ha.get_host(host.uuid,
|
||||
host.failover_segment_id)
|
||||
self.assertEqual(result.name, updated_host.name)
|
Loading…
Reference in New Issue