diff --git a/hooks/nova_compute_context.py b/hooks/nova_compute_context.py index f24edd18..ddc2dd00 100644 --- a/hooks/nova_compute_context.py +++ b/hooks/nova_compute_context.py @@ -336,7 +336,19 @@ class NovaComputeLibvirtOverrideContext(context.OSContextGenerator): class NovaComputeVirtContext(context.OSContextGenerator): - interfaces = [] + interfaces = ['cloud-compute'] + + @property + def allow_resize_to_same_host(self): + for rid in relation_ids('cloud-compute'): + for unit in related_units(rid): + _allow_resize_same_host =\ + relation_get('allow_resize_to_same_host', + rid=rid, + unit=unit) + if _allow_resize_same_host: + return bool_from_string(_allow_resize_same_host) + return False def __call__(self): ctxt = {} @@ -346,6 +358,7 @@ class NovaComputeVirtContext(context.OSContextGenerator): ctxt['enable_live_migration'] = config('enable-live-migration') ctxt['resume_guests_state_on_host_boot'] =\ config('resume-guests-state-on-host-boot') + ctxt['allow_resize_to_same_host'] = self.allow_resize_to_same_host return ctxt diff --git a/templates/train/nova.conf b/templates/train/nova.conf index 91074692..74fbf848 100644 --- a/templates/train/nova.conf +++ b/templates/train/nova.conf @@ -177,6 +177,10 @@ disk_allocation_ratio = {{ disk_allocation_ratio }} default_ephemeral_format = {{ default_ephemeral_format }} {% endif %} +{% if allow_resize_to_same_host -%} +allow_resize_to_same_host = {{ allow_resize_to_same_host }} +{% endif -%} + [pci] {% if pci_passthrough_whitelist -%} passthrough_whitelist = {{ pci_passthrough_whitelist }} diff --git a/unit_tests/test_nova_compute_contexts.py b/unit_tests/test_nova_compute_contexts.py index 98eedbc4..f3a99d6c 100644 --- a/unit_tests/test_nova_compute_contexts.py +++ b/unit_tests/test_nova_compute_contexts.py @@ -655,7 +655,9 @@ class NovaComputeContextTests(CharmTestCase): self.test_config.set('virt-type', 'lxd') lxd = context.NovaComputeVirtContext() - self.assertEqual({'resume_guests_state_on_host_boot': False}, lxd()) + self.assertEqual( + {'resume_guests_state_on_host_boot': False, + 'allow_resize_to_same_host': False}, lxd()) def test_lxd_live_migration_opts_yakkety(self): self.kv.return_value = FakeUnitdata(**{'host_uuid': self.host_uuid}) @@ -667,6 +669,7 @@ class NovaComputeContextTests(CharmTestCase): self.assertEqual( {'enable_live_migration': True, 'resume_guests_state_on_host_boot': False, + 'allow_resize_to_same_host': False, 'virt_type': 'lxd'}, lxd()) def test_resume_guests_state_on_host_boot(self): @@ -675,7 +678,45 @@ class NovaComputeContextTests(CharmTestCase): self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} self.test_config.set('resume-guests-state-on-host-boot', True) lxd = context.NovaComputeVirtContext() - self.assertEqual({'resume_guests_state_on_host_boot': True}, lxd()) + self.assertEqual( + {'resume_guests_state_on_host_boot': True, + 'allow_resize_to_same_host': False}, lxd()) + + def test_allow_resize_to_same_host_empty(self): + self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} + self.relation_ids.return_value = ['cloud-compute:0'] + self.related_units.return_value = 'nova-cloud-controller/0' + self.test_relation.set({ + 'allow_resize_to_same_host': None, + }) + self.assertEqual( + {'resume_guests_state_on_host_boot': False, + 'allow_resize_to_same_host': False}, + context.NovaComputeVirtContext()()) + + def test_allow_resize_to_same_host_enabled(self): + self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} + self.relation_ids.return_value = ['cloud-compute:0'] + self.related_units.return_value = 'nova-cloud-controller/0' + self.test_relation.set({ + 'allow_resize_to_same_host': 'true', + }) + self.assertEqual( + {'resume_guests_state_on_host_boot': False, + 'allow_resize_to_same_host': True}, + context.NovaComputeVirtContext()()) + + def test_allow_resize_to_same_host_disabled(self): + self.lsb_release.return_value = {'DISTRIB_CODENAME': 'lucid'} + self.relation_ids.return_value = ['cloud-compute:0'] + self.related_units.return_value = 'nova-cloud-controller/0' + self.test_relation.set({ + 'allow_resize_to_same_host': 'false', + }) + self.assertEqual( + {'resume_guests_state_on_host_boot': False, + 'allow_resize_to_same_host': False}, + context.NovaComputeVirtContext()()) @patch.object(context.uuid, 'uuid4') def test_libvirt_new_uuid(self, mock_uuid):