Merge "Add basic tests for OSC plugin baremetal node commands"

This commit is contained in:
Jenkins 2016-11-17 00:11:37 +00:00 committed by Gerrit Code Review
commit ea433420d9
5 changed files with 217 additions and 0 deletions

View File

@ -0,0 +1,97 @@
# 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 json
from tempest.lib.common.utils import data_utils
from tempest.lib import exceptions
from ironicclient.tests.functional import base
class TestCase(base.FunctionalTestBase):
def openstack(self, *args, **kwargs):
return self.clients.openstack(*args, **kwargs)
def get_opts(self, fields=None, output_format='json'):
"""Get options for OSC output fields format.
:param List fields: List of fields to get
:param String output_format: Select output format
:return: String of formatted options
"""
if not fields:
return ' -f {0}'.format(output_format)
return ' -f {0} {1}'.format(output_format,
' '.join(['-c ' + it for it in fields]))
def node_create(self, driver='fake', name=None, params=''):
"""Create baremetal node and add cleanup.
:param String driver: Driver for a new node
:param String name: Name for a new node
:param String params: Additional args and kwargs
:return: JSON object of created node
"""
if not name:
name = data_utils.rand_name('baremetal')
opts = self.get_opts()
output = self.openstack('baremetal node create {0} '
'--driver {1} --name {2} {3}'
.format(opts, driver, name, params))
self.addCleanup(self.node_delete, name, True)
if not output:
self.fail('Baremetal node has not been created!')
return json.loads(output)
def node_list(self, fields=None, params=''):
"""List baremetal nodes.
:param List fields: List of fields to show
:param String params: Additional kwargs
:return: list of JSON node objects
"""
opts = self.get_opts(fields=fields)
output = self.openstack('baremetal node list {0} {1}'
.format(opts, params))
return json.loads(output)
def node_show(self, identifier, fields=None, params=''):
"""Show specified baremetal node.
:param String identifier: Name or UUID of the node
:param List fields: List of fields to show
:param List params: Additional kwargs
:return: JSON object of node
"""
opts = self.get_opts(fields)
output = self.openstack('baremetal node show {0} {1} {2}'
.format(opts, identifier, params))
return json.loads(output)
def node_delete(self, identifier, ignore_exceptions=False):
"""Try to delete baremetal node by name or UUID.
:param String identifier: Name or UUID of the node
:param Bool ignore_exceptions: Ignore exception (needed for cleanUp)
:return: raw values output
"""
try:
return self.openstack('baremetal node delete {0}'
.format(identifier))
except exceptions.CommandFailed:
if not ignore_exceptions:
raise

View File

@ -0,0 +1,119 @@
# 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.
import ddt
from tempest.lib.common.utils import data_utils
from ironicclient.tests.functional.osc.v1 import base
@ddt.ddt
class BaremetalNodeTests(base.TestCase):
"""Functional tests for baremetal node commands."""
def setUp(self):
super(BaremetalNodeTests, self).setUp()
self.node = self.node_create()
def test_create_name_uuid(self):
"""Check baremetal node create command with name and UUID.
Test steps:
1) Create baremetal node in setUp.
2) Create one more baremetal node explicitly
with specified name and UUID.
3) Check that node successfully created.
"""
uuid = data_utils.rand_uuid()
name = data_utils.rand_name('baremetal-node')
node_info = self.node_create(name=name,
params='--uuid {0}'.format(uuid))
self.assertEqual(node_info['uuid'], uuid)
self.assertEqual(node_info['name'], name)
self.assertEqual(node_info['driver'], 'fake')
self.assertEqual(node_info['maintenance'], False)
node_list = self.node_list()
self.assertIn(uuid, [x['UUID'] for x in node_list])
self.assertIn(name, [x['Name'] for x in node_list])
@ddt.data('name', 'uuid')
def test_delete(self, key):
"""Check baremetal node delete command with name/UUID argument.
Test steps:
1) Create baremetal node in setUp.
2) Delete baremetal node by name/UUID.
3) Check that node deleted successfully.
"""
output = self.node_delete(self.node[key])
self.assertIn('Deleted node {0}'.format(self.node[key]), output)
node_list = self.node_list()
self.assertNotIn(self.node['name'], [x['Name'] for x in node_list])
self.assertNotIn(self.node['uuid'], [x['UUID'] for x in node_list])
def test_list(self):
"""Check baremetal node list command.
Test steps:
1) Create baremetal node in setUp.
2) List baremetal nodes.
3) Check node name in nodes list.
"""
node_list = self.node_list()
self.assertIn(self.node['name'], [x['Name'] for x in node_list])
self.assertIn(self.node['uuid'], [x['UUID'] for x in node_list])
@ddt.data('name', 'uuid')
def test_set(self, key):
"""Check baremetal node set command calling it by name/UUID.
Test steps:
1) Create baremetal node in setUp.
2) Set another name for node calling it by name/UUID.
3) Check that baremetal node name was changed.
"""
new_name = data_utils.rand_name('newnodename')
self.openstack('baremetal node set --name {0} {1}'
.format(new_name, self.node[key]))
show_prop = self.node_show(self.node['uuid'], ['name'])
self.assertEqual(new_name, show_prop['name'])
@ddt.data('name', 'uuid')
def test_unset(self, key):
"""Check baremetal node unset command calling it by node name/UUID.
Test steps:
1) Create baremetal node in setUp.
2) Unset name of baremetal node calling it by node name/UUID.
3) Check that node has no more name.
"""
self.openstack('baremetal node unset --name {0}'
.format(self.node[key]))
show_prop = self.node_show(self.node['uuid'], ['name'])
self.assertIsNone(show_prop['name'])
@ddt.data('name', 'uuid')
def test_show(self, key):
"""Check baremetal node show command with name and UUID arguments.
Test steps:
1) Create baremetal node in setUp.
2) Show baremetal node calling it with name and UUID arguments.
3) Check name, uuid and driver in node show output.
"""
node = self.node_show(self.node[key],
['name', 'uuid', 'driver'])
self.assertEqual(self.node['name'], node['name'])
self.assertEqual(self.node['uuid'], node['uuid'])
self.assertEqual(self.node['driver'], node['driver'])

View File

@ -16,3 +16,4 @@ sphinx!=1.3b1,<1.4,>=1.2.1 # BSD
testtools>=1.4.0 # MIT
tempest>=12.1.0 # Apache-2.0
os-testr>=0.8.0 # Apache-2.0
ddt>=1.0.1 # MIT