From f60f0a86972b5387fcbefed74abf4a3a6e9b244b Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Tue, 24 Jul 2018 20:28:27 +0900 Subject: [PATCH] Create and delete reservation provider This patch adds the process to create/delete blazar reservation provider when creating/deleting a host in blazar. Change-Id: Ifc739ffd95ca912556fb0b6e43bca12441248521 Blueprint: placement-api --- blazar/plugins/oshosts/host_plugin.py | 9 ++++++++ .../oshosts/test_physical_host_plugin.py | 21 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/blazar/plugins/oshosts/host_plugin.py b/blazar/plugins/oshosts/host_plugin.py index 72119a9d..ecb46c45 100644 --- a/blazar/plugins/oshosts/host_plugin.py +++ b/blazar/plugins/oshosts/host_plugin.py @@ -29,6 +29,7 @@ from blazar.plugins import base from blazar.plugins import oshosts as plugin from blazar import status from blazar.utils.openstack import nova +from blazar.utils.openstack import placement from blazar.utils import plugins as plugins_utils from blazar.utils import trusts @@ -87,6 +88,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper): project_domain_name=CONF.os_admin_project_domain_name) self.monitor = PhysicalHostMonitorPlugin() self.monitor.register_healing_handler(self.heal_reservations) + self.placement_client = placement.BlazarPlacementClient() def reserve_resource(self, reservation_id, values): """Create reservation.""" @@ -352,6 +354,9 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper): if any([len(key) > 64 for key in extra_capabilities_keys]): raise manager_ex.ExtraCapabilityTooLong() + self.placement_client.create_reservation_provider( + host_details['service_name']) + pool = nova.ReservationPool() pool.add_computehost(self.freepool_name, host_details['service_name']) @@ -368,6 +373,8 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper): # transactions pool.remove_computehost(self.freepool_name, host_details['service_name']) + self.placement_client.delete_reservation_provider( + host_details['service_name']) raise e for key in extra_capabilities: values = {'computehost_id': host['id'], @@ -480,6 +487,8 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper): pool = nova.ReservationPool() pool.remove_computehost(self.freepool_name, host['service_name']) + self.placement_client.delete_reservation_provider( + host['service_name']) # NOTE(sbauza): Extracapabilities will be destroyed thanks to # the DB FK. db_api.host_destroy(host_id) diff --git a/blazar/tests/plugins/oshosts/test_physical_host_plugin.py b/blazar/tests/plugins/oshosts/test_physical_host_plugin.py index 3f76ad42..a637c156 100644 --- a/blazar/tests/plugins/oshosts/test_physical_host_plugin.py +++ b/blazar/tests/plugins/oshosts/test_physical_host_plugin.py @@ -33,6 +33,7 @@ from blazar.plugins.oshosts import host_plugin from blazar import tests from blazar.utils.openstack import base from blazar.utils.openstack import nova +from blazar.utils.openstack import placement from blazar.utils import trusts CONF = cfg.CONF @@ -168,11 +169,24 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.get_servers_per_host.return_value = None self.get_extra_capabilities = self.patch( self.fake_phys_plugin, '_get_extra_capabilities') - self.get_extra_capabilities.return_value = { 'foo': 'bar', 'buzz': 'word', } + + self.placement = placement + self.prov_create = self.patch(self.placement.BlazarPlacementClient, + 'create_reservation_provider') + self.prov_create.return_value = { + "generation": 0, + "name": "blazar_foo", + "uuid": "7d2590ae-fb85-4080-9306-058b4c915e3f", + "parent_provider_uuid": "542df8ed-9be2-49b9-b4db-6d3183ff8ec8", + "root_provider_uuid": "542df8ed-9be2-49b9-b4db-6d3183ff8ec8" + } + self.prov_delete = self.patch(self.placement.BlazarPlacementClient, + 'delete_reservation_provider') + self.fake_phys_plugin.setup(None) self.trusts = trusts @@ -204,6 +218,7 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.get_extra_capabilities.return_value = {} host = self.fake_phys_plugin.create_computehost(self.fake_host) self.db_host_create.assert_called_once_with(self.fake_host) + self.prov_create.assert_called_once_with('foo') self.assertEqual(self.fake_host, host) def test_create_host_with_extra_capabilities(self): @@ -219,6 +234,7 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.db_host_create.return_value = self.fake_host host = self.fake_phys_plugin.create_computehost(fake_request) self.db_host_create.assert_called_once_with(self.fake_host) + self.prov_create.assert_called_once_with('foo') self.db_host_extra_capability_create.assert_called_once_with(fake_capa) self.assertEqual(fake_host, host) @@ -257,6 +273,8 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.assertRaises(db_exceptions.BlazarDBException, self.fake_phys_plugin.create_computehost, self.fake_host) + self.prov_create.assert_called_once_with('foo') + self.prov_delete.assert_called_once_with('foo') def test_create_host_having_issue_when_storing_extra_capability(self): def fake_db_host_extra_capability_create(*args, **kwargs): @@ -362,6 +380,7 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.fake_phys_plugin.delete_computehost(self.fake_host_id) self.db_host_destroy.assert_called_once_with(self.fake_host_id) + self.prov_delete.assert_called_once_with('foo') self.get_servers_per_host.assert_called_once_with( self.fake_host["hypervisor_hostname"])