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
This commit is contained in:
parent
7b038bc10a
commit
d4a3e6a58b
|
@ -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': [
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 <devno>,<portno>,<mac>;
|
||||
# len(" ") = 1 # space
|
||||
# len(<devno>) = 4
|
||||
# len(<portno>) = 1
|
||||
# len(<mac>) = 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
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue