diff options
author | Bilal Baqar <bbaqar@plumgrid.com> | 2016-03-28 11:50:55 -0700 |
---|---|---|
committer | Bilal Baqar <bbaqar@plumgrid.com> | 2016-03-28 11:50:55 -0700 |
commit | 769e214bdf5cfe0efc93dc4e29c54037661e1f1d (patch) | |
tree | 047f57354f61c426b3f1ef8f080d7067ada5f969 | |
parent | 89817b2437c390f55672256d5e5318598bebdaa6 (diff) | |
parent | 8deb2c6d6280b4b28398ef8f5e601d3db7c1735d (diff) |
restart_on_stop Ticket: [SOL-950]
- Added restart_on_stop decorator function which starts plumgrid service is it has been stopped in the function
- Added restart_on_change to config-changed hook so that any config changes result in plugrid restart
- ifc_list_gateway only removed when change in ifcs.conf
-rwxr-xr-x | hooks/pg_gw_hooks.py | 12 | ||||
-rw-r--r-- | hooks/pg_gw_utils.py | 15 | ||||
-rw-r--r-- | unit_tests/test_pg_gw_hooks.py | 1 |
3 files changed, 18 insertions, 10 deletions
diff --git a/hooks/pg_gw_hooks.py b/hooks/pg_gw_hooks.py index ad020ed..1d3f87d 100755 --- a/hooks/pg_gw_hooks.py +++ b/hooks/pg_gw_hooks.py | |||
@@ -14,8 +14,6 @@ from charmhelpers.core.hookenv import ( | |||
14 | config, | 14 | config, |
15 | ) | 15 | ) |
16 | 16 | ||
17 | from charmhelpers.core.host import service_running | ||
18 | |||
19 | from charmhelpers.fetch import ( | 17 | from charmhelpers.fetch import ( |
20 | apt_install, | 18 | apt_install, |
21 | configure_sources, | 19 | configure_sources, |
@@ -24,7 +22,6 @@ from charmhelpers.fetch import ( | |||
24 | from pg_gw_utils import ( | 22 | from pg_gw_utils import ( |
25 | register_configs, | 23 | register_configs, |
26 | ensure_files, | 24 | ensure_files, |
27 | restart_pg, | ||
28 | restart_map, | 25 | restart_map, |
29 | stop_pg, | 26 | stop_pg, |
30 | determine_packages, | 27 | determine_packages, |
@@ -35,6 +32,7 @@ from pg_gw_utils import ( | |||
35 | fabric_interface_changed, | 32 | fabric_interface_changed, |
36 | load_iptables, | 33 | load_iptables, |
37 | restart_on_change, | 34 | restart_on_change, |
35 | restart_on_stop, | ||
38 | director_cluster_ready | 36 | director_cluster_ready |
39 | ) | 37 | ) |
40 | 38 | ||
@@ -71,6 +69,8 @@ def plumgrid_changed(): | |||
71 | 69 | ||
72 | 70 | ||
73 | @hooks.hook('config-changed') | 71 | @hooks.hook('config-changed') |
72 | @restart_on_stop() | ||
73 | @restart_on_change(restart_map()) | ||
74 | def config_changed(): | 74 | def config_changed(): |
75 | ''' | 75 | ''' |
76 | This hook is run when a config parameter is changed. | 76 | This hook is run when a config parameter is changed. |
@@ -83,10 +83,6 @@ def config_changed(): | |||
83 | if charm_config.changed('fabric-interfaces'): | 83 | if charm_config.changed('fabric-interfaces'): |
84 | if not fabric_interface_changed(): | 84 | if not fabric_interface_changed(): |
85 | log("Fabric interface already set") | 85 | log("Fabric interface already set") |
86 | else: | ||
87 | stop_pg() | ||
88 | if charm_config.changed('external-interfaces'): | ||
89 | stop_pg() | ||
90 | if (charm_config.changed('install_sources') or | 86 | if (charm_config.changed('install_sources') or |
91 | charm_config.changed('plumgrid-build') or | 87 | charm_config.changed('plumgrid-build') or |
92 | charm_config.changed('install_keys') or | 88 | charm_config.changed('install_keys') or |
@@ -100,8 +96,6 @@ def config_changed(): | |||
100 | load_iovisor() | 96 | load_iovisor() |
101 | ensure_mtu() | 97 | ensure_mtu() |
102 | CONFIGS.write_all() | 98 | CONFIGS.write_all() |
103 | if not service_running('plumgrid'): | ||
104 | restart_pg() | ||
105 | 99 | ||
106 | 100 | ||
107 | @hooks.hook('upgrade-charm') | 101 | @hooks.hook('upgrade-charm') |
diff --git a/hooks/pg_gw_utils.py b/hooks/pg_gw_utils.py index 5bf695c..b4e2f98 100644 --- a/hooks/pg_gw_utils.py +++ b/hooks/pg_gw_utils.py | |||
@@ -393,6 +393,19 @@ def director_cluster_ready(): | |||
393 | return True if dirs_count == 1 or dirs_count == 3 else False | 393 | return True if dirs_count == 1 or dirs_count == 3 else False |
394 | 394 | ||
395 | 395 | ||
396 | def restart_on_stop(): | ||
397 | """ | ||
398 | Starts plumgrid service if it is stopped | ||
399 | """ | ||
400 | def wrap(f): | ||
401 | def wrapped_f(*args, **kwargs): | ||
402 | f(*args, **kwargs) | ||
403 | if not service_running('plumgrid'): | ||
404 | restart_pg() | ||
405 | return wrapped_f | ||
406 | return wrap | ||
407 | |||
408 | |||
396 | def restart_on_change(restart_map): | 409 | def restart_on_change(restart_map): |
397 | """ | 410 | """ |
398 | Restart services based on configuration files changing | 411 | Restart services based on configuration files changing |
@@ -403,6 +416,8 @@ def restart_on_change(restart_map): | |||
403 | f(*args, **kwargs) | 416 | f(*args, **kwargs) |
404 | for path in restart_map: | 417 | for path in restart_map: |
405 | if path_hash(path) != checksums[path]: | 418 | if path_hash(path) != checksums[path]: |
419 | if path == PG_IFCS_CONF: | ||
420 | ensure_files() | ||
406 | restart_pg() | 421 | restart_pg() |
407 | break | 422 | break |
408 | return wrapped_f | 423 | return wrapped_f |
diff --git a/unit_tests/test_pg_gw_hooks.py b/unit_tests/test_pg_gw_hooks.py index b218be3..eb879c6 100644 --- a/unit_tests/test_pg_gw_hooks.py +++ b/unit_tests/test_pg_gw_hooks.py | |||
@@ -24,7 +24,6 @@ TO_PATCH = [ | |||
24 | 'configure_sources', | 24 | 'configure_sources', |
25 | 'ensure_files', | 25 | 'ensure_files', |
26 | 'stop_pg', | 26 | 'stop_pg', |
27 | 'restart_pg', | ||
28 | 'load_iovisor', | 27 | 'load_iovisor', |
29 | 'ensure_mtu', | 28 | 'ensure_mtu', |
30 | 'add_lcm_key', | 29 | 'add_lcm_key', |