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

Proposed by Łukasz Zemczak
Status: Merged
Merge reported by: Steve Langasek
Merged at revision: not available
Proposed branch: lp:~sil2100/ubuntu-system-image/server-redirect_in_scripts
Merge into: lp:ubuntu-system-image/server
Diff against target: 154 lines (+49/-20)
4 files modified
bin/copy-image (+21/-10)
bin/import-images (+6/-0)
bin/set-phased-percentage (+11/-5)
bin/tag-image (+11/-5)
To merge this branch: bzr merge lp:~sil2100/ubuntu-system-image/server-redirect_in_scripts
Reviewer Review Type Date Requested Status
Steve Langasek (community) Approve
Barry Warsaw Pending
Review via email: mp+298211@code.launchpad.net

Commit message

Add proper checks for handling the per-device channel redirects in our scripts (import-image, copy-image, tag-image and set-phased-percentage). No unit tests as currently we have no unit-test support for scripts and the testability branch is yet to land.

Description of the change

Add proper checks for handling the per-device channel redirects in our scripts (import-image, copy-image, tag-image and set-phased-percentage). No unit tests as currently we have no unit-test support for scripts and the testability branch is yet to land.

These changes will be propagated to the testability branch, so that we don't miss the same checks [1].

[1] https://code.launchpad.net/~sil2100/ubuntu-system-image/server_script_testability

To post a comment you must log in.
Revision history for this message
Steve Langasek (vorlon) wrote :

Please see inline comments.

review: Needs Fixing
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Ok, will remove the refactoring as mentioned. I simply didn't want to write tons of additional boilerplate code as I had to do channels = pub.list_channels() anyway since otherwise I wouldn't be able to fit in the 80 column size-limit for PEP8. So I thought I might as well just use it everywhere.

As for the redirect, see my inline reply - but the consensus is: we would generally want to support this as this would be one of the use-cases.

Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Steve, with all due respect, can't I leave the small refectoring in place? This just introduces additional unnecessary work for me (and testing, since I need to make sure it's still working correctly and I didn't break anything with a semi-whole revert).

293. By Łukasz Zemczak

Change output wording.

Revision history for this message
Steve Langasek (vorlon) wrote :

I was not asking for a revert, I was asking for the unrelated changes to be isolated into separate commits (which would require a rebase of this branch).

