summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Hussey <sh8121@att.com>2019-01-24 17:16:08 -0600
committerScott Hussey <sh8121@att.com>2019-01-25 11:22:59 -0600
commit8d56122554cda0ab57a39907509c60de260e1079 (patch)
treede9420125dc3790e9aeb6a1a7c91c8dcad7eb67a
parent7f50e96ff37cbfd95611066eded6a715509b4e7e (diff)
(fix) Give systemd service access to env
- The service to register the rack controller pod does not have access to the MAAS_API_KEY env var so it fails to deregister when needed. Change-Id: I16bc63ef14a2dab463dfdca11b7e3ca13d508a9e
Notes
Notes (review): Code-Review+2: Sean Eagan <sean.eagan@att.com> Code-Review+1: Nishant Kumar <nishant.e.kumar@ericsson.com> Code-Review+1: Michael Beaver <michaelbeaver64@gmail.com> Code-Review+2: Bryan Strassner <strassner.bryan@gmail.com> Workflow+1: Bryan Strassner <strassner.bryan@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 25 Jan 2019 17:51:05 +0000 Reviewed-on: https://review.openstack.org/633088 Project: openstack/airship-maas Branch: refs/heads/master
-rw-r--r--charts/maas/templates/bin/_register-rack-controller.sh.tpl48
-rw-r--r--images/maas-rack-controller/Dockerfile3
-rw-r--r--images/maas-rack-controller/scripts/register-rack-controller.service2
3 files changed, 48 insertions, 5 deletions
diff --git a/charts/maas/templates/bin/_register-rack-controller.sh.tpl b/charts/maas/templates/bin/_register-rack-controller.sh.tpl
index 3280643..37e4bb0 100644
--- a/charts/maas/templates/bin/_register-rack-controller.sh.tpl
+++ b/charts/maas/templates/bin/_register-rack-controller.sh.tpl
@@ -6,11 +6,48 @@ set -x
6# to source the maas system_id 6# to source the maas system_id
7HOST_MOUNT_PATH=${HOST_MOUNT_PATH:-"/host_cloud-init/"} 7HOST_MOUNT_PATH=${HOST_MOUNT_PATH:-"/host_cloud-init/"}
8 8
9get_impacted_nets() {
10 system_id="$1"
11 maas local fabrics read | jq -cr 'map(.vlans) | map(.[]) | map(select(.primary_rack == "'"$system_id"'" or .secondary_rack == "'"$system_id"'")) | .[] | {vid, fabric_id}'
12}
13
14detach_rack_controller() {
15 system_id="$1"
16 for net in $(get_impacted_nets "$system_id");
17 do
18 vid=$(echo "$net" | jq -r .vid)
19 fid=$(echo "$net" | jq -r .fabric_id)
20 maas local vlan update "$fid" "$vid" primary_rack='' secondary_rack=''
21 done
22}
23
9unregister_maas_rack() { 24unregister_maas_rack() {
10 sys_id="$1" 25 sys_id="$1"
11 echo "Deregister this pod as MAAS rack controller ${sys_id}." 26 echo "Deregister this pod as MAAS rack controller ${sys_id}."
27
12 maas login local "$MAAS_ENDPOINT" "$MAAS_API_KEY" 28 maas login local "$MAAS_ENDPOINT" "$MAAS_API_KEY"
13 maas local rack-controller delete "$sys_id" 29
30 if [[ $? -ne 0 ]];
31 then
32 echo "Could not login to MAAS API."
33 exit $?
34 fi
35
36 detach_rack_controller "$sys_id"
37
38 while [ 1 ];
39 do
40 maas local rack-controller delete "$sys_id"
41
42 if [[ $? -ne 0 ]];
43 then
44 echo "Could not delete rack controller."
45 sleep 10
46 else
47 break
48 fi
49 done
50
14 rm -f ~maas/maas_id 51 rm -f ~maas/maas_id
15 rm -f ~maas/secret 52 rm -f ~maas/secret
16} 53}
@@ -28,7 +65,7 @@ register_maas_rack() {
28 # register forever 65 # register forever
29 while [ 1 ]; 66 while [ 1 ];
30 do 67 do
31 if maas-rack register --url=${MAAS_ENDPOINT} --secret="${MAAS_REGION_SECRET}"; 68 if maas-rack register --url="${MAAS_ENDPOINT}" --secret="${MAAS_REGION_SECRET}";
32 then 69 then
33 echo "Successfully registered with MaaS Region Controller" 70 echo "Successfully registered with MaaS Region Controller"
34 break 71 break
@@ -70,7 +107,12 @@ then
70 if [[ "$HOST_SYSTEM_ID" != "$POD_SYSTEM_ID" ]] 107 if [[ "$HOST_SYSTEM_ID" != "$POD_SYSTEM_ID" ]]
71 then 108 then
72 unregister_maas_rack "$POD_SYSTEM_ID" 109 unregister_maas_rack "$POD_SYSTEM_ID"
73 register_maas_rack "$HOST_SYTEM_ID" 110 if $?;
111 then
112 echo "Unregister of $POD_SYSTEM_ID failed, exitting."
113 exit 1
114 fi
115 register_maas_rack "$HOST_SYSTEM_ID"
74 else 116 else
75 echo "Found existing maas_id, assuming already registered." 117 echo "Found existing maas_id, assuming already registered."
76 fi 118 fi
diff --git a/images/maas-rack-controller/Dockerfile b/images/maas-rack-controller/Dockerfile
index 9420ea3..e9b1d8f 100644
--- a/images/maas-rack-controller/Dockerfile
+++ b/images/maas-rack-controller/Dockerfile
@@ -19,7 +19,8 @@ RUN apt-get -qq update && \
19 software-properties-common \ 19 software-properties-common \
20 libvirt-bin \ 20 libvirt-bin \
21 systemd \ 21 systemd \
22 patch 22 patch \
23 jq
23# Don't start any optional services except for the few we need. 24# Don't start any optional services except for the few we need.
24 25
25RUN find /etc/systemd/system \ 26RUN find /etc/systemd/system \
diff --git a/images/maas-rack-controller/scripts/register-rack-controller.service b/images/maas-rack-controller/scripts/register-rack-controller.service
index 0bf64b4..fb439d3 100644
--- a/images/maas-rack-controller/scripts/register-rack-controller.service
+++ b/images/maas-rack-controller/scripts/register-rack-controller.service
@@ -5,7 +5,7 @@ After=network-online.target
5 5
6[Service] 6[Service]
7Type=oneshot 7Type=oneshot
8PassEnvironment=MAAS_ENDPOINT MAAS_REGION_SECRET 8PassEnvironment=MAAS_ENDPOINT MAAS_REGION_SECRET MAAS_API_KEY HOST_MOUNT_PATH
9ExecStart=/usr/local/bin/register-rack-controller.sh 9ExecStart=/usr/local/bin/register-rack-controller.sh
10 10
11[Install] 11[Install]