Browse Source

Hold services down until config rendered

Change-Id: I1dc570a26bfa97f5612c7b82f06181b2f4e6a665
Closes-Bug: #1837379
changes/11/672011/2
Frode Nordahl 2 months ago
parent
commit
871bcaaeb3
No account linked to committer's email address

+ 13
- 0
src/lib/charm/openstack/dragent.py View File

@@ -19,6 +19,7 @@ from __future__ import absolute_import
19 19
 
20 20
 import collections
21 21
 
22
+import charmhelpers.core as ch_core
22 23
 import charmhelpers.contrib.network.ip as ch_ip
23 24
 
24 25
 import charms_openstack.charm
@@ -155,6 +156,18 @@ class DRAgentCharm(charms_openstack.charm.OpenStackCharm):
155 156
             self.release_pkg,
156 157
             self.package_codenames)
157 158
 
159
+    def disable_services(self):
160
+        """Disble services, typically used awaiting required relations."""
161
+        for service in self.services:
162
+            ch_core.host.service('disable', service)
163
+            ch_core.host.service('stop', service)
164
+
165
+    def enable_services(self):
166
+        """Enable services, typically used when required relations complete."""
167
+        for service in self.services:
168
+            ch_core.host.service('enable', service)
169
+            ch_core.host.service('start', service)
170
+
158 171
 
159 172
 class RockyDRAgentCharm(DRAgentCharm):
160 173
 

+ 16
- 0
src/reactive/dragent_handlers.py View File

@@ -63,6 +63,21 @@ def configure_ssl(amqp):
63 63
         instance.configure_ssl()
64 64
 
65 65
 
66
+@reactive.when('charm.installed')
67
+@reactive.when_not('config.rendered')
68
+def disable_services():
69
+    with charm.provide_charm_instance() as instance:
70
+        instance.disable_services()
71
+        instance.assess_status()
72
+
73
+
74
+@reactive.when('config.rendered')
75
+def enable_services():
76
+    with charm.provide_charm_instance() as instance:
77
+        instance.enable_services()
78
+        instance.assess_status()
79
+
80
+
66 81
 @reactive.when('amqp.available')
67 82
 def render_configs(*args):
68 83
     """Render the configuration for dynamic routing when all the interfaces are
@@ -71,4 +86,5 @@ def render_configs(*args):
71 86
     with charm.provide_charm_instance() as instance:
72 87
         instance.upgrade_if_available(args)
73 88
         instance.render_with_interfaces(args)
89
+        reactive.set_flag('config.rendered')
74 90
         instance.assess_status()

+ 6
- 0
unit_tests/test_dragent_handlers.py View File

@@ -40,6 +40,11 @@ class TestDRAgentHooks(test_utils.TestRegisteredHooks):
40 40
                 'setup_amqp_req': ('amqp.connected', ),
41 41
                 'render_configs': ('amqp.available', ),
42 42
                 'configure_ssl': ('amqp.available.ssl', ),
43
+                'enable_services': ('config.rendered',),
44
+                'disable_services': ('charm.installed',),
45
+            },
46
+            'when_not': {
47
+                'disable_services': ('config.rendered',),
43 48
             },
44 49
         }
45 50
         self.registered_hooks_test_helper(handlers, hook_set, defaults)
@@ -92,4 +97,5 @@ class TestDRAgentHandlers(test_utils.PatchHelper):
92 97
             (amqp,))
93 98
         self.dragent_charm.render_with_interfaces.assert_called_once_with(
94 99
             (amqp,))
100
+        self.set_flag.assert_called_once_with('config.rendered')
95 101
         self.dragent_charm.assess_status.assert_called_once()

Loading…
Cancel
Save