~canonical-ci-engineering/core-image-watcher/15.04-edge-core-image-watcher

« back to all changes in this revision

Viewing changes to core_image_watcher/__init__.py

  • Committer: Ubuntu CI Bot
  • Author(s): Parameswaran Sivatharman
  • Date: 2015-06-02 18:05:43 UTC
  • mfrom: (16.1.4 image-info-from-constants)
  • Revision ID: ubuntu_ci_bot-20150602180543-8d861vqnb0zpq0u7
Obtain image specific information from constants.py.  [r=Francis Ginther]

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
        logger.info('Triggering request: %s', body, extra=extra)
50
50
        try:
51
51
            queue = connection.SimpleQueue(
52
 
                'core.image.{}'.format(constants.API_VERSION))
 
52
                constants.OUTPUT_QUEUE)
53
53
            queue.put(body)
54
54
            queue.close()
55
55
        except Exception as exc:
57
57
        logger.info('Done!', extra=extra)
58
58
 
59
59
 
60
 
def _get_version_string_output(channel, device):
 
60
def _get_version_string_output(release, channel, device):
61
61
    """Obtains a bytestring of the images info from the core image server"""
62
62
    cmd = [
63
63
        'ubuntu-device-flash',
64
64
        'query',
65
65
        '--list-images',
66
 
        '--channel={}'.format(channel),
 
66
        '--channel=ubuntu-core/{}/{}'.format(release, channel),
67
67
        '--device={}'.format(device),
68
68
    ]
69
69
    images = b''
75
75
        return images
76
76
 
77
77
 
78
 
def _get_latest_image_version(channel,
 
78
def _get_latest_image_version(release,
 
79
                              channel,
79
80
                              device,
80
81
                              get_output=_get_version_string_output):
81
82
    """Returns largest image version"""
82
 
    images = get_output(channel, device).split()
 
83
    images = get_output(release, channel, device).split()
83
84
    if (len(images) >= 2):
84
85
        return images[-2].decode('utf-8').replace(':', '')
85
86
 
110
111
 
111
112
 
112
113
def _check_for_new_image(location,
 
114
                         release,
113
115
                         channel,
114
116
                         device,
115
117
                         latest_image_version=_get_latest_image_version,
116
118
                         cached_version=_cache_version_to_disk):
117
119
    """Check if a new image is present in the core image server"""
118
 
    latest_version = latest_image_version(channel, device)
 
120
    latest_version = latest_image_version(release, channel, device)
119
121
    try:
120
122
        ret = cached_version(location, latest_version)
121
123
        if not ret:
127
129
        return None
128
130
    body = {
129
131
        'image_name': latest_version,
 
132
        'release': release,
130
133
        'channel': channel,
131
134
        'device': device,
132
135
        'request_id': uuid(),
155
158
    logger.info('Started!', extra=logging_extra)
156
159
 
157
160
    amqp_uris = config.get('amqp', 'uris').split()
158
 
    location = config.get('image', 'location')
159
 
    channel = config.get('image', 'channel')
160
 
    device = config.get('image', 'device')
161
 
    poll_period = float(config.get('image', 'poll_period'))
 
161
    location = constants.LOCATION
 
162
    release = constants.RELEASE
 
163
    channel = constants.CHANNEL
 
164
    device = constants.DEVICE
 
165
    poll_period = float(constants.POLL_PERIOD)
162
166
 
163
167
    try:
164
168
        while True:
165
169
            message_body = _check_for_new_image(location,
 
170
                                                release,
166
171
                                                channel,
167
172
                                                device)
168
173
            if message_body: