Presence of both no_proxy and NO_PROXY environment variables causes Checkbox to error when saving the output of the environment resource job.

Bug #1067280 reported by Brendan Donegan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Checkbox
Fix Released
High
Unassigned

Bug Description

Since the environment resource job has been introduced into Checkbox, the following exception has started appearing in the log:

2012-10-16 10:24:02,699 ERROR Error running event handler <string> MessageInfo.message_file(<_io.StringIO object at 0xa4ba32c>) for event type 'message-file'
Traceback (most recent call last):
  File "/home/brendand/src/checkbox/start_no_errors_test/checkbox/reactor.py", line 74, in fire
      results.append(handler(*args, **kwargs))
  File "<string>", line 112, in message_file
  File "/home/brendand/src/checkbox/start_no_errors_test/checkbox/lib/template_i18n.py", line 132, in load_file
             elements = super(TemplateI18n, self).load_file(*args, **kwargs)
  File "/home/brendand/src/checkbox/start_no_errors_test/checkbox/lib/template.py", line 99, in load_file
                    _save(field, value, extended)
  File "/home/brendand/src/checkbox/start_no_errors_test/checkbox/lib/template.py", line 85, in _save
                          % (filename, field, value))
  Exception: Template <stream> has a duplicate field 'no_proxy' with a new value 'localhost,127.0.0.0/8'.

After some debugging, what this conveys is that where Checkbox is trying to save the output of the environment resource job, it is encountering the anomaly that there is both a 'NO_PROXY' environment variable and a 'no_proxy' environment variable set. Why this is is currently unknown, but it's nothing to do with Checkbox. This causes the above validation error. The root cause of this in Checkbox is that the names of environment variables are getting converted to lower-case in the resource job, in order to keep consistency in the job files. It therefore see's 'no_proxy' twice.

Related branches

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

There are a few possibilities to deal with this, some less desirable than others -

1.) Retain the casing. This will look bad in the job files, as the requires line will have to be written like:

environment.ROUTERS == 'multiple'

(of course the environment_info plugin could be changed to use lowercase names for the variables)

2.) The resource job could filter duplicates

description: updated
Revision history for this message
Daniel Manrique (roadmr) wrote :

Pending review by Marc (our bash wizard) I think this would do the trick for option 2.

 IFS=$'\n'
 env | sed 's/=/:/g' | awk -F':' '{print tolower($1) ": " $2}' | sort | uniq

I also noticed that env variables (particularly DISPLAY and PATH) get chewed into oblivion by this (as awk separates by colons and then prints only the second field as the data) ; though as long as we don't depend too much on variables that contain colons we should be OK. Optionally we can fix this too...

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Not sure why I sed'ed = for : in the first place. Might be worth finding out what happens if we removed that step

Changed in checkbox:
status: New → Triaged
importance: Undecided → High
summary: - Presense of both no_proxy and NO_PROXY environment variables causes
+ Presence of both no_proxy and NO_PROXY environment variables causes
Checkbox to error when saving the output of the environment resource
job.
Revision history for this message
Daniel Manrique (roadmr) wrote :

Hey, this seems to work:

env | awk -F'=' '{print tolower($1) ": " $2}' | sort | uniq

Since the delimiter we specify with -F gets removed and then we replace it with the colon. Not sure if checkbox will be confused by more than one colon in resource key/value pairs, but I expect it can handle it just fine.

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Hmm, strictly speaking the above isn't going to work if the environment variables are named the same but have different values, i.e.:

no_proxy=foo

is different from

no_proxy=bar

Revision history for this message
Brendan Donegan (brendan-donegan) wrote :

Otherwise, the fix suggested works for this particular manifestation of the bug

Changed in checkbox:
status: Triaged → Fix Committed
Changed in checkbox:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.