Additional unit tests related to puppet configuration

This allows puppet unit test permutations for:
 IPv4 vs IPv6
 Controller / Worker / Storage / AIO
 CephBackend

This changes the unit test count for test_puppet from 5 to 45.
This alters the test_interface classes to have a slightly
different class hierarchy.

Change-Id: I83b04686e2d5b6976b3d7926e98d0507512220de
Story: 2005939
Task: 36055
Signed-off-by: Al Bailey <Al.Bailey@windriver.com>
This commit is contained in:
Al Bailey 2019-08-01 10:23:25 -05:00
parent 1d24b7f50e
commit 81cdfcecee
3 changed files with 129 additions and 91 deletions

View File

@ -24,6 +24,7 @@ from sysinv.common import constants
from sysinv.common import utils
from sysinv.openstack.common import context
from sysinv.openstack.common import uuidutils
from sysinv.tests import base
from sysinv.tests.db import utils as dbutils
@ -63,6 +64,34 @@ class BaseIPv6Mixin(object):
nameservers = ['2001:4860:4860::8888', '2001:4860:4860::8844']
class BaseCephStorageBackendMixin(object):
def setUp(self):
super(BaseCephStorageBackendMixin, self).setUp()
self._setup_ceph_backend()
# setup one or more storage monitors
self.mon_index = 0
self._create_storage_mon(self.host.hostname, self.host.id)
def _setup_ceph_backend(self, **kwargs):
kwargs['forisystemid'] = self.system['id']
t = dbutils.get_test_storage_tier()
kwargs['tier_id'] = t['id']
n = dbutils.get_test_ceph_storage_backend(**kwargs)
self.dbapi.storage_ceph_create(n)
def _create_storage_mon(self, hostname, ihost_id):
self.mon_index += 1
ceph_mon_dict = dbutils.get_test_mon(
id=self.mon_index,
uuid=uuidutils.generate_uuid(),
state=constants.SB_STATE_CONFIGURED,
task=constants.SB_TASK_NONE,
forihostid=ihost_id,
hostname=hostname)
return self.dbapi.ceph_mon_create(ceph_mon_dict)
@six.add_metaclass(abc.ABCMeta)
class BaseSystemTestCase(BaseIPv4Mixin, DbTestCase):
system_type = constants.TIS_STD_BUILD
@ -75,6 +104,21 @@ class BaseSystemTestCase(BaseIPv4Mixin, DbTestCase):
self.hosts = []
self.address_pools = []
self.networks = []
self._create_test_common()
def tearDown(self):
super(BaseSystemTestCase, self).tearDown()
self.system = None
self.load = None
self.drbd = None
self.remotelogging = None
self.user = None
self.dns = None
self.ntp = None
self.ptp = None
self.hosts = []
self.address_pools = []
self.networks = []
def _create_test_common(self):
self._create_test_system()
@ -228,6 +272,9 @@ class BaseHostTestCase(BaseSystemTestCase):
root_disk_device_node = '/dev/sda'
root_disk_device_type = constants.DEVICE_TYPE_SSD
def setUp(self):
super(BaseHostTestCase, self).setUp()
def _create_test_host(self, personality, subfunction=None, numa_nodes=1):
subfunctions = [personality]
if subfunction:
@ -286,8 +333,7 @@ class ControllerHostTestCase(BaseHostTestCase):
def setUp(self):
super(ControllerHostTestCase, self).setUp()
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
self._create_test_host_cpus(self.host, platform=16)
@ -295,7 +341,6 @@ class WorkerHostTestCase(BaseHostTestCase):
def setUp(self):
super(WorkerHostTestCase, self).setUp()
self._create_test_common()
self.host = self._create_test_host(constants.WORKER)
self._create_test_host_cpus(self.host, platform=1, vswitch=2, application=12)
self._create_test_host_addresses(self.host)
@ -305,7 +350,6 @@ class StorageHostTestCase(BaseHostTestCase):
def setUp(self):
super(StorageHostTestCase, self).setUp()
self._create_test_common()
self.host = self._create_test_host(constants.STORAGE)
self._create_test_host_cpus(self.host, platform=8)
self._create_test_host_addresses(self.host)
@ -317,7 +361,6 @@ class AIOHostTestCase(BaseHostTestCase):
def setUp(self):
super(AIOHostTestCase, self).setUp()
self._create_test_common()
self.host = self._create_test_host(constants.CONTROLLER, constants.WORKER)
self._create_test_host_cpus(self.host, platform=2, vswitch=2, application=11)

View File

