Merge lp:~alexandru-sirbu/cloud-init/bigstep-datasource-improvements into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Alex Sirbu
Status: Merged
Merged at revision: 1177
Proposed branch: lp:~alexandru-sirbu/cloud-init/bigstep-datasource-improvements
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 49 lines (+13/-1)
2 files modified
cloudinit/settings.py (+1/-0)
cloudinit/sources/DataSourceBigstep.py (+12/-1)
To merge this branch: bzr merge lp:~alexandru-sirbu/cloud-init/bigstep-datasource-improvements
Reviewer Review Type Date Requested Status
Dan Watkins Approve
Scott Moser Pending
Review via email: mp+288251@code.launchpad.net

Description of the change

Based on the proposal of smoser:

<smoser> Odd_Bloke, when you dont have that file there..
<smoser> i dontrecall. does cloud-init warn that the ds raised exception ?
<smoser> can you just try and catch the load_file and return false if not there ?

+ Added Bigstep as one of the default datasources in the settings.py file

To post a comment you must log in.
Revision history for this message
Dan Watkins (oddbloke) :
review: Needs Fixing
Revision history for this message
Alex Sirbu (alexandru-sirbu) wrote :

Commented on reviews.

Revision history for this message
Dan Watkins (oddbloke) wrote :

On 07/03/16 12:18, Alex Sirbu wrote:
>> === modified file 'cloudinit/sources/DataSourceBigstep.py'
>> --- cloudinit/sources/DataSourceBigstep.py 2016-03-02 08:53:47 +0000
>> +++ cloudinit/sources/DataSourceBigstep.py 2016-03-07 09:36:05 +0000
>> @@ -22,7 +23,13 @@
>> self.userdata_raw = ""
>>
>> def get_data(self, apply_filter=False):
>> - url = get_url_from_file()
>> + try:
>
> So, have the try catch there and return a NULL value or something similar and then return False if the url returned by the function has that value?

Yeah, I think that makes sense.

>> + url = get_url_from_file()
>> + except IOError as e:
>> + if e.errno == errno.ENOENT:
>
> Exactly, if the file does not exist (the case covered by the ENOENT) then it is ok, as we probably are on a non-Bigstep server. However, if another error is raised, then it is probably worthwhile to see and investigate the issue and is probably not caused by the inexistance of the file. The same error catching is also used in the load_config function in the read_conf from the util file -> the inexistance of the file is treated as an empty config, any other error is thrown anyway. Does an explanation need to be added in this case?

It's not immediately obvious to me, so I would still like one. Just
something like "If the file doesn't exist, this isn't Bigstep;
otherwise, this is broken Bigstep".

1179. By Alex Sirbu

Implemented review concerning position of try and more information about the caught exception.

Revision history for this message
Dan Watkins (oddbloke) :
review: Approve
Revision history for this message
Dan Watkins (oddbloke) wrote :

Thanks Alex, this looks good to me; I've added smoser to confirm that this addresses his concern.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/settings.py'
2--- cloudinit/settings.py 2015-03-04 17:42:34 +0000
3+++ cloudinit/settings.py 2016-03-07 12:31:21 +0000
4@@ -42,6 +42,7 @@
5 'CloudSigma',
6 'CloudStack',
7 'SmartOS',
8+ 'Bigstep',
9 # At the end to act as a 'catch' when none of the above work...
10 'None',
11 ],
12
13=== modified file 'cloudinit/sources/DataSourceBigstep.py'
14--- cloudinit/sources/DataSourceBigstep.py 2016-03-02 08:53:47 +0000
15+++ cloudinit/sources/DataSourceBigstep.py 2016-03-07 12:31:21 +0000
16@@ -5,6 +5,7 @@
17 #
18
19 import json
20+import errno
21
22 from cloudinit import log as logging
23 from cloudinit import sources
24@@ -23,6 +24,8 @@
25
26 def get_data(self, apply_filter=False):
27 url = get_url_from_file()
28+ if url is None:
29+ return False
30 response = url_helper.readurl(url)
31 decoded = json.loads(response.contents)
32 self.metadata = decoded["metadata"]
33@@ -32,7 +35,15 @@
34
35
36 def get_url_from_file():
37- content = util.load_file("/var/lib/cloud/data/seed/bigstep/url")
38+ try:
39+ content = util.load_file("/var/lib/cloud/data/seed/bigstep/url")
40+ except IOError as e:
41+ # If the file doesn't exist, then the server probably isn't a Bigstep
42+ # instance; otherwise, another problem exists which needs investigation
43+ if e.errno == errno.ENOENT:
44+ return None
45+ else:
46+ raise
47 return content
48
49 # Used to match classes to dependencies