From 5ffc750880f2b1d7c8ce3270a294601b791c6a8a Mon Sep 17 00:00:00 2001 From: Edward Hope-Morley Date: Tue, 25 Mar 2014 18:44:23 +0000 Subject: [PATCH] [hopem] Added use-syslog cfg option to allow logging to syslog --- config.yaml | 5 ++++ hooks/quantum_utils.py | 36 +++++++++++++++++-------- revision | 2 +- templates/folsom/dhcp_agent.ini | 1 + templates/folsom/l3_agent.ini | 1 + templates/folsom/metadata_agent.ini | 1 + templates/folsom/nova.conf | 1 + templates/folsom/ovs_quantum_plugin.ini | 2 ++ templates/folsom/quantum.conf | 1 + templates/havana/dhcp_agent.ini | 1 + templates/havana/l3_agent.ini | 1 + templates/havana/metadata_agent.ini | 1 + templates/havana/neutron.conf | 1 + templates/havana/nova.conf | 1 + templates/havana/ovs_neutron_plugin.ini | 2 ++ unit_tests/test_quantum_contexts.py | 24 ++++++++++++++--- 16 files changed, 66 insertions(+), 15 deletions(-) diff --git a/config.yaml b/config.yaml index d7b9ad45..63011664 100644 --- a/config.yaml +++ b/config.yaml @@ -50,6 +50,11 @@ options: type: string description: RabbitMQ Virtual Host default: openstack + use-syslog: + type: boolean + default: False + description: | + If set to True, supporting services will log to syslog. instance-mtu: type: int description: | diff --git a/hooks/quantum_utils.py b/hooks/quantum_utils.py index 45d318af..2efd9445 100644 --- a/hooks/quantum_utils.py +++ b/hooks/quantum_utils.py @@ -25,6 +25,9 @@ from charmhelpers.contrib.openstack.utils import ( ) import charmhelpers.contrib.openstack.context as context +from charmhelpers.contrib.openstack.context import ( + SyslogContext +) import charmhelpers.contrib.openstack.templating as templating from charmhelpers.contrib.openstack.neutron import headers_package from quantum_contexts import ( @@ -150,19 +153,22 @@ NOVA_CONFIG_FILES = { 'hook_contexts': [context.AMQPContext(), QuantumSharedDBContext(), NetworkServiceContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['nova-api-metadata'] }, } QUANTUM_SHARED_CONFIG_FILES = { QUANTUM_DHCP_AGENT_CONF: { - 'hook_contexts': [QuantumGatewayContext()], + 'hook_contexts': [QuantumGatewayContext(), + SyslogContext()], 'services': ['quantum-dhcp-agent'] }, QUANTUM_METADATA_AGENT_CONF: { 'hook_contexts': [NetworkServiceContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['quantum-metadata-agent'] }, } @@ -170,7 +176,8 @@ QUANTUM_SHARED_CONFIG_FILES.update(NOVA_CONFIG_FILES) NEUTRON_SHARED_CONFIG_FILES = { NEUTRON_DHCP_AGENT_CONF: { - 'hook_contexts': [QuantumGatewayContext()], + 'hook_contexts': [QuantumGatewayContext(), + SyslogContext()], 'services': ['neutron-dhcp-agent'] }, NEUTRON_DNSMASQ_CONF: { @@ -179,7 +186,8 @@ NEUTRON_SHARED_CONFIG_FILES = { }, NEUTRON_METADATA_AGENT_CONF: { 'hook_contexts': [NetworkServiceContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['neutron-metadata-agent'] }, } @@ -188,20 +196,23 @@ NEUTRON_SHARED_CONFIG_FILES.update(NOVA_CONFIG_FILES) QUANTUM_OVS_CONFIG_FILES = { QUANTUM_CONF: { 'hook_contexts': [context.AMQPContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['quantum-l3-agent', 'quantum-dhcp-agent', 'quantum-metadata-agent', 'quantum-plugin-openvswitch-agent'] }, QUANTUM_L3_AGENT_CONF: { - 'hook_contexts': [NetworkServiceContext()], + 'hook_contexts': [NetworkServiceContext(), + SyslogContext()], 'services': ['quantum-l3-agent'] }, # TODO: Check to see if this is actually required QUANTUM_OVS_PLUGIN_CONF: { 'hook_contexts': [QuantumSharedDBContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['quantum-plugin-openvswitch-agent'] }, EXT_PORT_CONF: { @@ -214,7 +225,8 @@ QUANTUM_OVS_CONFIG_FILES.update(QUANTUM_SHARED_CONFIG_FILES) NEUTRON_OVS_CONFIG_FILES = { NEUTRON_CONF: { 'hook_contexts': [context.AMQPContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['neutron-l3-agent', 'neutron-dhcp-agent', 'neutron-metadata-agent', @@ -222,13 +234,15 @@ NEUTRON_OVS_CONFIG_FILES = { }, NEUTRON_L3_AGENT_CONF: { 'hook_contexts': [NetworkServiceContext(), - L3AgentContext()], + L3AgentContext(), + SyslogContext()], 'services': ['neutron-l3-agent'] }, # TODO: Check to see if this is actually required NEUTRON_OVS_PLUGIN_CONF: { 'hook_contexts': [QuantumSharedDBContext(), - QuantumGatewayContext()], + QuantumGatewayContext(), + SyslogContext()], 'services': ['neutron-plugin-openvswitch-agent'] }, EXT_PORT_CONF: { diff --git a/revision b/revision index 4b9026d8..4b6f9c39 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -63 +64 \ No newline at end of file diff --git a/templates/folsom/dhcp_agent.ini b/templates/folsom/dhcp_agent.ini index 62672f37..2995a1c0 100644 --- a/templates/folsom/dhcp_agent.ini +++ b/templates/folsom/dhcp_agent.ini @@ -3,6 +3,7 @@ state_path = /var/lib/quantum interface_driver = quantum.agent.linux.interface.OVSInterfaceDriver dhcp_driver = quantum.agent.linux.dhcp.Dnsmasq root_helper = sudo /usr/bin/quantum-rootwrap /etc/quantum/rootwrap.conf +use_syslog = {{ use_syslog }} {% if plugin == 'nvp' %} ovs_use_veth = True enable_metadata_network = True diff --git a/templates/folsom/l3_agent.ini b/templates/folsom/l3_agent.ini index ff006324..a60c110c 100644 --- a/templates/folsom/l3_agent.ini +++ b/templates/folsom/l3_agent.ini @@ -6,3 +6,4 @@ admin_tenant_name = {{ service_tenant }} admin_user = {{ service_username }} admin_password = {{ service_password }} root_helper = sudo /usr/bin/quantum-rootwrap /etc/quantum/rootwrap.conf +use_syslog = {{ use_syslog }} diff --git a/templates/folsom/metadata_agent.ini b/templates/folsom/metadata_agent.ini index 44624192..7ea055a2 100644 --- a/templates/folsom/metadata_agent.ini +++ b/templates/folsom/metadata_agent.ini @@ -15,3 +15,4 @@ nova_metadata_port = 8775 # but it must match here and in the configuration used by the Nova Metadata # Server. NOTE: Nova uses a different key: quantum_metadata_proxy_shared_secret metadata_proxy_shared_secret = {{ shared_secret }} +use_syslog = {{ use_syslog }} diff --git a/templates/folsom/nova.conf b/templates/folsom/nova.conf index e58cfb32..6be73556 100644 --- a/templates/folsom/nova.conf +++ b/templates/folsom/nova.conf @@ -4,6 +4,7 @@ state_path=/var/lib/nova lock_path=/var/lock/nova root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf verbose=True +use_syslog = {{ use_syslog }} api_paste_config=/etc/nova/api-paste.ini enabled_apis=metadata multi_host=True diff --git a/templates/folsom/ovs_quantum_plugin.ini b/templates/folsom/ovs_quantum_plugin.ini index 8d6d415a..bc86b51f 100644 --- a/templates/folsom/ovs_quantum_plugin.ini +++ b/templates/folsom/ovs_quantum_plugin.ini @@ -1,3 +1,5 @@ +[DEFAULT] +use_syslog = {{ use_syslog }} [DATABASE] sql_connection = mysql://{{ quantum_user }}:{{ quantum_password }}@{{ database_host }}/{{ quantum_db }}?charset=utf8 reconnect_interval = 2 diff --git a/templates/folsom/quantum.conf b/templates/folsom/quantum.conf index be3ace39..a8054f80 100644 --- a/templates/folsom/quantum.conf +++ b/templates/folsom/quantum.conf @@ -5,6 +5,7 @@ rabbit_virtual_host = {{ rabbitmq_virtual_host }} rabbit_host = {{ rabbitmq_host }} rabbit_password = {{ rabbitmq_password }} debug = True +use_syslog = {{ use_syslog }} bind_host = 0.0.0.0 bind_port = 9696 core_plugin = {{ core_plugin }} diff --git a/templates/havana/dhcp_agent.ini b/templates/havana/dhcp_agent.ini index 6d76fac1..952c5b8f 100644 --- a/templates/havana/dhcp_agent.ini +++ b/templates/havana/dhcp_agent.ini @@ -7,6 +7,7 @@ state_path = /var/lib/neutron interface_driver = neutron.agent.linux.interface.OVSInterfaceDriver dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf +use_syslog = {{ use_syslog }} ovs_use_veth = True {% if instance_mtu -%} dnsmasq_config_file = /etc/neutron/dnsmasq.conf diff --git a/templates/havana/l3_agent.ini b/templates/havana/l3_agent.ini index 44a1970c..a7a19633 100644 --- a/templates/havana/l3_agent.ini +++ b/templates/havana/l3_agent.ini @@ -6,6 +6,7 @@ admin_tenant_name = {{ service_tenant }} admin_user = {{ service_username }} admin_password = {{ service_password }} root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf +use_syslog = {{ use_syslog }} ovs_use_veth = True handle_internal_only_routers = {{ handle_internal_only_router }} {% if ext_net_id %} diff --git a/templates/havana/metadata_agent.ini b/templates/havana/metadata_agent.ini index ed549b1e..8174a9cf 100644 --- a/templates/havana/metadata_agent.ini +++ b/templates/havana/metadata_agent.ini @@ -15,3 +15,4 @@ nova_metadata_port = 8775 # but it must match here and in the configuration used by the Nova Metadata # Server. NOTE: Nova uses a different key: neutron_metadata_proxy_shared_secret metadata_proxy_shared_secret = {{ shared_secret }} +use_syslog = {{ use_syslog }} diff --git a/templates/havana/neutron.conf b/templates/havana/neutron.conf index 74d99763..e7d97d38 100644 --- a/templates/havana/neutron.conf +++ b/templates/havana/neutron.conf @@ -5,6 +5,7 @@ rabbit_virtual_host = {{ rabbitmq_virtual_host }} rabbit_host = {{ rabbitmq_host }} rabbit_password = {{ rabbitmq_password }} debug = True +use_syslog = {{ use_syslog }} bind_host = 0.0.0.0 bind_port = 9696 core_plugin = {{ core_plugin }} diff --git a/templates/havana/nova.conf b/templates/havana/nova.conf index df66747c..5a009d5d 100644 --- a/templates/havana/nova.conf +++ b/templates/havana/nova.conf @@ -4,6 +4,7 @@ state_path=/var/lib/nova lock_path=/var/lock/nova root_helper=sudo nova-rootwrap /etc/nova/rootwrap.conf verbose=True +use_syslog = {{ use_syslog }} api_paste_config=/etc/nova/api-paste.ini enabled_apis=metadata multi_host=True diff --git a/templates/havana/ovs_neutron_plugin.ini b/templates/havana/ovs_neutron_plugin.ini index 95bf0a9a..604e1ec8 100644 --- a/templates/havana/ovs_neutron_plugin.ini +++ b/templates/havana/ovs_neutron_plugin.ini @@ -1,3 +1,5 @@ +[DEFAULT] +use_syslog = {{ use_syslog }} [DATABASE] sql_connection = mysql://{{ quantum_user }}:{{ quantum_password }}@{{ database_host }}/{{ quantum_db }}?charset=utf8 reconnect_interval = 2 diff --git a/unit_tests/test_quantum_contexts.py b/unit_tests/test_quantum_contexts.py index 147cb652..9db1b1f5 100644 --- a/unit_tests/test_quantum_contexts.py +++ b/unit_tests/test_quantum_contexts.py @@ -1,5 +1,10 @@ -from mock import MagicMock, patch +from mock import ( + Mock, + MagicMock, + patch +) import quantum_contexts +import sys from contextlib import contextmanager from test_utils import ( @@ -199,6 +204,7 @@ class TestQuantumGatewayContext(CharmTestCase): def setUp(self): super(TestQuantumGatewayContext, self).setUp(quantum_contexts, TO_PATCH) + self.config.side_effect = self.test_config.get @patch.object(quantum_contexts, 'get_shared_secret') @patch.object(quantum_contexts, 'get_host_ip') @@ -256,6 +262,19 @@ class TestHostIP(CharmTestCase): super(TestHostIP, self).setUp(quantum_contexts, TO_PATCH) self.config.side_effect = self.test_config.get + # Save and inject + self.mods = {'dns': None, 'dns.resolver': None} + for mod in self.mods: + if mod not in sys.modules: + sys.modules[mod] = Mock() + else: + del self.mods[mod] + + def tearDown(self): + super(TestHostIP, self).tearDown() + # Cleanup + for mod in self.mods.keys(): + del sys.modules[mod] def test_get_host_ip_already_ip(self): self.assertEquals(quantum_contexts.get_host_ip('10.5.0.1'), @@ -268,8 +287,7 @@ class TestHostIP(CharmTestCase): @patch('dns.resolver.query') def test_get_host_ip_hostname_unresolvable(self, _query): - class NXDOMAIN(Exception): - pass + class NXDOMAIN(Exception): pass _query.side_effect = NXDOMAIN() self.assertRaises(NXDOMAIN, quantum_contexts.get_host_ip, 'missing.example.com')