Merge lp:~adam-collard/charms/trusty/swift-storage/guard-paused-unit-service-restarts into lp:~openstack-charmers-archive/charms/trusty/swift-storage/next

Proposed by Adam Collard
Status: Superseded
Proposed branch: lp:~adam-collard/charms/trusty/swift-storage/guard-paused-unit-service-restarts
Merge into: lp:~openstack-charmers-archive/charms/trusty/swift-storage/next
Diff against target: 270 lines (+100/-31)
7 files modified
charmhelpers/contrib/network/ip.py (+5/-1)
charmhelpers/contrib/openstack/utils.py (+7/-5)
charmhelpers/core/hookenv.py (+11/-9)
hooks/swift_storage_hooks.py (+5/-3)
lib/misc_utils.py (+18/-0)
lib/swift_storage_utils.py (+4/-2)
tests/basic_deployment.py (+50/-11)
To merge this branch: bzr merge lp:~adam-collard/charms/trusty/swift-storage/guard-paused-unit-service-restarts
Reviewer Review Type Date Requested Status
Landscape Pending
OpenStack Charmers Pending
Review via email: mp+269528@code.launchpad.net

This proposal has been superseded by a proposal from 2015-09-02.

Description of the change

This is a follow up branch to https://code.launchpad.net/~adam-collard/charms/trusty/swift-storage/add-pause-resume-actions/+merge/268233 to prevent config-changed from blindly (re)starting services when the unit is paused.

Normal flow is pause(), (optionally) change config -> changes should be persisted on disk, but nothing started. resume() -> services started.

To post a comment you must log in.
Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #8938 swift-storage-next for adam-collard mp269528
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/8938/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8258 swift-storage-next for adam-collard mp269528
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/8258/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6082 swift-storage-next for adam-collard mp269528
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12215822/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6082/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_lint_check #8939 swift-storage-next for adam-collard mp269528
    LINT OK: passed

Build: http://10.245.162.77:8080/job/charm_lint_check/8939/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_unit_test #8259 swift-storage-next for adam-collard mp269528
    UNIT OK: passed

Build: http://10.245.162.77:8080/job/charm_unit_test/8259/

Revision history for this message
uosci-testing-bot (uosci-testing-bot) wrote :

charm_amulet_test #6083 swift-storage-next for adam-collard mp269528
    AMULET FAIL: amulet-test failed

AMULET Results (max last 2 lines):
make: *** [functional_test] Error 1
ERROR:root:Make target returned non-zero.

Full amulet test output: http://paste.ubuntu.com/12216361/
Build: http://10.245.162.77:8080/job/charm_amulet_test/6083/

97. By Adam Collard

