Merge ~rodsmith/maas-cert-server:fix-iperf-setup into maas-cert-server:master

Proposed by Rod Smith
Status: Merged
Approved by: Rod Smith
Approved revision: 8a313f23b964f6d10b2e9d86567b005cdc0da904
Merged at revision: ad7257bef41bdfcd9b0121c93196520ad50c24b5
Proposed branch: ~rodsmith/maas-cert-server:fix-iperf-setup
Merge into: maas-cert-server:master
Diff against target: 74 lines (+26/-14)
2 files modified
debian/changelog (+9/-0)
preseed/curtin_userdata_cert (+17/-14)
Reviewer Review Type Date Requested Status
Adrian Lane (community) Approve
Review via email: mp+401738@code.launchpad.net

Commit message

Fix iperf3 target setting and MAAS version detection in preseed

Description of the change

The iperf3 target setting was not working when MAAS was installed via snaps. This MR fixes the problem, albeit by requiring the iperf.conf file to be copied somewhere that the snap can read. This will need to be documented in MANIACS.

To support snaps, and earlier merge changed the preseed's method of detecting the MAAS version. This change has proven to be unreliable. This MR reverts to a (slightly altered) earlier method. This method works when MAAS is installed via Debian packages, but not via snaps; but as we're deprecating installation of MAAS via snaps for certification, this seems like an acceptable compromise.

To post a comment you must log in.
Revision history for this message
Adrian Lane (alanec) wrote :

LGMT-

review: Approve

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 df8bb27..583aa46 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,12 @@
6+maas-cert-server (0.6.3-0ppa1) focal; urgency=medium
7+
8+ * Add support in preseed for taking iperf target data from snap directory.
9+ * Reverted to a (slightly altered) older version of determining the MAAS
10+ version in preseed, since the new version was unreliable. Neither version
11+ works when MAAS is installed via a snap.
12+
13+ -- Rod Smith <rod.smith@canonical.com> Fri, 23 Apr 2021 16:08:10 -0400
14+
15 maas-cert-server (0.6.2-0ppa1) focal; urgency=medium
16
17 * Increased default size of LXD container in lxc-setup from 30 GB to
18diff --git a/preseed/curtin_userdata_cert b/preseed/curtin_userdata_cert
19index 623887c..2facb12 100644
20--- a/preseed/curtin_userdata_cert
21+++ b/preseed/curtin_userdata_cert
22@@ -1,21 +1,28 @@
23-# Get maas version
24+# Get maas version & iperf3 targets
25 {{py:
26 from subprocess import check_output
27 from shlex import split
28 import json
29 import netifaces as ni
30+
31+maas_version = "unknown"
32 try:
33- cache_output = check_output(['maas', 'admin', 'version', 'read']).decode('utf-8')
34+ cache_output = check_output(['apt-cache', 'policy', 'maas']).decode('utf-8')
35 except:
36- maas_version = "unknown"
37-else:
38- maas_version = json.loads(cache_output)['version'] + "-" + json.loads(cache_output)['subversion']
39+ cache_output = ""
40+for line in cache_output.splitlines():
41+ line = line.strip()
42+ if 'Installed:' in line:
43+ maas_version = line.split('Installed:')[1].strip()
44 try:
45- f = open('/etc/maas-cert-server/iperf.conf', 'r')
46- test_target_iperf = f.readline().rstrip()
47- f.close()
48+ with open('/etc/maas-cert-server/iperf.conf', 'r') as f:
49+ test_target_iperf = f.readline().rstrip()
50 except IOError:
51- test_target_iperf = "gateway"
52+ try:
53+ with open('/var/snap/maas/current/iperf.conf', 'r') as f:
54+ test_target_iperf = f.readline().rstrip()
55+ except IOError:
56+ test_target_iperf = "gateway"
57 iface = ni.gateways()['default'][ni.AF_INET][1];
58 maas_ip = ni.ifaddresses(iface)[ni.AF_INET][0]['addr']
59 }}
60@@ -121,13 +128,9 @@ anchor_bucket:
61 - &iperf
62 #!/bin/sh
63 echo "Setting up iperf...";
64- /bin/sed -i '/^#TEST_TARGET_FTP /s/^#//' /etc/xdg/canonical-certification.conf;
65- /bin/sed -i '/^#TEST_USER /s/^#//' /etc/xdg/canonical-certification.conf;
66- /bin/sed -i '/^#TEST_PASS /s/^#//' /etc/xdg/canonical-certification.conf;
67 /bin/sed -i '/^#TEST_TARGET_IPERF /s/^#//' /etc/xdg/canonical-certification.conf;
68 if [ "{{test_target_iperf}}" = "gateway" ] ; then
69- maas_ip=$(/sbin/ip route | awk '/default/ { print $3 }');
70- sed -i 's/ your-iperf-server.example.com/'"$maas_ip"'/g' /etc/xdg/canonical-certification.conf;
71+ sed -i 's/ your-iperf-server.example.com/{{maas_ip}}/g' /etc/xdg/canonical-certification.conf;
72 else
73 sed -i 's/ your-iperf-server.example.com/{{test_target_iperf}}/g' /etc/xdg/canonical-certification.conf;
74 fi;

Subscribers

People subscribed via source and target branches