diff --git a/hooks/hooks.py b/hooks/hooks.py index e9abe69..54aef91 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -48,6 +48,13 @@ from charmhelpers.contrib.network.ip import ( get_relation_ip, ) +from charmhelpers.contrib.openstack.utils import ( + is_unit_paused_set, + set_unit_upgrading, + clear_unit_upgrading, + clear_unit_paused, +) + from charmhelpers.fetch import ( apt_install, apt_purge, @@ -83,6 +90,8 @@ from utils import ( needs_maas_dns_migration, write_maas_dns_address, MAASConfigIncomplete, + pause_unit, + resume_unit, ) from charmhelpers.contrib.charmsupport import nrpe @@ -133,6 +142,12 @@ def get_transport(): @hooks.hook('config-changed') def config_changed(): + # if we are paused, delay doing any config changed hooks. + # It is forced on the resume. + if is_unit_paused_set(): + log("Unit is pause or upgrading. Skipping config_changed", "WARN") + return + setup_ocf_files() if config('prefer-ipv6'): @@ -481,6 +496,22 @@ def update_nrpe_config(): nrpe_setup.write() +@hooks.hook('pre-series-upgrade') +def series_upgrade_prepare(): + set_unit_upgrading() + if not is_unit_paused_set(): + pause_unit() + + +@hooks.hook('post-series-upgrade') +def series_upgrade_complete(): + log("Running complete series upgrade hook", "INFO") + clear_unit_paused() + clear_unit_upgrading() + config_changed() + resume_unit() + + if __name__ == '__main__': try: hooks.execute(sys.argv) diff --git a/hooks/post-series-upgrade b/hooks/post-series-upgrade new file mode 120000 index 0000000..9416ca6 --- /dev/null +++ b/hooks/post-series-upgrade @@ -0,0 +1 @@ +hooks.py \ No newline at end of file diff --git a/hooks/pre-series-upgrade b/hooks/pre-series-upgrade new file mode 120000 index 0000000..9416ca6 --- /dev/null +++ b/hooks/pre-series-upgrade @@ -0,0 +1 @@ +hooks.py \ No newline at end of file diff --git a/hooks/update-status b/hooks/update-status new file mode 120000 index 0000000..9416ca6 --- /dev/null +++ b/hooks/update-status @@ -0,0 +1 @@ +hooks.py \ No newline at end of file diff --git a/hooks/utils.py b/hooks/utils.py index cb9822b..c4d4cc7 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -47,6 +47,7 @@ from charmhelpers.contrib.openstack.utils import ( set_unit_paused, clear_unit_paused, is_unit_paused_set, + is_unit_upgrading_set, ) from charmhelpers.contrib.openstack.ha.utils import ( assert_charm_supports_dns_ha @@ -849,7 +850,7 @@ def pause_unit(): status, message = assess_status_helper() if status != 'active': messages.append(message) - if messages: + if messages and not is_unit_upgrading_set(): raise Exception("Couldn't pause: {}".format("; ".join(messages))) else: set_unit_paused() @@ -863,6 +864,14 @@ def assess_status_helper(): @returns status, message - status is workload status and message is any corresponding messages """ + + if is_unit_upgrading_set(): + return ("blocked", + "Ready for do-release-upgrde. Set complete when finished") + if is_unit_paused_set(): + return ("maintenance", + "Paused. Use 'resume' action to resume normal service.") + node_count = int(config('cluster_count')) status = 'active' message = 'Unit is ready and clustered'