Fail if instance is connected to a VLAN network

VLAN networking is not supported by nova-dpm. This patch
introduces a new exception that is thrown if somebody tries
to connect a DPM instance to a VLAN network.

Change-Id: I00e10d33040fed62a446b8a1df8eb9ae534a7a43
This commit is contained in:
Andreas Scheuring 2018-01-24 10:14:13 +01:00
parent 07055fe19e
commit 538030a03d
5 changed files with 46 additions and 6 deletions

View File

@ -19,7 +19,8 @@ from nova_dpm.virt.dpm.vif import DPMVIF
VIF_DICT = {
"details":
{"port_filter": False,
"object_id": "3ea09d2a-b18d-11e6-89a4-42f2e9ef1641"},
"object_id": "3ea09d2a-b18d-11e6-89a4-42f2e9ef1641",
"vlan": 1},
"address": "fa:16:3e:e4:9a:98",
"type": "dpm_vswitch",
"id": "703da361-9d4d-4441-b99b-e081c3e9cfbb"}
@ -43,9 +44,17 @@ class DPMVIFTestCase(TestCase):
def test_get_details(self):
details = {"port_filter": False,
"object_id": "3ea09d2a-b18d-11e6-89a4-42f2e9ef1641"}
"object_id": "3ea09d2a-b18d-11e6-89a4-42f2e9ef1641",
"vlan": 1}
self.assertEqual(details, self.vif_obj.details)
def test_get_dpm_nic_object_id(self):
self.assertEqual('3ea09d2a-b18d-11e6-89a4-42f2e9ef1641',
self.vif_obj.dpm_nic_object_id)
def test_get_vlan_id(self):
self.assertEqual(1, self.vif_obj.vlan_id)
def test_get_vlan_id_none(self):
vif_obj = DPMVIF({"details": {}})
self.assertIsNone(vif_obj.vlan_id)

View File

@ -257,6 +257,7 @@ class VmPartitionInstanceTestCase(TestCase):
vif.dpm_nic_object_id = "3ea09d2a-b18d-11e6-89a4-42f2e9ef1641"
vif.type = "dpm_vswitch"
vif.port_id = "703da361-9d4d-4441-b99b-e081c3e9cfbb"
vif.vlan_id = None
nic_interface = self.partition_inst.attach_nic(vif)
self.assertEqual(
'OpenStack_Port_703da361-9d4d-4441-b99b-e081c3e9cfbb',
@ -270,6 +271,15 @@ class VmPartitionInstanceTestCase(TestCase):
exceptions.InvalidVIFTypeError,
self.partition_inst.attach_nic, vif)
def test_attach_nic_vlan(self):
vif = mock.Mock()
vif.type = "dpm_vswitch"
vif.vlan_id = 1
self.assertRaises(
exceptions.InvalidNetworkTypeError,
self.partition_inst.attach_nic, vif)
@mock.patch.object(vm.PartitionInstance, 'attach_nic')
def test_attach_nics(self, mocked_attach_nic):
vif1 = {"address": "mac1"}

View File

@ -33,6 +33,13 @@ class InvalidVIFTypeError(NovaException):
"hipersockets adapters.")
class InvalidNetworkTypeError(NovaException):
msg_fmt = _("The instance is connected to a network of type %(type)s. "
"Only flat networks are supported for launching DPM "
"partitions. Please reconfigure your Neutron networks to "
"become flat provider networks.")
class BootOsSpecificParametersPropertyExceededError(NovaException):
"""The boot-os-specific-parameters property would exceed the allowed max"""
msg_fmt = _("Exceeded the maximum len for the partitions "

View File

@ -37,3 +37,11 @@ class DPMVIF(object):
@property
def dpm_nic_object_id(self):
return self.details['object_id']
@property
def vlan_id(self):
"""VLAN ID of VIF
@:returns vlan-id or None
"""
return self.details.get('vlan')

View File

@ -224,6 +224,15 @@ class PartitionInstance(object):
vif_obj.dpm_nic_object_id
}
@staticmethod
def _verify_vif_valid(vif_obj):
# Only dpm_vswitch attachments are supported for now
if vif_obj.type != "dpm_vswitch":
raise exceptions.InvalidVIFTypeError(type=vif_obj.type)
if vif_obj.vlan_id:
raise exceptions.InvalidNetworkTypeError(type="VLAN")
def attach_nics(self, network_info):
for vif_dict in network_info:
vif_obj = vif.DPMVIF(vif_dict)
@ -233,10 +242,7 @@ class PartitionInstance(object):
# TODO(preethipy): Implement the listener flow to register for
# nic creation events
LOG.debug("Creating nic interface for the instance")
# Only dpm_vswitch attachments are supported for now
if vif_obj.type != "dpm_vswitch":
raise exceptions.InvalidVIFTypeError(type=vif_obj.type)
self._verify_vif_valid(vif_obj)
dpm_nic_dict = self._get_nic_properties_dict(vif_obj)
LOG.debug("Creating NIC with properties: %s", dpm_nic_dict)