Create service files for CPNR Plugin

CPNR plugin has cpnr-dhcp-relay and cpnr-dns-relay
    processes which act as DHCP and DNS packet forwarder.

    This code changes make these two process to run as
    Service.

Change-Id: Icb0536c4112baf458e9375b79a1b1e29ad00ab06
This commit is contained in:
Deepak Kukrety 2016-06-20 10:04:10 +05:30
parent 74b2e124dc
commit 9214a8cc4a
11 changed files with 233 additions and 14 deletions

34
etc/cpnr/rootwrap.conf Normal file
View File

@ -0,0 +1,34 @@
# Configuration for cpnr-rootwrap
# This file should be owned by (and only-writeable by) the root user
[DEFAULT]
# List of directories to load filter definitions from (separated by ',').
# These directories MUST all be only writeable by root !
filters_path=/etc/cpnr/rootwrap.d,/usr/share/cpnr/rootwrap
# List of directories to search executables in, in case filters do not
# explicitely specify a full path (separated by ',')
# If not specified, defaults to system PATH environment variable.
# These directories MUST all be only writeable by root !
exec_dirs=/sbin,/usr/sbin,/bin,/usr/bin,/usr/local/bin,/usr/local/sbin
# Enable logging to syslog
# Default value is False
use_syslog=False
# Which syslog facility to use.
# Valid values include auth, authpriv, syslog, local0, local1...
# Default value is 'syslog'
syslog_log_facility=syslog
# Which messages to log.
# INFO means log all usage
# ERROR means only log unsuccessful attempts
syslog_log_level=ERROR
[xenapi]
# XenAPI configuration is only required by the L2 agent if it is to
# target a XenServer/XCP compute host's dom0.
xenapi_connection_url=<None>
xenapi_connection_username=root
xenapi_connection_password=<None>

View File

@ -0,0 +1,40 @@
# Copyright 2016 Cisco Systems, Inc.
# All Rights Reserved.
#
# 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.
#
description "CPNR DHCP Relay Conf"
start on runlevel [2345]
stop on runlevel [!2345]
env DST="/usr/local/bin/"
pre-start script
logger -t cpnr-dhcp-relay.conf "Pre-Starting CPNR DHCP Relay Agent"
test -r $DST/cpnr-dhcp-relay-agent|| { stop; exit 0; }
logger -t cpnr-dhcp-relay.conf "Starting CPNR DHCP Relay Agent"
end script
pre-stop script
logger -t cpnr-dhcp-relay.conf "Stopping CPNR DHCP Relay Agent"
end script
script
logger -t cpnr-dhcp-relay.conf "Starting NOW CPNR DHCP Relay Agent"
exec $DST/cpnr-dhcp-relay-agent--config-file /etc/neutron/dhcp_agent.ini
--log-file /var/log/cpnr/cpnr-dhcp-relay-agent.log
end script

View File

@ -0,0 +1,40 @@
# Copyright 2016 Cisco Systems, Inc.
# All Rights Reserved.
#
# 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.
#
description "CPNR DNS Relay Conf"
start on runlevel [2345]
stop on runlevel [!2345]
env DST="/usr/local/bin/"
pre-start script
logger -t cpnr-dns-relay.conf "Pre-Starting CPNR DNS Relay Agent"
test -r $DST/cpnr-dns-relay-agent || { stop; exit 0; }
logger -t cpnr-dns-relay.conf "Starting CPNR DNS Relay Agent"
end script
pre-stop script
logger -t cpnr-dns-relay.conf "Stopping CPNR DNS Relay Agent"
end script
script
logger -t cpnr-dns-relay.conf "Starting NOW CPNR DNS Relay Agent"
exec $DST/cpnr-dns-relay-agent --config-file /etc/neutron/dhcp_agent.ini
--log-file /var/log/cpnr/cpnr-dns-relay-agent.log
end script

View File

