Additional Sysinv Tox Tests
This commit adds additional tox tests for the interface_network API. The tests create interface_networks for both the controller and compute node, while verifying that invalid interface_networks will not be created. Story: 2003087 Task: 26508 Depends-On: https://review.openstack.org/#/c/602637 Change-Id: I1ed0e88bb69321963ad4888f13981baf59035b86 Signed-off-by: Patrick Bonnell <patrick.bonnell@windriver.com>
This commit is contained in:
parent
a99139b4af
commit
6b8b9a3914
@ -212,9 +212,10 @@ class InterfaceNetworkController(rest.RestController):
|
|||||||
result = self._query_interface_network(interface_network)
|
result = self._query_interface_network(interface_network)
|
||||||
if not result:
|
if not result:
|
||||||
return
|
return
|
||||||
raise exception.InterfaceNetworkAlreadyExists(
|
msg = _("Interface network with interface ID '%s' "
|
||||||
interface_id=interface_network['interface_id'],
|
"and network ID '%s' already exists."
|
||||||
network_id=interface_network['network_id'])
|
% (interface_network['interface_id'], interface_network['network_id']))
|
||||||
|
raise wsme.exc.ClientSideError(msg)
|
||||||
|
|
||||||
def _check_duplicate_type(self, interface_id, network_type):
|
def _check_duplicate_type(self, interface_id, network_type):
|
||||||
if network_type in NONDUPLICATE_NETWORK_TYPES:
|
if network_type in NONDUPLICATE_NETWORK_TYPES:
|
||||||
|
292
sysinv/sysinv/sysinv/sysinv/tests/api/test_interface_network.py
Normal file
292
sysinv/sysinv/sysinv/sysinv/tests/api/test_interface_network.py
Normal file
@ -0,0 +1,292 @@
|
|||||||
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013-2018 Wind River Systems, Inc.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
from six.moves import http_client
|
||||||
|
|
||||||
|
from sysinv.common import constants
|
||||||
|
from sysinv.tests.api import base
|
||||||
|
from sysinv.tests.db import utils as dbutils
|
||||||
|
|
||||||
|
|
||||||
|
class InterfaceNetworkTestCase(base.FunctionalTest):
|
||||||
|
def setUp(self):
|
||||||
|
super(InterfaceNetworkTestCase, self).setUp()
|
||||||
|
self.system = dbutils.create_test_isystem()
|
||||||
|
self.load = dbutils.create_test_load()
|
||||||
|
self.controller = dbutils.create_test_ihost(
|
||||||
|
id='1',
|
||||||
|
uuid=None,
|
||||||
|
forisystemid=self.system.id,
|
||||||
|
hostname='controller-0',
|
||||||
|
personality=constants.CONTROLLER,
|
||||||
|
subfunctions=constants.CONTROLLER,
|
||||||
|
invprovision=constants.PROVISIONED,
|
||||||
|
)
|
||||||
|
self.compute = dbutils.create_test_ihost(
|
||||||
|
id='2',
|
||||||
|
uuid=None,
|
||||||
|
forisystemid=self.system.id,
|
||||||
|
hostname='compute-0',
|
||||||
|
personality=constants.COMPUTE,
|
||||||
|
subfunctions=constants.COMPUTE,
|
||||||
|
mgmt_mac='01:02.03.04.05.C0',
|
||||||
|
mgmt_ip='192.168.24.12',
|
||||||
|
invprovision=constants.PROVISIONED,
|
||||||
|
)
|
||||||
|
self.address_pool_mgmt = dbutils.create_test_address_pool(
|
||||||
|
id=1,
|
||||||
|
network='192.168.204.0',
|
||||||
|
name='management',
|
||||||
|
ranges=[['192.168.204.2', '192.168.204.254']],
|
||||||
|
prefix=24)
|
||||||
|
self.mgmt_network = dbutils.create_test_network(
|
||||||
|
id=1,
|
||||||
|
name='mgmt',
|
||||||
|
type=constants.NETWORK_TYPE_MGMT,
|
||||||
|
link_capacity=1000,
|
||||||
|
vlan_id=2,
|
||||||
|
address_pool_id=self.address_pool_mgmt.id)
|
||||||
|
self.address_pool_infra = dbutils.create_test_address_pool(
|
||||||
|
id=2,
|
||||||
|
network='192.168.205.0',
|
||||||
|
name='infrastructure',
|
||||||
|
ranges=[['192.168.205.2', '192.168.205.254']],
|
||||||
|
prefix=24)
|
||||||
|
self.infra_network = dbutils.create_test_network(
|
||||||
|
id=2,
|
||||||
|
name='infra',
|
||||||
|
type=constants.NETWORK_TYPE_INFRA,
|
||||||
|
link_capacity=10000,
|
||||||
|
vlan_id=3,
|
||||||
|
address_pool_id=self.address_pool_infra.id)
|
||||||
|
self.address_pool_oam = dbutils.create_test_address_pool(
|
||||||
|
id=3,
|
||||||
|
network='128.224.150.0',
|
||||||
|
name='oam',
|
||||||
|
ranges=[['128.224.150.1', '128.224.151.254']],
|
||||||
|
prefix=23)
|
||||||
|
self.oam_network = dbutils.create_test_network(
|
||||||
|
id=3,
|
||||||
|
name='oam',
|
||||||
|
type=constants.NETWORK_TYPE_OAM,
|
||||||
|
address_pool_id=self.address_pool_oam.id)
|
||||||
|
self.address_pool_pxeboot = dbutils.create_test_address_pool(
|
||||||
|
id=4,
|
||||||
|
network='192.168.202.0',
|
||||||
|
name='pxeboot',
|
||||||
|
ranges=[['192.168.202.2', '192.168.202.254']],
|
||||||
|
prefix=23)
|
||||||
|
self.pxeboot_network = dbutils.create_test_network(
|
||||||
|
id=4,
|
||||||
|
type=constants.NETWORK_TYPE_PXEBOOT,
|
||||||
|
address_pool_id=self.address_pool_pxeboot.id)
|
||||||
|
|
||||||
|
def _post_and_check(self, ndict, expect_errors=False):
|
||||||
|
response = self.post_json('%s' % self._get_path(), ndict,
|
||||||
|
expect_errors)
|
||||||
|
if expect_errors:
|
||||||
|
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
|
||||||
|
self.assertEqual('application/json', response.content_type)
|
||||||
|
self.assertTrue(response.json['error_message'])
|
||||||
|
else:
|
||||||
|
self.assertEqual(http_client.OK, response.status_int)
|
||||||
|
return response
|
||||||
|
|
||||||
|
def _get_path(self, path=None):
|
||||||
|
if path:
|
||||||
|
return '/interface_networks/' + path
|
||||||
|
else:
|
||||||
|
return '/interface_networks'
|
||||||
|
|
||||||
|
|
||||||
|
class InterfaceNetworkCreateTestCase(InterfaceNetworkTestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(InterfaceNetworkCreateTestCase, self).setUp()
|
||||||
|
|
||||||
|
def test_create_mgmt_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.mgmt_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.mgmt_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
def test_create_infra_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.infra_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.infra_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
def test_create_oam_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.oam_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.oam_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
def test_create_pxeboot_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.pxeboot_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.pxeboot_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
def test_create_mgmt_infra_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=controller_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=compute_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.infra_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.infra_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=False)
|
||||||
|
|
||||||
|
# Expected error:
|
||||||
|
# You cannot assign a network of type 'oam' to an interface
|
||||||
|
# which is already assigned with a different network
|
||||||
|
def test_create_invalid_mgmt_oam_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=controller_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=compute_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.oam_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=True)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.oam_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=True)
|
||||||
|
|
||||||
|
# Expected error:
|
||||||
|
# You cannot assign a network of type 'pxeboot' to an interface
|
||||||
|
# which is already assigned with a different network
|
||||||
|
def test_create_invalid_mgmt_pxeboot_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=controller_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=compute_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.pxeboot_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=True)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.pxeboot_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=True)
|
||||||
|
|
||||||
|
# Expected error:
|
||||||
|
# Interface network with interface ID '%s' and
|
||||||
|
# network ID '%s' already exists."
|
||||||
|
def test_create_invalid_duplicate_mgmt_interface_network(self):
|
||||||
|
controller_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.controller.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=controller_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
compute_interface = dbutils.create_test_interface(
|
||||||
|
ifname='enp0s8',
|
||||||
|
forihostid=self.compute.id)
|
||||||
|
dbutils.create_test_interface_network(
|
||||||
|
interface_id=compute_interface.id,
|
||||||
|
network_id=self.mgmt_network.id)
|
||||||
|
|
||||||
|
controller_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=controller_interface.uuid,
|
||||||
|
network_uuid=self.mgmt_network.uuid)
|
||||||
|
self._post_and_check(controller_interface_network, expect_errors=True)
|
||||||
|
|
||||||
|
compute_interface_network = dbutils.post_get_test_interface_network(
|
||||||
|
interface_uuid=compute_interface.uuid,
|
||||||
|
network_uuid=self.mgmt_network.uuid)
|
||||||
|
self._post_and_check(compute_interface_network, expect_errors=True)
|
@ -681,11 +681,11 @@ def create_test_interface_network(**kw):
|
|||||||
:param kw: kwargs with overriding values for network's attributes.
|
:param kw: kwargs with overriding values for network's attributes.
|
||||||
:returns: Test Network DB object.
|
:returns: Test Network DB object.
|
||||||
"""
|
"""
|
||||||
network_interface = get_test_interface_network(**kw)
|
interface_network = get_test_interface_network(**kw)
|
||||||
if 'id' not in kw:
|
if 'id' not in kw:
|
||||||
del network_interface['id']
|
del interface_network['id']
|
||||||
dbapi = db_api.get_instance()
|
dbapi = db_api.get_instance()
|
||||||
return dbapi.network_interface_create(network_interface)
|
return dbapi.interface_network_create(interface_network)
|
||||||
|
|
||||||
|
|
||||||
def get_test_interface_network(**kw):
|
def get_test_interface_network(**kw):
|
||||||
@ -698,6 +698,14 @@ def get_test_interface_network(**kw):
|
|||||||
return inv
|
return inv
|
||||||
|
|
||||||
|
|
||||||
|
def post_get_test_interface_network(**kw):
|
||||||
|
inv = {
|
||||||
|
'interface_uuid': kw.get('interface_uuid'),
|
||||||
|
'network_uuid': kw.get('network_uuid'),
|
||||||
|
}
|
||||||
|
return inv
|
||||||
|
|
||||||
|
|
||||||
def get_test_storage_tier(**kw):
|
def get_test_storage_tier(**kw):
|
||||||
tier = {
|
tier = {
|
||||||
'id': kw.get('id', 321),
|
'id': kw.get('id', 321),
|
||||||
|
Loading…
Reference in New Issue
Block a user