Add unit status support
This commit is contained in:
commit
54e229e0e1
@ -121,10 +121,10 @@ class L3AgentContext(OSContextGenerator):
|
||||
return ctxt
|
||||
|
||||
|
||||
class NeutronGatewayContext(OSContextGenerator):
|
||||
class NeutronGatewayContext(NeutronAPIContext):
|
||||
|
||||
def __call__(self):
|
||||
api_settings = NeutronAPIContext()()
|
||||
api_settings = super(NeutronGatewayContext, self).__call__()
|
||||
ctxt = {
|
||||
'shared_secret': get_shared_secret(),
|
||||
'local_ip':
|
||||
|
@ -10,7 +10,9 @@ from charmhelpers.core.hookenv import (
|
||||
relation_set,
|
||||
relation_ids,
|
||||
unit_get,
|
||||
Hooks, UnregisteredHookError
|
||||
Hooks,
|
||||
UnregisteredHookError,
|
||||
status_set,
|
||||
)
|
||||
from charmhelpers.fetch import (
|
||||
apt_update,
|
||||
@ -34,6 +36,7 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
configure_installation_source,
|
||||
openstack_upgrade_available,
|
||||
os_requires_version,
|
||||
set_os_workload_status,
|
||||
)
|
||||
from charmhelpers.payload.execd import execd_preinstall
|
||||
from charmhelpers.core.sysctl import create as create_sysctl
|
||||
@ -64,6 +67,8 @@ from neutron_utils import (
|
||||
reassign_agent_resources,
|
||||
stop_neutron_ha_monitor_daemon,
|
||||
use_l3ha,
|
||||
REQUIRED_INTERFACES,
|
||||
check_optional_relations,
|
||||
)
|
||||
|
||||
hooks = Hooks()
|
||||
@ -72,12 +77,14 @@ CONFIGS = register_configs()
|
||||
|
||||
@hooks.hook('install.real')
|
||||
def install():
|
||||
status_set('maintenance', 'Executing pre-install')
|
||||
execd_preinstall()
|
||||
src = config('openstack-origin')
|
||||
if (lsb_release()['DISTRIB_CODENAME'] == 'precise' and
|
||||
src == 'distro'):
|
||||
src = 'cloud:precise-folsom'
|
||||
configure_installation_source(src)
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_update(fatal=True)
|
||||
apt_install('python-six', fatal=True) # Force upgrade
|
||||
if valid_plugin():
|
||||
@ -85,9 +92,12 @@ def install():
|
||||
fatal=True)
|
||||
apt_install(filter_installed_packages(get_packages()),
|
||||
fatal=True)
|
||||
status_set('maintenance', 'Git install')
|
||||
git_install(config('openstack-origin-git'))
|
||||
else:
|
||||
log('Please provide a valid plugin config', level=ERROR)
|
||||
message = 'Please provide a valid plugin config'
|
||||
log(message, level=ERROR)
|
||||
status_set('blocked', message)
|
||||
sys.exit(1)
|
||||
|
||||
# Legacy HA for Icehouse
|
||||
@ -100,10 +110,13 @@ def config_changed():
|
||||
global CONFIGS
|
||||
if git_install_requested():
|
||||
if config_value_changed('openstack-origin-git'):
|
||||
status_set('maintenance', 'Running Git install')
|
||||
git_install(config('openstack-origin-git'))
|
||||
CONFIGS.write_all()
|
||||
|
||||
elif not config('action-managed-upgrade'):
|
||||
if openstack_upgrade_available(get_common_package()):
|
||||
status_set('maintenance', 'Running openstack upgrade')
|
||||
do_openstack_upgrade(CONFIGS)
|
||||
|
||||
update_nrpe_config()
|
||||
@ -127,11 +140,14 @@ def config_changed():
|
||||
CONFIGS.write_all()
|
||||
configure_ovs()
|
||||
else:
|
||||
log('Please provide a valid plugin config', level=ERROR)
|
||||
message = 'Please provide a valid plugin config'
|
||||
log(message, level=ERROR)
|
||||
status_set('blocked', message)
|
||||
sys.exit(1)
|
||||
if config('plugin') == 'n1kv':
|
||||
if not git_install_requested():
|
||||
if config('enable-l3-agent'):
|
||||
status_set('maintenance', 'Installing apt packages')
|
||||
apt_install(filter_installed_packages('neutron-l3-agent'))
|
||||
else:
|
||||
apt_purge('neutron-l3-agent')
|
||||
@ -342,3 +358,5 @@ if __name__ == '__main__':
|
||||
hooks.execute(sys.argv)
|
||||
except UnregisteredHookError as e:
|
||||
log('Unknown hook {} - skipping.'.format(e))
|
||||
set_os_workload_status(CONFIGS, REQUIRED_INTERFACES,
|
||||
charm_func=check_optional_relations)
|
||||
|
@ -23,6 +23,8 @@ from charmhelpers.core.hookenv import (
|
||||
relations_of_type,
|
||||
unit_private_ip,
|
||||
is_relation_made,
|
||||
relation_ids,
|
||||
status_get,
|
||||
)
|
||||
from charmhelpers.core.templating import render
|
||||
from charmhelpers.fetch import (
|
||||
@ -35,6 +37,9 @@ from charmhelpers.contrib.network.ovs import (
|
||||
add_bridge_port,
|
||||
full_restart
|
||||
)
|
||||
from charmhelpers.contrib.hahelpers.cluster import (
|
||||
get_hacluster_config,
|
||||
)
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
configure_installation_source,
|
||||
get_os_codename_install_source,
|
||||
@ -43,7 +48,8 @@ from charmhelpers.contrib.openstack.utils import (
|
||||
git_clone_and_install,
|
||||
git_src_dir,
|
||||
git_pip_venv_dir,
|
||||
get_hostname
|
||||
get_hostname,
|
||||
set_os_workload_status,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.openstack.neutron import (
|
||||
@ -230,6 +236,13 @@ GIT_PACKAGE_BLACKLIST = [
|
||||
'quantum-plugin-openvswitch-agent',
|
||||
]
|
||||
|
||||
# The interface is said to be satisfied if anyone of the interfaces in the
|
||||
# list has a complete context.
|
||||
REQUIRED_INTERFACES = {
|
||||
'messaging': ['amqp', 'zeromq-configuration'],
|
||||
'neutron-plugin-api': ['neutron-plugin-api'],
|
||||
}
|
||||
|
||||
|
||||
def get_early_packages():
|
||||
'''Return a list of package for pre-install based on configured plugin'''
|
||||
@ -1236,3 +1249,21 @@ def git_post_install(projects_yaml):
|
||||
render('git/upstart/neutron-agent.upstart',
|
||||
'/etc/init/neutron-vpn-agent.conf',
|
||||
neutron_vpn_agent_context, perms=0o644)
|
||||
|
||||
|
||||
def check_optional_relations(configs):
|
||||
required_interfaces = {}
|
||||
if relation_ids('ha'):
|
||||
required_interfaces['ha'] = ['cluster']
|
||||
try:
|
||||
get_hacluster_config()
|
||||
except:
|
||||
return ('blocked',
|
||||
'hacluster missing configuration: '
|
||||
'vip, vip_iface, vip_cidr')
|
||||
|
||||
if required_interfaces:
|
||||
set_os_workload_status(configs, required_interfaces)
|
||||
return status_get()
|
||||
else:
|
||||
return 'unknown', 'No optional relations'
|
||||
|
@ -14,7 +14,7 @@ from charmhelpers.contrib.openstack.amulet.deployment import (
|
||||
from charmhelpers.contrib.openstack.amulet.utils import (
|
||||
OpenStackAmuletUtils,
|
||||
DEBUG,
|
||||
#ERROR
|
||||
# ERROR
|
||||
)
|
||||
|
||||
# Use DEBUG to turn on debug logging
|
||||
@ -936,7 +936,7 @@ class NeutronGatewayBasicDeployment(OpenStackAmuletDeployment):
|
||||
self.neutron.format = 'json'
|
||||
net_name = 'ext_net'
|
||||
|
||||
#Verify that the network doesn't exist
|
||||
# Verify that the network doesn't exist
|
||||
networks = self.neutron.list_networks(name=net_name)
|
||||
net_count = len(networks['networks'])
|
||||
if net_count != 0:
|
||||
@ -958,7 +958,7 @@ class NeutronGatewayBasicDeployment(OpenStackAmuletDeployment):
|
||||
if network['name'] != net_name:
|
||||
amulet.raise_status(amulet.FAIL, msg="network ext_net not found")
|
||||
|
||||
#Cleanup
|
||||
# Cleanup
|
||||
u.log.debug('Deleting neutron network...')
|
||||
self.neutron.delete_network(network['id'])
|
||||
|
||||
@ -992,18 +992,16 @@ class NeutronGatewayBasicDeployment(OpenStackAmuletDeployment):
|
||||
mtime = u.get_sentry_time(sentry)
|
||||
self.d.configure(juju_service, set_alternate)
|
||||
|
||||
# sleep_time = 90
|
||||
# sleep_time = 90
|
||||
for s, conf_file in services.iteritems():
|
||||
u.log.debug("Checking that service restarted: {}".format(s))
|
||||
if not u.validate_service_config_changed(sentry, mtime, s,
|
||||
conf_file):
|
||||
# conf_file,
|
||||
# sleep_time=sleep_time):
|
||||
self.d.configure(juju_service, set_default)
|
||||
msg = "service {} didn't restart after config change".format(s)
|
||||
amulet.raise_status(amulet.FAIL, msg=msg)
|
||||
|
||||
# Only do initial sleep on first service check
|
||||
# sleep_time = 0
|
||||
# sleep_time = 0
|
||||
|
||||
self.d.configure(juju_service, set_default)
|
||||
|
@ -4,6 +4,10 @@ with patch('charmhelpers.core.hookenv.config') as config:
|
||||
config.return_value = 'neutron'
|
||||
import neutron_utils as utils # noqa
|
||||
|
||||
from test_utils import (
|
||||
CharmTestCase
|
||||
)
|
||||
|
||||
# Need to do some early patching to get the module loaded.
|
||||
_register_configs = utils.register_configs
|
||||
_restart_map = utils.restart_map
|
||||
@ -11,16 +15,13 @@ _restart_map = utils.restart_map
|
||||
utils.register_configs = MagicMock()
|
||||
utils.restart_map = MagicMock()
|
||||
|
||||
import git_reinstall
|
||||
with patch('charmhelpers.core.hookenv.status_set'):
|
||||
import git_reinstall
|
||||
|
||||
# Unpatch it now that its loaded.
|
||||
utils.register_configs = _register_configs
|
||||
utils.restart_map = _restart_map
|
||||
|
||||
from test_utils import (
|
||||
CharmTestCase
|
||||
)
|
||||
|
||||
TO_PATCH = [
|
||||
'config',
|
||||
]
|
||||
|
@ -1,15 +1,16 @@
|
||||
from mock import patch
|
||||
import os
|
||||
|
||||
os.environ['JUJU_UNIT_NAME'] = 'neutron-gateway'
|
||||
|
||||
with patch('neutron_utils.register_configs') as register_configs:
|
||||
import openstack_upgrade
|
||||
|
||||
from test_utils import (
|
||||
CharmTestCase
|
||||
)
|
||||
|
||||
os.environ['JUJU_UNIT_NAME'] = 'neutron-gateway'
|
||||
|
||||
with patch('charmhelpers.core.hookenv.status_set'):
|
||||
with patch('neutron_utils.register_configs') as register_configs:
|
||||
import openstack_upgrade
|
||||
|
||||
TO_PATCH = [
|
||||
'do_openstack_upgrade',
|
||||
'config_changed',
|
||||
|
@ -7,7 +7,10 @@ _register_configs = utils.register_configs
|
||||
_restart_map = utils.restart_map
|
||||
utils.register_configs = MagicMock()
|
||||
utils.restart_map = MagicMock()
|
||||
import neutron_hooks as hooks
|
||||
|
||||
with patch('charmhelpers.core.hookenv.status_set'):
|
||||
import neutron_hooks as hooks
|
||||
|
||||
utils.register_configs = _register_configs
|
||||
utils.restart_map = _restart_map
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user