Merge lp:~rvb/maas/packaging.set-rabbitmq-creds into lp:~maas-maintainers/maas/packaging
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Andres Rodriguez on 2012-09-21 | ||||
| Approved revision: | 94 | ||||
| Merged at revision: | 93 | ||||
| Proposed branch: | lp:~rvb/maas/packaging.set-rabbitmq-creds | ||||
| Merge into: | lp:~maas-maintainers/maas/packaging | ||||
| Diff against target: |
86 lines (+40/-0) 4 files modified
debian/changelog (+6/-0) debian/maas.install (+3/-0) debian/maas.links (+1/-0) debian/maas.postinst (+30/-0) |
||||
| To merge this branch: | bzr merge lp:~rvb/maas/packaging.set-rabbitmq-creds | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Andres Rodriguez | Approve on 2012-09-21 | ||
| Gavin Panella (community) | 2012-09-19 | Needs Fixing on 2012-09-20 | |
|
Review via email:
|
|||
Commit Message
Add method in debian/
Description of the Change
Add method in debian/
- 90. By Raphaël Badin on 2012-09-20
-
Update changelog.
- 91. By Raphaël Badin on 2012-09-20
-
Merge trunk, fix conflicts.
| Julian Edwards (julian-edwards) wrote : | # |
On Thursday 20 September 2012 16:44:18 you wrote:
> Sorry, I'm preaching to the choir. I have written many many long
> complicated bash scripts in the past - forgive me for I have sinned -
> but now I'd like to see it eliminated. I don't expect you to do that
> here though.
I'm happy to be corrected by one of the packaging guys, but I'm not sure using
Python or Perl in postinst is a good idea. While it's probably installed due
to our dependencies, it can't be guaranteed to be available.
| Gavin Panella (allenap) wrote : | # |
On 21 Sep 2012 02:22, "Julian Edwards" <email address hidden> wrote:
>
> On Thursday 20 September 2012 16:44:18 you wrote:
> > Sorry, I'm preaching to the choir. I have written many many long
> > complicated bash scripts in the past - forgive me for I have sinned -
> > but now I'd like to see it eliminated. I don't expect you to do that
> > here though.
>
> I'm happy to be corrected by one of the packaging guys, but I'm not sure
using
> Python or Perl in postinst is a good idea. While it's probably installed
due
> to our dependencies, it can't be guaranteed to be available.
That's a good point, and, if it's the case, is another reason why we should
aim to get more of this stuff into the maas runtime instead of its
packages.
| Raphaël Badin (rvb) wrote : | # |
Thanks for the review Gavin. I think you've found a real issue because broker_url definitely contains forward-slashes… but please be aware that the code that creates the rabbitmq user and populates the config file is based (as in copied from) on existing code that is in that very same file (to set up the rabbitmq user used by longpoll). This does not make it right but as a non-packaging expert, I've tried to blend in with how the packaging scripts have been written so far.
| Gavin Panella (allenap) wrote : | # |
On 21 Sep 2012 08:11, "Raphaël Badin" <email address hidden> wrote:
>
> Thanks for the review Gavin. I think you've found a real issue because
broker_url definitely contains forward-slashes… but please be aware that
the code that creates the rabbitmq user and populates the config file is
based (as in copied from) on existing code that is in that very same file
(to set up the rabbitmq user used by longpoll). This does not make it
right but as a non-packaging expert, I've tried to blend in with how the
packaging scripts have been written so far.
Oh yeah, I accept that, and never expected you to rewrite everything. I,
er, got a bit carried away.
- 92. By Raphaël Badin on 2012-09-21
-
Use '|' as a separator for sed.
| Raphaël Badin (rvb) wrote : | # |
Ok, I've fixed the flaw you found (by using a different separator in the sed statement) and simplified the regexp a bit.
I'm not sure if it's possible/
- 93. By Raphaël Badin on 2012-09-21
-
Merge trunk.
- 94. By Raphaël Badin on 2012-09-21
-
s/maas_
local_celeryset tings.py/ maas_local_ celeryconfig. py/


[1]
+ if [ -x /usr/sbin/ rabbitmqctl ]; then
Just so you know, there's a genuine tab character in there.
Also, Scott has recommended to not hard-code paths. You can check for
the presence of a command (in bash) with:
if command -v rabbitmqctl >/dev/null; then
or:
if type -p rabbitmqctl >/dev/null; then
Yay for TIMTOWTDI.
[2]
+ if ! rabbitmqctl list_users | grep -qs "$workers_user"; then
Unless $workers_user is a regex, use fgrep here.
[3]
+ rabbitmqctl add_user "$workers_user" "$workers_pass" || true
Can you add a comment about why errors are being suppressed?
[4]
+ if grep -qs "^BROKER_URL\ \= '[a-zA- Z0-9]\{ 0,\}'$" /etc/maas/ maas_local_ celerysettings. py; then
You /may/ find that egrep has a more pleasant and familiar regex syntax.
[5]
+ if grep -qs "^BROKER_URL\ \= '[a-zA- Z0-9]\{ 0,\}'$" /etc/maas/ maas_local_ celerysettings. py; then url="amqp: //$workers_ user:$workers_ pass@$amqp_ host:$amqp_ port/$workers_ vhost" Z0-9]\{ 0,\}'$/ BROKER_ URL = '"$broker_url"'/" \ maas_local_ celerysettings. py
+ local broker_
+ sed -i "s/^BROKER_URL\ \= '[a-zA-
+ /etc/maas/
+ fi
Why is it checking for such a detailed match? Why not just set it?
Also, that sed command is going to break because broker_url contains
forward-slashes. How about:
local broker_ url="amqp: //$workers_ user:$workers_ pass@$amqp_ host:$amqp_ port/$workers_ vhost" maas_local_ celerysettings. py" "${broker_url}" <<'EOF' URL)\b. *$', r'\1 = %r' % url, dir=dirname( conffile) ) write(output)
python - "/etc/maas/
from os import fdopen, rename
from os.path import dirname
from re import MULTILINE, sub
from sys import argv
from tempfile import mkstemp
conffile, url = argv[1:]
with open(conffile, "rb") as stream:
output = sub(
r'^(BROKER_
stream.read(), flags=MULTILINE)
fd, filename = mkstemp(
with fdopen(fd, "wb") as stream:
stream.
rename(filename, conffile)
EOF
It's long, but it makes sense, gets quoting right, and is
failure-safe.
Or, how about bash and awk:
local conffile= "/etc/maas/ maas_local_ celerysettings. py" .tmp.XXXXXX)
local conftemp=$(mktemp /etc/maas/
trap 'rm -f "${conftemp}"' EXIT
local broker_ url="amqp: //$workers_ user:$workers_ pass@$amqp_ host:$amqp_ port/$workers_ vhost" url_escaped= $(python -c 'import sys; sys.stdout. write(repr( sys.argv[ 1]))' "$broker_url") broker_ url_escaped} " \
local broker_
awk --assign "url=${
'/^BROKER_URL\y/ { print "BROKER_URL = " url; next } { print }' \
"${conffile}" > "${conftemp}"
mv "${conftemp}" "${conffile}"
The Python snippet gets quoting right, but it's line-noise otherwise.
Do you know what kicks both their arses?
url="amqp: //$workers_ user:$workers_ pass@$amqp_ host:$amqp_ port/$workers_ vhost" \ URL)\b. */\1 = "$ENV{'url'}"/' \ maas_local_ celerysettings. py
perl -pe 's/^(BROKER_
-i /etc/maas/
It doesn't guarantee correct quoting though, because it doesn't know
Python rules, and I'm not sure if -i is atomic.
In all, I think the Perl solution fits the hand best, but the Python
solution is more correct, and, if you actually switch to Python as a
replacement for sh/bash, it'll fit the hand well too. sh/bash is
just... arc...