Exemplo n.º 1
0
 def test__returns_multiple_resource_for_hwe_resources(self):
     os = factory.make_name('os')
     series = factory.make_name('series')
     name = '%s/%s' % (os, series)
     arch = factory.make_name('arch')
     subarches = [factory.make_name('hwe') for _ in range(3)]
     resources = [
         factory.make_usable_boot_resource(rtype=BOOT_RESOURCE_TYPE.SYNCED,
                                           name=name,
                                           architecture='%s/%s' %
                                           (arch, subarch))
         for subarch in subarches
     ]
     images = []
     for resource in resources:
         label = resource.get_latest_complete_set().label
         purposes = [factory.make_name('purpose') for _ in range(3)]
         arch, subarch = resource.split_arch()
         images.extend([
             make_rpc_boot_image(osystem=os,
                                 release=series,
                                 architecture=arch,
                                 subarchitecture=subarch,
                                 label=label,
                                 purpose=purpose) for purpose in purposes
         ])
     self.assertItemsEqual(
         resources,
         BootResource.objects.get_resources_matching_boot_images(images))
Exemplo n.º 2
0
    def test_fallback_to_ListBootImages_on_old_clusters(self):
        rack_1 = factory.make_RackController()
        rack_2 = factory.make_RackController()
        rack_3 = factory.make_RackController()

        images = [make_rpc_boot_image() for _ in range(3)]

        # Limit the region's event loop to only the "rpc" service.
        self.useFixture(RegionEventLoopFixture("rpc"))
        # Now start the region's event loop.
        self.useFixture(RunningEventLoopFixture())
        # This fixture allows us to simulate mock clusters.
        rpc = self.useFixture(MockLiveRegionToClusterRPCFixture())

        # This simulates an older cluster, one without ListBootImagesV2.
        rack_1 = rpc.makeCluster(rack_1, ListBootImages)
        rack_1.ListBootImages.return_value = succeed({"images": images})

        # This simulates a newer cluster, one with ListBootImagesV2.
        rack_2 = rpc.makeCluster(rack_2, ListBootImagesV2)
        rack_2.ListBootImagesV2.return_value = succeed({"images": images})

        # This simulates a broken cluster.
        rack_3 = rpc.makeCluster(rack_3, ListBootImagesV2)
        rack_3.ListBootImagesV2.side_effect = ZeroDivisionError

        self.assertItemsEqual(images, self.get())
Exemplo n.º 3
0
 def test__returns_False_if_image_label_doesnt_match_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split('/')
     arch, subarch = resource.split_arch()
     image = make_rpc_boot_image(
         osystem=os, release=series,
         architecture=arch, subarchitecture=subarch,
         label=factory.make_name('label'))
     self.assertFalse(BootResource.objects.boot_images_are_in_sync([image]))
Exemplo n.º 4
0
 def test__returns_True_for_uploaded_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.UPLOADED)
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     image = make_rpc_boot_image(
         osystem="custom", release=resource.name,
         architecture=arch, subarchitecture=subarch,
         label=label)
     self.assertTrue(BootResource.objects.boot_images_are_in_sync([image]))
Exemplo n.º 5
0
 def test__returns_True_for_generated_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.GENERATED)
     os, series = resource.name.split('/')
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     image = make_rpc_boot_image(
         osystem=os, release=series,
         architecture=arch, subarchitecture=subarch,
         label=label)
     self.assertTrue(BootResource.objects.boot_images_are_in_sync([image]))
Exemplo n.º 6
0
 def test__returns_False_if_image_subarch_not_supported_by_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split('/')
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     image = make_rpc_boot_image(
         osystem=os, release=series,
         architecture=arch, subarchitecture=factory.make_name('subarch'),
         label=label)
     self.assertFalse(BootResource.objects.boot_images_are_in_sync([image]))
