Merge ~rodsmith/maas-cert-server:fix-uuid-1000 into maas-cert-server:master

Proposed by Rod Smith
Status: Merged
Approved by: Rod Smith
Approved revision: 9a68685e619957a2ccc6c9cf2d8adbbdebc58962
Merged at revision: f8ccf9659113562de1286a7bf321c0405ef2356f
Proposed branch: ~rodsmith/maas-cert-server:fix-uuid-1000
Merge into: maas-cert-server:master
Diff against target: 253 lines (+82/-46)
2 files modified
debian/changelog (+8/-0)
usr/sbin/maniacs-setup (+74/-46)
Reviewer Review Type Date Requested Status
Jeff Lane  Approve
Review via email: mp+437853@code.launchpad.net

Commit message

Updated maniacs-setup for MAAS 3.3.0 & to fix problem if no UID 1000 present

Description of the change

This started as a UID 1000 fix (for bug #2004543); but in fixing that bug, I discovered that the MAAS snap is now installing MAAS 3.3.0 by default, and that has created a series of problems for maniacs-setup, the most serious of which is described in bug #2008022. I also discovered a bug in MAAS 3.3.0 (bug #2008421), and incorporated a workaround for that. This MR therefore addresses all of these bug reports, and a number of minor tweaks (although it does not fix the MAAS bug; it just works around it).

To post a comment you must log in.
Revision history for this message
Jeff Lane  (bladernr) wrote :

Seems OK to me. This fixes both the UID1000 issue as well as issues with MAAS 3.3.0.

review: Approve
Revision history for this message
Jeff Lane  (bladernr) wrote :

Additional comment: for future consideration, I wonder if we shouldn't be tying etiher MCS packaging, or have the script fail, if the right version of MAAS isn't there... each new version of MAAS seems to break things and I wonder thus if this shouldn't be more discrimatory and fail if, for example, 3.3.0 isn't installed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 0513a08..4c040cc 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,11 @@
6+maas-cert-server (0.7.3-0ppa1) jammy; urgency=medium
7+
8+ * Fixed bug in maniacs-setup that caused it to fail if there
9+ was no user with a UID of 1000 on the computer.
10+ * Adjusted maniacs-setup to work with MAAS 3.3.0.
11+
12+ -- Rod Smith <rodsmith@louiswu.rodsbooks.com> Thu, 23 Feb 2023 17:10:13 -0500
13+
14 maas-cert-server (0.7.2-0ppa1) jammy; urgency=medium
15
16 * Clean up maniacs-setup code
17diff --git a/usr/sbin/maniacs-setup b/usr/sbin/maniacs-setup
18index 2ca34ca..adef490 100755
19--- a/usr/sbin/maniacs-setup
20+++ b/usr/sbin/maniacs-setup
21@@ -144,7 +144,8 @@ setup_globals() {
22 PROGRESS_TRACKER=$MCS_DATA/progress
23 MIRROR_TRACKER=$MCS_DATA/apt-mirror.out
24 RERUN=no
25- DEFAULT_USER=$(getent passwd | awk -v val=1000 -F ":" '$3==val{print $1}')
26+ DEFAULT_USER=$(logname)
27+ DEFAULT_GROUP=$(id -gn "$DEFAULT_USER")
28 if [ -z "$DEFAULT_USER" ] ; then
29 echo "The default user (who must have a UID of 1000) can't be determined!"
30 echo "Exiting!"
31@@ -167,7 +168,6 @@ setup_globals() {
32 SUPPORTED_RELEASES=$(distro-info --supported)
33 CLOUD_ARCHES="amd64 i386 arm64 armhf ppc64el s390x"
34 CLOUD_MIRROR="$MIRROR_HOME/cloud"
35- RETRY=10
36 MIRRORED=0
37
38 # Any of the preceding values can be overridden in the config file....
39@@ -219,6 +219,7 @@ setup_network_addresses() {
40 INTERNAL_IP=$(ip -4 addr show "$INTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f1)
41 INTERNAL_BROADCAST=$(ip -4 addr show "$INTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f5)
42 INTERNAL_NETMASK=$(ip -4 addr show "$INTERNAL_NET" | grep inet | tr -s " " | cut -d" " -f3 | cut -d"/" -f2)
43+ INTERNAL_NETBLOCK=$(ipcalc -n "$INTERNAL_IP"/"$INTERNAL_NETMASK" | grep Network | tr -s " " | cut -d " " -f 2) || true
44 # INTERNAL_NETSTART is currently unused; but if necessary in the future,
45 # uncomment the below line....
46 # INTERNAL_NETSTART=$(ipcalc -n "$INTERNAL_IP"/"$INTERNAL_NETMASK" | grep Network | tr -s " " | cut -d " " -f 2 | cut -d "/" -f 1)
47@@ -299,6 +300,7 @@ setup_postgresql() {
48 echo "* you supply."
49 get_password
50 DB_PASS=$PASSWORD
51+ sudo usermod -a -G "$DEFAULT_GROUP" postgres
52 sudo -u postgres psql -c "CREATE USER \"maas\" WITH ENCRYPTED PASSWORD '$PASSWORD'"
53 echo "*"
54 echo "* Now creating a PostgresQL database (called 'maasdb')...."
55@@ -331,24 +333,51 @@ reconfigure_controllers() {
56 dpkg-reconfigure -fnoninteractive maas-rack-controller
57 }
58
59+ENSURE_RUNNING_TRIES=2
60
61 ensure_running() {
62- local job="$1"
63- local count=1
64- while true; do
65- if (service "$job" status | grep -qs "running"); then
66- break
67- fi
68- invoke-rc.d "$job" start
69- sleep 1
70- count=$((count+1))
71- if [ $count -gt $RETRY ]; then
72- echo "$job refused to start [$RETRY] times"
73+ local controller_online="Offline"
74+
75+ local PRIMARY_RACK
76+ PRIMARY_RACK=$(maas admin rack-controllers read | jshon -a -e system_id | tr -d '"')
77+ controller_online=$(maas admin rack-controller read "$PRIMARY_RACK" | \
78+ jshon -e commissioning_status_name | tr -d '"' | \
79+ head -n 1)
80+
81+ # MAAS 3.3.0 sometimes doesn't finish its initial commissioning, so we
82+ # restart it to give it a kick in the pants and wait for commissioning
83+ # to complete....
84+ if [[ $USE_SNAPS == 1 && $controller_online != "Passed" ]] ; then
85+ echo "* Restarting MAAS"
86+ snap restart maas.supervisor &> /dev/null
87+ until maas admin events query &> /dev/null ; do
88+ echo "* Waiting for MAAS to restart...."
89+ sleep 2
90+ done
91+ # Sleep 5 more seconds, just for good measure....
92+ sleep 5
93+ fi
94+
95+ local TRIES_LEFT=20
96+ while [[ $controller_online != "Passed" && $TRIES_LEFT -gt 0 ]] ; do
97+ sleep 3
98+ controller_online=$(maas admin rack-controller read "$PRIMARY_RACK" | \
99+ jshon -e commissioning_status_name | tr -d '"' | \
100+ head -n 1)
101+ echo "* Waiting for the MAAS controller; current status is $controller_online...."
102+ (( TRIES_LEFT-- )) || true
103+ done
104+ if [[ $TRIES_LEFT -eq 0 ]] ; then
105+ if [[ $ENSURE_RUNNING_TRIES -gt 0 ]] ; then
106+ # Sometimes even one restart fails, so try again....
107+ ((ENSURE_RUNNING_TRIES--))
108+ ensure_running
109+ else
110+ echo "* MAAS commissioning is incomplete; exiting!"
111 exit 1
112 fi
113- done
114-}
115-
116+ fi
117+} # ensure_running()
118
119 login_maas_admin() {
120 if [ $USE_SNAPS == 1 ] ; then
121@@ -358,22 +387,22 @@ login_maas_admin() {
122 local APIKEY
123 APIKEY=$(maas-region apikey --username "$DEFAULT_USER" | tail -n1)
124 fi
125- echo "Logging into maas at '$MAAS_URL' with '$APIKEY'"
126+ echo "* Logging into maas at '$MAAS_URL' with '$APIKEY'"
127+
128 set +e
129 local RETURN_CODE=1
130 local TRIES_LEFT=20
131 # MAAS can take a while to become accessible, so keep trying to
132 # log in until it is available, or until we get tired of trying....
133 while [[ $RETURN_CODE != 0 && $TRIES_LEFT -gt 0 ]] ; do
134- echo "Attempting a login...."
135+ echo "* Attempting a login...."
136 maas login admin "$MAAS_URL" "$APIKEY" &> /dev/null
137 RETURN_CODE=$?
138 (( TRIES_LEFT-- )) || true
139- if [ $RETURN_CODE != 0 ] ; then
140- sleep 3
141- fi
142+ sleep 3
143 done
144 set -e
145+ ensure_running
146 }
147
148
149@@ -381,6 +410,7 @@ setup_maas_admin() {
150 # Configure the MAAS admin user
151 # Sadly, there's no way to test if the user has been created already,
152 # so ignore errors for idempotence
153+
154 echo
155 echo "***************************************************************************"
156 if [ "$(check_set_progress "${FUNCNAME[0]}")" == "completed" ] ; then
157@@ -775,7 +805,6 @@ setup_ip_ranges() {
158 local third_octet_plus3
159 local internal16
160 local internal24
161- local cidr
162 echo
163 echo "***************************************************************************"
164 if [ "$(check_set_progress "${FUNCNAME[0]}")" == "completed" ] ; then
165@@ -790,26 +819,13 @@ setup_ip_ranges() {
166 ((third_octet_plus1="$third_octet"+1))
167 ((third_octet_plus2="$third_octet"+2))
168 ((third_octet_plus3="$third_octet"+3))
169- cidr=$(ipcalc -n "$INTERNAL_IP"/"$INTERNAL_NETMASK" | grep Netmask | tr -s " " | cut -d " " -f4) || true
170- if [ -z "$cidr" ] ; then
171- local is_valid=false
172- local numbers='^[0-9]+$'
173- while [ "$is_valid" != true ] ; do
174- echo -n "* Could not compute the CIDR netmask! Please enter it here (1-31): "
175- read -r cidr
176- if [[ "$cidr" =~ $numbers ]] ; then
177- if [ "$cidr" -gt 0 ] && [ "$cidr" -lt 32 ] ; then
178- is_valid=true
179- fi
180- fi
181- done
182- fi
183+
184 # In MAAS 2.1 and later, two IP address ranges can be explicitly marked,
185 # leaving a third implied:
186 # * A range managed by DHCP (set explicitly)
187 # * A reserved range NOT used by MAAS (set explicitly)
188 # * A range used by MAAS for "auto-assign" addresses (everything not set explicitly)
189- if [ "$cidr" -gt 24 ] ; then
190+ if [ "$INTERNAL_NETMASK" -gt 24 ] ; then
191 echo "* Your internal network has too few addresses; please specify the values"
192 echo "* for two IP address ranges: reserved (never used by MAAS) and DHCP"
193 echo "* (used by MAAS with DHCP). Note that a third range is implicit -- those"
194@@ -825,7 +841,7 @@ setup_ip_ranges() {
195 echo -n "* High IP address for DHCP addresses: "
196 read -r DHCP_RANGE_HIGH
197 else
198- if [ "$cidr" = 24 ] ; then
199+ if [ "$INTERNAL_NETMASK" = 24 ] ; then
200 RESERVED_RANGE_LOW="$internal24.1"
201 RESERVED_RANGE_HIGH="$internal24.9"
202 DHCP_RANGE_LOW="$internal24.10"
203@@ -833,7 +849,7 @@ setup_ip_ranges() {
204 AUTO_ASSIGN_LOW="$internal24.128"
205 AUTO_ASSIGN_HIGH="$internal24.254"
206 fi
207- if [ "$cidr" = 23 ] ; then
208+ if [ "$INTERNAL_NETMASK" = 23 ] ; then
209 RESERVED_RANGE_LOW="$internal24.1"
210 RESERVED_RANGE_HIGH="$internal24.50"
211 DHCP_RANGE_LOW="$internal24.51"
212@@ -841,7 +857,7 @@ setup_ip_ranges() {
213 AUTO_ASSIGN_LOW="$internal16.$third_octet_plus1.0"
214 AUTO_ASSIGN_HIGH="$internal16.$third_octet_plus1.254"
215 fi
216- if [ "$cidr" -lt 23 ] ; then
217+ if [ "$INTERNAL_NETMASK" -lt 23 ] ; then
218 RESERVED_RANGE_LOW="$internal24.1"
219 RESERVED_RANGE_HIGH="$internal24.255"
220 DHCP_RANGE_LOW="$internal16.$third_octet_plus1.0"
221@@ -863,14 +879,26 @@ setup_ip_ranges() {
222 RANGES=$(maas admin ipranges read | grep end_ip) || true
223 if [ -z "$RANGES" ] ; then
224 echo "* Initializing rack controller"
225- maas admin ipranges create type=dynamic start_ip="$DHCP_RANGE_LOW" end_ip="$DHCP_RANGE_HIGH" > /dev/null
226- maas admin ipranges create type=reserved start_ip="$RESERVED_RANGE_LOW" end_ip="$RESERVED_RANGE_HIGH" > /dev/null
227- INTERNAL_FABRIC=$(maas admin ipranges read | jshon -a -e subnet -e vlan -e fabric | tr -d '"' | head -n 1)
228- PRIMARY_RACK=$(maas admin rack-controllers read | jshon -a -e hostname | tr -d '"')
229- maas admin vlan update "$INTERNAL_FABRIC" untagged dhcp_on=True primary_rack="$PRIMARY_RACK" > /dev/null
230+ if dpkg --compare-versions "$MAAS_VERSION" "ge" "3.3" ; then
231+ maas admin ipranges create type=dynamic start_ip="$DHCP_RANGE_LOW" \
232+ end_ip="$DHCP_RANGE_HIGH" cidr="$INTERNAL_NETBLOCK" > /dev/null
233+ maas admin ipranges create type=reserved start_ip="$RESERVED_RANGE_LOW" \
234+ end_ip="$RESERVED_RANGE_HIGH" cidr="$INTERNAL_NETBLOCK" > /dev/null
235+ else
236+ maas admin ipranges create type=dynamic start_ip="$DHCP_RANGE_LOW" \
237+ end_ip="$DHCP_RANGE_HIGH" > /dev/null
238+ maas admin ipranges create type=reserved start_ip="$RESERVED_RANGE_LOW" \
239+ end_ip="$RESERVED_RANGE_HIGH" > /dev/null
240+ fi
241+ INTERNAL_FABRIC=$(maas admin ipranges read | \
242+ jshon -a -e subnet -e vlan -e fabric | \
243+ tr -d '"' | head -n 1)
244+ PRIMARY_RACK=$(maas admin rack-controllers read | jshon -a -e system_id | tr -d '"')
245+ maas admin vlan update "$INTERNAL_FABRIC" untagged dhcp_on=True \
246+ primary_rack="$PRIMARY_RACK" > /dev/null
247 local SUBNET_ID
248 SUBNET_ID=$(maas admin ipranges read | jshon -a -e subnet -e id | head -n 1)
249- maas admin subnet update "$SUBNET_ID" gateway_ip="$INTERNAL_IP"
250+ maas admin subnet update "$SUBNET_ID" gateway_ip="$INTERNAL_IP" > /dev/null
251 else
252 echo "* Rack controller DHCP configuration already exists; leaving it alone!"
253 echo "* You should use the MAAS web UI to reconfigure your ranges!"

Subscribers

People subscribed via source and target branches