def test_create_delete_image(self):

        # Create a new image
        name = data_utils.rand_name('image')
        meta = {'image_type': 'test'}
        body = self.client.create_image(self.server_id, name, meta)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.client.wait_for_image_status(image_id, 'ACTIVE')

        # Verify the image was created correctly
        image = self.client.get_image(image_id)
        self.assertEqual(name, image['name'])
        self.assertEqual('test', image['metadata']['image_type'])

        original_image = self.client.get_image(self.image_ref)

        # Verify minRAM is the same as the original image
        self.assertEqual(image['minRam'], original_image['minRam'])

        # Verify minDisk is the same as the original image or the flavor size
        flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
        self.assertIn(str(image['minDisk']),
                      (str(original_image['minDisk']), str(flavor_disk_size)))

        # Verify the image was deleted correctly
        self.client.delete_image(image_id)
        self.client.wait_for_resource_deletion(image_id)
    def test_create_delete_image(self):

        # Create a new image
        name = data_utils.rand_name('image')
        meta = {'image_type': 'test'}
        body = self.client.create_image(self.server_id, name, meta)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.client.wait_for_image_status(image_id, 'ACTIVE')

        # Verify the image was created correctly
        image = self.client.get_image(image_id)
        self.assertEqual(name, image['name'])
        self.assertEqual('test', image['metadata']['image_type'])

        original_image = self.client.get_image(self.image_ref)

        # Verify minRAM is the same as the original image
        self.assertEqual(image['minRam'], original_image['minRam'])

        # Verify minDisk is the same as the original image or the flavor size
        flavor_disk_size = self._get_default_flavor_disk_size(self.flavor_ref)
        self.assertIn(str(image['minDisk']),
                      (str(original_image['minDisk']), str(flavor_disk_size)))

        # Verify the image was deleted correctly
        self.client.delete_image(image_id)
        self.client.wait_for_resource_deletion(image_id)
    def test_create_image_specify_multibyte_character_image_name(self):
        # prefix character is:
        # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm

        # We use a string with 3 byte utf-8 character due to bug
        # #1370954 in glance which will 500 if mysql is used as the
        # backend and it attempts to store a 4 byte utf-8 character
        utf8_name = data_utils.rand_name('\xe2\x82\xa1')
        body = self.client.create_image(self.server_id, utf8_name)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.addCleanup(self.client.delete_image, image_id)
    def test_create_image_specify_multibyte_character_image_name(self):
        # prefix character is:
        # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm

        # We use a string with 3 byte utf-8 character due to bug
        # #1370954 in glance which will 500 if mysql is used as the
        # backend and it attempts to store a 4 byte utf-8 character
        utf8_name = data_utils.rand_name('\xe2\x82\xa1')
        body = self.client.create_image(self.server_id, utf8_name)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.addCleanup(self.client.delete_image, image_id)
    def test_delete_image_that_is_not_yet_active(self):
        # Return an error while trying to delete an image what is creating

        snapshot_name = data_utils.rand_name('test-snap')
        body = self.client.create_image(self.server_id, snapshot_name)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.image_ids.append(image_id)
        self.addCleanup(self._reset_server)

        # Do not wait, attempt to delete the image, ensure it's successful
        self.client.delete_image(image_id)
        self.image_ids.remove(image_id)

        self.assertRaises(lib_exc.NotFound, self.client.get_image, image_id)
Example #6
0
    def test_create_second_image_when_first_image_is_being_saved(self):
        # Disallow creating another image when first image is being saved

        # Create first snapshot
        snapshot_name = data_utils.rand_name('test-snap')
        body = self.client.create_image(self.server_id, snapshot_name)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.image_ids.append(image_id)
        self.addCleanup(self._reset_server)

        # Create second snapshot
        alt_snapshot_name = data_utils.rand_name('test-snap')
        self.assertRaises(lib_exc.Conflict, self.client.create_image,
                          self.server_id, alt_snapshot_name)
    def test_create_second_image_when_first_image_is_being_saved(self):
        # Disallow creating another image when first image is being saved

        # Create first snapshot
        snapshot_name = data_utils.rand_name('test-snap')
        body = self.client.create_image(self.server_id,
                                        snapshot_name)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.image_ids.append(image_id)
        self.addCleanup(self._reset_server)

        # Create second snapshot
        alt_snapshot_name = data_utils.rand_name('test-snap')
        self.assertRaises(lib_exc.Conflict, self.client.create_image,
                          self.server_id, alt_snapshot_name)
