Ejemplo n.º 1
0
 def test_delete_image(self):
     self.patch_object(openstack_utils, "delete_resource")
     glance_mock = mock.MagicMock()
     openstack_utils.delete_image(glance_mock, 'b46c2d83')
     self.delete_resource.assert_called_once_with(glance_mock.images,
                                                  'b46c2d83',
                                                  msg="glance image")
Ejemplo n.º 2
0
    def test_100_create_image(self):
        """Create an image and do a simple validation of it.

        The OpenStack Swift API is used to do the validation, since the Ceph
        Rados Gateway serves an API which is compatible with that.
        """
        image_name = 'zaza-ceph-rgw-image'
        openstack_utils.create_image(
            glance=self.glance_client,
            image_url=openstack_utils.find_cirros_image(arch='x86_64'),
            image_name=image_name,
            backend='swift')
        headers, containers = self.swift.get_account()
        self.assertEqual(len(containers), 1)
        container_name = containers[0].get('name')
        headers, objects = self.swift.get_container(container_name)
        images = openstack_utils.get_images_by_name(self.glance_client,
                                                    image_name)
        self.assertEqual(len(images), 1)
        image = images[0]
        total_bytes = 0
        for ob in objects:
            if '{}-'.format(image['id']) in ob['name']:
                total_bytes = total_bytes + int(ob['bytes'])
        logging.info('Checking glance image size {} matches swift '
                     'image size {}'.format(image['size'], total_bytes))
        self.assertEqual(image['size'], total_bytes)
        openstack_utils.delete_image(self.glance_client, image['id'])
Ejemplo n.º 3
0
    def test_100_create_delete_image(self):
        """Create an image and do a simple validation of it.

        Validate the size of the image in both Glance API and actual S3 bucket.
        """
        image_name = "zaza-s3-test-image"
        openstack_utils.create_image(
            glance=self.glance_client,
            image_url=openstack_utils.find_cirros_image(arch="x86_64"),
            image_name=image_name,
            backend="s3",
        )
        images = openstack_utils.get_images_by_name(self.glance_client,
                                                    image_name)
        self.assertEqual(len(images), 1)
        image = images[0]

        s3_client = boto3.client(
            "s3",
            endpoint_url=self.s3_store_host,
            aws_access_key_id=self.s3_store_access_key,
            aws_secret_access_key=self.s3_store_secret_key,
        )
        response = s3_client.head_object(Bucket=self.s3_store_bucket,
                                         Key=image["id"])
        logging.info(
            "Checking glance image size {} matches S3 object's ContentLength "
            "{}".format(image["size"], response["ContentLength"]))
        self.assertEqual(image["size"], response["ContentLength"])
        openstack_utils.delete_image(self.glance_client, image["id"])
Ejemplo n.º 4
0
    def test_100_create_delete_image(self):
        """Create an image and do a simple validation of it.

        Validate the size of the image in both Glance API and Cinder API.
        """
        image_name = "zaza-cinder-test-image"
        openstack_utils.create_image(
            glance=self.glance_client,
            image_url=openstack_utils.find_cirros_image(arch="x86_64"),
            image_name=image_name,
            backend="cinder",
        )
        images = openstack_utils.get_images_by_name(self.glance_client,
                                                    image_name)
        self.assertEqual(len(images), 1)
        image = images[0]

        volume_name = 'image-' + image["id"]
        volumes = openstack_utils.get_volumes_by_name(self.cinder_client,
                                                      volume_name)
        self.assertEqual(len(volumes), 1)
        volume = volumes[0]

        logging.info("Checking glance image size {} matches volume size {} "
                     "GB".format(image["size"], volume.size))
        image_size_in_gb = int(math.ceil(float(image["size"]) / 1024**3))
        self.assertEqual(image_size_in_gb, volume.size)
        openstack_utils.delete_image(self.glance_client, image["id"])
Ejemplo n.º 5
0
 def test_100_create_image(self):
     """Create an image and do simple validation of image in swift."""
     glance_setup.add_lts_image(image_name=self.image_name)
     headers, containers = self.swift.get_account()
     self.assertEqual(len(containers), 1)
     container_name = containers[0].get('name')
     headers, objects = self.swift.get_container(container_name)
     images = openstack_utils.get_images_by_name(self.glance_client,
                                                 self.image_name)
     self.assertEqual(len(images), 1)
     image = images[0]
     total_bytes = 0
     for ob in objects:
         if '{}-'.format(image['id']) in ob['name']:
             total_bytes = total_bytes + int(ob['bytes'])
     logging.info('Checking glance image size {} matches swift '
                  'image size {}'.format(image['size'], total_bytes))
     self.assertEqual(image['size'], total_bytes)
     openstack_utils.delete_image(self.glance_client, image['id'])
Ejemplo n.º 6
0
 def test_410_glance_image_create_delete(self):
     """Create an image and then delete it."""
     image_url = openstack_utils.find_cirros_image(arch='x86_64')
     image = openstack_utils.create_image(self.glance_client, image_url,
                                          'cirrosimage')
     openstack_utils.delete_image(self.glance_client, image.id)