Initial workload status support.
This commit is contained in:
@@ -33,7 +33,8 @@ from lib.swift_utils import (
|
||||
all_responses_equal,
|
||||
ensure_www_dir_permissions,
|
||||
is_paused,
|
||||
pause_aware_restart_on_change
|
||||
pause_aware_restart_on_change,
|
||||
assess_status,
|
||||
)
|
||||
|
||||
import charmhelpers.contrib.openstack.utils as openstack
|
||||
@@ -56,6 +57,7 @@ from charmhelpers.core.hookenv import (
|
||||
ERROR,
|
||||
Hooks, UnregisteredHookError,
|
||||
open_port,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.core.host import (
|
||||
service_reload,
|
||||
@@ -96,11 +98,13 @@ CONFIGS = register_configs()
|
||||
|
||||
@hooks.hook('install.real')
|
||||
def install():
|
||||
status_set('maintenance', 'Executing pre-install')
|
||||
execd_preinstall()
|
||||
src = config('openstack-origin')
|
||||
if src != 'distro':
|
||||
openstack.configure_installation_source(src)
|
||||
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_update(fatal=True)
|
||||
rel = openstack.get_os_codename_install_source(src)
|
||||
pkgs = determine_packages(rel)
|
||||
@@ -125,6 +129,7 @@ def install():
|
||||
@pause_aware_restart_on_change(restart_map())
|
||||
def config_changed():
|
||||
if config('prefer-ipv6'):
|
||||
status_set('maintenance', 'Configuring ipv6')
|
||||
setup_ipv6()
|
||||
|
||||
configure_https()
|
||||
@@ -135,7 +140,9 @@ def config_changed():
|
||||
if not config('action-managed-upgrade') and \
|
||||
openstack.openstack_upgrade_available('python-swift'):
|
||||
do_openstack_upgrade(CONFIGS)
|
||||
status_set('maintenance', 'Running openstack upgrade')
|
||||
|
||||
status_set('maintenance', 'Updating and balancing rings')
|
||||
update_rings(min_part_hours=config('min-hours'))
|
||||
|
||||
if not config('disable-ring-balance') and is_elected_leader(SWIFT_HA_RES):
|
||||
@@ -519,6 +526,7 @@ def main():
|
||||
hooks.execute(sys.argv)
|
||||
except UnregisteredHookError as e:
|
||||
log('Unknown hook {} - skipping.'.format(e), level=DEBUG)
|
||||
assess_status()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -43,7 +43,8 @@ from charmhelpers.core.hookenv import (
|
||||
relation_set,
|
||||
relation_ids,
|
||||
related_units,
|
||||
status_get
|
||||
status_get,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
apt_update,
|
||||
@@ -547,17 +548,7 @@ def should_balance(rings):
|
||||
if config('disable-ring-balance'):
|
||||
return False
|
||||
|
||||
for ring in rings:
|
||||
builder = _load_builder(ring).to_dict()
|
||||
replicas = builder['replicas']
|
||||
zones = [dev['zone'] for dev in builder['devs']]
|
||||
num_zones = len(set(zones))
|
||||
if num_zones < replicas:
|
||||
log("Not enough zones (%d) defined to allow ring balance "
|
||||
"(need >= %d)" % (num_zones, replicas), level=INFO)
|
||||
return False
|
||||
|
||||
return True
|
||||
return has_minimum_zones(rings)
|
||||
|
||||
|
||||
def do_openstack_upgrade(configs):
|
||||
@@ -1013,3 +1004,34 @@ def pause_aware_restart_on_change(restart_map):
|
||||
else:
|
||||
return restart_on_change(restart_map)(f)
|
||||
return wrapper
|
||||
|
||||
|
||||
def has_minimum_zones(rings):
|
||||
"""Determine if enough zones exist to satisfy minimum replicas"""
|
||||
for ring in rings:
|
||||
builder = _load_builder(ring).to_dict()
|
||||
replicas = builder['replicas']
|
||||
zones = [dev['zone'] for dev in builder['devs']]
|
||||
num_zones = len(set(zones))
|
||||
if num_zones < replicas:
|
||||
log("Not enough zones (%d) defined to satisfy minimum replicas "
|
||||
"(need >= %d)" % (num_zones, replicas), level=INFO)
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def assess_status():
|
||||
"""Assess status of current unit"""
|
||||
# Check for required swift-storage relation
|
||||
if len(relation_ids('swift-storage')) < 1:
|
||||
status_set('blocked', 'Missing relation: storage')
|
||||
return
|
||||
|
||||
# Verify there are enough storage zones to satisfy minimum replicas
|
||||
rings = [r for r in SWIFT_RINGS.itervalues()]
|
||||
if not has_minimum_zones(rings):
|
||||
status_set('blocked',
|
||||
'Not enough storage zones for minimum replicas')
|
||||
else:
|
||||
status_set('active', 'Unit is ready')
|
||||
|
||||
Reference in New Issue
Block a user