Merge lp:~caio1982/ubuntu-system-image/remote-sis-generator-skips-metadata into lp:ubuntu-system-image/server

Proposed by Caio Begotti
Status: Needs review
Proposed branch: lp:~caio1982/ubuntu-system-image/remote-sis-generator-skips-metadata
Merge into: lp:ubuntu-system-image/server
Diff against target: 157 lines (+44/-14)
1 file modified
lib/systemimage/generators.py (+44/-14)
To merge this branch: bzr merge lp:~caio1982/ubuntu-system-image/remote-sis-generator-skips-metadata
Reviewer Review Type Date Requested Status
Barry Warsaw (community) Needs Fixing
Review via email: mp+260210@code.launchpad.net

Description of the change

Feel free to replace this code with whatever you guys think is best but please do fix this bug :-)

I think the commit message is pretty descriptive so let me know if you need more info. We found a situation with Capomastro's instance of image server where only the first device in a channel list would have its Ubuntu rootfs's versioning right, so this address that problem as... well... we definitely need the rootfs versions to be right. People were chasing us for that last week :-(

Before: https://pastebin.canonical.com/132002/

After: https://pastebin.canonical.com/132001/

To post a comment you must log in.
273. By Caio Begotti

add missing debug logging to the existing (!!!) fixes for the problem we originally saw... so apparently only the remote s-i-s generator was behind this :-)

Revision history for this message
Barry Warsaw (barry) wrote :

Thanks for taking on this bug. I've added some comments, but none that you really need to address in this branch.

What I *do* think needs fixing before this can land is... tests! Can you please add a test for the bug? As Steve pointed out in my own branch, the best way to ensure this fixes the problem is to apply the test-adding diff, see the test fail, then add the fix and see it succeed.

The change looks okay on the face of it, but please add a test.

review: Needs Fixing
Revision history for this message
Caio Begotti (caio1982) wrote :

Thanks, Barry! Just filed https://bugs.launchpad.net/ubuntu-system-image/+bug/1461263 for the encoding bit. It might take me a while to write tests for this MR though as I honestly don't know the code much and I see all the other generators are missing tests for metadata (at least for version_detail) and they should have some.

Revision history for this message
Barry Warsaw (barry) wrote :

On Jun 02, 2015, at 09:05 PM, Caio Begotti wrote:

>Thanks, Barry! Just filed
>https://bugs.launchpad.net/ubuntu-system-image/+bug/1461263 for the encoding
>bit.

Thanks!

>It might take me a while to write tests for this MR though as I honestly
>don't know the code much and I see all the other generators are missing tests
>for metadata (at least for version_detail) and they should have some.

Yep. You can't get to 100% in one fell swoop, but every new test is an
investment in the future quality of the project.

Unmerged revisions

273. By Caio Begotti

add missing debug logging to the existing (!!!) fixes for the problem we originally saw... so apparently only the remote s-i-s generator was behind this :-)

272. By Caio Begotti

make the remote system-image generator respect the metadata of existing images

this is a really big problem when you have multiple devices in the same channel and both pull the same ubuntu rootfs, exactly like we have right now for arale... e.g. 'arale' and 'generic' devices both pulling a stable ubuntu rootfs from system-image.ubuntu.com

device 'generic' first pulls it just fine and loads its json with the metadata, including ubuntu='' versioning, but then when the 'arale' device imports its stuff, the ubuntu rootfs has been imported already so the path matches and the generator returns it without loading its json file

