Add simple create/show/delete functional tests for all baremetal resources
Required adding support for min_microversion to the base test class. Change-Id: I0aeb2b5fcb4575938bfbb8d7ca9b29d1f77a2ee5
This commit is contained in:
parent
9dd1c62501
commit
ac8df03fd1
57
openstack/tests/functional/baremetal/base.py
Normal file
57
openstack/tests/functional/baremetal/base.py
Normal file
@ -0,0 +1,57 @@
|
||||
# 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 openstack.tests.functional import base
|
||||
|
||||
|
||||
class BaseBaremetalTest(base.BaseFunctionalTest):
|
||||
|
||||
min_microversion = None
|
||||
node_id = None
|
||||
|
||||
def setUp(self):
|
||||
super(BaseBaremetalTest, self).setUp()
|
||||
self.require_service('baremetal',
|
||||
min_microversion=self.min_microversion)
|
||||
|
||||
def create_chassis(self, **kwargs):
|
||||
chassis = self.conn.baremetal.create_chassis(**kwargs)
|
||||
self.addCleanup(
|
||||
lambda: self.conn.baremetal.delete_chassis(chassis.id,
|
||||
ignore_missing=True))
|
||||
return chassis
|
||||
|
||||
def create_node(self, driver='fake-hardware', **kwargs):
|
||||
node = self.conn.baremetal.create_node(driver=driver, **kwargs)
|
||||
self.node_id = node.id
|
||||
self.addCleanup(
|
||||
lambda: self.conn.baremetal.delete_node(self.node_id,
|
||||
ignore_missing=True))
|
||||
self.assertIsNotNone(self.node_id)
|
||||
return node
|
||||
|
||||
def create_port(self, node_id=None, **kwargs):
|
||||
node_id = node_id or self.node_id
|
||||
port = self.conn.baremetal.create_port(node_uuid=node_id, **kwargs)
|
||||
self.addCleanup(
|
||||
lambda: self.conn.baremetal.delete_port(port.id,
|
||||
ignore_missing=True))
|
||||
return port
|
||||
|
||||
def create_port_group(self, node_id=None, **kwargs):
|
||||
node_id = node_id or self.node_id
|
||||
port_group = self.conn.baremetal.create_port_group(node_uuid=node_id,
|
||||
**kwargs)
|
||||
self.addCleanup(
|
||||
lambda: self.conn.baremetal.delete_port_group(port_group.id,
|
||||
ignore_missing=True))
|
||||
return port_group
|
@ -0,0 +1,41 @@
|
||||
# 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 openstack import exceptions
|
||||
from openstack.tests.functional.baremetal import base
|
||||
|
||||
|
||||
class TestBareMetalChassis(base.BaseBaremetalTest):
|
||||
|
||||
def test_chassis_create_get_delete(self):
|
||||
chassis = self.create_chassis()
|
||||
|
||||
loaded = self.conn.baremetal.get_chassis(chassis.id)
|
||||
self.assertEqual(loaded.id, chassis.id)
|
||||
|
||||
self.conn.baremetal.delete_chassis(chassis, ignore_missing=False)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.get_chassis, chassis.id)
|
||||
|
||||
def test_chassis_negative_non_existing(self):
|
||||
uuid = "5c9dcd04-2073-49bc-9618-99ae634d8971"
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.get_chassis, uuid)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.find_chassis, uuid,
|
||||
ignore_missing=False)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.delete_chassis, uuid,
|
||||
ignore_missing=False)
|
||||
self.assertIsNone(self.conn.baremetal.find_chassis(uuid))
|
||||
self.assertIsNone(self.conn.baremetal.delete_chassis(uuid))
|
@ -11,28 +11,12 @@
|
||||
# under the License.
|
||||
|
||||
from openstack import exceptions
|
||||
from openstack.tests.functional import base
|
||||
from openstack.tests.functional.baremetal import base
|
||||
|
||||
|
||||
class TestBareMetalNode(base.BaseFunctionalTest):
|
||||
|
||||
node_id = None
|
||||
|
||||
def setUp(self):
|
||||
super(TestBareMetalNode, self).setUp()
|
||||
self.require_service('baremetal')
|
||||
|
||||
def tearDown(self):
|
||||
if self.node_id:
|
||||
self.conn.baremetal.delete_node(self.node_id, ignore_missing=True)
|
||||
super(TestBareMetalNode, self).tearDown()
|
||||
|
||||
class TestBareMetalNode(base.BaseBaremetalTest):
|
||||
def test_node_create_get_delete(self):
|
||||
node = self.conn.baremetal.create_node(driver='fake-hardware',
|
||||
name='node-name')
|
||||
self.node_id = node.id
|
||||
self.assertIsNotNone(self.node_id)
|
||||
|
||||
node = self.create_node(name='node-name')
|
||||
self.assertEqual(node.name, 'node-name')
|
||||
self.assertEqual(node.driver, 'fake-hardware')
|
||||
self.assertEqual(node.provision_state, 'available')
|
||||
@ -56,8 +40,7 @@ class TestBareMetalNode(base.BaseFunctionalTest):
|
||||
self.conn.baremetal.get_node, self.node_id)
|
||||
|
||||
def test_node_create_in_enroll_provide(self):
|
||||
node = self.conn.baremetal.create_node(driver='fake-hardware',
|
||||
provision_state='enroll')
|
||||
node = self.create_node(provision_state='enroll')
|
||||
self.node_id = node.id
|
||||
|
||||
self.assertEqual(node.driver, 'fake-hardware')
|
||||
|
50
openstack/tests/functional/baremetal/test_baremetal_port.py
Normal file
50
openstack/tests/functional/baremetal/test_baremetal_port.py
Normal file
@ -0,0 +1,50 @@
|
||||
# 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 openstack import exceptions
|
||||
from openstack.tests.functional.baremetal import base
|
||||
|
||||
|
||||
class TestBareMetalPort(base.BaseBaremetalTest):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBareMetalPort, self).setUp()
|
||||
self.node = self.create_node()
|
||||
|
||||
def test_port_create_get_delete(self):
|
||||
port = self.create_port(address='11:22:33:44:55:66')
|
||||
self.assertEqual(self.node_id, port.node_id)
|
||||
# Can be None if the microversion is too small, so we make sure it is
|
||||
# not False.
|
||||
self.assertNotEqual(port.is_pxe_enabled, False)
|
||||
self.assertIsNone(port.port_group_id)
|
||||
|
||||
loaded = self.conn.baremetal.get_port(port.id)
|
||||
self.assertEqual(loaded.id, port.id)
|
||||
|
||||
self.conn.baremetal.delete_port(port, ignore_missing=False)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.get_port, port.id)
|
||||
|
||||
def test_port_negative_non_existing(self):
|
||||
uuid = "5c9dcd04-2073-49bc-9618-99ae634d8971"
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.get_port, uuid)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.find_port, uuid,
|
||||
ignore_missing=False)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.delete_port, uuid,
|
||||
ignore_missing=False)
|
||||
self.assertIsNone(self.conn.baremetal.find_port(uuid))
|
||||
self.assertIsNone(self.conn.baremetal.delete_port(uuid))
|
@ -0,0 +1,48 @@
|
||||
# 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 openstack import exceptions
|
||||
from openstack.tests.functional.baremetal import base
|
||||
|
||||
|
||||
class TestBareMetalPortGroup(base.BaseBaremetalTest):
|
||||
|
||||
min_microversion = '1.23'
|
||||
|
||||
def setUp(self):
|
||||
super(TestBareMetalPortGroup, self).setUp()
|
||||
self.node = self.create_node()
|
||||
|
||||
def test_port_group_create_get_delete(self):
|
||||
port_group = self.create_port_group()
|
||||
|
||||
loaded = self.conn.baremetal.get_port_group(port_group.id)
|
||||
self.assertEqual(loaded.id, port_group.id)
|
||||
|
||||
self.conn.baremetal.delete_port_group(port_group,
|
||||
ignore_missing=False)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.get_port_group, port_group.id)
|
||||
|
||||
def test_port_group_negative_non_existing(self):
|
||||
uuid = "5c9dcd04-2073-49bc-9618-99ae634d8971"
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.get_port_group, uuid)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.find_port_group, uuid,
|
||||
ignore_missing=False)
|
||||
self.assertRaises(exceptions.NotFoundException,
|
||||
self.conn.baremetal.delete_port_group, uuid,
|
||||
ignore_missing=False)
|
||||
self.assertIsNone(self.conn.baremetal.find_port_group(uuid))
|
||||
self.assertIsNone(self.conn.baremetal.delete_port_group(uuid))
|
@ -13,6 +13,7 @@
|
||||
import os
|
||||
import openstack.config
|
||||
|
||||
from keystoneauth1 import discover
|
||||
from keystoneauth1 import exceptions as _exceptions
|
||||
from openstack import connection
|
||||
from openstack.tests import base
|
||||
@ -51,7 +52,7 @@ class BaseFunctionalTest(base.TestCase):
|
||||
|
||||
# TODO(shade) Replace this with call to conn.has_service when we've merged
|
||||
# the shade methods into Connection.
|
||||
def require_service(self, service_type, **kwargs):
|
||||
def require_service(self, service_type, min_microversion=None, **kwargs):
|
||||
"""Method to check whether a service exists
|
||||
|
||||
Usage:
|
||||
@ -64,7 +65,20 @@ class BaseFunctionalTest(base.TestCase):
|
||||
:returns: True if the service exists, otherwise False.
|
||||
"""
|
||||
try:
|
||||
self.conn.session.get_endpoint(service_type=service_type, **kwargs)
|
||||
data = self.conn.session.get_endpoint_data(
|
||||
service_type=service_type, **kwargs)
|
||||
except _exceptions.EndpointNotFound:
|
||||
self.skipTest('Service {service_type} not found in cloud'.format(
|
||||
service_type=service_type))
|
||||
|
||||
if not min_microversion:
|
||||
return
|
||||
|
||||
if not (data.min_microversion and data.max_microversion and
|
||||
discover.version_between(data.min_microversion,
|
||||
data.max_microversion,
|
||||
min_microversion)):
|
||||
self.skipTest('Service {service_type} does not provide '
|
||||
'microversion {ver}'.format(
|
||||
service_type=service_type,
|
||||
ver=min_microversion))
|
||||
|
Loading…
Reference in New Issue
Block a user