Extract new method get_nic_properties_dict

We extract the pieces that generate the nic dict from the attach_nic
method into a separate method. This allows overwriting the creation
of the dict once we support for example ssc.

Change-Id: I17642d78b62eb71b0d89bec1fb6cd552b11f6fd8
This commit is contained in:
Andreas Scheuring 2018-01-16 10:32:17 +01:00
parent 443a1bd547
commit 7b038bc10a
2 changed files with 28 additions and 15 deletions

View File

@ -220,6 +220,21 @@ class VmPartitionInstanceTestCase(TestCase):
self.part_name,
self.partition_inst.get_partition().get_property('name'))
def test__get_nic_properties_dict(self):
cfg.CONF.set_override("host", "subset")
vif = mock.Mock()
vif.dpm_nic_object_id = "nic_oid"
vif.mac = "mac"
vif.port_id = "port_id"
nic_props = self.partition_inst._get_nic_properties_dict(vif)
self.assertEqual("OpenStack_Port_port_id", nic_props["name"])
self.assertEqual("OpenStack mac=mac, CPCSubset=subset",
nic_props["description"])
self.assertEqual("/api/virtual-switches/nic_oid",
nic_props["virtual-switch-uri"])
def test_attach_nic(self):
vif = mock.Mock()
vif.mac = "fa:16:3e:e4:9a:98"

View File

@ -171,29 +171,27 @@ class PartitionInstance(object):
'boot-os-specific-parameters': data
})
@staticmethod
def _get_nic_properties_dict(vif_obj):
return {
"name": "OpenStack_Port_" + str(vif_obj.port_id),
"description": "OpenStack mac=" + vif_obj.mac + ", CPCSubset=" +
CONF.host,
"virtual-switch-uri": "/api/virtual-switches/" +
vif_obj.dpm_nic_object_id
}
def attach_nic(self, vif_obj):
# TODO(preethipy): Implement the listener flow to register for
# nic creation events
LOG.debug("Creating nic interface for the instance")
port_id = vif_obj.port_id
vif_type = vif_obj.type
mac = vif_obj.mac
dpm_object_id = vif_obj.dpm_nic_object_id
# Only dpm_vswitch attachments are supported for now
if vif_type != "dpm_vswitch":
if vif_obj.type != "dpm_vswitch":
raise Exception
dpm_nic_dict = {
"name": "OpenStack_Port_" + str(port_id),
"description": "OpenStack mac=" + mac +
", CPCSubset=" +
CONF.host,
"virtual-switch-uri": "/api/virtual-switches/"
+ dpm_object_id
}
LOG.debug("Creating NIC %s", dpm_nic_dict)
dpm_nic_dict = self._get_nic_properties_dict(vif_obj)
LOG.debug("Creating NIC with properties: %s", dpm_nic_dict)
nic_interface = self.partition.nics.create(dpm_nic_dict)
LOG.debug("NIC created successfully %s with URI %s",
nic_interface.properties['name'],