Merge lp:~sil2100/ubuntu-system-image/server-different_devices into lp:ubuntu-system-image/server

Proposed by Łukasz Zemczak on 2016-03-18
Status: Merged
Merged at revision: 288
Proposed branch: lp:~sil2100/ubuntu-system-image/server-different_devices
Merge into: lp:ubuntu-system-image/server
Diff against target: 136 lines (+64/-15)
2 files modified
lib/systemimage/generators.py (+12/-3)
lib/systemimage/tests/test_generators.py (+52/-12)
To merge this branch: bzr merge lp:~sil2100/ubuntu-system-image/server-different_devices
Reviewer Review Type Date Requested Status
Barry Warsaw (community) 2016-03-18 Approve on 2016-03-21
Review via email: mp+289534@code.launchpad.net

Commit Message

Add an additional optional argument to the system-image generator to sync tarballs from different devices.

Description of the Change

Add an additional optional argument to the system-image generator to sync tarballs from different devices.

To post a comment you must log in.
Barry Warsaw (barry) wrote :

Comments inlined but otherwise LGTM.

review: Approve
Łukasz Zemczak (sil2100) wrote :

Thanks for the comments Barry! Let me address those quickly. One of the reasons the self.assertIsNone() method is not used as I tend to try and keep the same code-style as it was originally used. So, a copy-paste since Stephane didn't use it in the original test code. Same for the private method I exported - it was a simple copy-paste in that case.

288. By Łukasz Zemczak on 2016-03-22

Use assertIsNone instead of what was already in the test-suite.

Barry Warsaw (barry) wrote :

On Mar 22, 2016, at 11:33 AM, Łukasz Zemczak wrote:

>Thanks for the comments Barry! Let me address those quickly. One of the
>reasons the self.assertIsNone() method is not used as I tend to try and keep
>the same code-style as it was originally used. So, a copy-paste since
>Stephane didn't use it in the original test code. Same for the private method
>I exported - it was a simple copy-paste in that case.

Gotcha. We should probably schedule some tech-debt reduction work. Might
make a good Foundations virtual sprint topic.

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 2016-02-10 18:03:44 +0000
3+++ lib/systemimage/generators.py 2016-03-22 12:07:40 +0000
4@@ -1267,24 +1267,33 @@
5 channel_name = arguments[0]
6 prefix = arguments[1]
7
8+ options = {}
9+ if len(arguments) > 2:
10+ options = unpack_arguments(arguments[2])
11+
12+ # We also support an optional argument to use a different source device
13+ device_name = environment['device_name']
14+ if 'device' in options:
15+ device_name = options['device']
16+
17 # Run some checks
18 pub = tree.Tree(conf)
19 if channel_name not in pub.list_channels():
20 logger.debug("Channel not in the published list: %s" % channel_name)
21 return None
22
23- if (not environment['device_name'] in
24+ if (device_name not in
25 pub.list_channels()[channel_name]['devices']):
26 logger.debug("Device not in the channel list")
27 return None
28
29 # Try to find the file
30- device = pub.get_device(channel_name, environment['device_name'])
31+ device = pub.get_device(channel_name, device_name)
32
33 full_images = sorted([image for image in device.list_images()
34 if image['type'] == "full"],
35 key=lambda image: image['version'])
36- logger.debug("List of full images founds %s" % full_images)
37+ logger.debug("List of full images found %s" % full_images)
38
39 # No images
40 if not full_images:
41
42=== modified file 'lib/systemimage/tests/test_generators.py'
43--- lib/systemimage/tests/test_generators.py 2016-03-16 18:31:30 +0000
44+++ lib/systemimage/tests/test_generators.py 2016-03-22 12:07:40 +0000
45@@ -62,6 +62,20 @@
46 def tearDown(self):
47 shutil.rmtree(self.temp_directory)
48
49+ def _publish_dummy_to_channel(self, device):
50+ """Helper function used to publish a dummy image for selected device"""
51+ open(os.path.join(self.config.publish_path, "file-1.tar.xz"),
52+ "w+").close()
53+
54+ with open(os.path.join(self.config.publish_path, "file-1.json"),
55+ "w+") as fd:
56+ fd.write(json.dumps({'version_detail': "abcd"}))
57+
58+ gpg.sign_file(self.config, "image-signing",
59+ os.path.join(self.config.publish_path, "file-1.tar.xz"))
60+ device.create_image("full", 1234, "abc", ["file-1.tar.xz"],
61+ minversion=1233, bootme=True)
62+
63 @unittest.skipUnless(HAS_TEST_KEYS, MISSING_KEYS_WARNING)
64 def test_unpack_arguments(self):
65 self.assertEqual(generators.unpack_arguments("a=1,b=2"),
66@@ -844,7 +858,7 @@
67 self.assertEqual(
68 generators.generate_file_system_image(self.config,
69 ['invalid', 'file'],
70- {}),
71+ environment),
72 None)
73
74 # Check for device name
75@@ -864,17 +878,7 @@
76 None)
77
78 # Publish some random stuff
79- open(os.path.join(self.config.publish_path, "file-1.tar.xz"),
80- "w+").close()
81-
82- with open(os.path.join(self.config.publish_path, "file-1.json"),
83- "w+") as fd:
84- fd.write(json.dumps({'version_detail': "abcd"}))
85-
86- gpg.sign_file(self.config, "image-signing",
87- os.path.join(self.config.publish_path, "file-1.tar.xz"))
88- self.device.create_image("full", 1234, "abc", ["file-1.tar.xz"],
89- minversion=1233, bootme=True)
90+ self._publish_dummy_to_channel(self.device)
91
92 # Invalid filename
93 self.assertEqual(
94@@ -891,6 +895,42 @@
95 os.path.join(self.config.publish_path, "file-1.tar.xz"))
96
97 @unittest.skipUnless(HAS_TEST_KEYS, MISSING_KEYS_WARNING)
98+ def test_generate_file_system_image_different_device(self):
99+ """Test the system-image generator for a different source device."""
100+ environment = {}
101+ environment['channel_name'] = "test"
102+ environment['device'] = self.device
103+ environment['device_name'] = "test"
104+ environment['new_files'] = []
105+ environment['version'] = 1234
106+ environment['version_detail'] = []
107+
108+ self.tree.create_device("test", "source")
109+ source_device = self.tree.get_device("test", "source")
110+
111+ # Invalid device
112+ self.assertIsNone(
113+ generators.generate_file(self.config, "system-image",
114+ ['test', 'file', 'device=invalid'],
115+ environment))
116+
117+ # Empty channel in correct device
118+ self.assertIsNone(
119+ generators.generate_file(self.config, "system-image",
120+ ['test', 'file', 'device=source'],
121+ environment))
122+
123+ # Publish some random stuff
124+ self._publish_dummy_to_channel(source_device)
125+
126+ # Normal run
127+ self.assertEqual(
128+ generators.generate_file(self.config, "system-image",
129+ ['test', 'file', 'device=source'],
130+ environment),
131+ os.path.join(self.config.publish_path, "file-1.tar.xz"))
132+
133+ @unittest.skipUnless(HAS_TEST_KEYS, MISSING_KEYS_WARNING)
134 @mock.patch("systemimage.tools.repack_recovery_keyring")
135 @mock.patch("systemimage.generators.urlretrieve")
136 @mock.patch("systemimage.generators.urlopen")

Subscribers

People subscribed via source and target branches