~smoser/simplestreams/trunk.moved-to-git

« back to all changes in this revision

Viewing changes to tests/unittests/test_glancemirror.py

  • Committer: Scott Moser
  • Date: 2017-11-02 19:03:37 UTC
  • mfrom: (448.2.4 trunk.1686086)
  • Revision ID: smoser@ubuntu.com-20171102190337-sdgzf8w38y7ds9ld
OpenStack: support uploading squash images for nova-lxd.

Previously, populating a nova-lxd cloud was possible by using
root.tar.gz. A filter like:
  ftype~(root.tar.gz|root.tar.xz)
would cause simplestreams to upload an image with 'disk-format' of
root-tar.

However, Ubuntu 17.04 and newer do not have root.tar.gz or root.tar.xz
images available. Currently here is what is available:
 14.04: root.tar.gz root.tar.xz
 16.04: root.tar.gz root.tar.xz squashfs
 17.10: squashfs

If we simply expected the user to change their filter to include
  root.tar.xz|squashfs
Then they would get two lxd images imported for 16.04 each version.

The change here is to not do anything for an item insert, but instead
insert when the version's insert is called. Then, all the information
about what images there are is available, and it can "pick"
one or the other. Currently preference is given to the .tar.xz format.

The end result is that now users can specify an ftype filter of:
  ftype~(root.tar.gz|root.tar.xz|squashfs)
and the right thing will be done.

Also here is simple knowledge that the squashfs type should be
uploaded to glance with a 'disk_format' of 'squashfs'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
333
333
 
334
334
        self.assertEqual("root-tar", create_arguments["disk_format"])
335
335
 
 
336
    def test_prepare_glance_arguments_disk_format_squashfs(self):
 
337
        # squashfs images are acceptable for nova-lxd
 
338
        source_entry = {"ftype": "squashfs"}
 
339
        create_arguments = self.mirror.prepare_glance_arguments(
 
340
            "foobuntu-X", source_entry, image_md5_hash=None, image_size=None,
 
341
            image_properties=None)
 
342
 
 
343
        self.assertEqual("squashfs", create_arguments["disk_format"])
 
344
 
336
345
    def test_prepare_glance_arguments_size(self):
337
346
        # Size is read from image metadata if defined.
338
347
        source_entry = {"size": 5}
476
485
        pedigree = (
477
486
            u'com.ubuntu.cloud:server:14.04:amd64', u'20160602', u'disk1.img')
478
487
        product = source_index[u'products'][pedigree[0]]
479
 
        image_data = product[u'versions'][pedigree[1]][u'items'][pedigree[2]]
 
488
        ver_data = product[u'versions'][pedigree[1]]
 
489
        image_data = ver_data[u'items'][pedigree[2]]
480
490
 
481
491
        content_source = MemoryContentSource(
482
492
            url="http://image-store/fooubuntu-X-disk1.img",
495
505
 
496
506
        self.mirror.insert_item(
497
507
            image_data, source_index, target, pedigree, content_source)
 
508
        self.mirror.insert_version(
 
509
            ver_data, source_index, target, pedigree[0:2])
498
510
 
499
511
        passed_create_kwargs = self.mirror.gclient.images.create_calls[0]
500
512
 
538
550
        pedigree = (
539
551
            u'com.ubuntu.cloud:server:14.04:amd64', u'20160602', u'disk1.img')
540
552
        product = source_index[u'products'][pedigree[0]]
541
 
        image_data = product[u'versions'][pedigree[1]][u'items'][pedigree[2]]
 
553
        ver_data = product[u'versions'][pedigree[1]]
 
554
        image_data = ver_data[u'items'][pedigree[2]]
542
555
 
543
556
        content_source = MemoryContentSource(
544
557
            url="http://image-store/fooubuntu-X-disk1.img",
557
570
 
558
571
        self.mirror.insert_item(
559
572
            image_data, source_index, target, pedigree, content_source)
 
573
        self.mirror.insert_version(
 
574
            image_data, source_index, target, pedigree[0:2])
560
575
 
561
576
        passed_create_kwargs = self.mirror.gclient.images.create_calls[0]
562
577
 
609
624
        source_index = copy.deepcopy(TEST_SOURCE_INDEX_ENTRY)
610
625
        pedigree = TEST_IMAGE_PEDIGREE
611
626
        product = source_index[u'products'][pedigree[0]]
612
 
        image_data = product[u'versions'][pedigree[1]][u'items'][pedigree[2]]
 
627
        ver_data = product[u'versions'][pedigree[1]]
 
628
        image_data = ver_data[u'items'][pedigree[2]]
613
629
 
614
630
        content_source = MemoryContentSource(
615
631
            url="http://image-store/fooubuntu-X-disk1.img",
627
643
 
628
644
        self.mirror.insert_item(
629
645
            image_data, source_index, target, pedigree, content_source)
 
646
        self.mirror.insert_version(
 
647
            ver_data, source_index, target, pedigree[0:2])
630
648
 
631
649
        stored_index_content = self.mirror.store.data[
632
650
            'streams/v1/auto.sync.json']