Merge "Create and delete reservation provider"

This commit is contained in:
Zuul 2018-11-26 19:31:42 +00:00 committed by Gerrit Code Review
commit 1ecec18b21
2 changed files with 29 additions and 1 deletions

View File

@ -29,6 +29,7 @@ from blazar.plugins import base
from blazar.plugins import oshosts as plugin from blazar.plugins import oshosts as plugin
from blazar import status from blazar import status
from blazar.utils.openstack import nova from blazar.utils.openstack import nova
from blazar.utils.openstack import placement
from blazar.utils import plugins as plugins_utils from blazar.utils import plugins as plugins_utils
from blazar.utils import trusts from blazar.utils import trusts
@ -87,6 +88,7 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
project_domain_name=CONF.os_admin_project_domain_name) project_domain_name=CONF.os_admin_project_domain_name)
self.monitor = PhysicalHostMonitorPlugin() self.monitor = PhysicalHostMonitorPlugin()
self.monitor.register_healing_handler(self.heal_reservations) self.monitor.register_healing_handler(self.heal_reservations)
self.placement_client = placement.BlazarPlacementClient()
def reserve_resource(self, reservation_id, values): def reserve_resource(self, reservation_id, values):
"""Create reservation.""" """Create reservation."""
@ -352,6 +354,9 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
if any([len(key) > 64 for key in extra_capabilities_keys]): if any([len(key) > 64 for key in extra_capabilities_keys]):
raise manager_ex.ExtraCapabilityTooLong() raise manager_ex.ExtraCapabilityTooLong()
self.placement_client.create_reservation_provider(
host_details['service_name'])
pool = nova.ReservationPool() pool = nova.ReservationPool()
pool.add_computehost(self.freepool_name, pool.add_computehost(self.freepool_name,
host_details['service_name']) host_details['service_name'])
@ -368,6 +373,8 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
# transactions # transactions
pool.remove_computehost(self.freepool_name, pool.remove_computehost(self.freepool_name,
host_details['service_name']) host_details['service_name'])
self.placement_client.delete_reservation_provider(
host_details['service_name'])
raise e raise e
for key in extra_capabilities: for key in extra_capabilities:
values = {'computehost_id': host['id'], values = {'computehost_id': host['id'],
@ -480,6 +487,8 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper):
pool = nova.ReservationPool() pool = nova.ReservationPool()
pool.remove_computehost(self.freepool_name, pool.remove_computehost(self.freepool_name,
host['service_name']) host['service_name'])
self.placement_client.delete_reservation_provider(
host['service_name'])
# NOTE(sbauza): Extracapabilities will be destroyed thanks to # NOTE(sbauza): Extracapabilities will be destroyed thanks to
# the DB FK. # the DB FK.
db_api.host_destroy(host_id) db_api.host_destroy(host_id)

View File

@ -33,6 +33,7 @@ from blazar.plugins.oshosts import host_plugin
from blazar import tests from blazar import tests
from blazar.utils.openstack import base from blazar.utils.openstack import base
from blazar.utils.openstack import nova from blazar.utils.openstack import nova
from blazar.utils.openstack import placement
from blazar.utils import trusts from blazar.utils import trusts
CONF = cfg.CONF CONF = cfg.CONF
@ -168,11 +169,24 @@ class PhysicalHostPluginTestCase(tests.TestCase):
self.get_servers_per_host.return_value = None self.get_servers_per_host.return_value = None
self.get_extra_capabilities = self.patch( self.get_extra_capabilities = self.patch(
self.fake_phys_plugin, '_get_extra_capabilities') self.fake_phys_plugin, '_get_extra_capabilities')
self.get_extra_capabilities.return_value = { self.get_extra_capabilities.return_value = {
'foo': 'bar', 'foo': 'bar',
'buzz': 'word', '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.fake_phys_plugin.setup(None)
self.trusts = trusts self.trusts = trusts
@ -204,6 +218,7 @@ class PhysicalHostPluginTestCase(tests.TestCase):
self.get_extra_capabilities.return_value = {} self.get_extra_capabilities.return_value = {}
host = self.fake_phys_plugin.create_computehost(self.fake_host) host = self.fake_phys_plugin.create_computehost(self.fake_host)
self.db_host_create.assert_called_once_with(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) self.assertEqual(self.fake_host, host)
def test_create_host_with_extra_capabilities(self): 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 self.db_host_create.return_value = self.fake_host
host = self.fake_phys_plugin.create_computehost(fake_request) host = self.fake_phys_plugin.create_computehost(fake_request)
self.db_host_create.assert_called_once_with(self.fake_host) 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.db_host_extra_capability_create.assert_called_once_with(fake_capa)
self.assertEqual(fake_host, host) self.assertEqual(fake_host, host)
@ -257,6 +273,8 @@ class PhysicalHostPluginTestCase(tests.TestCase):
self.assertRaises(db_exceptions.BlazarDBException, self.assertRaises(db_exceptions.BlazarDBException,
self.fake_phys_plugin.create_computehost, self.fake_phys_plugin.create_computehost,
self.fake_host) 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 test_create_host_having_issue_when_storing_extra_capability(self):
def fake_db_host_extra_capability_create(*args, **kwargs): 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.fake_phys_plugin.delete_computehost(self.fake_host_id)
self.db_host_destroy.assert_called_once_with(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.get_servers_per_host.assert_called_once_with(
self.fake_host["hypervisor_hostname"]) self.fake_host["hypervisor_hostname"])