no ubuntu='' version string for any other devices in the channel :-(

fun fact: a 'generic' device is always processed first, even if it was created later because of a sorting done in the device list (i haven't really checked it so i assum it happens), so with the current code ONLY the 'generic' devices get their ubuntu='' version right for all those rootfs tarballs

271. By Caio Begotti

remove unnecessary (and too verbose) logging, as over time the server will be so crowded with images this might be totally useless and poluting

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/systemimage/generators.py'
2--- lib/systemimage/generators.py 2015-04-10 17:35:24 +0000
3+++ lib/systemimage/generators.py 2015-05-26 21:23:25 +0000
4@@ -283,10 +283,13 @@
5
6 # Return pre-existing entries
7 if os.path.exists(path):
8+ json_path = path.replace(".tar.xz", ".json")
9+ logger.debug("Image exists, loading its {}".format(json_path))
10 # Get the real version number (in case it got copied)
11- if os.path.exists(path.replace(".tar.xz", ".json")):
12- with open(path.replace(".tar.xz", ".json"), "r") as fd:
13+ if os.path.exists(json_path):
14+ with open(json_path, "r") as fd:
15 metadata = json.loads(fd.read())
16+ logger.debug("Metadata found: {}".format(metadata))
17
18 if "version_detail" in metadata:
19 version_detail = metadata['version_detail']
20@@ -441,10 +444,13 @@
21
22 # Return pre-existing entries
23 if os.path.exists(path):
24+ json_path = path.replace(".tar.xz", ".json")
25+ logger.debug("Image exists, loading its {}".format(json_path))
26 # Get the real version number (in case it got copied)
27- if os.path.exists(path.replace(".tar.xz", ".json")):
28- with open(path.replace(".tar.xz", ".json"), "r") as fd:
29+ if os.path.exists(json_path):
30+ with open(json_path, "r") as fd:
31 metadata = json.loads(fd.read())
32+ logger.debug("Metadata found: {}".format(metadata))
33
34 if "version_detail" in metadata:
35 version_detail = metadata['version_detail']
36@@ -669,10 +675,13 @@
37
38 # Return pre-existing entries
39 if os.path.exists(path):
40+ json_path = path.replace(".tar.xz", ".json")
41+ logger.debug("Image exists, loading its {}".format(json_path))
42 # Get the real version number (in case it got copied)
43- if os.path.exists(path.replace(".tar.xz", ".json")):
44- with open(path.replace(".tar.xz", ".json"), "r") as fd:
45+ if os.path.exists(json_path):
46+ with open(json_path, "r") as fd:
47 metadata = json.loads(fd.read())
48+ logger.debug("Metadata found: {}".format(metadata))
49
50 if "version_detail" in metadata:
51 version_detail = metadata['version_detail']
52@@ -792,10 +801,13 @@
53
54 # Return pre-existing entries
55 if os.path.exists(path):
56+ json_path = path.replace(".tar.xz", ".json")
57+ logger.debug("Image exists, loading its {}".format(json_path))
58 # Get the real version number (in case it got copied)
59- if os.path.exists(path.replace(".tar.xz", ".json")):
60- with open(path.replace(".tar.xz", ".json"), "r") as fd:
61+ if os.path.exists(json_path):
62+ with open(json_path, "r") as fd:
63 metadata = json.loads(fd.read())
64+ logger.debug("Metadata found: {}".format(metadata))
65
66 if "version_detail" in metadata:
67 version_detail = metadata['version_detail']
68@@ -901,6 +913,7 @@
69 if os.path.exists(old_path.replace(".tar.xz", ".json")):
70 with open(old_path.replace(".tar.xz", ".json"), "r") as fd:
71 metadata = json.loads(fd.read())
72+ logger.debug("Metadata found: {}".format(metadata))
73
74 if "version_detail" in metadata:
75 version_detail = metadata['version_detail']
76@@ -919,10 +932,13 @@
77
78 # Return pre-existing entries
79 if os.path.exists(path):
80+ json_path = path.replace(".tar.xz", ".json")
81+ logger.debug("Image exists, loading its {}".format(json_path))
82 # Get the real version number (in case it got copied)
83- if os.path.exists(path.replace(".tar.xz", ".json")):
84- with open(path.replace(".tar.xz", ".json"), "r") as fd:
85+ if os.path.exists(json_path):
86+ with open(json_path, "r") as fd:
87 metadata = json.loads(fd.read())
88+ logger.debug("Metadata found: {}".format(metadata))
89
90 if "version_detail" in metadata:
91 version_detail = metadata['version_detail']
92@@ -965,10 +981,13 @@
93
94 # Return pre-existing entries
95 if os.path.exists(path):
96+ json_path = path.replace(".tar.xz", ".json")
97+ logger.debug("Image exists, loading its {}".format(json_path))
98 # Get the real version number (in case it got copied)
99- if os.path.exists(path.replace(".tar.xz", ".json")):
100- with open(path.replace(".tar.xz", ".json"), "r") as fd:
101+ if os.path.exists(json_path):
102+ with open(json_path, "r") as fd:
103 metadata = json.loads(fd.read())
104+ logger.debug("Metadata found: {}".format(metadata))
105
106 if "version_detail" in metadata:
107 version_detail = metadata['version_detail']
108@@ -1160,7 +1179,6 @@
109 full_images = sorted([image for image in index_json['images']
110 if image['type'] == "full"],
111 key=lambda image: image['version'])
112- logger.debug("List of full images founds %s" % full_images)
113
114 # No images
115 if not full_images:
116@@ -1176,6 +1194,17 @@
117 logger.debug("Path generated: %s" % path)
118
119 if os.path.exists(path):
120+ json_path = path.replace(".tar.xz", ".json")
121+ logger.debug("Image exists, loading its {}".format(json_path))
122+ if os.path.exists(json_path):
123+ with open(json_path, "r") as fd:
124+ metadata = json.loads(fd.read())
125+ logger.debug("Metadata found: {}".format(metadata))
126+
127+ if "version_detail" in metadata:
128+ environment['version_detail'].append(
129+ metadata['version_detail'])
130+
131 return path
132
133 # Create the target if needed
134@@ -1224,6 +1253,7 @@
135 gpg.sign_file(conf, "image-signing", json_path)
136 with open(json_path, "r") as fd:
137 metadata = json.loads(fd.read())
138+ logger.debug("Metadata found: {}".format(metadata))
139
140 if "version_detail" in metadata:
141 environment['version_detail'].append(
142@@ -1265,7 +1295,6 @@
143 full_images = sorted([image for image in device.list_images()
144 if image['type'] == "full"],
145 key=lambda image: image['version'])
146- logger.debug("List of full images founds %s" % full_images)
147
148 # No images
149 if not full_images:
150@@ -1283,6 +1312,7 @@
151 if os.path.exists(path.replace(".tar.xz", ".json")):
152 with open(path.replace(".tar.xz", ".json"), "r") as fd:
153 metadata = json.loads(fd.read())
154+ logger.debug("Metadata found: {}".format(metadata))
155
156 if "version_detail" in metadata:
157 environment['version_detail'].append(

Subscribers

People subscribed via source and target branches

to all changes: