Merge lp:~cyphermox/maas/maas-enlist-wget-not-curl into lp:~maas-maintainers/maas/maas-enlist

Proposed by Mathieu Trudel-Lapierre
Status: Merged
Merged at revision: 42
Proposed branch: lp:~cyphermox/maas/maas-enlist-wget-not-curl
Merge into: lp:~maas-maintainers/maas/maas-enlist
Diff against target: 60 lines (+17/-15)
1 file modified
bin/maas-enlist (+17/-15)
To merge this branch: bzr merge lp:~cyphermox/maas/maas-enlist-wget-not-curl
Reviewer Review Type Date Requested Status
Mike Pontillo (community) Needs Fixing
Review via email: mp+270110@code.launchpad.net

Description of the change

Use wget instead of curl.

At the very least, this allows maas-enlist to work as a d-i module, for use with "Multiple installs using MAAS" from the server CD boot menu.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

In this case it looks like the original curl implementation is more robust, since it URL encodes the parameters properly, whereas the wget implementation will just concatenate them into the URL string.

I would rather split this into enlist_node_wget() and enlist_node_curl() and have a --wget parameter to choose the wget backend if desired, leaving the curl backend the default.

review: Needs Fixing
Revision history for this message
Mike Pontillo (mpontillo) wrote :

I just tested both implementations and confirmed the issue. (the wget implementation, for example, doesn't work with power parameters whose passwords have the '&' character in them).

I noticed another difference as well: the original `curl` implementation helpfully prints the JSON output from the MAAS API call to stdout, whereas the wget version redirects it to /dev/null, leaving the user with no real indication of success or failure. That should be fixed as well before this lands.

Revision history for this message
Mike Pontillo (mpontillo) wrote :

(to be clear, I'm okay with NOT fixing all the issues with the wget version, as long as it has it's own separate --wget option to select wget for the I/O.)

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

If you want to do that, you will need to explicitly change also the maas-enlist call in maas-enlist-udeb.postinst to use --wget.

Note, it doesn't seem like the url encoding is really useful in this case, and it is still possible to urlencode programmatically outside wget before passing the parameters. I chose not to, because the MAC address could be passed without encoding (received just fine with the ':').

Revision history for this message
Mike Pontillo (mpontillo) wrote :

Perhaps we'll just prefer curl, if installed, and fall back to wget if not found, then.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/maas-enlist'
2--- bin/maas-enlist 2014-02-25 15:52:42 +0000
3+++ bin/maas-enlist 2015-09-03 20:21:26 +0000
4@@ -37,12 +37,12 @@
5 echo "$mac"
6 }
7
8-get_mac_address_curl_parms() {
9+get_mac_address_parms() {
10 local args="" input_string="$1"
11 OIFS=$IFS; IFS=","; set -- $input_string; IFS=$OIFS
12 for i in "$@";
13 do
14- args="${args} --data-urlencode mac_addresses=${i}"
15+ args="${args}&mac_addresses=${i}"
16 #mac_address="$mac_address""&mac_addresses=""${i}";
17 done
18 echo "${args# }"
19@@ -78,6 +78,7 @@
20 _RET=${_RET%%/*};
21 echo "$_RET";
22 }
23+
24 enlist_node() {
25 serverurl="${1}"
26 mac="${2}"
27@@ -88,19 +89,20 @@
28 power_params="${7}"
29
30 local macparms=""
31- macparms=$(get_mac_address_curl_parms "$mac")
32-
33- curl \
34- --data-urlencode "op=new" \
35- --data-urlencode "autodetect_nodegroup=1" \
36- --data-urlencode "hostname=${hostname}" \
37- --data-urlencode "architecture=${arch}" \
38- --data-urlencode "subarchitecture=${subarch}" \
39- --data-urlencode "power_type=${power_type}" \
40- --data-urlencode "power_parameters=${power_params}" \
41- ${macparms} \
42- "${serverurl}"
43-
44+ macparms=$(get_mac_address_parms "$mac")
45+
46+ local params="op=new"
47+ params="${params}&autodetect_nodegroup=1"
48+ params="${params}&hostname=${hostname}"
49+ params="${params}&architecture=${arch}"
50+ params="${params}&subarchitecture=${subarch}"
51+ params="${params}&power_type=${power_type}"
52+ params="${params}&power_parameters=${power_params}"
53+ params="${params}${macparms}"
54+
55+ wget -q -O/dev/null \
56+ "${serverurl}" \
57+ --post-data="$params"
58 }
59
60 Error () {

Subscribers

People subscribed via source and target branches