Exemplo n.º 1
0
    def delete_image(self, params):
        """Delete `BootResource` by its ID."""
        # Must be administrator.
        assert self.user.is_superuser, "Permission denied."
        if 'id' not in params:
            raise HandlerValidationError({'id': ['This field is required.']})
        # Convert resource into a set of resources that make up this image.
        # An image in UI is a set of resource each with different subarches
        # and kflavor.
        resource = BootResource.objects.get(id=params['id'])
        if resource.rtype == BOOT_RESOURCE_TYPE.SYNCED:
            os, release = resource.name.split('/')
            arch, subarch = resource.architecture.split('/')
            resources = BootResource.objects.filter(
                name=resource.name, architecture__startswith=arch)
            # Remove the selection that provides the initial resource. All
            # other resources will come from the same selection.
            for selection in BootSourceSelection.objects.all():
                if image_passes_filter([selection.to_dict()], os, arch,
                                       subarch, release, '*'):
                    # This selection provided this image, remove it.
                    selection.delete()

            # Remove the whole set of resources.
            resources.delete()
        else:
            # Delete just this resource.
            resource.delete()
        return self.poll({})
 def test_any_image_passes_empty_filter(self):
     os, arch, subarch, kflavor, release, label = make_image_spec()
     self.assertTrue(
         download_descriptions.image_passes_filter(
             [], os, arch, subarch, release, label
         )
     )
 def test_any_image_passes_none_filter(self):
     os, arch, subarch, _, release, label = make_image_spec()
     self.assertTrue(
         download_descriptions.image_passes_filter(
             None, os, arch, subarch, release, label
         )
     )
Exemplo n.º 4
0
 def test_filter_checks_labels(self):
     image = make_image_spec()
     self.assertFalse(
         download_descriptions.image_passes_filter([
             self.make_filter_from_image(
                 image._replace(label=factory.make_name('other-label')))
         ], image.os, image.arch, image.subarch, image.release,
                                                   image.label))
Exemplo n.º 5
0
 def test_image_passes_if_one_filter_matches(self):
     image = make_image_spec()
     self.assertTrue(
         download_descriptions.image_passes_filter([
             self.make_filter_from_image(),
             self.make_filter_from_image(image),
             self.make_filter_from_image(),
         ], image.os, image.arch, image.subarch, image.release,
                                                   image.label))
 def test_image_does_not_pass_nonmatching_filter(self):
     image = make_image_spec()
     self.assertFalse(
         download_descriptions.image_passes_filter(
             [self.make_filter_from_image()],
             image.os,
             image.arch,
             image.subarch,
             image.release,
             image.label,
         ))