Tests for exposing conductors

Add tests for the API change of exposed conductors.

Story: 1724474
Task: 28565

Change-Id: Ib0c3855ce8a65a530a2530094d11f497fb2e3023
This commit is contained in:
Kaifeng Wang 2018-12-18 14:22:39 +08:00
parent 31c97f9c95
commit 4f21307528
3 changed files with 100 additions and 0 deletions

View File

@ -103,6 +103,11 @@ class BaremetalClient(base.BaremetalClient):
"""List all existing drivers."""
return self._list_request('drivers')
@base.handle_errors
def list_conductors(self, **kwargs):
"""List all registered conductors."""
return self._list_request('conductors', **kwargs)
@base.handle_errors
def show_node(self, uuid, api_version=None):
"""Gets a specific node.
@ -199,6 +204,14 @@ class BaremetalClient(base.BaremetalClient):
"""
return self._show_request('drivers', driver_name)
def show_conductor(self, hostname):
"""Gets a specific conductor.
:param hostname: Hostname of conductor.
:return: Serialized conductor as a dictionary.
"""
return self._show_request('conductors', hostname)
@base.handle_errors
def create_node(self, chassis_id=None, **kwargs):
"""Create a baremetal node with the specified parameters.

View File

@ -0,0 +1,56 @@
# 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.
from tempest import config
from tempest.lib import decorators
from ironic_tempest_plugin.tests.api.admin import base
CONF = config.CONF
class TestConductors(base.BaseBaremetalTest):
"""Tests for conductors."""
min_microversion = '1.49'
@decorators.idempotent_id('b6d62be4-53a6-43c6-ae78-bff9d1b4efc1')
def test_list_conductors(self):
_, conductors = self.client.list_conductors()
self.assertTrue(len(conductors['conductors']) > 0)
cond = conductors['conductors'].pop()
self.assertIn('hostname', cond)
self.assertIn('conductor_group', cond)
self.assertIn('alive', cond)
self.assertNotIn('drivers', cond)
@decorators.idempotent_id('ca3de366-d80a-4e97-b19b-42d594e8d148')
def test_list_conductors_detail(self):
_, conductors = self.client.list_conductors(detail=True)
self.assertTrue(len(conductors['conductors']) > 0)
cond = conductors['conductors'].pop()
self.assertIn('hostname', cond)
self.assertIn('conductor_group', cond)
self.assertIn('alive', cond)
self.assertIn('drivers', cond)
@decorators.idempotent_id('7e1829e2-3945-4508-a3d9-c8ebe9463fd8')
def test_show_conductor(self):
_, conductors = self.client.list_conductors()
self.assertTrue(len(conductors['conductors']) > 0)
conductor = conductors['conductors'].pop()
_, conductor = self.client.show_conductor(conductor['hostname'])
self.assertIn('hostname', conductor)
self.assertIn('conductor_group', conductor)
self.assertIn('alive', conductor)
self.assertIn('drivers', conductor)

View File

@ -170,6 +170,11 @@ class TestNodes(base.BaseBaremetalTest):
_, loaded_node = self.client.show_node(self.node['uuid'])
self.assertNotIn('fault', loaded_node)
@decorators.idempotent_id('e5470656-bb65-4173-be83-2df3fc9aed24')
def test_conductor_hidden(self):
_, loaded_node = self.client.show_node(self.node['uuid'])
self.assertNotIn('conductor', loaded_node)
class TestNodesResourceClass(base.BaseBaremetalTest):
@ -944,3 +949,29 @@ class TestNodesProtectedOldApi(base.BaseBaremetalTest):
self.client.update_node, self.node['uuid'], protected=True)
# 400 for old ironic, 406 for new ironic with old microversion.
self.assertIn(exc.resp.status, (400, 406))
class TestNodeConductor(base.BaseBaremetalTest):
"""Tests for conductor field of baremetal nodes."""
min_microversion = '1.49'
def setUp(self):
super(TestNodeConductor, self).setUp()
_, self.chassis = self.create_chassis()
_, self.node = self.create_node(self.chassis['uuid'])
@decorators.idempotent_id('1af888b2-2a19-43da-8181-a5381d6ff536')
def test_conductor_exposed(self):
_, loaded_node = self.client.show_node(self.node['uuid'])
self.assertIn('conductor', loaded_node)
@decorators.idempotent_id('53bcef99-2989-4755-aa8f-c31037cd15de')
def test_list_nodes_by_conductor(self):
_, loaded_node = self.client.show_node(self.node['uuid'])
hostname = loaded_node['conductor']
_, nodes = self.client.list_nodes(conductor=hostname)
self.assertIn(self.node['uuid'],
[n['uuid'] for n in nodes['nodes']])