diff --git a/blazar/plugins/oshosts/host_plugin.py b/blazar/plugins/oshosts/host_plugin.py index f19a7dd9..f0c43636 100644 --- a/blazar/plugins/oshosts/host_plugin.py +++ b/blazar/plugins/oshosts/host_plugin.py @@ -35,10 +35,14 @@ from blazar.utils import trusts plugin_opts = [ cfg.StrOpt('on_end', default='on_end', + deprecated_for_removal=True, + deprecated_since='0.3.0', help='Actions which we will use in the end of the lease'), cfg.StrOpt('on_start', default='on_start', - help='Actions which we will use at the start of the lease'), + deprecated_for_removal=True, + deprecated_since='0.3.0', + help='Actions which we will use at the start of the lease') ] CONF = cfg.CONF @@ -185,15 +189,17 @@ class PhysicalHostPlugin(base.BasePlugin, nova.NovaClientWrapper): {'status': 'completed'}) allocations = db_api.host_allocation_get_all_by_values( reservation_id=reservation['id']) - pool = rp.ReservationPool() for allocation in allocations: db_api.host_allocation_destroy(allocation['id']) - if self.nova.hypervisors.get( - self._get_hypervisor_from_name_or_id( - allocation['compute_host_id']) - ).__dict__['running_vms'] == 0: - pool.delete(reservation['resource_id']) - # TODO(frossigneux) Kill, migrate, or increase fees... + pool = rp.ReservationPool() + for host in pool.get_computehosts(reservation['resource_id']): + for server in self.nova.servers.list( + search_opts={"host": host}): + self.nova.servers.delete(server=server) + try: + pool.delete(reservation['resource_id']) + except manager_ex.AggregateNotFound: + pass def _get_extra_capabilities(self, host_id): extra_capabilities = {} diff --git a/blazar/tests/plugins/test_physical_host_plugin.py b/blazar/tests/plugins/test_physical_host_plugin.py index 5a75c9de..9b60ee32 100644 --- a/blazar/tests/plugins/test_physical_host_plugin.py +++ b/blazar/tests/plugins/test_physical_host_plugin.py @@ -32,6 +32,7 @@ from blazar.plugins.oshosts import nova_inventory from blazar.plugins.oshosts import reservation_pool as rp from blazar import tests from blazar.utils.openstack import base +from blazar.utils.openstack.nova import ServerManager from blazar.utils import trusts @@ -161,6 +162,8 @@ class PhysicalHostPluginTestCase(tests.TestCase): self.trust_ctx = self.patch(self.trusts, 'create_ctx_from_trust') self.trust_create = self.patch(self.trusts, 'create_trust') + self.ServerManager = ServerManager + def test_get_host(self): host = self.fake_phys_plugin.get_computehost(self.fake_host_id) self.db_host_get.assert_called_once_with('1') @@ -687,10 +690,13 @@ class PhysicalHostPluginTestCase(tests.TestCase): host_allocation_destroy = self.patch( self.db_api, 'host_allocation_destroy') - delete = self.patch(self.rp.ReservationPool, 'delete') - self.patch(self.fake_phys_plugin, '_get_hypervisor_from_name_or_id') - get_hypervisors = self.patch(self.nova.hypervisors, 'get') - get_hypervisors.return_value = mock.MagicMock(running_vms=1) + get_computehosts = self.patch(self.rp.ReservationPool, + 'get_computehosts') + get_computehosts.return_value = ['host'] + list_servers = self.patch(self.ServerManager, 'list') + list_servers.return_value = ['server1', 'server2'] + delete_server = self.patch(self.ServerManager, 'delete') + delete_pool = self.patch(self.rp.ReservationPool, 'delete') self.fake_phys_plugin.on_end(u'04de74e8-193a-49d2-9ab8-cba7b49e45e8') reservation_update.assert_called_with( u'593e7028-c0d1-4d76-8642-2ffd890b324c', {'status': 'completed'}) @@ -698,7 +704,9 @@ class PhysicalHostPluginTestCase(tests.TestCase): u'35fc4e6a-ba57-4a36-be30-6012377a0387', {'status': 'completed'}) host_allocation_destroy.assert_called_with( u'bfa9aa0b-8042-43eb-a4e6-4555838bf64f') - assert not delete.called + delete_server.assert_any_call(server='server1') + delete_server.assert_any_call(server='server2') + delete_pool.assert_called_with(u'04de74e8-193a-49d2-9ab8-cba7b49e45e8') def test_on_end_without_instances(self): reservation_get_all_by_values = self.patch( @@ -731,10 +739,13 @@ class PhysicalHostPluginTestCase(tests.TestCase): host_allocation_destroy = self.patch( self.db_api, 'host_allocation_destroy') - delete = self.patch(self.rp.ReservationPool, 'delete') - self.patch(self.fake_phys_plugin, '_get_hypervisor_from_name_or_id') - get_hypervisors = self.patch(self.nova.hypervisors, 'get') - get_hypervisors.return_value = mock.MagicMock(running_vms=0) + get_computehosts = self.patch(self.rp.ReservationPool, + 'get_computehosts') + get_computehosts.return_value = ['host'] + list_servers = self.patch(self.ServerManager, 'list') + list_servers.return_value = [] + delete_server = self.patch(self.ServerManager, 'delete') + delete_pool = self.patch(self.rp.ReservationPool, 'delete') self.fake_phys_plugin.on_end(u'04de74e8-193a-49d2-9ab8-cba7b49e45e8') reservation_update.assert_called_with( u'593e7028-c0d1-4d76-8642-2ffd890b324c', {'status': 'completed'}) @@ -742,7 +753,8 @@ class PhysicalHostPluginTestCase(tests.TestCase): u'35fc4e6a-ba57-4a36-be30-6012377a0387', {'status': 'completed'}) host_allocation_destroy.assert_called_with( u'bfa9aa0b-8042-43eb-a4e6-4555838bf64f') - delete.assert_called_with(u'04de74e8-193a-49d2-9ab8-cba7b49e45e8') + delete_server.assert_not_called() + delete_pool.assert_called_with(u'04de74e8-193a-49d2-9ab8-cba7b49e45e8') def test_matching_hosts_not_allocated_hosts(self): def host_allocation_get_all_by_values(**kwargs): diff --git a/doc/source/userdoc/installation.guide.rst b/doc/source/userdoc/installation.guide.rst index 1b81562b..9037071a 100644 --- a/doc/source/userdoc/installation.guide.rst +++ b/doc/source/userdoc/installation.guide.rst @@ -126,8 +126,6 @@ Then edit */etc/blazar/blazar.conf* using the following example: auth_uri= [physical:host] - on_start=on_start - on_end=on_end aggregate_freepool_name=freepool project_id_key=blazar:project blazar_owner=blazar:owner diff --git a/releasenotes/notes/delete-on-end-3a6d3ced93ffed25.yaml b/releasenotes/notes/delete-on-end-3a6d3ced93ffed25.yaml new file mode 100644 index 00000000..f36830dd --- /dev/null +++ b/releasenotes/notes/delete-on-end-3a6d3ced93ffed25.yaml @@ -0,0 +1,10 @@ +--- +features: + - | + The physical-host plugin has been changed to force-delete all instances on + leased hosts at the end of a lease for preventing failures of other + following leases. +deprecations: + - | + The *on_start* and the *on_end* configs for the physical-host plugin have + been removed.