From 818ca43e78ea7d8a908cefa41970bd26f4ddea26 Mon Sep 17 00:00:00 2001 From: Maurice Escher Date: Wed, 21 Apr 2021 10:11:03 +0200 Subject: [PATCH] init_host should be called before RPC consumer is created This change adds a new hook to Manager class called init_host_with_rpc() to allow services like scheduler to do something once RPC is ready. Copied from cinder https://opendev.org/openstack/cinder/commit/65fa80c361f71158cc492dfc520dc4a63ccfa419 and https://opendev.org/openstack/cinder/commit/60c563f72d2d6d008fca03f0a058941f3807e1a8 Change-Id: Iac6507a6e395c55f0fec453650009f08c2bb6563 Closes-Bug: #1271568 (cherry picked from commit 0339802a5d0801cda19c464a87853b60982ae011) (cherry picked from commit 887c4bf4c041cfaafaf1c47edb9262574bbb959a) (cherry picked from commit d3481f5c2645fa96c710b4298c44ba915f7d9d92) (cherry picked from commit ad9042b2551d944aa9bf17488117419daf42e9c2) --- manila/manager.py | 14 +++++++++++++- manila/scheduler/manager.py | 2 +- manila/service.py | 4 +++- manila/tests/scheduler/test_manager.py | 4 ++-- ...ix-rpc-init-host-with-rpc-6e76afa553b4f2af.yaml | 6 ++++++ 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/bug-1271568-fix-rpc-init-host-with-rpc-6e76afa553b4f2af.yaml diff --git a/manila/manager.py b/manila/manager.py index 210c9d706c..296b9f0c98 100644 --- a/manila/manager.py +++ b/manila/manager.py @@ -101,7 +101,19 @@ class Manager(base.Base, PeriodicTasks): def init_host(self): """Handle initialization if this is a standalone service. - Child classes should override this method. + A hook point for services to execute tasks before the services are made + available (i.e. showing up on RPC and starting to accept RPC calls) to + other components. Child classes should override this method. + + """ + pass + + def init_host_with_rpc(self): + """A hook for service to do jobs after RPC is ready. + + Like init_host(), this method is a hook where services get a chance + to execute tasks that *need* RPC. Child classes should override + this method. """ pass diff --git a/manila/scheduler/manager.py b/manila/scheduler/manager.py index 3a5957e5a2..d60ba00aa2 100644 --- a/manila/scheduler/manager.py +++ b/manila/scheduler/manager.py @@ -83,7 +83,7 @@ class SchedulerManager(manager.Manager): self.message_api = message_api.API() super(SchedulerManager, self).__init__(*args, **kwargs) - def init_host(self): + def init_host_with_rpc(self): ctxt = context.get_admin_context() self.request_service_capabilities(ctxt) diff --git a/manila/service.py b/manila/service.py index 32345cc562..bce1effd4c 100644 --- a/manila/service.py +++ b/manila/service.py @@ -105,6 +105,7 @@ class Service(service.Service): LOG.info('Starting %(topic)s node (version %(version_string)s)', {'topic': self.topic, 'version_string': version_string}) self.model_disconnected = False + self.manager.init_host() ctxt = context.get_admin_context() if self.coordinator: @@ -126,7 +127,8 @@ class Service(service.Service): self.rpcserver = rpc.get_server(target, endpoints) self.rpcserver.start() - self.manager.init_host() + self.manager.init_host_with_rpc() + if self.report_interval: pulse = loopingcall.FixedIntervalLoopingCall(self.report_state) pulse.start(interval=self.report_interval, diff --git a/manila/tests/scheduler/test_manager.py b/manila/tests/scheduler/test_manager.py index b1f0fc12ea..a3caccfecc 100644 --- a/manila/tests/scheduler/test_manager.py +++ b/manila/tests/scheduler/test_manager.py @@ -89,14 +89,14 @@ class SchedulerManagerTestCase(test.TestCase): self.assertIsInstance(test_manager.driver, filter.FilterScheduler) - def test_init_host(self): + def test_init_host_with_rpc(self): self.mock_object(context, 'get_admin_context', mock.Mock(return_value='fake_admin_context')) self.mock_object(self.manager, 'request_service_capabilities') - self.manager.init_host() + self.manager.init_host_with_rpc() self.manager.request_service_capabilities.assert_called_once_with( 'fake_admin_context') diff --git a/releasenotes/notes/bug-1271568-fix-rpc-init-host-with-rpc-6e76afa553b4f2af.yaml b/releasenotes/notes/bug-1271568-fix-rpc-init-host-with-rpc-6e76afa553b4f2af.yaml new file mode 100644 index 0000000000..d83830731b --- /dev/null +++ b/releasenotes/notes/bug-1271568-fix-rpc-init-host-with-rpc-6e76afa553b4f2af.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + An issue with RPC handling on service restart was addressed by ensuring + proper initialization before creating the RPC consumer. See `bug 1271568 + `_ for more details.