Stop services appropriate for the installation and convert unit_private_ip to hostnames if needed

This commit is contained in:
Liam Young 2013-11-28 13:12:39 +00:00
parent 96f4b40c1b
commit f8ffb0c2c7
5 changed files with 59 additions and 16 deletions

View File

@ -17,7 +17,6 @@ from charmhelpers.fetch import (
from charmhelpers.core.host import (
restart_on_change,
lsb_release,
service_stop
)
from charmhelpers.contrib.hahelpers.cluster import(
eligible_leader
@ -27,7 +26,7 @@ from charmhelpers.contrib.hahelpers.apache import(
)
from charmhelpers.contrib.openstack.utils import (
configure_installation_source,
openstack_upgrade_available
openstack_upgrade_available,
)
from charmhelpers.payload.execd import execd_preinstall
@ -42,6 +41,7 @@ from quantum_utils import (
valid_plugin,
configure_ovs,
reassign_agent_resources,
stop_services
)
from quantum_contexts import (
DB_USER, QUANTUM_DB,
@ -143,8 +143,7 @@ def cluster_departed():
@hooks.hook('cluster-relation-broken')
@hooks.hook('stop')
def stop():
service_stop('neutron-l3-agent')
stop_services()
if __name__ == '__main__':
try:

View File

@ -1,9 +1,12 @@
from charmhelpers.core.host import service_running
from charmhelpers.core.host import (
service_running,
service_stop
)
from charmhelpers.core.hookenv import (
log,
config,
relations_of_type,
unit_private_ip,
unit_private_ip
)
from charmhelpers.fetch import (
apt_install,
@ -12,12 +15,13 @@ from charmhelpers.fetch import (
from charmhelpers.contrib.network.ovs import (
add_bridge,
add_bridge_port,
full_restart,
full_restart
)
from charmhelpers.contrib.openstack.utils import (
configure_installation_source,
get_os_codename_install_source,
get_os_codename_package
get_os_codename_package,
get_hostname
)
import charmhelpers.contrib.openstack.context as context
@ -272,6 +276,16 @@ def register_configs():
return configs
def stop_services():
name = networking_name()
svcs = set()
for ctxt in CONFIG_FILES[name][config('plugin')].itervalues():
for svc in ctxt['services']:
svcs.add(svc)
for svc in svcs:
service_stop(svc)
def restart_map():
'''
Determine the correct resource map to be passed to
@ -321,7 +335,8 @@ def reassign_agent_resources():
partner_gateways = [unit_private_ip().split('.')[0]]
for partner_gateway in relations_of_type(reltype='cluster'):
partner_gateways.append(partner_gateway['private-address'].split('.')[0])
gateway_hostname = get_hostname(partner_gateway['private-address'])
partner_gateways.append(gateway_hostname.partition('.')[0])
agents = quantum.list_agents(agent_type=DHCP_AGENT)
dhcp_agents = []
@ -335,7 +350,7 @@ def reassign_agent_resources():
agent['id'])['networks']:
networks[network['id']] = agent['id']
else:
if agent['host'].split('.')[0] in partner_gateways:
if agent['host'].partition('.')[0] in partner_gateways:
dhcp_agents.append(agent['id'])
agents = quantum.list_agents(agent_type=L3_AGENT)

View File

@ -1 +1 @@
57
59

View File

@ -35,7 +35,7 @@ TO_PATCH = [
'get_common_package',
'execd_preinstall',
'lsb_release',
'service_stop',
'stop_services',
]
@ -161,4 +161,4 @@ class TestQuantumHooks(CharmTestCase):
def test_stop(self):
self._call_hook('stop')
self.service_stop.assert_called_with('neutron-l3-agent')
self.stop_services.assert_called

View File

@ -36,6 +36,7 @@ TO_PATCH = [
'NetworkServiceContext',
'unit_private_ip',
'relations_of_type',
'service_stop',
]
@ -178,6 +179,30 @@ class TestQuantumUtils(CharmTestCase):
['hook_contexts']
)
def test_stop_services_nvp(self):
self.config.return_value = 'nvp'
quantum_utils.stop_services()
calls = [call('neutron-dhcp-agent'),
call('nova-api-metadata'),
call('neutron-metadata-agent')]
self.service_stop.assert_has_calls(
calls,
any_order=True,
)
def test_stop_services_ovs(self):
self.config.return_value = 'ovs'
quantum_utils.stop_services()
calls = [call('neutron-dhcp-agent'),
call('neutron-plugin-openvswitch-agent'),
call('nova-api-metadata'),
call('neutron-l3-agent'),
call('neutron-metadata-agent')]
self.service_stop.assert_has_calls(
calls,
any_order=True,
)
def test_restart_map_nvp(self):
self.config.return_value = 'nvp'
ex_map = {
@ -358,6 +383,7 @@ cluster1 = ['cluster1-machine1.internal']
cluster2 = ['cluster2-machine1.internal', 'cluster2-machine2.internal'
'cluster2-machine3.internal']
class TestQuantumAgentReallocation(CharmTestCase):
def setUp(self):
if not neutronclient:
@ -393,14 +419,16 @@ class TestQuantumAgentReallocation(CharmTestCase):
self.NetworkServiceContext.return_value = \
DummyNetworkServiceContext(return_value=network_context)
dummy_client = MagicMock()
dummy_client.list_agents.side_effect = agents_some_dead_cl2.itervalues()
dummy_client.list_agents.side_effect = \
agents_some_dead_cl2.itervalues()
dummy_client.list_networks_on_dhcp_agent.return_value = \
dhcp_agent_networks
dummy_client.list_routers_on_l3_agent.return_value = \
l3_agent_routers
_client.return_value = dummy_client
self.unit_private_ip.return_value = 'cluster2-machine1.internal'
self.relations_of_type.return_value = [ { 'private-address': 'cluster2-machine3.internal' }]
self.relations_of_type.return_value = \
[{'private-address': 'cluster2-machine3.internal'}]
quantum_utils.reassign_agent_resources()
# Ensure routers removed from dead l3 agent
@ -433,7 +461,8 @@ class TestQuantumAgentReallocation(CharmTestCase):
self.NetworkServiceContext.return_value = \
DummyNetworkServiceContext(return_value=network_context)
dummy_client = MagicMock()
dummy_client.list_agents.side_effect = agents_some_dead_cl1.itervalues()
dummy_client.list_agents.side_effect = \
agents_some_dead_cl1.itervalues()
dummy_client.list_networks_on_dhcp_agent.return_value = \
dhcp_agent_networks
dummy_client.list_routers_on_l3_agent.return_value = \