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
This commit is contained in:
Brandon Logan 2015-10-20 01:26:25 -05:00 committed by Adam Harwell
parent 8057fba637
commit 21058fae59
7 changed files with 56 additions and 0 deletions

View File

@ -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 =

View File

@ -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,

View File

@ -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')

View File

@ -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 }}

View File

@ -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.")),
]

View File

@ -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)

View File

@ -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):