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
=== modified file 'lib/systemimage/generators.py'
--- lib/systemimage/generators.py 2015-04-10 17:35:24 +0000
+++ lib/systemimage/generators.py 2015-05-26 21:23:25 +0000
@@ -283,10 +283,13 @@
283283
284 # Return pre-existing entries284 # Return pre-existing entries
285 if os.path.exists(path):285 if os.path.exists(path):
286 json_path = path.replace(".tar.xz", ".json")
287 logger.debug("Image exists, loading its {}".format(json_path))
286 # Get the real version number (in case it got copied)288 # Get the real version number (in case it got copied)
287 if os.path.exists(path.replace(".tar.xz", ".json")):289 if os.path.exists(json_path):
288 with open(path.replace(".tar.xz", ".json"), "r") as fd:290 with open(json_path, "r") as fd:
289 metadata = json.loads(fd.read())291 metadata = json.loads(fd.read())
292 logger.debug("Metadata found: {}".format(metadata))
290293
291 if "version_detail" in metadata:294 if "version_detail" in metadata:
292 version_detail = metadata['version_detail']295 version_detail = metadata['version_detail']
@@ -441,10 +444,13 @@
441444
442 # Return pre-existing entries445 # Return pre-existing entries
443 if os.path.exists(path):446 if os.path.exists(path):
447 json_path = path.replace(".tar.xz", ".json")
448 logger.debug("Image exists, loading its {}".format(json_path))
444 # Get the real version number (in case it got copied)449 # Get the real version number (in case it got copied)
445 if os.path.exists(path.replace(".tar.xz", ".json")):450 if os.path.exists(json_path):
446 with open(path.replace(".tar.xz", ".json"), "r") as fd:451 with open(json_path, "r") as fd:
447 metadata = json.loads(fd.read())452 metadata = json.loads(fd.read())
453 logger.debug("Metadata found: {}".format(metadata))
448454
449 if "version_detail" in metadata:455 if "version_detail" in metadata:
450 version_detail = metadata['version_detail']456 version_detail = metadata['version_detail']
@@ -669,10 +675,13 @@
669675
670 # Return pre-existing entries676 # Return pre-existing entries
671 if os.path.exists(path):677 if os.path.exists(path):
678 json_path = path.replace(".tar.xz", ".json")
679 logger.debug("Image exists, loading its {}".format(json_path))
672 # Get the real version number (in case it got copied)680 # Get the real version number (in case it got copied)
673 if os.path.exists(path.replace(".tar.xz", ".json")):681 if os.path.exists(json_path):
674 with open(path.replace(".tar.xz", ".json"), "r") as fd:682 with open(json_path, "r") as fd:
675 metadata = json.loads(fd.read())683 metadata = json.loads(fd.read())
684 logger.debug("Metadata found: {}".format(metadata))
676685
677 if "version_detail" in metadata:686 if "version_detail" in metadata:
678 version_detail = metadata['version_detail']687 version_detail = metadata['version_detail']
@@ -792,10 +801,13 @@
792801
793 # Return pre-existing entries802 # Return pre-existing entries
794 if os.path.exists(path):803 if os.path.exists(path):
804 json_path = path.replace(".tar.xz", ".json")
805 logger.debug("Image exists, loading its {}".format(json_path))
795 # Get the real version number (in case it got copied)806 # Get the real version number (in case it got copied)
796 if os.path.exists(path.replace(".tar.xz", ".json")):807 if os.path.exists(json_path):
797 with open(path.replace(".tar.xz", ".json"), "r") as fd:808 with open(json_path, "r") as fd:
798 metadata = json.loads(fd.read())809 metadata = json.loads(fd.read())
810 logger.debug("Metadata found: {}".format(metadata))
799811
800 if "version_detail" in metadata:812 if "version_detail" in metadata:
801 version_detail = metadata['version_detail']813 version_detail = metadata['version_detail']
@@ -901,6 +913,7 @@
901 if os.path.exists(old_path.replace(".tar.xz", ".json")):913 if os.path.exists(old_path.replace(".tar.xz", ".json")):
902 with open(old_path.replace(".tar.xz", ".json"), "r") as fd:914 with open(old_path.replace(".tar.xz", ".json"), "r") as fd:
903 metadata = json.loads(fd.read())915 metadata = json.loads(fd.read())
916 logger.debug("Metadata found: {}".format(metadata))
904917
905 if "version_detail" in metadata:918 if "version_detail" in metadata:
906 version_detail = metadata['version_detail']919 version_detail = metadata['version_detail']
@@ -919,10 +932,13 @@
919932
920 # Return pre-existing entries933 # Return pre-existing entries
921 if os.path.exists(path):934 if os.path.exists(path):
935 json_path = path.replace(".tar.xz", ".json")
936 logger.debug("Image exists, loading its {}".format(json_path))
922 # Get the real version number (in case it got copied)937 # Get the real version number (in case it got copied)
923 if os.path.exists(path.replace(".tar.xz", ".json")):938 if os.path.exists(json_path):
924 with open(path.replace(".tar.xz", ".json"), "r") as fd:939 with open(json_path, "r") as fd:
925 metadata = json.loads(fd.read())940 metadata = json.loads(fd.read())
941 logger.debug("Metadata found: {}".format(metadata))
926942
927 if "version_detail" in metadata:943 if "version_detail" in metadata:
928 version_detail = metadata['version_detail']944 version_detail = metadata['version_detail']
@@ -965,10 +981,13 @@
965981
966 # Return pre-existing entries982 # Return pre-existing entries
967 if os.path.exists(path):983 if os.path.exists(path):
984 json_path = path.replace(".tar.xz", ".json")
985 logger.debug("Image exists, loading its {}".format(json_path))
968 # Get the real version number (in case it got copied)986 # Get the real version number (in case it got copied)
969 if os.path.exists(path.replace(".tar.xz", ".json")):987 if os.path.exists(json_path):
970 with open(path.replace(".tar.xz", ".json"), "r") as fd:988 with open(json_path, "r") as fd:
971 metadata = json.loads(fd.read())989 metadata = json.loads(fd.read())
990 logger.debug("Metadata found: {}".format(metadata))
972991
973 if "version_detail" in metadata:992 if "version_detail" in metadata:
974 version_detail = metadata['version_detail']993 version_detail = metadata['version_detail']
@@ -1160,7 +1179,6 @@
1160 full_images = sorted([image for image in index_json['images']1179 full_images = sorted([image for image in index_json['images']
1161 if image['type'] == "full"],1180 if image['type'] == "full"],
1162 key=lambda image: image['version'])1181 key=lambda image: image['version'])
1163 logger.debug("List of full images founds %s" % full_images)
11641182
1165 # No images1183 # No images
1166 if not full_images:1184 if not full_images:
@@ -1176,6 +1194,17 @@
1176 logger.debug("Path generated: %s" % path)1194 logger.debug("Path generated: %s" % path)
11771195
1178 if os.path.exists(path):1196 if os.path.exists(path):
1197 json_path = path.replace(".tar.xz", ".json")
1198 logger.debug("Image exists, loading its {}".format(json_path))
1199 if os.path.exists(json_path):
1200 with open(json_path, "r") as fd:
1201 metadata = json.loads(fd.read())
1202 logger.debug("Metadata found: {}".format(metadata))
1203
1204 if "version_detail" in metadata:
1205 environment['version_detail'].append(
1206 metadata['version_detail'])
1207
1179 return path1208 return path
11801209
1181 # Create the target if needed1210 # Create the target if needed
@@ -1224,6 +1253,7 @@
1224 gpg.sign_file(conf, "image-signing", json_path)1253 gpg.sign_file(conf, "image-signing", json_path)
1225 with open(json_path, "r") as fd:1254 with open(json_path, "r") as fd:
1226 metadata = json.loads(fd.read())1255 metadata = json.loads(fd.read())
1256 logger.debug("Metadata found: {}".format(metadata))
12271257
1228 if "version_detail" in metadata:1258 if "version_detail" in metadata:
1229 environment['version_detail'].append(1259 environment['version_detail'].append(
@@ -1265,7 +1295,6 @@
1265 full_images = sorted([image for image in device.list_images()1295 full_images = sorted([image for image in device.list_images()
1266 if image['type'] == "full"],1296 if image['type'] == "full"],
1267 key=lambda image: image['version'])1297 key=lambda image: image['version'])
1268 logger.debug("List of full images founds %s" % full_images)
12691298
1270 # No images1299 # No images
1271 if not full_images:1300 if not full_images:
@@ -1283,6 +1312,7 @@
1283 if os.path.exists(path.replace(".tar.xz", ".json")):1312 if os.path.exists(path.replace(".tar.xz", ".json")):
1284 with open(path.replace(".tar.xz", ".json"), "r") as fd:1313 with open(path.replace(".tar.xz", ".json"), "r") as fd:
1285 metadata = json.loads(fd.read())1314 metadata = json.loads(fd.read())
1315 logger.debug("Metadata found: {}".format(metadata))
12861316
1287 if "version_detail" in metadata:1317 if "version_detail" in metadata:
1288 environment['version_detail'].append(1318 environment['version_detail'].append(

Subscribers

People subscribed via source and target branches

to all changes: