Merge lp:~psivaa/core-image-watcher/image-info-from-constants into lp:core-image-watcher/vivid-edge-core-image-watcher

Proposed by Para Siva
Status: Merged
Approved by: Para Siva
Approved revision: 20
Merged at revision: 17
Proposed branch: lp:~psivaa/core-image-watcher/image-info-from-constants
Merge into: lp:core-image-watcher/vivid-edge-core-image-watcher
Diff against target: 241 lines (+43/-48)
5 files modified
README.rst (+1/-1)
core-service.conf (+0/-6)
core_image_watcher/__init__.py (+15/-10)
core_image_watcher/constants.py (+16/-25)
core_image_watcher/tests/test_image_watcher.py (+11/-6)
To merge this branch: bzr merge lp:~psivaa/core-image-watcher/image-info-from-constants
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Review via email: mp+260846@code.launchpad.net

Commit message

Obtain image specific information from constants.py.

Description of the change

Obtain image specific information from constants.py. It was agreed that separate worker will be spun for different image channels.

The relevant worker log:

2015-06-02 16:22:26,381 core_image_watcher INFO: Triggering request: {'channel': 'ubuntu-core/15.04/edge', 'device': 'generic_amd64', 'request_id': '44c52bb7-deb8-42ac-974e-7377a7259647', 'image_name': '74'}

As discussed, the output rabbitmq channel will be the same as one used for rolling_edge. (channel name will be `core-image-v1`)

To post a comment you must log in.
Revision history for this message
Francis Ginther (fginther) wrote :

This looks like the right change. You probably also want to move the rabbit queue name(s) to the constants file, but that doesn't need to be done here.

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

Ooops. I missed something.

The format u-d-f uses channels changed a few weeks back. As a result, the core-image-publisher was modified to hardcode the names for the channel and release. The problem is that the u-d-f query operations still use the "ubuntu-core/15.04/edge" format, but when actually downloading an image, all three components of this have to be specified separately. For the snappy-proposed-selftest-agent, we took the approach of specifying "RELEASE" and "CHANNEL" as independent constants and then letting the code organize them into the right usage. We should do the same thing here. But again, this could be done as a follow on MP.

19. By Para Siva

Seperate channel and release from old channel

Revision history for this message
Para Siva (psivaa) wrote :

Thanks for the comment, I've now introduced RELEASE here and constructed the 'channel' for u-d-f query from them.
This is the output now:

  2015-06-02 17:29:17,356 core_image_watcher INFO: Triggering request: {'channel': 'edge', 'request_id': '9200b538-0019-47df-96f2-f15b80f50343', 'release': '15.04', 'image_name': '74', 'device': 'generic_amd64'}

Revision history for this message
Francis Ginther (fginther) wrote :

This looks good, thanks for splitting channel and release.

review: Approve
20. By Para Siva

