~sil2100/ubuntu-system-image/server_script_testability

« back to all changes in this revision

Viewing changes to bin/copy-image

  • Committer: Łukasz 'sil2100' Zemczak
  • Date: 2015-11-05 17:34:29 UTC
  • mto: This revision was merged to the branch mainline in revision 281.
  • Revision ID: lukasz.zemczak@canonical.com-20151105173429-7yzqcb5hdi1xlxk0
WIP commit to have a backup to some of my testing ideas.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
                     "destination channel.")
166
166
 
167
167
    # Generate a list of required deltas
168
 
    delta_base = []
169
 
 
170
 
    # If channel not configured, use dest channel as a deltabase by default
171
 
    conf_deltabase = (conf.channels[args.destination_channel].deltabase
172
 
                      if args.destination_channel in conf.channels
173
 
                      else [args.destination_channel])
174
 
 
175
 
    for base_channel in conf_deltabase:
176
 
        # Skip missing channels
177
 
        if base_channel not in pub.list_channels():
178
 
            continue
179
 
 
180
 
        # Skip missing devices
181
 
        if args.device not in (pub.list_channels()
182
 
                               [base_channel]['devices']):
183
 
            continue
184
 
 
185
 
        # Extract the latest full image
186
 
        base_device = pub.get_device(base_channel, args.device)
187
 
        base_images = sorted([image
188
 
                              for image in base_device.list_images()
189
 
                              if image['type'] == "full"],
190
 
                             key=lambda image: image['version'])
191
 
 
192
 
        # Check if the version is valid and add it
193
 
        if base_images and base_images[-1]['version'] in full_images:
194
 
            if full_images[base_images[-1]['version']] not in delta_base:
195
 
                delta_base.append(full_images
196
 
                                  [base_images[-1]['version']])
197
 
                logging.debug("Source version for delta: %s" %
198
 
                              base_images[-1]['version'])
 
168
    delta_base = tools.get_required_deltas(
 
169
        conf, pub, args.destination_channel, args.device)
199
170
 
200
171
    # Create new empty entries
201
172
    new_images = {'full': {'files': []}}
203
174
        new_images['delta_%s' % delta['version']] = {'files': []}
204
175
 
205
176
    # Extract current version_detail and files
206
 
    version_detail = ""
207
 
    for entry in source_image['files']:
208
 
        path = os.path.realpath("%s/%s" % (conf.publish_path, entry['path']))
209
 
 
210
 
        filename = path.split("/")[-1]
211
 
 
212
 
        # Look for version-X.tar.xz
213
 
        if filename == "version-%s.tar.xz" % args.version:
214
 
            # Extract the metadata
215
 
            if os.path.exists(path.replace(".tar.xz", ".json")):
216
 
                with open(path.replace(".tar.xz", ".json"), "r") as fd:
217
 
                    metadata = json.loads(fd.read())
218
 
                    if "channel.ini" in metadata:
219
 
                        version_detail = metadata['channel.ini'].get(
220
 
                            "version_detail", None)
221
 
        else:
222
 
            new_images['full']['files'].append(path)
223
 
    logging.debug("Source version_detail is: %s" % version_detail)
 
177
    version_detail = tools.extract_files_and_version(
 
178
        conf, source_image['files'], args.version, new_images['full']['files'])
224
179
 
225
180
    # Generate new version tarball
226
181
    environment = {}
235
190
 
236
191
    # Add new tag if requested
237
192
    if args.tag:
238
 
        for detail in environment['version_detail']:
239
 
            if detail.startswith("tag="):
240
 
                environment['version_detail'].remove(detail)
241
 
 
242
 
        environment['version_detail'].append("tag=%s" % args.tag)
 
193
        tools.set_tag_on_version_detail(
 
194
            environment['version_detail'], args.tag)
243
195
        logging.info("Setting tag for image to '%s'" % args.tag)
244
196
 
245
197
    logging.info("Generating new version tarball for '%s' (%s)"