Example #8
0
    def create_image_from_server(cls, server_id, **kwargs):
        """Wrapper utility that returns an image created from the server."""
        name = data_utils.rand_name(cls.__name__ + "-image")
        if 'name' in kwargs:
            name = kwargs.pop('name')

        image = cls.images_client.create_image(server_id, name)
        image_id = data_utils.parse_image_id(image.response['location'])
        cls.images.append(image_id)

        if 'wait_until' in kwargs:
            cls.images_client.wait_for_image_status(image_id,
                                                    kwargs['wait_until'])
            image = cls.images_client.show_image(image_id)

            if kwargs['wait_until'] == 'ACTIVE':
                if kwargs.get('wait_for_server', True):
                    cls.servers_client.wait_for_server_status(server_id,
                                                              'ACTIVE')
        return image
Example #9
0
    def test_create_backup(self):
        # Positive test:create backup successfully and rotate backups correctly
        # create the first and the second backup
        backup1 = data_utils.rand_name('backup-1')
        resp = self.servers_client.create_backup(self.server_id,
                                                 'daily',
                                                 2,
                                                 backup1).response
        oldest_backup_exist = True

        # the oldest one should be deleted automatically in this test
        def _clean_oldest_backup(oldest_backup):
            if oldest_backup_exist:
                try:
                    self.os.image_client.delete_image(oldest_backup)
                except lib_exc.NotFound:
                    pass
                else:
                    LOG.warning("Deletion of oldest backup %s should not have "
                                "been successful as it should have been "
                                "deleted during rotation." % oldest_backup)

        image1_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(_clean_oldest_backup, image1_id)
        self.os.image_client.wait_for_image_status(image1_id, 'active')

        backup2 = data_utils.rand_name('backup-2')
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        resp = self.servers_client.create_backup(self.server_id,
                                                 'daily',
                                                 2,
                                                 backup2).response
        image2_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image2_id)
        self.os.image_client.wait_for_image_status(image2_id, 'active')

        # verify they have been created
        properties = {
            'image_type': 'backup',
            'backup_type': "daily",
            'instance_uuid': self.server_id,
        }
        image_list = self.os.image_client.image_list_detail(
            properties,
            status='active',
            sort_key='created_at',
            sort_dir='asc')
        self.assertEqual(2, len(image_list))
        self.assertEqual((backup1, backup2),
                         (image_list[0]['name'], image_list[1]['name']))

        # create the third one, due to the rotation is 2,
        # the first one will be deleted
        backup3 = data_utils.rand_name('backup-3')
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        resp = self.servers_client.create_backup(self.server_id,
                                                 'daily',
                                                 2,
                                                 backup3).response
        image3_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image3_id)
        # the first back up should be deleted
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        self.os.image_client.wait_for_resource_deletion(image1_id)
        oldest_backup_exist = False
        image_list = self.os.image_client.image_list_detail(
            properties,
            status='active',
            sort_key='created_at',
            sort_dir='asc')
        self.assertEqual(2, len(image_list),
                         'Unexpected number of images for '
                         'v2:test_create_backup; was the oldest backup not '
                         'yet deleted? Image list: %s' %
                         [image['name'] for image in image_list])
        self.assertEqual((backup2, backup3),
                         (image_list[0]['name'], image_list[1]['name']))