Expand list-comp to full for-loop, use SWIFT_SVCS instead of ACCOUNT + CONTAINER + OBJECT (ack's review)

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'charmhelpers/contrib/network/ip.py'
--- charmhelpers/contrib/network/ip.py 2015-03-04 09:54:59 +0000
+++ charmhelpers/contrib/network/ip.py 2015-09-01 16:09:33 +0000
@@ -435,8 +435,12 @@
435435
436 rev = dns.reversename.from_address(address)436 rev = dns.reversename.from_address(address)
437 result = ns_query(rev)437 result = ns_query(rev)
438
438 if not result:439 if not result:
439 return None440 try:
441 result = socket.gethostbyaddr(address)[0]
442 except:
443 return None
440 else:444 else:
441 result = address445 result = address
442446
443447
=== modified file 'charmhelpers/contrib/openstack/utils.py'
--- charmhelpers/contrib/openstack/utils.py 2015-08-17 13:44:42 +0000
+++ charmhelpers/contrib/openstack/utils.py 2015-09-01 16:09:33 +0000
@@ -1,5 +1,3 @@
1#!/usr/bin/python
2
3# Copyright 2014-2015 Canonical Limited.1# Copyright 2014-2015 Canonical Limited.
4#2#
5# This file is part of charm-helpers.3# This file is part of charm-helpers.
@@ -195,9 +193,9 @@
195 error_out(e)193 error_out(e)
196194
197195
198def get_os_version_codename(codename):196def get_os_version_codename(codename, version_map=OPENSTACK_CODENAMES):
199 '''Determine OpenStack version number from codename.'''197 '''Determine OpenStack version number from codename.'''
200 for k, v in six.iteritems(OPENSTACK_CODENAMES):198 for k, v in six.iteritems(version_map):
201 if v == codename:199 if v == codename:
202 return k200 return k
203 e = 'Could not derive OpenStack version for '\201 e = 'Could not derive OpenStack version for '\
@@ -429,7 +427,11 @@
429 import apt_pkg as apt427 import apt_pkg as apt
430 src = config('openstack-origin')428 src = config('openstack-origin')
431 cur_vers = get_os_version_package(package)429 cur_vers = get_os_version_package(package)
432 available_vers = get_os_version_install_source(src)430 if "swift" in package:
431 codename = get_os_codename_install_source(src)
432 available_vers = get_os_version_codename(codename, SWIFT_CODENAMES)
433 else:
434 available_vers = get_os_version_install_source(src)
433 apt.init()435 apt.init()
434 return apt.version_compare(available_vers, cur_vers) == 1436 return apt.version_compare(available_vers, cur_vers) == 1
435437
436438
=== modified file 'charmhelpers/core/hookenv.py'
--- charmhelpers/core/hookenv.py 2015-08-17 13:44:42 +0000
+++ charmhelpers/core/hookenv.py 2015-09-01 16:09:33 +0000
@@ -767,21 +767,23 @@
767767
768768
769def status_get():769def status_get():
770 """Retrieve the previously set juju workload state770 """Retrieve the previously set juju workload state and message
771771
772 If the status-set command is not found then assume this is juju < 1.23 and772 If the status-get command is not found then assume this is juju < 1.23 and
773 return 'unknown'773 return 'unknown', ""
774
774 """775 """
775 cmd = ['status-get']776 cmd = ['status-get', "--format=json", "--include-data"]
776 try:777 try:
777 raw_status = subprocess.check_output(cmd, universal_newlines=True)778 raw_status = subprocess.check_output(cmd)
778 status = raw_status.rstrip()
779 return status
780 except OSError as e:779 except OSError as e:
781 if e.errno == errno.ENOENT:780 if e.errno == errno.ENOENT:
782 return 'unknown'781 return ('unknown', "")
783 else:782 else:
784 raise783 raise
784 else:
785 status = json.loads(raw_status.decode("UTF-8"))
786 return (status["status"], status["message"])
785787
786788
787def translate_exc(from_exc, to_exc):789def translate_exc(from_exc, to_exc):
788790
=== modified file 'hooks/swift_storage_hooks.py'
--- hooks/swift_storage_hooks.py 2015-07-17 09:57:19 +0000
+++ hooks/swift_storage_hooks.py 2015-09-01 16:09:33 +0000
@@ -18,6 +18,8 @@
18 setup_rsync,18 setup_rsync,
19)19)
2020
21from lib.misc_utils import pause_aware_restart_on_change
22
21from charmhelpers.core.hookenv import (23from charmhelpers.core.hookenv import (
22 Hooks, UnregisteredHookError,24 Hooks, UnregisteredHookError,
23 config,25 config,
@@ -32,7 +34,7 @@
32 apt_update,34 apt_update,
33 filter_installed_packages35 filter_installed_packages
34)36)
35from charmhelpers.core.host import restart_on_change, rsync37from charmhelpers.core.host import rsync
36from charmhelpers.payload.execd import execd_preinstall38from charmhelpers.payload.execd import execd_preinstall
3739
38from charmhelpers.contrib.openstack.utils import (40from charmhelpers.contrib.openstack.utils import (
@@ -63,7 +65,7 @@
6365
6466
65@hooks.hook('config-changed')67@hooks.hook('config-changed')
66@restart_on_change(RESTART_MAP)68@pause_aware_restart_on_change(RESTART_MAP)
67def config_changed():69def config_changed():
68 if config('prefer-ipv6'):70 if config('prefer-ipv6'):
69 assert_charm_supports_ipv6()71 assert_charm_supports_ipv6()
@@ -104,7 +106,7 @@
104106
105107
106@hooks.hook('swift-storage-relation-changed')108@hooks.hook('swift-storage-relation-changed')
107@restart_on_change(RESTART_MAP)109@pause_aware_restart_on_change(RESTART_MAP)
108def swift_storage_relation_changed():110def swift_storage_relation_changed():
109 rings_url = relation_get('rings_url')111 rings_url = relation_get('rings_url')
110 swift_hash = relation_get('swift_hash')112 swift_hash = relation_get('swift_hash')
111113
=== modified file 'lib/misc_utils.py'
--- lib/misc_utils.py 2015-07-17 10:51:25 +0000
+++ lib/misc_utils.py 2015-09-01 16:09:33 +0000
@@ -16,12 +16,14 @@
16from charmhelpers.core.host import (16from charmhelpers.core.host import (
17 mounts,17 mounts,
18 umount,18 umount,
19 restart_on_change,
19)20)
2021
21from charmhelpers.core.hookenv import (22from charmhelpers.core.hookenv import (
22 log,23 log,
23 INFO,24 INFO,
24 ERROR,25 ERROR,
26 status_get,
25)27)
2628
27DEFAULT_LOOPBACK_SIZE = '5G'29DEFAULT_LOOPBACK_SIZE = '5G'
@@ -83,3 +85,19 @@
83 remove_lvm_physical_volume(block_device)85 remove_lvm_physical_volume(block_device)
84 else:86 else:
85 zap_disk(block_device)87 zap_disk(block_device)
88
89
90def is_paused(status_get=status_get):
91 """Is the unit paused?"""
92 status, message = status_get()
93 return status == "maintenance" and message.startswith("Paused")
94
95
96def pause_aware_restart_on_change(restart_map):
97 """Avoids restarting services if config changes when unit is paused."""
98 def wrapper(f):
99 if is_paused():
100 return f
101 else:
102 return restart_on_change(restart_map)(f)
103 return wrapper
86104
=== modified file 'lib/swift_storage_utils.py'
--- lib/swift_storage_utils.py 2015-08-11 13:59:31 +0000
+++ lib/swift_storage_utils.py 2015-09-01 16:09:33 +0000
@@ -10,6 +10,7 @@
10from misc_utils import (10from misc_utils import (
11 ensure_block_device,11 ensure_block_device,
12 clean_storage,12 clean_storage,
13 is_paused
13)14)
1415
15from swift_storage_context import (16from swift_storage_context import (
@@ -151,8 +152,9 @@
151 apt_upgrade(options=dpkg_opts, fatal=True, dist=True)152 apt_upgrade(options=dpkg_opts, fatal=True, dist=True)
152 configs.set_release(openstack_release=new_os_rel)153 configs.set_release(openstack_release=new_os_rel)
153 configs.write_all()154 configs.write_all()
154 [service_restart(svc) for svc in155 if not is_paused():
155 (ACCOUNT_SVCS + CONTAINER_SVCS + OBJECT_SVCS)]156 [service_restart(svc) for svc in
157 (ACCOUNT_SVCS + CONTAINER_SVCS + OBJECT_SVCS)]
156158
157159
158def _is_storage_ready(partition):160def _is_storage_ready(partition):
159161
=== modified file 'tests/basic_deployment.py'
--- tests/basic_deployment.py 2015-08-22 04:12:14 +0000
+++ tests/basic_deployment.py 2015-09-01 16:09:33 +0000
@@ -429,19 +429,10 @@
429429
430 # Config file affected by juju set config change, and430 # Config file affected by juju set config change, and
431 # services which are expected to restart upon config change431 # services which are expected to restart upon config change
432 services = {'swift-account-server': 'account-server.conf',432 services = {'swift-object-server': 'object-server.conf',
433 'swift-account-auditor': 'account-server.conf',
434 'swift-account-reaper': 'account-server.conf',
435 'swift-account-replicator': 'account-server.conf',
436 'swift-container-server': 'container-server.conf',
437 'swift-container-auditor': 'container-server.conf',
438 'swift-container-replicator': 'container-server.conf',
439 'swift-container-updater': 'container-server.conf',
440 'swift-object-server': 'object-server.conf',
441 'swift-object-auditor': 'object-server.conf',433 'swift-object-auditor': 'object-server.conf',
442 'swift-object-replicator': 'object-server.conf',434 'swift-object-replicator': 'object-server.conf',
443 'swift-object-updater': 'object-server.conf',435 'swift-object-updater': 'object-server.conf'}
444 'swift-container-sync': 'container-server.conf'}
445436
446 # Make config change, check for service restarts437 # Make config change, check for service restarts
447 u.log.debug('Making config change on {}...'.format(juju_service))438 u.log.debug('Making config change on {}...'.format(juju_service))
@@ -510,3 +501,51 @@
510 u.log.debug('Checking pause/resume actions...')501 u.log.debug('Checking pause/resume actions...')
511 self._test_pause()502 self._test_pause()
512 self._test_resume()503 self._test_resume()
504
505 def test_920_no_restart_on_config_change_when_paused(self):
506 """Verify that the specified services are not restarted when the config
507 is changed and the unit is paused."""
508 u.log.info('Checking that system services do not get restarted '
509 'when charm config changes but unit is paused...')
510 sentry = self.swift_storage_sentry
511 juju_service = 'swift-storage'
512
513 # Expected default and alternate values
514 set_default = {'object-server-threads-per-disk': '4'}
515 set_alternate = {'object-server-threads-per-disk': '2'}
516
517 services = ['swift-account-server',
518 'swift-account-auditor',
519 'swift-account-reaper',
520 'swift-account-replicator',
521 'swift-container-server',
522 'swift-container-auditor',
523 'swift-container-replicator',
524 'swift-container-updater',
525 'swift-object-server',
526 'swift-object-auditor',
527 'swift-object-replicator',
528 'swift-object-updater',
529 'swift-container-sync']
530 if self._get_openstack_release() < self.precise_icehouse:
531 services.remove('swift-container-sync')
532
533 # Pause the unit
534 u.log.debug('Pausing the unit...')
535 pause_action_id = u.run_action(sentry, "pause")
536 assert u.wait_on_action(pause_action_id), "Pause action failed."
537
538 # Make config change, check for service restarts
539 u.log.debug('Making config change on {}...'.format(juju_service))
540 self.d.configure(juju_service, set_alternate)
541
542 for service in services:
543 u.log.debug("Checking that service didn't start while "
544 "paused: {}".format(service))
545 # No explicit assert because get_process_id_list will do it for us
546 u.get_process_id_list(
547 sentry, service, expect_success=False)
548
549 self.d.configure(juju_service, set_default)
550 resume_action_id = u.run_action(sentry, "resume")
551 assert u.wait_on_action(resume_action_id), "Resume action failed."

Subscribers

People subscribed via source and target branches