@ -0,0 +1,35 @@
# Copyright 2016 Cisco Systems, Inc.
# All Rights Reserved.
#
# 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.
#
[Unit]
Description=CPNR DHCP Relay Agent
After=syslog.target network.target
[Service]
Type=simple
User=cpnr
Environment="OPTS1=--config-file"
Environment="OPTS2=/etc/neutron/dhcp_agent.ini"
Environment="OPTS3=--log-file"
Environment="OPTS4=/var/log/cpnr/cpnr-dhcp-relay-agent.log"
ExecStart=/usr/bin/sudo /usr/bin/cpnr-rootwrap /etc/cpnr/rootwrap.conf cpnr-dhcp-relay-agent $OPTS1 $OPTS2 $OPTS3 $OPTS4
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,34 @@
# Copyright 2016 Cisco Systems, Inc.
# All Rights Reserved.
#
# 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.
#
[Unit]
Description=CPNR DNS Relay Agent
After=syslog.target network.target
[Service]
Type=simple
User=cpnr
Environment="OPTS1=--config-file"
Environment="OPTS2=/etc/neutron/dhcp_agent.ini"
Environment="OPTS3=--log-file"
Environment="OPTS4=/var/log/cpnr/cpnr-dns-relay-agent.log"
ExecStart=/usr/bin/sudo /usr/bin/cpnr-rootwrap /etc/cpnr/rootwrap.conf cpnr-dns-relay-agent $OPTS1 $OPTS2 $OPTS3 $OPTS4
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=multi-user.target

View File

@ -18,16 +18,19 @@ import mock
import socket
from networking_cisco.plugins.cisco.cpnr.cpnr_client import UnexpectedError
from networking_cisco.plugins.cisco.cpnr.dhcp_relay import cfg
from networking_cisco.plugins.cisco.cpnr.dhcp_relay import DhcpPacket
from networking_cisco.plugins.cisco.cpnr.dhcp_relay import DhcpRelayAgent
from networking_cisco.plugins.cisco.cpnr.dhcp_relay import OPTS
from networking_cisco.plugins.cisco.cpnr.cpnr_dhcp_relay_agent import (
DhcpPacket)
from networking_cisco.plugins.cisco.cpnr.cpnr_dhcp_relay_agent import (
DhcpRelayAgent)
from networking_cisco.plugins.cisco.cpnr.cpnr_dhcp_relay_agent import cfg
from networking_cisco.plugins.cisco.cpnr.cpnr_dhcp_relay_agent import OPTS
import unittest
class TestDhcpRelayAgent(unittest.TestCase):
@mock.patch('networking_cisco.plugins.cisco.cpnr.dhcp_relay.netns')
@mock.patch('networking_cisco.plugins.cisco.'
'cpnr.cpnr_dhcp_relay_agent.netns')
@mock.patch('socket.socket')
def test_open_dhcp_ext_socket(self, mock_socket, mock_netns):
cfg.CONF.register_opts(OPTS, 'cisco_pnr')
@ -64,7 +67,8 @@ class TestDhcpRelayAgent(unittest.TestCase):
'255.0.0.0'))
sock, addr = relay._open_dhcp_ext_socket()
@mock.patch('networking_cisco.plugins.cisco.cpnr.dhcp_relay.netns')
@mock.patch('networking_cisco.plugins.cisco.'
'cpnr.cpnr_dhcp_relay_agent.netns')
@mock.patch('socket.socket')
def test_open_dhcp_int_socket(self, mock_socket, mock_netns):
cfg.CONF.register_opts(OPTS, 'cisco_pnr')

View File