I've split out the refactor work into a commit and landed this separately; your branch can then land on top. This branch looks good now, and doesn't introduce testsuite regressions, so merging.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/copy-image'
2--- bin/copy-image 2015-11-12 12:47:12 +0000
3+++ bin/copy-image 2016-06-24 11:06:41 +0000
4@@ -78,38 +78,49 @@
5 pub = tree.Tree(conf)
6
7 # Do some checks
8- if args.source_channel not in pub.list_channels():
9+ channels = pub.list_channels()
10+ if args.source_channel not in channels:
11 parser.error("Invalid source channel: %s" % args.source_channel)
12
13- if args.destination_channel not in pub.list_channels():
14+ if args.destination_channel not in channels:
15 parser.error("Invalid destination channel: %s" %
16 args.destination_channel)
17
18- if args.device not in pub.list_channels()[args.source_channel]['devices']:
19+ if args.device not in channels[args.source_channel]['devices']:
20 parser.error("Invalid device for source channel: %s" %
21 args.device)
22
23 if args.device not in \
24- pub.list_channels()[args.destination_channel]['devices']:
25+ channels[args.destination_channel]['devices']:
26 parser.error("Invalid device for destination channel: %s" %
27 args.device)
28
29- if "alias" in pub.list_channels()[args.source_channel] and \
30- pub.list_channels()[args.source_channel]['alias'] \
31+ if "alias" in channels[args.source_channel] and \
32+ channels[args.source_channel]['alias'] \
33 != args.source_channel:
34 parser.error("Source channel is an alias.")
35
36- if "alias" in pub.list_channels()[args.destination_channel] and \
37- pub.list_channels()[args.destination_channel]['alias'] \
38+ if "alias" in channels[args.destination_channel] and \
39+ channels[args.destination_channel]['alias'] \
40 != args.destination_channel:
41 parser.error("Destination channel is an alias.")
42
43- if "redirect" in pub.list_channels()[args.source_channel]:
44+ if "redirect" in channels[args.source_channel]:
45 parser.error("Source channel is a redirect.")
46
47- if "redirect" in pub.list_channels()[args.destination_channel]:
48+ if "redirect" in channels[args.destination_channel]:
49 parser.error("Destination channel is a redirect.")
50
51+ src_device = channels[args.source_channel]['devices'][args.device]
52+ if "redirect" in src_device:
53+ parser.error("Source device is a redirect. Use original channel "
54+ "%s instead." % src_device['redirect'])
55+
56+ dest_device = channels[args.destination_channel]['devices'][args.device]
57+ if "redirect" in dest_device:
58+ parser.error("Destination device is a redirect. Use original channel "
59+ "%s instead." % dest_device['redirect'])
60+
61 if args.tag and "," in args.tag:
62 parser.error("Image tag cannot include the character ','.")
63
64
65=== modified file 'bin/import-images'
66--- bin/import-images 2015-03-11 20:55:00 +0000
67+++ bin/import-images 2016-06-24 11:06:41 +0000
68@@ -82,6 +82,12 @@
69 for device_name in pub.list_channels()[channel_name]['devices']:
70 logging.info("Processing device: %s" % device_name)
71
72+ device_entry = \
73+ pub.list_channels()[channel_name]['devices'][device_name]
74+ if "redirect" in device_entry:
75+ logging.info("Device is a redirect, not considering.")
76+ continue
77+
78 device = pub.get_device(channel_name, device_name)
79
80 # Extract last full version
81
82=== modified file 'bin/set-phased-percentage'
83--- bin/set-phased-percentage 2014-04-17 16:34:11 +0000
84+++ bin/set-phased-percentage 2016-06-24 11:06:41 +0000
85@@ -59,23 +59,29 @@
86 pub = tree.Tree(conf)
87
88 # Do some checks
89- if args.channel not in pub.list_channels():
90+ channels = pub.list_channels()
91+ if args.channel not in channels:
92 parser.error("Invalid channel: %s" % args.channel)
93
94- if args.device not in pub.list_channels()[args.channel]['devices']:
95+ if args.device not in channels[args.channel]['devices']:
96 parser.error("Invalid device for source channel: %s" %
97 args.device)
98
99 if args.percentage < 0 or args.percentage > 100:
100 parser.error("Invalid value: %s" % args.percentage)
101
102- if "alias" in pub.list_channels()[args.channel] and \
103- pub.list_channels()[args.channel]['alias'] != args.channel:
104+ if "alias" in channels[args.channel] and \
105+ channels[args.channel]['alias'] != args.channel:
106 parser.error("Channel is an alias.")
107
108- if "redirect" in pub.list_channels()[args.channel]:
109+ if "redirect" in channels[args.channel]:
110 parser.error("Channel is a redirect.")
111
112+ target_device = channels[args.channel]['devices'][args.device]
113+ if "redirect" in target_device:
114+ parser.error("Target device is a redirect. Use original channel "
115+ "%s instead." % target_device['redirect'])
116+
117 dev = pub.get_device(args.channel, args.device)
118 logging.info("Setting phased-percentage of '%s' to %s%%" %
119 (args.version, args.percentage))
120
121=== modified file 'bin/tag-image'
122--- bin/tag-image 2015-11-12 12:47:12 +0000
123+++ bin/tag-image 2016-06-24 11:06:41 +0000
124@@ -73,20 +73,26 @@
125 pub = tree.Tree(conf)
126
127 # Do some checks
128- if args.channel not in pub.list_channels():
129+ channels = pub.list_channels()
130+ if args.channel not in channels:
131 parser.error("Invalid channel: %s" % args.channel)
132
133- if args.device not in pub.list_channels()[args.channel]['devices']:
134+ if args.device not in channels[args.channel]['devices']:
135 parser.error("Invalid device for channel: %s" % args.device)
136
137- if "alias" in pub.list_channels()[args.channel] and \
138- pub.list_channels()[args.channel]['alias'] \
139+ if "alias" in channels[args.channel] and \
140+ channels[args.channel]['alias'] \
141 != args.channel:
142 parser.error("Channel is an alias.")
143
144- if "redirect" in pub.list_channels()[args.channel]:
145+ if "redirect" in channels[args.channel]:
146 parser.error("Channel is a redirect.")
147
148+ target_device = channels[args.channel]['devices'][args.device]
149+ if "redirect" in target_device:
150+ parser.error("Target device is a redirect. Use original channel "
151+ "%s instead." % target_device['redirect'])
152+
153 if "," in args.tag:
154 parser.error("Image tag cannot include the character ','.")
155

Subscribers

People subscribed via source and target branches