Merge lp:~psivaa/core-image-watcher/channel-release-for-image-publisher into lp:core-image-watcher

Proposed by Para Siva
Status: Merged
Approved by: Para Siva
Approved revision: 18
Merged at revision: 17
Proposed branch: lp:~psivaa/core-image-watcher/channel-release-for-image-publisher
Merge into: lp:core-image-watcher
Diff against target: 226 lines (+40/-45)
4 files modified
core-service.conf (+0/-6)
core_image_watcher/__init__.py (+15/-10)
core_image_watcher/constants.py (+14/-23)
core_image_watcher/tests/test_image_watcher.py (+11/-6)
To merge this branch: bzr merge lp:~psivaa/core-image-watcher/channel-release-for-image-publisher
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Review via email: mp+261065@code.launchpad.net

Commit message

Separating channel and release for the 'old' core-image-watcher for agreeing to core-image-publisher API contract.

Description of the change

Separating channel and release for the 'old' core-image-watcher for providing the payload that the new core-image-publisher uses. Same changes as was done for lp:core-image-watcher/15.04-edge-core-image-watcher. This is being proposed in preparation for changes to be done in core-image-publisher to use the channel and release data from the payload it receives from the watcher.

To post a comment you must log in.
18. By Para Siva

correct output queue

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

Looks good.

review: Approve

Preview Diff

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

Subscribers

People subscribed via source and target branches