Move the channel name to constants

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'README.rst'
2--- README.rst 2015-04-01 01:12:25 +0000
3+++ README.rst 2015-06-02 16:50:01 +0000
4@@ -8,7 +8,7 @@
5
6 Branch the code::
7
8- $ bzr branch lp:core-image-watcher
9+ $ bzr branch lp:core-image-watcher/15.04-edge-core-image-watcher
10
11 Install the Service
12 ========================
13
14=== modified file 'core-service.conf'
15--- core-service.conf 2015-03-31 14:27:00 +0000
16+++ core-service.conf 2015-06-02 16:50:01 +0000
17@@ -3,12 +3,6 @@
18 [amqp]
19 uris = amqp://guest:guest@localhost:5672//
20
21-[image]
22-channel = ubuntu-core/devel-proposed
23-device = generic_amd64
24-location = /tmp/latest-core-image-version
25-poll_period = 60
26-
27 [logstash]
28 host = 127.0.0.1
29 port = 5959
30
31=== modified file 'core_image_watcher/__init__.py'
32--- core_image_watcher/__init__.py 2015-04-08 01:59:01 +0000
33+++ core_image_watcher/__init__.py 2015-06-02 16:50:01 +0000
34@@ -49,7 +49,7 @@
35 logger.info('Triggering request: %s', body, extra=extra)
36 try:
37 queue = connection.SimpleQueue(
38- 'core.image.{}'.format(constants.API_VERSION))
39+ constants.OUTPUT_QUEUE)
40 queue.put(body)
41 queue.close()
42 except Exception as exc:
43@@ -57,13 +57,13 @@
44 logger.info('Done!', extra=extra)
45
46
47-def _get_version_string_output(channel, device):
48+def _get_version_string_output(release, channel, device):
49 """Obtains a bytestring of the images info from the core image server"""
50 cmd = [
51 'ubuntu-device-flash',
52 'query',
53 '--list-images',
54- '--channel={}'.format(channel),
55+ '--channel=ubuntu-core/{}/{}'.format(release, channel),
56 '--device={}'.format(device),
57 ]
58 images = b''
59@@ -75,11 +75,12 @@
60 return images
61
62
63-def _get_latest_image_version(channel,
64+def _get_latest_image_version(release,
65+ channel,
66 device,
67 get_output=_get_version_string_output):
68 """Returns largest image version"""
69- images = get_output(channel, device).split()
70+ images = get_output(release, channel, device).split()
71 if (len(images) >= 2):
72 return images[-2].decode('utf-8').replace(':', '')
73
74@@ -110,12 +111,13 @@
75
76
77 def _check_for_new_image(location,
78+ release,
79 channel,
80 device,
81 latest_image_version=_get_latest_image_version,
82 cached_version=_cache_version_to_disk):
83 """Check if a new image is present in the core image server"""
84- latest_version = latest_image_version(channel, device)
85+ latest_version = latest_image_version(release, channel, device)
86 try:
87 ret = cached_version(location, latest_version)
88 if not ret:
89@@ -127,6 +129,7 @@
90 return None
91 body = {
92 'image_name': latest_version,
93+ 'release': release,
94 'channel': channel,
95 'device': device,
96 'request_id': uuid(),
97@@ -155,14 +158,16 @@
98 logger.info('Started!', extra=logging_extra)
99
100 amqp_uris = config.get('amqp', 'uris').split()
101- location = config.get('image', 'location')
102- channel = config.get('image', 'channel')
103- device = config.get('image', 'device')
104- poll_period = float(config.get('image', 'poll_period'))
105+ location = constants.LOCATION
106+ release = constants.RELEASE
107+ channel = constants.CHANNEL
108+ device = constants.DEVICE
109+ poll_period = float(constants.POLL_PERIOD)
110
111 try:
112 while True:
113 message_body = _check_for_new_image(location,
114+ release,
115 channel,
116 device)
117 if message_body:
118
119=== modified file 'core_image_watcher/constants.py'
120--- core_image_watcher/constants.py 2015-04-01 01:14:59 +0000
121+++ core_image_watcher/constants.py 2015-06-02 16:50:01 +0000
122@@ -14,34 +14,25 @@
123 # You should have received a copy of the GNU General Public License
124 # along with this program. If not, see <http://www.gnu.org/licenses/>.
125 #
126-
127 """Constants for this service."""
128
129+import socket
130
131-API_VERSION = "v1"
132
133 SOLUTION_NAME = "core-image-testing"
134
135-SERVICE_NAME = "core-image-watcher"
136-
137-
138-def _get_hostname():
139- """Return sanitized contents of /etc/hostname.
140-
141- It is necessary because current juju hostnames (juju-<env-name>-machine-#)
142- are too big due to our long environment names ('<spec_name>-<MD5>').
143- Linux (DNS for RFC1035, really) only supports labels up to 64 chars and
144- the fallback varies from tool to tool, `cloud-init` chokes on longer
145- names and sets 'ubuntu' (which is the value considered by socket.get*),
146- `hostnamectl` (systemd) would truncate the given data.
147-
148- None of this is ideal to our applications, that's why we will operate
149- on the pristine /etc/hostname and remove the 'juju-' and '-machine' terms
150- added by juju.
151- """
152- with open('/etc/hostname') as fd:
153- hostname = fd.read()
154- return hostname.replace('juju-', '').replace('-machine', '').strip()
155-
156-
157-HOSTNAME = _get_hostname()
158+SERVICE_NAME = "15.04-edge-core-image-watcher"
159+
160+OUTPUT_QUEUE = 'core-image-v1'
161+
162+RELEASE = "15.04"
163+
164+CHANNEL = 'edge'
165+
166+DEVICE = "generic_amd64"
167+
168+LOCATION = "/tmp/latest-15.04_edge-image-version"
169+
170+POLL_PERIOD = 60
171+
172+HOSTNAME = socket.gethostname()
173
174=== modified file 'core_image_watcher/tests/test_image_watcher.py'
175--- core_image_watcher/tests/test_image_watcher.py 2015-04-07 23:58:33 +0000
176+++ core_image_watcher/tests/test_image_watcher.py 2015-06-02 16:50:01 +0000
177@@ -65,32 +65,35 @@
178 self.assertEqual(return_value, '112')
179
180 def test_get_latest_version(self):
181- def get_output(channel, device):
182+ def get_output(release, channel, device):
183 return b"295: description='fake295'\n\
184 296: description='fake296'\n\
185 297: description='fake297'\n\
186 298: description='fake338'\n"
187- observed = _get_latest_image_version('fakechannel',
188+ observed = _get_latest_image_version('fakerelease',
189+ 'fakechannel',
190 'fakedevice',
191 get_output)
192 self.assertEqual(observed, '298')
193
194 def test_dont_get_latest_version(self):
195- def get_output(channel, device):
196+ def get_output(release, channel, device):
197 return b"100: description='fake100'\n"
198- observed = _get_latest_image_version('fakechannel',
199+ observed = _get_latest_image_version('fakerelease',
200+ 'fakechannel',
201 'fakedevice',
202 get_output)
203 self.assertEqual(observed, '100')
204
205 def test_check_for_new_image(self):
206- def _get_latest_image_version(channel, device):
207+ def _get_latest_image_version(release, channel, device):
208 return '100'
209
210 def _cache_version_to_disk(location, latest_version):
211 return '99'
212
213 body = _check_for_new_image('fakelocation',
214+ 'fakerelease',
215 'fakechannel',
216 'fakedevice',
217 _get_latest_image_version,
218@@ -101,6 +104,7 @@
219 {
220 'device': Equals('fakedevice'),
221 'image_name': Equals('100'),
222+ 'release': Equals('fakerelease'),
223 'channel': Equals('fakechannel'),
224 'request_id': NotEquals(''),
225 }
226@@ -108,13 +112,14 @@
227 )
228
229 def test_check_for_no_new_image(self):
230- def _get_latest_image_version(channel, device):
231+ def _get_latest_image_version(release, channel, device):
232 return '100'
233
234 def _cache_version_to_disk(location, latest_version):
235 return None
236
237 body = _check_for_new_image('fakelocation',
238+ 'fakerelease',
239 'fakechannel',
240 'fakedevice',
241 _get_latest_image_version,

Subscribers

People subscribed via source and target branches