Neutron sidecar wrappers use netns they were invoked with

Neutron uses namespaces with different prefixes depending on
configuration and the nature of the resource. This patch changes the
wrappers to use the "ip netns identify" command to determine the target
namespace for the sidecar instead of trying to guess from the command
line options.

Change-Id: If58bb9dabebf201b592fb450a663ae2f24374e00
Closes-Bug: #1773823
This commit is contained in:
Brent Eagles 2018-05-28 13:43:03 -02:30
parent de4a61d7d8
commit 684521fc84
13 changed files with 22 additions and 42 deletions

@ -82,7 +82,6 @@ class tripleo::profile::base::neutron::dhcp_agent_wrappers (
tripleo::profile::base::neutron::wrappers::haproxy{'dhcp_haproxy_process_wrapper':
haproxy_process_wrapper => $haproxy_process_wrapper,
haproxy_image => $haproxy_image,
ns_prefix => 'qdhcp',
bind_socket => $bind_socket
}
}

@ -111,7 +111,6 @@ class tripleo::profile::base::neutron::l3_agent_wrappers (
tripleo::profile::base::neutron::wrappers::haproxy{'l3_haproxy_process_wrapper':
haproxy_process_wrapper => $haproxy_process_wrapper,
haproxy_image => $haproxy_image,
ns_prefix => 'qrouter',
bind_socket => $bind_socket,
}
}
@ -134,7 +133,6 @@ class tripleo::profile::base::neutron::l3_agent_wrappers (
tripleo::profile::base::neutron::wrappers::keepalived{'l3_keepalived':
keepalived_process_wrapper => $keepalived_process_wrapper,
keepalived_image => $keepalived_image,
ns_prefix => 'qrouter',
bind_socket => $bind_socket,
}
unless $keepalived_state_change_wrapper {
@ -142,7 +140,6 @@ class tripleo::profile::base::neutron::l3_agent_wrappers (
}
tripleo::profile::base::neutron::wrappers::keepalived_state_change{'l3_keepalived_state_change':
keepalived_state_change_wrapper => $keepalived_state_change_wrapper,
ns_prefix => 'qrouter',
bind_socket => $bind_socket,
}
}

@ -24,16 +24,12 @@
# [*haproxy_image*]
# Docker image name for haproxy.
#
# [*ns_prefix*]
# Prefix for namespace (e.g. qrouter-, qdhcp-)
#
# [*bind_socket*]
# Socket for accessing the docker daemon.
#
define tripleo::profile::base::neutron::wrappers::haproxy (
$haproxy_process_wrapper,
$haproxy_image,
$ns_prefix,
$bind_socket,
) {
file { $haproxy_process_wrapper:
@ -41,7 +37,6 @@ define tripleo::profile::base::neutron::wrappers::haproxy (
mode => '0755',
content => epp('tripleo/neutron/haproxy.epp', {
'image_name' => $haproxy_image,
'ns_prefix' => $ns_prefix,
'bind_socket' => $bind_socket,
})
}

@ -24,16 +24,12 @@
# [*keepalived_image*]
# Docker image name for keepalived.
#
# [*ns_prefix*]
# Prefix for namespace (e.g. qrouter-, qdhcp-)
#
# [*bind_socket*]
# Socket for accessing the docker daemon.
#
define tripleo::profile::base::neutron::wrappers::keepalived (
$keepalived_process_wrapper,
$keepalived_image,
$ns_prefix,
$bind_socket,
) {
file { $keepalived_process_wrapper:
@ -41,7 +37,6 @@ define tripleo::profile::base::neutron::wrappers::keepalived (
mode => '0755',
content => epp('tripleo/neutron/keepalived.epp', {
'image_name' => $keepalived_image,
'ns_prefix' => $ns_prefix,
'bind_socket' => $bind_socket,
})
}

@ -21,22 +21,17 @@
# [*keepalived_state_change_wrapper*]
# Filename for neutron-keepalived-state-change wrapper script.
#
# [*ns_prefix*]
# Prefix for namespace (e.g. qrouter-, qdhcp-)
#
# [*bind_socket*]
# Socket for accessing the docker daemon.
#
define tripleo::profile::base::neutron::wrappers::keepalived_state_change (
$keepalived_state_change_wrapper,
$ns_prefix,
$bind_socket,
) {
file { $keepalived_state_change_wrapper:
ensure => file,
mode => '0755',
content => epp('tripleo/neutron/neutron-keepalived-state-change.epp', {
'ns_prefix' => $ns_prefix,
'bind_socket' => $bind_socket
})
}

@ -29,7 +29,6 @@ describe 'tripleo::profile::base::neutron::wrappers::haproxy' do
{
:haproxy_process_wrapper => '/usr/local/bin/haproxy',
:haproxy_image => 'a_registry/some_container_name:some_tag',
:ns_prefix => 'puppet-test',
:bind_socket => 'unix:///run/another/docker.sock'
}
}
@ -42,7 +41,7 @@ describe 'tripleo::profile::base::neutron::wrappers::haproxy' do
/a_registry.some_container_name.some_tag/
)
is_expected.to contain_file('/usr/local/bin/haproxy').with_content(
/^NAME=neutron-haproxy-puppet-test-/
/^NAME=neutron-haproxy-/
)
is_expected.to contain_file('/usr/local/bin/haproxy').with_content(
/export DOCKER_HOST="unix:...run.another.docker.sock/

@ -29,7 +29,6 @@ describe 'tripleo::profile::base::neutron::wrappers::keepalived' do
{
:keepalived_process_wrapper => '/usr/local/bin/keepalived',
:keepalived_image => 'a_registry/some_container_name:some_tag',
:ns_prefix => 'puppet-test',
:bind_socket => 'unix:///run/another/docker.sock'
}
}

@ -28,7 +28,6 @@ describe 'tripleo::profile::base::neutron::wrappers::keepalived_state_change' do
let(:params) {
{
:keepalived_state_change_wrapper => '/usr/local/bin/keepalived-state-change',
:ns_prefix => 'puppet-test',
:bind_socket => 'unix:///run/another/docker.sock'
}
}
@ -38,7 +37,7 @@ describe 'tripleo::profile::base::neutron::wrappers::keepalived_state_change' do
:mode => '0755'
)
is_expected.to contain_file('/usr/local/bin/keepalived-state-change').with_content(
/ip.netns.exec.*puppet-test.*neutron-keepalived-state-change/
/ip.netns.exec.*neutron-keepalived-state-change/
)
is_expected.to contain_file('/usr/local/bin/keepalived-state-change').with_content(
/export DOCKER_HOST="unix:...run.another.docker.sock/

@ -13,8 +13,9 @@ ARGS="$@"
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
NETWORK_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
NAME=neutron-dibbler-${NETWORK_ID}
NETNS=$(ip netns identify)
NAME=neutron-dibbler-${NETNS}
docker stop $NAME || true
docker rm -f $NAME || true
@ -29,4 +30,4 @@ docker run --detach \
-u root \
--name $NAME \
<%=$image_name%> \
ip netns exec qrouter-${NETWORK_ID} /usr/sbin/dibbler-client run $ARGS
ip netns exec ${NETNS} /usr/sbin/dibbler-client run $ARGS

@ -10,9 +10,9 @@ ARGS="$@"
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
NETWORK_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
NETNS=$(ip netns identify)
NAME=neutron-dnsmasq-${NETNS}
NAME=neutron-dnsmasq-${NETWORK_ID}
docker stop $NAME || true
docker rm -f $NAME || true
@ -27,4 +27,4 @@ docker run --detach \
-u root \
--name $NAME \
<%=$image_name%> \
ip netns exec qdhcp-${NETWORK_ID} /usr/sbin/dnsmasq -k $ARGS
ip netns exec ${NETNS} /usr/sbin/dnsmasq -k $ARGS

@ -1,4 +1,4 @@
<%- | String $image_name = '', String $ns_prefix = '', String $bind_socket = '' | -%>
<%- | String $image_name = '', String $bind_socket = '' | -%>
#!/bin/bash
export DOCKER_HOST="<%=$bind_socket%>"
@ -10,8 +10,9 @@ ARGS="$@"
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
NETWORK_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
NAME=neutron-haproxy-<%=$ns_prefix%>-${NETWORK_ID}
NETNS=$(ip netns identify)
NAME=neutron-haproxy-${NETNS}
docker stop $NAME || true
docker rm -f $NAME || true
@ -26,4 +27,4 @@ docker run --detach \
-u root \
--name $NAME \
<%=$image_name%> \
ip netns exec <%=$ns_prefix%>-${NETWORK_ID} /usr/sbin/haproxy -Ds $ARGS
ip netns exec ${NETNS} /usr/sbin/haproxy -Ds $ARGS

@ -1,4 +1,4 @@
<%- | String $image_name = '', String $ns_prefix = '', String $bind_socket = '' | -%>
<%- | String $image_name = '', String $bind_socket = '' | -%>
#!/bin/bash
export DOCKER_HOST="<%=$bind_socket%>"
@ -10,8 +10,8 @@ ARGS="$@"
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
ROUTER_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
NAME=neutron-keepalived-<%=$ns_prefix%>-${ROUTER_ID}
NETNS=$(ip netns identify)
NAME=neutron-keepalived-${NETNS}
docker stop $NAME || true
docker rm -f $NAME || true
@ -29,4 +29,4 @@ docker run --detach \
-u root \
--name $NAME \
<%=$image_name%> \
ip netns exec <%=$ns_prefix%>-${ROUTER_ID} /usr/sbin/keepalived -n -l -D $ARGS
ip netns exec ${NETNS} /usr/sbin/keepalived -n -l -D $ARGS

@ -1,4 +1,4 @@
<%- | String $ns_prefix = '', String $bind_socket = '' | -%>
<%- | String $bind_socket = '' | -%>
#!/bin/bash
export DOCKER_HOST="<%=$bind_socket%>"
@ -10,8 +10,8 @@ ARGS="$@"
# dnsmasq --no-hosts --no-resolv --except-interface=lo \
# --pid-file=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/pid \
# --dhcp-hostsfile=/var/lib/neutron/dhcp/317716b8-919a-4a6f-8db1-78128ec3b100/host ...
NS_ID=$(echo $ARGS| awk '{if (match($0, /(\w{8}-\w{4}-\w{4}-\w{4}-\w{12})/,m)) print m[0] }')
NAME=neutron-keepalived-<%=$ns_prefix%>-${NS_ID}
NETNS=$(ip netns identify)
NAME=neutron-keepalived-${NETNS}
# The state change daemon only runs as a daemon for the moment so we need to
# run it within an existing container with a sensibly matching lifetime. The
@ -29,4 +29,4 @@ docker exec --detach \
-u root \
--privileged \
$NAME \
ip netns exec <%=$ns_prefix%>-${NS_ID} /usr/bin/neutron-keepalived-state-change $ARGS
ip netns exec ${NETNS} /usr/bin/neutron-keepalived-state-change $ARGS