Merge "Fix NIC attachment"

This commit is contained in:
Jenkins 2017-01-13 02:33:46 +00:00 committed by Gerrit Code Review
commit 42f8e1f6c3
3 changed files with 50 additions and 37 deletions

View File

@ -50,17 +50,31 @@ class VmNicTestCase(TestCase):
def test_attach_nic(self, mock_debug):
vif1 = {'id': 1234, 'type': 'dpm_vswitch',
'address': "12-34-56-78-9A-BC",
'address': '12-34-56-78-9A-BC',
'details':
{'object-id': '00000000-aaaa-bbbb-cccc-abcdabcdabcd'}}
network_info = [vif1]
nic_interface = self.inst.attach_nic(self.conf, network_info)
self.assertEqual(nic_interface.properties['name'],
"OpenStack_Port_1234")
self.assertEqual(nic_interface.properties['object-uri'],
"/api/partitions/00000000-aaaa-bbbb-"
"cccc-abcdabcdabcd/nics/00000000-nics-"
"bbbb-cccc-abcdabcdabcd")
{'object_id': '00000000-aaaa-bbbb-cccc-abcdabcdabcd'}}
ret_val = mock.MagicMock()
# Required to satisfy dict[..] operations on mocks
ret_val .__getitem__.side_effect = dict.__getitem__
with mock.patch.object(fakezhmcclient.NicManager, 'create',
return_value=ret_val) as mock_create:
nic_interface = self.inst.attach_nic(self.conf, vif1)
self.assertEqual(ret_val, nic_interface)
self.assertTrue(mock_create.called)
call_arg_dict = mock_create.mock_calls[0][1][0]
# Name
self.assertTrue(call_arg_dict['name'].startswith('OpenStack'))
self.assertIn(str(1234), call_arg_dict['name'])
# Description
self.assertTrue(call_arg_dict['description'].startswith('OpenStack'))
self.assertIn('mac=12-34-56-78-9A-BC', call_arg_dict['description'])
self.assertIn('CPCSubset=' + self.conf['cpcsubset_name'],
call_arg_dict['description'])
# virtual-switch-uri
self.assertEqual(
'/api/virtual-switches/00000000-aaaa-bbbb-cccc-abcdabcdabcd',
call_arg_dict['virtual-switch-uri'])
class VmHBATestCase(TestCase):

View File

@ -225,7 +225,8 @@ class DPMDriver(driver.ComputeDriver):
inst = vm.Instance(instance, self._cpc, self._client, flavor)
inst.create(inst.properties())
inst.attach_nic(self._conf, network_info)
for vif in network_info:
inst.attach_nic(self._conf, vif)
block_device_mapping = driver.block_device_info_get_mapping(
block_device_info)

View File

@ -40,7 +40,6 @@ DPM_TO_NOVA_STATE = {
utils.PartitionState.STARTING: power_state.PAUSED
}
OBJECT_ID = 'object-id'
CPCSUBSET_NAME = 'cpcsubset_name'
LOG = logging.getLogger(__name__)
zhmcclient = client_proxy.import_zhmcclient()
@ -80,37 +79,36 @@ class Instance(object):
partition_manager = zhmcclient.PartitionManager(self.cpc)
self.partition = partition_manager.create(properties)
def attach_nic(self, conf, network_info):
def attach_nic(self, conf, vif):
# TODO(preethipy): Implement the listener flow to register for
# nic creation events
LOG.debug("Creating nic interface for the instance")
for vif in network_info:
port_id = vif['id']
vif_type = vif['type']
mac = vif['address']
vif_details = vif['details']
dpm_object_id = vif_details['object_id']
port_id = vif['id']
vif_type = vif['type']
mac = vif['address']
vif_details = vif['details']
dpm_object_id = vif_details[OBJECT_ID]
# Only dpm_vswitch attachments are supported for now
if vif_type != "dpm_vswitch":
raise Exception
# Only dpm_vswitch attachments are supported for now
if vif_type != "dpm_vswitch":
raise Exception
dpm_nic_dict = {
"name": "OpenStack_Port_" + str(port_id),
"description": "OpenStack mac= " + mac +
", CPCSubset= " +
conf[CPCSUBSET_NAME],
"virtual-switch-uri": "/api/virtual-switches/"
+ dpm_object_id
}
nic_interface = self.partition.nics.create(dpm_nic_dict)
LOG.debug("NIC created successfully %(nic_name)s "
"with URI %(nic_uri)s"
% {'nic_name': nic_interface.properties['name'],
'nic_uri': nic_interface.properties[
'virtual-switch-uri']})
dpm_nic_dict = {
"name": "OpenStack_Port_" + str(port_id),
"description": "OpenStack mac=" + mac +
", CPCSubset=" +
conf[CPCSUBSET_NAME],
"virtual-switch-uri": "/api/virtual-switches/"
+ dpm_object_id
}
LOG.debug("Creating NIC %s", dpm_nic_dict)
nic_interface = self.partition.nics.create(dpm_nic_dict)
LOG.debug("NIC created successfully %(nic_name)s "
"with URI %(nic_uri)s"
% {'nic_name': nic_interface.properties['name'],
'nic_uri': nic_interface.properties[
'virtual-switch-uri']})
return nic_interface
def attachHba(self, conf):