Add context to PartitionInstance

For some actions (e.g. downloading an image) we need the context
to be present in PartitionIstance. This patch introduces
the context property in this class. In addition context is set
during launch.

It is not required during other operations for now.

Change-Id: I01b7bee02e79c9b141731a88f7afb77bed7ae1cc
This commit is contained in:
Andreas Scheuring 2018-01-18 11:11:42 +01:00
parent 2548d56f95
commit 6d78828226
3 changed files with 15 additions and 4 deletions

View File

@ -243,6 +243,16 @@ class DPMDriverInstanceTestCase(TestCase):
self.dpmdriver = driver.DPMDriver(None)
self.dpmdriver._client = self.client
@mock.patch.object(driver.DPMDriver, '_get_partition_instance')
def test_spawn_context(self, mocked_get_part_inst):
"""Make sure that context is provided to the PartitionInstance"""
mock_context = mock.Mock()
mock_inst = mock.Mock()
self.dpmdriver.spawn(mock_context, mock_inst, None, None, None, None,
[])
mocked_get_part_inst.assert_called_once_with(mock_inst, mock_context)
@mock.patch.object(vm.PartitionInstance, 'get_partition')
@mock.patch.object(vm.PartitionInstance, 'create')
@mock.patch.object(vm.PartitionInstance, 'properties')

View File

@ -70,11 +70,11 @@ class DPMDriver(driver.ComputeDriver):
self.volume_drivers = self._get_volume_drivers()
def _get_partition_instance(self, instance):
def _get_partition_instance(self, instance, context=None):
if instance.image_ref != '':
raise exceptions.BootFromImageNotSupported()
else:
return vm.PartitionInstance(instance, self._cpc)
return vm.PartitionInstance(instance, self._cpc, context)
def init_host(self, host):
"""Driver initialization of the hypervisor node"""
@ -303,7 +303,7 @@ class DPMDriver(driver.ComputeDriver):
admin_password, allocations, network_info=None,
block_device_info=None):
inst = self._get_partition_instance(instance)
inst = self._get_partition_instance(instance, context)
# The creation of NICs is limited in DPM by the partitions
# boot-os-specific-parameters property. It is used to pass additional

View File

@ -119,10 +119,11 @@ def cpcsubset_partition_list(cpc):
class PartitionInstance(object):
def __init__(self, instance, cpc):
def __init__(self, instance, cpc, context=None):
self.instance = instance
self.cpc = cpc
self.partition = self.get_partition()
self.context = context
@staticmethod
def create_object(instance, cpc, flavor=None):