From 2548d56f958571c15c445b89a26da1135467d9c4 Mon Sep 17 00:00:00 2001 From: Andreas Scheuring Date: Tue, 16 Jan 2018 13:07:17 +0100 Subject: [PATCH] Create nic string for os-specific-params in PartitionInst class Till now the String was generated and set from the driver class. This patch moves both actions into the PartitionInstance class. This allows us overwriting this method once we support another partition type (e.g. ssc). Change-Id: If535cbdcdf878f5e9e2f91d0f0d1128021efcbbc --- nova_dpm/tests/unit/virt/dpm/test_driver.py | 8 +++-- nova_dpm/tests/unit/virt/dpm/test_vm.py | 14 ++++++++ nova_dpm/virt/dpm/driver.py | 40 +-------------------- nova_dpm/virt/dpm/vm.py | 38 ++++++++++++++++++++ 4 files changed, 59 insertions(+), 41 deletions(-) diff --git a/nova_dpm/tests/unit/virt/dpm/test_driver.py b/nova_dpm/tests/unit/virt/dpm/test_driver.py index b0d844e..a0d94d1 100644 --- a/nova_dpm/tests/unit/virt/dpm/test_driver.py +++ b/nova_dpm/tests/unit/virt/dpm/test_driver.py @@ -260,9 +260,8 @@ class DPMDriverInstanceTestCase(TestCase): @mock.patch.object(vm.PartitionInstance, 'launch') @mock.patch.object(vm.PartitionInstance, 'attach_hbas') @mock.patch.object(vm.PartitionInstance, 'properties') - @mock.patch.object(driver.DPMDriver, '_get_nic_string_for_guest_os') def test_spawn_attach_nic(self, mock_prop, mock_attachHba, mock_launch, - mock_hba_uri, mock_get_bprops, mock_nic_string): + mock_hba_uri, mock_get_bprops): cpc = self.client.cpcs.find(**{"object-id": "2"}) self.dpmdriver._cpc = cpc @@ -289,6 +288,11 @@ class DPMDriverInstanceTestCase(TestCase): self.assertEqual(nics[0].name, "OpenStack_Port_foo-id") self.assertEqual(nics[1].name, "OpenStack_Port_foo-id2") + self.assertIn("8001,0,aabbccddeeff;", + partition.get_property("boot-os-specific-parameters")) + self.assertIn("8002,0,112233445566;", + partition.get_property("boot-os-specific-parameters")) + def test_list_instances(self): self.flags(host="fakemini") cpc = self.client.cpcs.find(**{"object-id": "3"}) diff --git a/nova_dpm/tests/unit/virt/dpm/test_vm.py b/nova_dpm/tests/unit/virt/dpm/test_vm.py index 0d85502..ceeaa65 100755 --- a/nova_dpm/tests/unit/virt/dpm/test_vm.py +++ b/nova_dpm/tests/unit/virt/dpm/test_vm.py @@ -222,6 +222,20 @@ class VmPartitionInstanceTestCase(TestCase): self.part_name, self.partition_inst.get_partition().get_property('name')) + def test__set_nic_string_in_os_specific_parameters(self): + nic = mock.Mock() + nic.get_property = lambda prop: {'device-number': 'devno'}[prop] + + vif_obj = mock.Mock() + vif_obj.mac = 'mac' + + self.partition_inst._set_nic_string_in_os_specific_parameters(nic, + vif_obj) + + boot_os_params = self.partition_inst.partition.get_property( + 'boot-os-specific-parameters') + self.assertIn('devno,0,mac;', boot_os_params) + def test__get_nic_properties_dict(self): cfg.CONF.set_override("host", "subset") vif = mock.Mock() diff --git a/nova_dpm/virt/dpm/driver.py b/nova_dpm/virt/dpm/driver.py index e72ef89..720e4f0 100644 --- a/nova_dpm/virt/dpm/driver.py +++ b/nova_dpm/virt/dpm/driver.py @@ -281,42 +281,6 @@ class DPMDriver(driver.ComputeDriver): """ self.prep_for_spawn(context=None, instance=instance) - def _get_nic_string_for_guest_os(self, nic, vif_obj): - """Generate the NIC string that must be available from inside the OS - - Passing the string into the operating system is achieved via appending - it to the partitions boot-os-specific-parameters property. - The value of this property will then be appended to the kernels cmdline - and be accessible from within the instance under /proc/cmdline. - It is ignored by the Linux Boot process but can be parsed by - other userspace tools and scripts. - - This allows the following operations to be done from within the - Instance/Partitions Operating System: - - * Replace the z Systems Firmware generated MAC address - of the NIC with the one generated from Neutron. The MAC can be - removed from this parameter once it is possible to set the correct - MAC right on DPM NIC creation. - - * Configure the physical network adapter port to be used. - The port number can be removed once Linux is able to get this - information via a different channel. - """ - # Format: ,,; - # : The DPM device number - # : The network adapters port that should be usd - # : MAC address without deliminator. This saves 5 additional - # characters in the limited boot-os-specific-parameters property - # Example: 0001,1,aabbccddeeff; - # TODO(andreas_s): Update once provided by Neutron. Till - # then default to 0 - nic_boot_parms = "{devno},0,{mac};".format( - devno=nic.get_property("device-number"), - mac=vif_obj.mac.replace(":", "") - ) - return nic_boot_parms - def prep_for_spawn(self, context, instance, flavor=None): @@ -357,9 +321,7 @@ class DPMDriver(driver.ComputeDriver): )) for vif_dict in network_info: vif_obj = DPMVIF(vif_dict) - nic = inst.attach_nic(vif_obj) - inst.append_to_boot_os_specific_parameters( - self._get_nic_string_for_guest_os(nic, vif_obj)) + inst.attach_nic(vif_obj) inst.set_boot_properties( self._get_block_device_mapping(block_device_info)) diff --git a/nova_dpm/virt/dpm/vm.py b/nova_dpm/virt/dpm/vm.py index 3fe72cd..c0beeb7 100644 --- a/nova_dpm/virt/dpm/vm.py +++ b/nova_dpm/virt/dpm/vm.py @@ -174,6 +174,43 @@ class PartitionInstance(object): 'boot-os-specific-parameters': new_data }) + def _set_nic_string_in_os_specific_parameters(self, nic, vif_obj): + """Generate the NIC string that must be available from inside the OS + + Passing the string into the operating system is achieved via appending + it to the partitions boot-os-specific-parameters property. + The value of this property will then be appended to the kernels cmdline + and be accessible from within the instance under /proc/cmdline. + It is ignored by the Linux Boot process but can be parsed by + other userspace tools and scripts. + + This allows the following operations to be done from within the + Instance/Partitions Operating System: + + * Replace the z Systems Firmware generated MAC address + of the NIC with the one generated from Neutron. The MAC can be + removed from this parameter once it is possible to set the correct + MAC right on DPM NIC creation. + + * Configure the physical network adapter port to be used. + The port number can be removed once Linux is able to get this + information via a different channel. + """ + # Format: ,,; + # : A space to ensure separation from other parameters + # : The DPM device number + # : The network adapters port that should be usd + # : MAC address without deliminator. This saves 5 additional + # characters in the limited boot-os-specific-parameters property + # Example: 0001,1,aabbccddeeff; + # TODO(andreas_s): Update once provided by Neutron. Till + # then default to 0 + nic_boot_parms = "{devno},0,{mac};".format( + devno=nic.get_property("device-number"), + mac=vif_obj.mac.replace(":", "") + ) + self.append_to_boot_os_specific_parameters(nic_boot_parms) + @staticmethod def _get_nic_properties_dict(vif_obj): return { @@ -199,6 +236,7 @@ class PartitionInstance(object): LOG.debug("NIC created successfully %s with URI %s", nic_interface.properties['name'], nic_interface.properties['virtual-switch-uri']) + self._set_nic_string_in_os_specific_parameters(nic_interface, vif_obj) return nic_interface def attach_hbas(self):