Example #10
0
    def test_create_backup(self):
        # Positive test:create backup successfully and rotate backups correctly
        # create the first and the second backup
        backup1 = data_utils.rand_name('backup-1')
        resp = self.servers_client.create_backup(self.server_id, 'daily', 2,
                                                 backup1).response
        oldest_backup_exist = True

        # the oldest one should be deleted automatically in this test
        def _clean_oldest_backup(oldest_backup):
            if oldest_backup_exist:
                try:
                    self.os.image_client.delete_image(oldest_backup)
                except lib_exc.NotFound:
                    pass
                else:
                    LOG.warning("Deletion of oldest backup %s should not have "
                                "been successful as it should have been "
                                "deleted during rotation." % oldest_backup)

        image1_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(_clean_oldest_backup, image1_id)
        self.os.image_client.wait_for_image_status(image1_id, 'active')

        backup2 = data_utils.rand_name('backup-2')
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        resp = self.servers_client.create_backup(self.server_id, 'daily', 2,
                                                 backup2).response
        image2_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image2_id)
        self.os.image_client.wait_for_image_status(image2_id, 'active')

        # verify they have been created
        properties = {
            'image_type': 'backup',
            'backup_type': "daily",
            'instance_uuid': self.server_id,
        }
        image_list = self.os.image_client.list_images(detail=True,
                                                      properties=properties,
                                                      status='active',
                                                      sort_key='created_at',
                                                      sort_dir='asc')
        self.assertEqual(2, len(image_list))
        self.assertEqual((backup1, backup2),
                         (image_list[0]['name'], image_list[1]['name']))

        # create the third one, due to the rotation is 2,
        # the first one will be deleted
        backup3 = data_utils.rand_name('backup-3')
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        resp = self.servers_client.create_backup(self.server_id, 'daily', 2,
                                                 backup3).response
        image3_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image3_id)
        # the first back up should be deleted
        self.servers_client.wait_for_server_status(self.server_id, 'ACTIVE')
        self.os.image_client.wait_for_resource_deletion(image1_id)
        oldest_backup_exist = False
        image_list = self.os.image_client.list_images(detail=True,
                                                      properties=properties,
                                                      status='active',
                                                      sort_key='created_at',
                                                      sort_dir='asc')
        self.assertEqual(
            2, len(image_list), 'Unexpected number of images for '
            'v2:test_create_backup; was the oldest backup not '
            'yet deleted? Image list: %s' %
            [image['name'] for image in image_list])
        self.assertEqual((backup2, backup3),
                         (image_list[0]['name'], image_list[1]['name']))
Example #11
0
 def test_parse_image_id(self):
     actual = data_utils.parse_image_id("/foo/bar/deadbeaf")
     self.assertEqual("deadbeaf", actual)
 def test_parse_image_id(self):
     actual = data_utils.parse_image_id("/foo/bar/deadbeaf")
     self.assertEqual("deadbeaf", actual)
Example #13
0
    def test_create_backup(self):
        # Positive test:create backup successfully and rotate backups correctly
        # create the first and the second backup
        backup1 = data_utils.rand_name("backup-1")
        resp = self.servers_client.create_backup(self.server_id, "daily", 2, backup1).response
        oldest_backup_exist = True

        # the oldest one should be deleted automatically in this test
        def _clean_oldest_backup(oldest_backup):
            if oldest_backup_exist:
                try:
                    self.os.image_client.delete_image(oldest_backup)
                except lib_exc.NotFound:
                    pass
                else:
                    LOG.warning(
                        "Deletion of oldest backup %s should not have "
                        "been successful as it should have been "
                        "deleted during rotation." % oldest_backup
                    )

        image1_id = data_utils.parse_image_id(resp["location"])
        self.addCleanup(_clean_oldest_backup, image1_id)
        self.os.image_client.wait_for_image_status(image1_id, "active")

        backup2 = data_utils.rand_name("backup-2")
        self.servers_client.wait_for_server_status(self.server_id, "ACTIVE")
        resp = self.servers_client.create_backup(self.server_id, "daily", 2, backup2).response
        image2_id = data_utils.parse_image_id(resp["location"])
        self.addCleanup(self.os.image_client.delete_image, image2_id)
        self.os.image_client.wait_for_image_status(image2_id, "active")

        # verify they have been created
        properties = {"image_type": "backup", "backup_type": "daily", "instance_uuid": self.server_id}
        image_list = self.os.image_client.list_images(
            detail=True, properties=properties, status="active", sort_key="created_at", sort_dir="asc"
        )
        self.assertEqual(2, len(image_list))
        self.assertEqual((backup1, backup2), (image_list[0]["name"], image_list[1]["name"]))

        # create the third one, due to the rotation is 2,
        # the first one will be deleted
        backup3 = data_utils.rand_name("backup-3")
        self.servers_client.wait_for_server_status(self.server_id, "ACTIVE")
        resp = self.servers_client.create_backup(self.server_id, "daily", 2, backup3).response
        image3_id = data_utils.parse_image_id(resp["location"])
        self.addCleanup(self.os.image_client.delete_image, image3_id)
        # the first back up should be deleted
        self.servers_client.wait_for_server_status(self.server_id, "ACTIVE")
        self.os.image_client.wait_for_resource_deletion(image1_id)
        oldest_backup_exist = False
        image_list = self.os.image_client.list_images(
            detail=True, properties=properties, status="active", sort_key="created_at", sort_dir="asc"
        )
        self.assertEqual(
            2,
            len(image_list),
            "Unexpected number of images for "
            "v2:test_create_backup; was the oldest backup not "
            "yet deleted? Image list: %s" % [image["name"] for image in image_list],
        )
        self.assertEqual((backup2, backup3), (image_list[0]["name"], image_list[1]["name"]))