Merge lp:~mariogrip/ubuntu-system-image/device-alias into lp:ubuntu-system-image/server

Proposed by Marius Gripsgard 
Status: Needs review
Proposed branch: lp:~mariogrip/ubuntu-system-image/device-alias
Merge into: lp:ubuntu-system-image/server
Diff against target: 84 lines (+67/-0)
1 file modified
lib/systemimage/tree.py (+67/-0)
To merge this branch: bzr merge lp:~mariogrip/ubuntu-system-image/device-alias
Reviewer Review Type Date Requested Status
Łukasz Zemczak (community) Needs Fixing
Steve Langasek (community) Disapprove
Review via email: mp+284169@code.launchpad.net

Description of the change

Add support for Device alias

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

This doesn't look like a maintainable design to me. You are attaching device aliases to individual channels. This means that the same device alias, on two different channels, can point to two different devices. And if a device is removed from a channel, there's nothing in this code that ensures the alias is removed with it; so a channel might have dangling aliases to a device that has been removed from that channel.

I would prefer to see device aliases handled globally, not per channel.

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

First of all, thanks for the proposition!

Sadly I must agree with Steve here, although a bit less strictly. Even though handling aliases per-channel might look like a logical thing because, well, we have per-channel devices, there's one key thing to remember here. Even though devices are essentially defined per-channel, any device is global - i.e. if you copy an image for device 'mako' from channel foo to channel bar, system-image assumes that the device 'mako' is the same as the one in channel foo. If we let defining aliases per channel this might become a bit hairy and confusing - one alias could point to one device in one channel and to another one in a different one, but those devices could potentially different as it's just an 'alias'.

In this particular case I would also opt for a global approach instead.

But continuing the review beyond the design considerations: first of all, remember we would need tests for this implemented as well. The tree parts are well unit-testable so we would need tests for all the new functionality added.
Another thing: for internal configuration in system-image we try to follow the dash-separated form for naming, not camelCase - so deviceAlias would be better off being device-alias instead.

review: Needs Fixing

Unmerged revisions

284. By Marius Gripsgard 

Add support for Device alias

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/systemimage/tree.py'
2--- lib/systemimage/tree.py 2015-10-27 15:25:38 +0000
3+++ lib/systemimage/tree.py 2016-01-27 18:19:19 +0000
4@@ -306,6 +306,54 @@
5
6 return True
7
8+ def change_device_alias(self, channel_name, device_name, new_device_name, target_device_name):
9+ """
10+ Change a device alias entry
11+ """
12+
13+ with channels_json(self.config, self.indexpath, True) as channels:
14+ if channel_name not in channels:
15+ raise KeyError("Couldn't find channel: %s" % channel_name)
16+
17+ if target_device_name not in channels[channel_name]['devices']:
18+ raise KeyError("Couldn't find target device: %s" % target_device_name)
19+
20+ if device_name not in channels[channel_name]['deviceAlias']:
21+ raise KeyError("Device alias does not exists: %s" % device_name)
22+
23+
24+ channels[channel_name]['deviceAlias'].pop(device_name)
25+
26+ alias = {}
27+ alias["device"] = target_device_name
28+ channels[channel_name]['deviceAlias'][new_device_name] = alias
29+
30+ return True
31+
32+ def create_device_alias(self, channel_name, device_name, target_device_name):
33+ """
34+ Creates a new device alias entry
35+ """
36+
37+ with channels_json(self.config, self.indexpath, True) as channels:
38+ if channel_name not in channels:
39+ raise KeyError("Couldn't find channel: %s" % channel_name)
40+
41+ if target_device_name not in channels[channel_name]['devices']:
42+ raise KeyError("Couldn't find target device: %s" % target_device_name)
43+
44+ if "deviceAlias" in channels[channel_name]:
45+ if device_name in channels[channel_name]['deviceAlias']:
46+ raise KeyError("Device alias already exists: %s" % device_name)
47+ else:
48+ channels[channel_name]['deviceAlias'] = {}
49+
50+ alias = {}
51+ alias["device"] = target_device_name
52+ channels[channel_name]['deviceAlias'][device_name] = alias
53+
54+ return True
55+
56 def create_device(self, channel_name, device_name, keyring_path=None):
57 """
58 Creates a new device entry in the tree.
59@@ -516,6 +564,25 @@
60
61 return True
62
63+ def remove_device_alias(self, channel_name, device_name):
64+ """
65+ Removes a device alias entry
66+ """
67+
68+ with channels_json(self.config, self.indexpath, True) as channels:
69+ if channel_name not in channels:
70+ raise KeyError("Couldn't find channel: %s" % channel_name)
71+
72+ if device_name not in channels[channel_name]['deviceAlias']:
73+ raise KeyError("Couldn't find device alias: %s" % device_name)
74+
75+ channels[channel_name]['deviceAlias'].pop(device_name)
76+
77+ if not channels[channel_name]['deviceAlias']:
78+ channels[channel_name].pop('deviceAlias')
79+
80+ return True
81+
82 def remove_device(self, channel_name, device_name):
83 """
84 Remove a device and everything it contains.

Subscribers

People subscribed via source and target branches