Exemplo n.º 7
0
 def test__returns_resource_with_wildcard_label(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split('/')
     arch, subarch = resource.split_arch()
     image = make_rpc_boot_image(
         osystem=os, release=series,
         architecture=arch, subarchitecture=subarch,
         label='*')
     self.assertItemsEqual(
         [resource],
         BootResource.objects.get_resources_matching_boot_images([image]))
Exemplo n.º 8
0
 def test__returns_empty_list_if_label_doesnt_match_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split('/')
     arch, subarch = resource.split_arch()
     image = make_rpc_boot_image(
         osystem=os, release=series,
         architecture=arch, subarchitecture=subarch,
         label=factory.make_name('label'))
     self.assertEqual(
         [],
         BootResource.objects.get_resources_matching_boot_images([image]))
Exemplo n.º 9
0
 def test__returns_True_if_image_has_multiple_purposes(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split('/')
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     purposes = [factory.make_name('purpose') for _ in range(3)]
     images = [
         make_rpc_boot_image(
             osystem=os, release=series,
             architecture=arch, subarchitecture=subarch,
             label=label, purpose=purpose)
         for purpose in purposes
         ]
     self.assertTrue(BootResource.objects.boot_images_are_in_sync(images))
Exemplo n.º 10
0
 def test_returns_resource_for_uploaded_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.UPLOADED)
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     image = make_rpc_boot_image(
         osystem="custom",
         release=resource.name,
         architecture=arch,
         subarchitecture=subarch,
         label=label,
     )
     self.assertItemsEqual(
         [resource],
         BootResource.objects.get_resources_matching_boot_images([image]),
     )
Exemplo n.º 11
0
 def test_returns_resource_for_generated_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.GENERATED)
     os, series = resource.name.split("/")
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     image = make_rpc_boot_image(
         osystem=os,
         release=series,
         architecture=arch,
         subarchitecture=subarch,
         label=label,
     )
     self.assertItemsEqual(
         [resource],
         BootResource.objects.get_resources_matching_boot_images([image]),
     )
Exemplo n.º 12
0
 def test_returns_empty_list_if_subarch_not_supported_by_resource(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split("/")
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     image = make_rpc_boot_image(
         osystem=os,
         release=series,
         architecture=arch,
         subarchitecture=factory.make_name("subarch"),
         label=label,
     )
     self.assertEqual(
         [],
         BootResource.objects.get_resources_matching_boot_images([image]),
     )
Exemplo n.º 13
0
    def test_ignores_failures_when_talking_to_clusters(self):
        factory.make_RackController()
        factory.make_RackController()
        factory.make_RackController()
        self.useFixture(RunningClusterRPCFixture())

        images = [make_rpc_boot_image() for _ in range(3)]

        clients = getAllClients()
        for index, client in enumerate(clients):
            callRemote = self.patch(client._conn, "callRemote")
            if index == 0:
                # The first client returns correct image information.
                callRemote.return_value = succeed({"images": images})
            else:
                # All clients but the first raise an exception.
                callRemote.side_effect = ZeroDivisionError()

        self.assertItemsEqual(images, self.get())
Exemplo n.º 14
0
 def test_returns_bootloader_if_matching(self):
     resource = factory.make_usable_boot_resource(
         name="bootloader/uefi",
         bootloader_type="uefi",
         rtype=BOOT_RESOURCE_TYPE.SYNCED,
     )
     os, series = resource.name.split("/")
     arch, subarch = resource.split_arch()
     image = make_rpc_boot_image(
         osystem=os,
         release=series,
         architecture=arch,
         subarchitecture=subarch,
         label="*",
     )
     self.assertItemsEqual(
         [resource],
         BootResource.objects.get_resources_matching_boot_images([image]),
     )
Exemplo n.º 15
0
 def test_returns_one_resource_if_image_has_multiple_purposes(self):
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED)
     os, series = resource.name.split("/")
     arch, subarch = resource.split_arch()
     label = resource.get_latest_complete_set().label
     purposes = [factory.make_name("purpose") for _ in range(3)]
     images = [
         make_rpc_boot_image(
             osystem=os,
             release=series,
             architecture=arch,
             subarchitecture=subarch,
             label=label,
             purpose=purpose,
         ) for purpose in purposes
     ]
     self.assertItemsEqual(
         [resource],
         BootResource.objects.get_resources_matching_boot_images(images),
     )
Exemplo n.º 16
0
    def test_returns_boot_images_on_all_clusters(self):
        factory.make_RackController()
        factory.make_RackController()
        factory.make_RackController()
        self.useFixture(RunningClusterRPCFixture())

        images = [make_rpc_boot_image() for _ in range(3)]
        available_images = list(images)
        available_images.pop()

        clients = getAllClients()
        for index, client in enumerate(clients):
            callRemote = self.patch(client._conn, "callRemote")
            if index == 0:
                # The first client returns all images.
                callRemote.return_value = succeed({"images": images})
            else:
                # All clients but the first return only available images.
                callRemote.return_value = succeed({"images": available_images})

        expected_images = images if self.all else available_images
        self.assertItemsEqual(expected_images, self.get())
Exemplo n.º 17
0
 def test__returns_False_if_no_resources_but_images(self):
     BootResource.objects.all().delete()
     images = [make_rpc_boot_image() for _ in range(3)]
     self.assertFalse(BootResource.objects.boot_images_are_in_sync(images))
Exemplo n.º 18
0
 def test__returns_empty_list_if_no_resources_but_images(self):
     BootResource.objects.all().delete()
     images = [make_rpc_boot_image() for _ in range(3)]
     self.assertEqual(
         [],
         BootResource.objects.get_resources_matching_boot_images(images))