@ -32,19 +32,10 @@ NETWORKTYPES_WITH_V4_ROUTES = [constants.NETWORK_TYPE_DATA]
NETWORKTYPES_WITH_V6_ROUTES = [constants.NETWORK_TYPE_DATA]
class BaseTestCase(base.PuppetTestCaseMixin, dbbase.BaseHostTestCase):
def setUp(self):
super(BaseTestCase, self).setUp()
self.ports = []
self.interfaces = []
self.addresses = []
self.routes = []
def _setup_configuration(self):
# Create a single system and host for basic functional test
self._create_test_common()
self.host = self._create_test_host(constants.CONTROLLER)
class InterfaceTestCaseMixin(base.PuppetTestCaseMixin):
""" This InterfaceTestCaseMixin needs to be used with a subclass
of BaseHostTestCase
"""
def assertIn(self, needle, haystack, message=''):
"""Custom assertIn that handles object comparison"""
@ -52,7 +43,7 @@ class BaseTestCase(base.PuppetTestCaseMixin, dbbase.BaseHostTestCase):
# compare objects based on unique DB identifier
needle = needle.id
haystack = [o.id for o in haystack]
super(BaseTestCase, self).assertIn(needle, haystack, message)
super(InterfaceTestCaseMixin, self).assertIn(needle, haystack, message)
def assertEqual(self, expected, observed, message=''):
"""Custom assertEqual that handles object comparison"""
@ -60,7 +51,7 @@ class BaseTestCase(base.PuppetTestCaseMixin, dbbase.BaseHostTestCase):
isinstance(observed, objbase.SysinvObject)):
expected = expected.id
observed = observed.id
super(BaseTestCase, self).assertEqual(expected, observed, message)
super(InterfaceTestCaseMixin, self).assertEqual(expected, observed, message)
def _setup_address_and_routes(self, iface):
if not iface['ifclass'] or iface['ifclass'] == constants.INTERFACE_CLASS_NONE:
@ -267,8 +258,7 @@ class BaseTestCase(base.PuppetTestCaseMixin, dbbase.BaseHostTestCase):
'forisystemid': self.system.id,
'subfunctions': ",".join(subfunctions)}
self.host = dbutils.create_test_ihost(**host)
return host
return dbutils.create_test_ihost(**host)
@puppet.puppet_context
def _update_context(self):
@ -279,15 +269,26 @@ class BaseTestCase(base.PuppetTestCaseMixin, dbbase.BaseHostTestCase):
self.operator.context.update(self.context)
def _setup_context(self):
self.ports = []
self.interfaces = []
self.addresses = []
self.routes = []
self._setup_configuration()
self._update_context()
def _setup_configuration(self):
pass
class InterfaceTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase):
def setUp(self):
super(InterfaceTestCase, self).setUp()
self._setup_context()
class InterfaceTestCase(BaseTestCase):
def _setup_configuration(self):
# Create a single port/interface for basic function testing
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
self.port, self.iface = self._create_ethernet_test(
"mgmt0", constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_MGMT)
@ -302,10 +303,6 @@ class InterfaceTestCase(BaseTestCase):
self.iface.save(self.admin_context)
super(InterfaceTestCase, self)._update_context()
def setUp(self):
super(InterfaceTestCase, self).setUp()
self._setup_context()
def test_is_platform_network_type_true(self):
self.iface['ifclass'] = constants.INTERFACE_CLASS_PLATFORM
self.iface['networktype'] = constants.NETWORK_TYPE_MGMT
@ -1365,18 +1362,7 @@ class InterfaceTestCase(BaseTestCase):
return port, iface
class InterfaceHostTestCase(BaseTestCase):
def _setup_configuration(self):
# Personality is set to worker to avoid issues due to missing OAM
# interface in this empty/dummy configuration
self._create_test_common()
self._create_test_host(constants.WORKER)
def _update_context(self):
# ensure DB entries are updated prior to updating the context which
# will re-read the entries from the DB.
self.host.save(self.admin_context)
super(InterfaceHostTestCase, self)._update_context()
class InterfaceHostTestCase(InterfaceTestCaseMixin, dbbase.BaseHostTestCase):
def setUp(self):
super(InterfaceHostTestCase, self).setUp()
@ -1390,6 +1376,17 @@ class InterfaceHostTestCase(BaseTestCase):
self.expected_mlx_interfaces = []
self.expected_bmc_interface = None
def _setup_configuration(self):
# Personality is set to worker to avoid issues due to missing OAM
# interface in this empty/dummy configuration
self.host = self._create_test_host(constants.WORKER)
def _update_context(self):
# ensure DB entries are updated prior to updating the context which
# will re-read the entries from the DB.
self.host.save(self.admin_context)
super(InterfaceHostTestCase, self)._update_context()
def _create_hieradata_directory(self):
hiera_path = os.path.join(os.environ['VIRTUAL_ENV'], 'hieradata')
if not os.path.exists(hiera_path):
@ -1503,8 +1500,7 @@ class InterfaceControllerEthernet(InterfaceHostTestCase):
def _setup_configuration(self):
# Setup a sample configuration where all platform interfaces are
# ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
self._create_ethernet_test('oam', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_OAM)
self._create_ethernet_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
@ -1523,8 +1519,7 @@ class InterfaceControllerBond(InterfaceHostTestCase):
def _setup_configuration(self):
# Setup a sample configuration where all platform interfaces are
# aggregated ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
self._create_bond_test('oam', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_OAM)
self._create_bond_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
@ -1547,8 +1542,7 @@ class InterfaceControllerVlanOverBond(InterfaceHostTestCase):
def _setup_configuration(self):
# Setup a sample configuration where all platform interfaces are
# vlan interfaces over aggregated ethernet interfaces
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
bond = self._create_bond_test('pxeboot',
constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
@ -1573,8 +1567,7 @@ class InterfaceControllerVlanOverEthernet(InterfaceHostTestCase):
def _setup_configuration(self):
# Setup a sample configuration where all platform interfaces are
# vlan interfaces over ethernet interfaces
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
port, iface = self._create_ethernet_test(
'pxeboot', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
@ -1597,8 +1590,7 @@ class InterfaceComputeEthernet(InterfaceHostTestCase):
def _setup_configuration(self):
# Setup a sample configuration where the personality is set to a
# worker and all interfaces are ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.WORKER)
self.host = self._create_test_host(constants.WORKER)
self._create_ethernet_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_MGMT)
self._create_ethernet_test('cluster-host', constants.INTERFACE_CLASS_PLATFORM,
@ -1639,8 +1631,7 @@ class InterfaceComputeVlanOverEthernet(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# worker and all interfaces are vlan interfaces over ethernet
# interfaces.
self._create_test_common()
self._create_test_host(constants.WORKER)
self.host = self._create_test_host(constants.WORKER)
port, iface = self._create_ethernet_test(
'pxeboot', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
@ -1667,9 +1658,8 @@ class InterfaceComputeVlanOverEthernet(InterfaceHostTestCase):
class InterfaceComputeBond(InterfaceHostTestCase):
def _setup_configuration(self):
# Setup a sample configuration where the personality is set to a
self._create_test_common()
# worker and all interfaces are aggregated ethernet interfaces.
self._create_test_host(constants.WORKER)
self.host = self._create_test_host(constants.WORKER)
self._create_bond_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_MGMT)
self._create_bond_test('cluster-host', constants.INTERFACE_CLASS_PLATFORM,
@ -1701,8 +1691,7 @@ class InterfaceComputeVlanOverBond(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# worker and all interfaces are vlan interfaces over ethernet
# interfaces.
self._create_test_common()
self._create_test_host(constants.WORKER)
self.host = self._create_test_host(constants.WORKER)
bond = self._create_bond_test('pxeboot',
constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
@ -1739,8 +1728,7 @@ class InterfaceCpeEthernet(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a controller subfunction and all interfaces are
# ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
self._create_ethernet_test('oam', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_OAM)
self._create_ethernet_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
@ -1784,8 +1772,7 @@ class InterfaceCpeVlanOverEthernet(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a controller subfunction and all interfaces are
# vlan interfaces over ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
port, iface = self._create_ethernet_test(
'pxeboot', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
@ -1816,8 +1803,7 @@ class InterfaceCpeBond(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a controller subfunction and all interfaces are
# aggregated ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
self._create_bond_test('oam', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_OAM)
self._create_bond_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
@ -1849,8 +1835,7 @@ class InterfaceCpeVlanOverBond(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a controller subfunction and all interfaces are
# vlan interfaces over aggregated ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER)
self.host = self._create_test_host(constants.CONTROLLER)
bond = self._create_bond_test('pxeboot', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
self._create_vlan_test('oam', constants.INTERFACE_CLASS_PLATFORM,
@ -1883,8 +1868,7 @@ class InterfaceCpeComputeEthernet(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a worker subfunction and all interfaces are
# ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER, constants.WORKER)
self.host = self._create_test_host(constants.CONTROLLER, constants.WORKER)
self._create_ethernet_test('data', constants.INTERFACE_CLASS_DATA,
constants.NETWORK_TYPE_DATA)
self._create_ethernet_test('sriov', constants.INTERFACE_CLASS_PCI_SRIOV,
@ -1928,8 +1912,7 @@ class InterfaceCpeComputeVlanOverEthernet(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a worker subfunction and all interfaces are
# vlan interfaces over ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER, constants.WORKER)
self.host = self._create_test_host(constants.CONTROLLER, constants.WORKER)
port, iface = self._create_ethernet_test(
'pxeboot', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)
@ -1960,8 +1943,7 @@ class InterfaceCpeComputeBond(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a worker subfunction and all interfaces are
# aggregated ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER, constants.WORKER)
self.host = self._create_test_host(constants.CONTROLLER, constants.WORKER)
self._create_bond_test('oam', constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_OAM)
self._create_bond_test('mgmt', constants.INTERFACE_CLASS_PLATFORM,
@ -1993,8 +1975,7 @@ class InterfaceCpeComputeVlanOverBond(InterfaceHostTestCase):
# Setup a sample configuration where the personality is set to a
# controller with a worker subfunction and all interfaces are
# vlan interfaces over aggregated ethernet interfaces.
self._create_test_common()
self._create_test_host(constants.CONTROLLER, constants.WORKER)
self.host = self._create_test_host(constants.CONTROLLER, constants.WORKER)
bond = self._create_bond_test('pxeboot',
constants.INTERFACE_CLASS_PLATFORM,
constants.NETWORK_TYPE_PXEBOOT)

View File

@ -3,18 +3,15 @@
# SPDX-License-Identifier: Apache-2.0
#
from sysinv.common import constants
from sysinv.tests.db import base as dbbase
from sysinv.tests.puppet import base
class PuppetOperatorTestCase(base.PuppetTestCaseMixin,
dbbase.BaseHostTestCase):
def setUp(self):
super(PuppetOperatorTestCase, self).setUp()
self._create_test_common()
class PuppetOperatorTestSuite(base.PuppetTestCaseMixin):
"""When PuppetOperatorTestSuite is added as a Mixin
to a testcase which is a subclass of BaseHostTestCase
these testcases are added to it
"""
def test_create_static_config(self):
self.operator.create_static_config()
@ -33,50 +30,67 @@ class PuppetOperatorTestCase(base.PuppetTestCaseMixin,
assert self.mock_write_config.called
def test_update_host_config(self):
host = self._create_test_host(constants.CONTROLLER)
self.operator.update_host_config(host)
self.operator.update_host_config(self.host)
assert self.mock_write_config.called
class PlatformIPv4ControllerHostTestCase(base.PuppetTestCaseMixin,
# ============= IPv4 environment tests ==============
# Tests all puppet operations for a Controller (defaults to IPv4)
class PlatformIPv4ControllerHostTestCase(PuppetOperatorTestSuite,
dbbase.ControllerHostTestCase):
pass
class PlatformIPv4WorkerHostTestCase(base.PuppetTestCaseMixin,
# Tests all puppet operations for a Worker (defaults to IPv4)
class PlatformIPv4WorkerHostTestCase(PuppetOperatorTestSuite,
dbbase.WorkerHostTestCase):
pass
class PlatformIPv4StorageHostTestCase(base.PuppetTestCaseMixin,
# Tests all puppet operations for a Storage Host (defaults to IPv4)
class PlatformIPv4StorageHostTestCase(PuppetOperatorTestSuite,
dbbase.StorageHostTestCase):
pass
class PlatformIPv4AIOHostTestCase(base.PuppetTestCaseMixin,
# Tests all puppet operations for an AIO Host (defaults to IPv4)
class PlatformIPv4AIOHostTestCase(PuppetOperatorTestSuite,
dbbase.AIOHostTestCase):
pass
class PlatformIPv6ControllerHostTestCase(base.PuppetTestCaseMixin,
# ============= IPv6 environment tests ==============
# Tests all puppet operations for a Controller using IPv6
class PlatformIPv6ControllerHostTestCase(PuppetOperatorTestSuite,
dbbase.BaseIPv6Mixin,
dbbase.ControllerHostTestCase):
pass
class PlatformIPv6WorkerHostTestCase(base.PuppetTestCaseMixin,
# Tests all puppet operations for a Worker using IPv6
class PlatformIPv6WorkerHostTestCase(PuppetOperatorTestSuite,
dbbase.BaseIPv6Mixin,
dbbase.WorkerHostTestCase):
pass
class PlatformIPv6StorageHostTestCase(base.PuppetTestCaseMixin,
# Tests all puppet operations for a Storage Host using IPv6
class PlatformIPv6StorageHostTestCase(PuppetOperatorTestSuite,
dbbase.BaseIPv6Mixin,
dbbase.StorageHostTestCase):
pass
class PlatformIPv6AIOHostTestCase(base.PuppetTestCaseMixin,
# Tests all puppet operations for an AIO Host using IPv6
class PlatformIPv6AIOHostTestCase(PuppetOperatorTestSuite,
dbbase.BaseIPv6Mixin,
dbbase.AIOHostTestCase):
pass
# ============= Ceph Backend environment tests ==============
# Tests all puppet operations for an AIO Host using IPv4 and Ceph Backend
class PlatformCephBackendAIOHostTestCase(PuppetOperatorTestSuite,
dbbase.BaseCephStorageBackendMixin,
dbbase.AIOHostTestCase):
pass