From d4a3e6a58ba1657b4f5cd96b60391b59265714b9 Mon Sep 17 00:00:00 2001 From: Andreas Scheuring Date: Tue, 16 Jan 2018 12:35:39 +0100 Subject: [PATCH] Change how we set the boot-os-specific-params for a nic For each nic we need to add some data to the partitions boot-os-specific-parameters property. Till now we were accumulating everything to a single string which set the property once. The new approach is to update the property for each nic. This leads to more read/write accesses on this partition property. But on the other hand we're gaining flexibility. E.g. someone might want to add a NIC after spawn. Or some other data should be added. Those scenarios were not supported in the past. This is also helpful to move this code into the partitioninstance class. In the future this action might not be required for all type of partitions (e.g. not for ssc). Change-Id: I0262f2660b3e89b455bb1b1ece016342c8347c80 --- nova_dpm/tests/unit/virt/dpm/test_data.py | 3 +++ nova_dpm/tests/unit/virt/dpm/test_vm.py | 25 +++++++++++++++++------ nova_dpm/virt/dpm/constants.py | 3 ++- nova_dpm/virt/dpm/driver.py | 5 ++--- nova_dpm/virt/dpm/vm.py | 9 +++++--- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/nova_dpm/tests/unit/virt/dpm/test_data.py b/nova_dpm/tests/unit/virt/dpm/test_data.py index 8a31697..7f625ef 100644 --- a/nova_dpm/tests/unit/virt/dpm/test_data.py +++ b/nova_dpm/tests/unit/virt/dpm/test_data.py @@ -153,6 +153,9 @@ def create_session_1(): 'description': 'Partition #1 in CPC #3', 'initial-memory': 512, 'ifl-processors': 1, + # The zhmcclient mock support does not provide an + # empty default value + 'boot-os-specific-parameters': "" }, 'hbas': [ diff --git a/nova_dpm/tests/unit/virt/dpm/test_vm.py b/nova_dpm/tests/unit/virt/dpm/test_vm.py index 1704838..0d85502 100755 --- a/nova_dpm/tests/unit/virt/dpm/test_vm.py +++ b/nova_dpm/tests/unit/virt/dpm/test_vm.py @@ -152,7 +152,9 @@ class VmPartitionInstanceTestCase(TestCase): 'name': self.part_name, 'description': self.part_description, 'initial-memory': 512, - 'maximum-memory': 512 + 'maximum-memory': 512, + # The zhmcclient mock support does not provide an empty default + 'boot-os-specific-parameters': "" } # Create partition in a cpc not from openstack # and used same uuid of instance to create @@ -254,19 +256,30 @@ class VmPartitionInstanceTestCase(TestCase): Exception, self.partition_inst.attach_nic, vif) - def test_set_boot_os_specific_parameters(self): + def test_append_to_boot_os_specific_parameters_empty(self): data = '1800,0,fa163ee49a98;' - self.partition_inst.set_boot_os_specific_parameters(data) + self.partition_inst.append_to_boot_os_specific_parameters(data) self.assertEqual( - data, + " " + data, self.partition_inst.get_partition().get_property( 'boot-os-specific-parameters')) - def test_set_boot_os_specific_parameters_negative(self): + def test_append_to_boot_os_specific_parameters_value(self): + data = '1800,0,fa163ee49a98;' + self.partition_inst.partition.update_properties({ + 'boot-os-specific-parameters': 'foo' + }) + self.partition_inst.append_to_boot_os_specific_parameters(data) + self.assertEqual( + "foo " + data, + self.partition_inst.get_partition().get_property( + 'boot-os-specific-parameters')) + + def test_append_to_boot_os_specific_parameters_too_long(self): data = 257 * 'a' self.assertRaises( exceptions.BootOsSpecificParametersPropertyExceededError, - self.partition_inst.set_boot_os_specific_parameters, data) + self.partition_inst.append_to_boot_os_specific_parameters, data) @mock.patch.object(vm.BlockDevice, "get_target_wwpn") @mock.patch.object(vm.PartitionInstance, "get_boot_hba") diff --git a/nova_dpm/virt/dpm/constants.py b/nova_dpm/virt/dpm/constants.py index c118899..4b3fa18 100644 --- a/nova_dpm/virt/dpm/constants.py +++ b/nova_dpm/virt/dpm/constants.py @@ -17,11 +17,12 @@ # additional information for a NIC into the Operating System. # The boot-os-specific-parameters property is limited to 256 chars. # The format for a nic is ,,; +# len(" ") = 1 # space # len() = 4 # len() = 1 # len() = 12 # len (,,;) = 3 -# total len per NIC: 20 +# total len per NIC: 21 # Max number of NICs = 256/20 = 12 MAX_NICS_PER_PARTITION = 12 diff --git a/nova_dpm/virt/dpm/driver.py b/nova_dpm/virt/dpm/driver.py index 7fe801f..e72ef89 100644 --- a/nova_dpm/virt/dpm/driver.py +++ b/nova_dpm/virt/dpm/driver.py @@ -355,12 +355,11 @@ class DPMDriver(driver.ComputeDriver): max_ports=constants.MAX_NICS_PER_PARTITION, current_ports=len(network_info) )) - nic_boot_string = "" for vif_dict in network_info: vif_obj = DPMVIF(vif_dict) nic = inst.attach_nic(vif_obj) - nic_boot_string += self._get_nic_string_for_guest_os(nic, vif_obj) - inst.set_boot_os_specific_parameters(nic_boot_string) + inst.append_to_boot_os_specific_parameters( + self._get_nic_string_for_guest_os(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 e658ba6..3fe72cd 100644 --- a/nova_dpm/virt/dpm/vm.py +++ b/nova_dpm/virt/dpm/vm.py @@ -159,16 +159,19 @@ class PartitionInstance(object): partition_manager = self.cpc.partitions self.partition = partition_manager.create(properties) - def set_boot_os_specific_parameters(self, data): - """Set the boot-os-specific-parameters property + def append_to_boot_os_specific_parameters(self, data): + """Append something to the boot-os-specific-parameters property The value of this property will be appended to the kernels cmdline argument. """ + current = self.partition.get_property("boot-os-specific-parameters") + new_data = "%(current)s %(data)s" % {'current': current, 'data': data} + if len(data) > constants.BOOT_OS_SPECIFIC_PARAMETERS_MAX_LEN: raise exceptions.BootOsSpecificParametersPropertyExceededError() self.partition.update_properties({ - 'boot-os-specific-parameters': data + 'boot-os-specific-parameters': new_data }) @staticmethod