@ -19,15 +19,17 @@ import socket
import unittest
from networking_cisco.plugins.cisco.cpnr.cpnr_client import UnexpectedError
from networking_cisco.plugins.cisco.cpnr.dns_relay import cfg
from networking_cisco.plugins.cisco.cpnr.dns_relay import DnsPacket
from networking_cisco.plugins.cisco.cpnr.dns_relay import DnsRelayAgent
from networking_cisco.plugins.cisco.cpnr.dns_relay import OPTS
from networking_cisco.plugins.cisco.cpnr.cpnr_dns_relay_agent import (
DnsRelayAgent)
from networking_cisco.plugins.cisco.cpnr.cpnr_dns_relay_agent import cfg
from networking_cisco.plugins.cisco.cpnr.cpnr_dns_relay_agent import DnsPacket
from networking_cisco.plugins.cisco.cpnr.cpnr_dns_relay_agent import OPTS
class TestDnsRelayAgent(unittest.TestCase):
@mock.patch('networking_cisco.plugins.cisco.cpnr.dns_relay.netns')
@mock.patch('networking_cisco.plugins.cisco.'
'cpnr.cpnr_dns_relay_agent.netns')
@mock.patch('socket.socket')
def test_open_dns_ext_socket(self,
mock_socket,
@ -69,7 +71,8 @@ class TestDnsRelayAgent(unittest.TestCase):
mock_netns.iflist.return_value.append(('lo', '127.0.0.1', '255.0.0.0'))
sock, addr, port = relay._open_dns_ext_socket()
@mock.patch('networking_cisco.plugins.cisco.cpnr.dns_relay.netns')
@mock.patch('networking_cisco.plugins.cisco.'
'cpnr.cpnr_dns_relay_agent.netns')
@mock.patch('socket.socket')
def test_open_dns_int_socket(self,
mock_socket,

View File

@ -34,6 +34,19 @@ data_files =
etc/saf/init/fabric-enabler-server.service
etc/saf/init/fabric-enabler-agent.conf
etc/saf/init/fabric-enabler-agent.service
etc/systemd/system =
etc/systemd/system/cpnr-dhcp-relay.service
etc/systemd/system/cpnr-dns-relay.service
lib/systemd/system =
etc/systemd/system/cpnr-dhcp-relay.service
etc/systemd/system/cpnr-dns-relay.service
etc/init =
etc/init/cpnr-dhcp-relay.conf
etc/init/cpnr-dns-relay.conf
etc/cpnr =
etc/cpnr/rootwrap.conf
usr/share/cpnr/rootwrap =
usr/share/cpnr/rootwrap/cpnr.filters
[global]
setup-hooks =
@ -47,8 +60,10 @@ console_scripts =
fabric-enabler-server = networking_cisco.apps.saf.dfa_enabler_server:dfa_server
fabric-enabler-agent = networking_cisco.apps.saf.dfa_enabler_agent:dfa_agent
fabric-enabler-cli = networking_cisco.apps.saf.dfa_cli:dfa_cli
cpnr-dhcp-relay = networking_cisco.plugins.cisco.cpnr.dhcp_relay:main
cpnr-dns-relay = networking_cisco.plugins.cisco.cpnr.dns_relay:main
cpnr-dhcp-relay-agent= networking_cisco.plugins.cisco.cpnr.cpnr_dhcp_relay_agent:main
cpnr-dns-relay-agent = networking_cisco.plugins.cisco.cpnr.cpnr_dns_relay_agent:main
cpnr-rootwrap = oslo_rootwrap.cmd:main
neutron.ml2.type_drivers =
nexus_vxlan = networking_cisco.plugins.ml2.drivers.cisco.nexus.type_nexus_vxlan:NexusVxlanTypeDriver
neutron.ml2.mechanism_drivers =

View File

@ -0,0 +1,14 @@
# cpnr-rootwrap command filters for nodes on which neutron is
# expected to control network
#
# This file should be owned by (and only-writeable by) the root user
# format seems to be
# cmd-name: filter-name, raw-command, user, args
[Filters]
# cpnr-dhcp-relay-agent
cpnr-dhcp-relay-agent: CommandFilter, cpnr-dhcp-relay-agent, root
# cpnr-dns-relay-agent
cpnr-dns-relay-agent: CommandFilter, cpnr-dns-relay-agent, root