Merge ~holmanb/curtin:master into curtin:master

Proposed by Brett Holman
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: 122d28d686bb34feec3b60358f6c5fd078c38e85
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~holmanb/curtin:master
Merge into: curtin:master
Diff against target: 62 lines (+20/-13)
2 files modified
tests/vmtests/__init__.py (+16/-11)
tools/find-tgt (+4/-2)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Michael Hudson-Doyle Pending
Review via email: mp+433147@code.launchpad.net

Commit message

support older versions of iproute2

Description of the change

Bionic's iproute2 package contains a half-baked -json implementation; ip address and ip link work, while ip route simply accepts the flag but gives non-json output. This proposal works around that.

To post a comment you must log in.
Revision history for this message
Brett Holman (holmanb) wrote :

More details in the original github PR comment.

https://github.com/canonical/curtin/pull/5

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
~holmanb/curtin:master updated
88bce1e... by Brett Holman <email address hidden>

use older ss syntax

Revision history for this message
Brett Holman (holmanb) wrote :

More failures here: https://jenkins.canonical.com/server-team/view/cloud-init/job/curtin-cloud-init-sru/7/console

The '=' sign in the ss command works fine locally on Jammy, but not on Bionic. Removing that works on both.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
~holmanb/curtin:master updated
c556aeb... by Brett Holman <email address hidden>

work around old iproute2 in tests

122d28d... by Brett Holman <email address hidden>

match lookup behavior of -json

Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Brett Holman (holmanb) wrote :

Our curtin job in Jenkins is currently[1] running against the latest iteration of this branch to validate cloud-init's 22.4 SRU. If this passes on torkoal, it should help with validating this MR.

[1] https://jenkins.canonical.com/server-team/view/cloud-init/job/curtin-cloud-init-sru/8/console

Revision history for this message
Brett Holman (holmanb) wrote :

It passed

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/tests/vmtests/__init__.py b/tests/vmtests/__init__.py
2index 467c8a2..09c4c21 100644
3--- a/tests/vmtests/__init__.py
4+++ b/tests/vmtests/__init__.py
5@@ -2412,17 +2412,22 @@ def boot_log_wrap(name, func, cmd, console_log, timeout, purpose):
6 def get_lan_ip():
7 (out, _) = util.subp(['ip', 'a'], capture=True)
8 info = ip_a_to_dict(out)
9- (routes, _) = util.subp(['ip', '-json', 'route', 'show'], capture=True)
10- gwdevs = []
11- for route in json.loads(routes):
12- if route['dst'] == 'default':
13- gwdevs.append(route['dev'])
14- if len(gwdevs) > 0:
15- dev = gwdevs.pop()
16- addr = info[dev].get('inet4')[0].get('address')
17- else:
18- raise OSError('could not get local ip address')
19- return addr
20+ try:
21+ (routes, _) = util.subp(['ip', '-json', 'route', 'show'], capture=True)
22+ gwdevs = []
23+ for route in json.loads(routes):
24+ if route['dst'] == 'default':
25+ gwdevs.append(route['dev'])
26+ if len(gwdevs) > 0:
27+ dev = gwdevs.pop()
28+ return info[dev].get('inet4')[0].get('address')
29+ except json.decoder.JSONDecodeError:
30+ # default via 10.247.8.1 dev eth0 onlink
31+ for line in routes.split('\n'):
32+ if "default" in line:
33+ dev = line.split()[4]
34+ return info[dev].get('inet4')[0].get('address')
35+ raise OSError('could not get local ip address')
36
37
38 def kernel_boot_cmdline_for_mac(mac):
39diff --git a/tools/find-tgt b/tools/find-tgt
40index e269beb..ec784f6 100755
41--- a/tools/find-tgt
42+++ b/tools/find-tgt
43@@ -35,6 +35,8 @@ for r in json.load(sys.stdin):
44 print(r["dev"])
45 break
46 ')
47+ # on bionic, ip -json route show doesn't produce json
48+ [ -n "$dev" ] || dev=$(ip route show | grep ^default | awk '{print $5}')
49 [ -n "$dev" ] || { error "failed to find ipv4 device"; return 1; }
50 addr=$(ip addr show dev "$dev" |
51 awk '$1 == "inet" {gsub(/\/.*/,"", $2); print $2; exit}')
52@@ -52,8 +54,8 @@ wait_for_tgtd() {
53 local out="" pidstgt="" name="tgtd"
54 while :; do
55 # did we succesfully attach to the correct port?
56- out=$(ss --no-header --processes --listening --numeric "src = inet:$portal" 2>/dev/null) ||
57- fail "failed to ss --no-header --processes --listening --numeric src = inet:$portal"
58+ out=$(ss --no-header --processes --listening --numeric "src inet:$portal" 2>/dev/null) ||
59+ fail "failed to ss --no-header --processes --listening --numeric src inet:$portal"
60 pidstgt=$(echo "$out" | awk '{ print $7; exit(0); }')
61 if echo $pidstgt | grep --quiet "pid=$pid,"; then
62 error "expected pid $pid is listening on $portal on try $try."

Subscribers

People subscribed via source and target branches