From 21058fae594a978cba5976b8622a2aaf85c20845 Mon Sep 17 00:00:00 2001 From: Brandon Logan Date: Tue, 20 Oct 2015 01:26:25 -0500 Subject: [PATCH] REST Amp Agent: Handle interfaces file too The amphora agent should be able to add interfaces by using the /etc/network/interfaces file as well as the /etc/network/interfaces.d/*.cfg files. Closes-Bug: #1507889 Change-Id: I7840931fc426a0c74386512dfae3666d223049f8 --- etc/octavia.conf | 6 +++ .../backends/agent/agent_jinja_cfg.py | 2 + .../backends/agent/api_server/util.py | 2 + .../templates/amphora_agent_conf.template | 1 + octavia/common/config.py | 4 ++ .../backends/agent/api_server/test_utils.py | 37 +++++++++++++++++++ .../backends/agent/test_agent_jinja_cfg.py | 4 ++ 7 files changed, 56 insertions(+) create mode 100644 octavia/tests/unit/amphorae/backends/agent/api_server/test_utils.py diff --git a/etc/octavia.conf b/etc/octavia.conf index 30cfecc97b..2c233ba0fc 100644 --- a/etc/octavia.conf +++ b/etc/octavia.conf @@ -169,3 +169,9 @@ # cleanup_interval = 30 # Amphora expiry age in seconds. Default is 1 week # amphora_expiry_age = 604800 + +[amphora_agent] +# agent_server_ca = /etc/octavia/certs/client_ca.pem +# agent_server_cert = /etc/octavia/certs/server.pem +# agent_server_network_dir = /etc/network/interfaces.d/ +# agent_server_network_file = diff --git a/octavia/amphorae/backends/agent/agent_jinja_cfg.py b/octavia/amphorae/backends/agent/agent_jinja_cfg.py index 998d0dcd73..6b380be1cc 100644 --- a/octavia/amphorae/backends/agent/agent_jinja_cfg.py +++ b/octavia/amphorae/backends/agent/agent_jinja_cfg.py @@ -43,6 +43,8 @@ class AgentJinjaTemplater(object): 'agent_server_cert': CONF.amphora_agent.agent_server_cert, 'agent_server_network_dir': CONF.amphora_agent.agent_server_network_dir, + 'agent_server_network_file': + CONF.amphora_agent.agent_server_network_file, 'amphora_id': amphora_id, 'base_cert_dir': CONF.haproxy_amphora.base_cert_dir, 'base_path': CONF.haproxy_amphora.base_path, diff --git a/octavia/amphorae/backends/agent/api_server/util.py b/octavia/amphorae/backends/agent/api_server/util.py index 04a5c5c067..57173609fa 100644 --- a/octavia/amphorae/backends/agent/api_server/util.py +++ b/octavia/amphorae/backends/agent/api_server/util.py @@ -64,5 +64,7 @@ def is_listener_running(listener_id): def get_network_interface_file(interface): + if CONF.amphora_agent.agent_server_network_file: + return CONF.amphora_agent.agent_server_network_file return os.path.join(CONF.amphora_agent.agent_server_network_dir, interface + '.cfg') diff --git a/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template b/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template index c67ebd5730..469e160204 100644 --- a/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template +++ b/octavia/amphorae/backends/agent/templates/amphora_agent_conf.template @@ -33,4 +33,5 @@ heartbeat_key = {{ heartbeat_key }} agent_server_ca = {{ agent_server_ca }} agent_server_cert = {{ agent_server_cert }} agent_server_network_dir = {{ agent_server_network_dir }} +agent_server_network_file = {{ agent_server_network_file }} amphora_id = {{ amphora_id }} diff --git a/octavia/common/config.py b/octavia/common/config.py index 9aa7e9337e..f8d584b52c 100644 --- a/octavia/common/config.py +++ b/octavia/common/config.py @@ -91,6 +91,10 @@ amphora_agent_opts = [ default='/etc/network/interfaces.d/', help=_("The directory where new network interfaces " "are located")), + cfg.StrOpt('agent_server_network_file', + help=_("The file where the network interfaces are located. " + "Specifying this will override any value set for " + "agent_server_network_dir.")), # Do not specify in octavia.conf, loaded at runtime cfg.StrOpt('amphora_id', help=_("The amphora ID.")), ] diff --git a/octavia/tests/unit/amphorae/backends/agent/api_server/test_utils.py b/octavia/tests/unit/amphorae/backends/agent/api_server/test_utils.py new file mode 100644 index 0000000000..74ede72929 --- /dev/null +++ b/octavia/tests/unit/amphorae/backends/agent/api_server/test_utils.py @@ -0,0 +1,37 @@ +# Copyright 2015 Rackspace. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import os + +from oslo_config import cfg + +from octavia.amphorae.backends.agent.api_server import util +from octavia.tests.unit import base + + +class TestUtils(base.TestCase): + + def test_get_network_interface_file(self): + dir = '/etc/network/interfaces.d' + file = '/etc/network/interfaces' + interface = 'eth0' + cfg.CONF.set_override('agent_server_network_dir', dir, + group='amphora_agent') + path = util.get_network_interface_file(interface) + expected_path = os.path.join(dir, interface + '.cfg') + self.assertEqual(expected_path, path) + cfg.CONF.set_override('agent_server_network_file', file, + group='amphora_agent') + path = util.get_network_interface_file(interface) + self.assertEqual(file, path) diff --git a/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py b/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py index 517ea0cc99..6c8d32471e 100644 --- a/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py +++ b/octavia/tests/unit/amphorae/backends/agent/test_agent_jinja_cfg.py @@ -34,6 +34,8 @@ class AgentJinjaTestCase(base.TestCase): agent_server_cert='/etc/octavia/certs/server.pem') conf.config(group="amphora_agent", agent_server_network_dir='/etc/network/interfaces.d/') + conf.config(group="amphora_agent", + agent_server_network_file='/etc/network/interfaces') conf.config(group="haproxy_amphora", base_cert_dir='/var/lib/octavia/certs') conf.config(group="haproxy_amphora", base_path='/var/lib/octavia') @@ -68,6 +70,8 @@ class AgentJinjaTestCase(base.TestCase): '/etc/octavia/certs/server.pem\n' 'agent_server_network_dir = ' '/etc/network/interfaces.d/\n' + 'agent_server_network_file = ' + '/etc/network/interfaces\n' 'amphora_id = ' + AMP_ID) def test_build_agent_config(self):