Functional tests for port groups in ironicclient
Add sanity tests for the following commands: portgroup-create, portgroup-delete, portgroup-list, portgroup-show, portgroup-update, portgroup-port-list. Portgroup API works since microversion 1.25. Closes-Bug: #1562035 Change-Id: If629ba39d07c1a999d60c70b343619179bb3447e
This commit is contained in:
parent
2c5d112a2d
commit
e8daa4795c
@ -31,6 +31,8 @@ class FunctionalTestBase(base.ClientTestBase):
|
||||
def setUp(self):
|
||||
super(FunctionalTestBase, self).setUp()
|
||||
self.client = self._get_clients()
|
||||
# NOTE(kromanenko) set ironic api version for portgroups
|
||||
self.pg_api_ver = '--ironic-api-version 1.25'
|
||||
|
||||
def _get_clients(self):
|
||||
# NOTE(aarefiev): {toxinidir} is a current working directory, so
|
||||
@ -373,8 +375,64 @@ class FunctionalTestBase(base.ClientTestBase):
|
||||
port_list = self.list_ports()
|
||||
return [x['UUID'] for x in port_list]
|
||||
|
||||
def update_port(self, port_id, operation, params=''):
|
||||
def update_port(self, port_id, operation, flags='', params=''):
|
||||
updated_port = self.ironic('port-update',
|
||||
flags=flags,
|
||||
params='{0} {1} {2}'
|
||||
.format(port_id, operation, params))
|
||||
return utils.get_dict_from_output(updated_port)
|
||||
|
||||
def create_portgroup(self, node_id, params=''):
|
||||
"""Create a new portgroup."""
|
||||
portgroup = self.ironic('portgroup-create',
|
||||
flags=self.pg_api_ver,
|
||||
params='--node {0} {1}'
|
||||
.format(node_id, params))
|
||||
if not portgroup:
|
||||
self.fail('Ironic portgroup failed to create!')
|
||||
portgroup = utils.get_dict_from_output(portgroup)
|
||||
self.addCleanup(self.delete_portgroup, portgroup['uuid'],
|
||||
ignore_exceptions=True)
|
||||
return portgroup
|
||||
|
||||
def delete_portgroup(self, portgroup_id, ignore_exceptions=False):
|
||||
"""Delete a port group."""
|
||||
try:
|
||||
self.ironic('portgroup-delete',
|
||||
flags=self.pg_api_ver,
|
||||
params=portgroup_id)
|
||||
except exceptions.CommandFailed:
|
||||
if not ignore_exceptions:
|
||||
raise
|
||||
|
||||
def list_portgroups(self, params=''):
|
||||
"""List the port groups."""
|
||||
return self.ironic('portgroup-list',
|
||||
flags=self.pg_api_ver,
|
||||
params=params)
|
||||
|
||||
def show_portgroup(self, portgroup_id, params=''):
|
||||
"""Show detailed information about a port group."""
|
||||
portgroup_show = self.ironic('portgroup-show',
|
||||
flags=self.pg_api_ver,
|
||||
params='{0} {1}'
|
||||
.format(portgroup_id, params))
|
||||
return utils.get_dict_from_output(portgroup_show)
|
||||
|
||||
def update_portgroup(self, portgroup_id, op, params=''):
|
||||
"""Update information about a port group."""
|
||||
updated_portgroup = self.ironic('portgroup-update',
|
||||
flags=self.pg_api_ver,
|
||||
params='{0} {1} {2}'
|
||||
.format(portgroup_id, op, params))
|
||||
return utils.get_dict_from_output(updated_portgroup)
|
||||
|
||||
def get_portgroup_uuids_from_portgroup_list(self):
|
||||
"""Get UUIDs from list of port groups."""
|
||||
portgroup_list = self.list_portgroups()
|
||||
return [x['UUID'] for x in portgroup_list]
|
||||
|
||||
def portgroup_port_list(self, portgroup_id, params=''):
|
||||
"""List the ports associated with a port group."""
|
||||
return self.ironic('portgroup-port-list', flags=self.pg_api_ver,
|
||||
params='{0} {1}'.format(portgroup_id, params))
|
||||
|
114
ironicclient/tests/functional/test_portgroup.py
Normal file
114
ironicclient/tests/functional/test_portgroup.py
Normal file
@ -0,0 +1,114 @@
|
||||
# Copyright (c) 2016 Mirantis, Inc.
|
||||
#
|
||||
# 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 ironicclient.tests.functional import base
|
||||
|
||||
|
||||
class PortGroupSanityTest(base.FunctionalTestBase):
|
||||
"""Sanity tests for testing actions with port groups.
|
||||
|
||||
Smoke test for the Ironic CLI port group subcommands:
|
||||
create, show, update, delete, list, port-list.
|
||||
"""
|
||||
def setUp(self):
|
||||
super(PortGroupSanityTest, self).setUp()
|
||||
self.node = self.create_node()
|
||||
self.port_group = self.create_portgroup(self.node['uuid'])
|
||||
|
||||
def test_portgroup_create(self):
|
||||
"""Test steps:
|
||||
|
||||
1) Create node and port group in setUp().
|
||||
2) Check that port group has been successfully created.
|
||||
"""
|
||||
portgroup_list_uuid = self.get_portgroup_uuids_from_portgroup_list()
|
||||
self.assertIn(self.port_group['uuid'], portgroup_list_uuid)
|
||||
|
||||
def test_portgroup_delete(self):
|
||||
"""Test steps:
|
||||
|
||||
1) Create node and port group in setUp().
|
||||
2) Delete port group.
|
||||
3) Check that port group has been successfully deleted.
|
||||
"""
|
||||
self.delete_portgroup(self.port_group['uuid'])
|
||||
portgroup_list_uuid = self.get_portgroup_uuids_from_portgroup_list()
|
||||
self.assertNotIn(self.port_group['uuid'], portgroup_list_uuid)
|
||||
|
||||
def test_portgroup_show(self):
|
||||
"""Test steps:
|
||||
|
||||
1) Create node and port group in setUp().
|
||||
2) Check that portgroup-show returns the same UUID as portgroup-create.
|
||||
"""
|
||||
portgroup_show = self.show_portgroup(self.port_group['uuid'])
|
||||
self.assertEqual(self.port_group['uuid'], portgroup_show['uuid'])
|
||||
self.assertEqual(self.port_group['name'], portgroup_show['name'])
|
||||
|
||||
def test_portgroup_list(self):
|
||||
"""Test steps:
|
||||
|
||||
1) Create node and port group in setUp().
|
||||
2) Create one more node and port group.
|
||||
3) Check that portgroup-list contains UUIDs
|
||||
of all created port groups.
|
||||
"""
|
||||
other_node = self.create_node()
|
||||
other_portgroup = self.create_portgroup(other_node['uuid'])
|
||||
|
||||
uuids = {x['UUID'] for x in self.list_portgroups()}
|
||||
|
||||
self.assertTrue({self.port_group['uuid'],
|
||||
other_portgroup['uuid']}.issubset(uuids))
|
||||
|
||||
def test_portgroup_update(self):
|
||||
"""Test steps:
|
||||
|
||||
1) Create node and port group in setUp().
|
||||
2) Create node to replace.
|
||||
3) Set new node to maintenance.
|
||||
4) Update port group by replacing node.
|
||||
5) Check that port group has been successfully updated.
|
||||
"""
|
||||
node_to_replace = self.create_node()
|
||||
self.set_node_maintenance(node_to_replace['uuid'], True)
|
||||
updated_portgroup = self.update_portgroup(
|
||||
self.port_group['uuid'], 'replace', params='node_uuid={0}'
|
||||
.format(node_to_replace['uuid'])
|
||||
)
|
||||
self.assertEqual(node_to_replace['uuid'],
|
||||
updated_portgroup['node_uuid'])
|
||||
self.assertNotEqual(self.port_group['node_uuid'],
|
||||
updated_portgroup['node_uuid'])
|
||||
|
||||
def test_portgroup_port_list(self):
|
||||
"""Test steps:
|
||||
|
||||
1) Create node and port group in setUp().
|
||||
2) Create a port.
|
||||
3) Set node to maintenance.
|
||||
4) Attach port to the port group.
|
||||
5) List the ports associated with a port group.
|
||||
6) Check port UUID in list.
|
||||
7) Check port address in list.
|
||||
"""
|
||||
port = self.create_port(self.node['uuid'])
|
||||
self.set_node_maintenance(self.node['uuid'], True)
|
||||
self.update_port(port['uuid'], 'replace',
|
||||
flags='--ironic-api-version 1.25',
|
||||
params='portgroup_uuid={0}'
|
||||
.format(self.port_group['uuid']))
|
||||
pg_port_list = self.portgroup_port_list(self.port_group['uuid'])
|
||||
self.assertIn(port['uuid'], [x['UUID'] for x in pg_port_list])
|
||||
self.assertIn(port['address'], [x['Address'] for x in pg_port_list])
|
Loading…
Reference in New Issue
Block a user