def setUpClass(cls):
        super(ListImageFiltersTest, cls).setUpClass()
        cls.client = cls.images_client

        name = rand_name("server")
        resp, cls.server1 = cls.servers_client.create_server(name, cls.image_ref, cls.flavor_ref)
        name = rand_name("server")
        resp, cls.server2 = cls.servers_client.create_server(name, cls.image_ref, cls.flavor_ref)
        cls.servers_client.wait_for_server_status(cls.server1["id"], "ACTIVE")
        cls.servers_client.wait_for_server_status(cls.server2["id"], "ACTIVE")

        # Create images to be used in the filter tests
        image1_name = rand_name("image")
        resp, body = cls.client.create_image(cls.server1["id"], image1_name)
        cls.image1_id = parse_image_id(resp["location"])
        cls.client.wait_for_image_resp_code(cls.image1_id, 200)
        cls.client.wait_for_image_status(cls.image1_id, "ACTIVE")
        resp, cls.image1 = cls.client.get_image(cls.image1_id)

        # Servers have a hidden property for when they are being imaged
        # Performing back-to-back create image calls on a single
        # server will sometimes cause failures
        image3_name = rand_name("image")
        resp, body = cls.client.create_image(cls.server2["id"], image3_name)
        cls.image3_id = parse_image_id(resp["location"])
        cls.client.wait_for_image_resp_code(cls.image3_id, 200)
        cls.client.wait_for_image_status(cls.image3_id, "ACTIVE")
        resp, cls.image3 = cls.client.get_image(cls.image3_id)

        image2_name = rand_name("image")
        resp, body = cls.client.create_image(cls.server1["id"], image2_name)
        cls.image2_id = parse_image_id(resp["location"])
        cls.client.wait_for_image_resp_code(cls.image2_id, 200)
        cls.client.wait_for_image_status(cls.image2_id, "ACTIVE")
        resp, cls.image2 = cls.client.get_image(cls.image2_id)
    def setUpClass(cls):
        super(ListImageFiltersTestJSON, cls).setUpClass()
        cls.client = cls.images_client

        resp, cls.server1 = cls.create_server()
        resp, cls.server2 = cls.create_server(wait_until='ACTIVE')
        # NOTE(sdague) this is faster than doing the sync wait_util on both
        cls.servers_client.wait_for_server_status(cls.server1['id'], 'ACTIVE')

        # Create images to be used in the filter tests
        image1_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server1['id'], image1_name)
        cls.image1_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image1_id, 200)
        cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
        resp, cls.image1 = cls.client.get_image(cls.image1_id)

        # Servers have a hidden property for when they are being imaged
        # Performing back-to-back create image calls on a single
        # server will sometimes cause failures
        image3_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server2['id'], image3_name)
        cls.image3_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image3_id, 200)
        cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
        resp, cls.image3 = cls.client.get_image(cls.image3_id)

        image2_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server1['id'], image2_name)
        cls.image2_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image2_id, 200)
        cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
        resp, cls.image2 = cls.client.get_image(cls.image2_id)
    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)
        oldest_backup_exist = True

        # the oldest one should be deleted automatically in this test
        def _clean_oldest_backup(oldest_backup):
            if oldest_backup_exist:
                self.images_client.delete_image(oldest_backup)

        image1_id = data_utils.parse_image_id(resp["location"])
        self.addCleanup(_clean_oldest_backup, image1_id)
        self.assertEqual(202, resp.status)
        self.images_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)
        image2_id = data_utils.parse_image_id(resp["location"])
        self.addCleanup(self.images_client.delete_image, image2_id)
        self.assertEqual(202, resp.status)
        self.images_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}
        resp, image_list = self.images_client.image_list_detail(properties, sort_key="created_at", sort_dir="asc")
        self.assertEqual(200, resp.status)
        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)
        image3_id = data_utils.parse_image_id(resp["location"])
        self.addCleanup(self.images_client.delete_image, image3_id)
        self.assertEqual(202, resp.status)
        # the first back up should be deleted
        self.images_client.wait_for_resource_deletion(image1_id)
        oldest_backup_exist = False
        resp, image_list = self.images_client.image_list_detail(properties, sort_key="created_at", sort_dir="asc")
        self.assertEqual(200, resp.status)
        self.assertEqual(
            2,
            len(image_list),
            "Unexpected number of images for "
            "v3: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"]))
Exemple #4
0
    def test_create_delete_image(self):

        # Create a new image
        name = rand_name('image')
        meta = {'image_type': 'test'}
        resp, body = self.client.create_image(self.server['id'], name, meta)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp['location'])
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, 'ACTIVE')

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

        # Verify minRAM and minDisk values are the same as the original image
        resp, original_image = self.client.get_image(self.image_ref)
        self.assertEqual(original_image['minRam'], image['minRam'])
        self.assertEqual(original_image['minDisk'], image['minDisk'])

        # Verify the image was deleted correctly
        resp, body = self.client.delete_image(image_id)
        self.assertEqual('204', resp['status'])
        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"])
        waiters.wait_for_image_status(self.client, image_id, "ACTIVE")

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

        original_image = self.client.show_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)
Exemple #6
0
    def test_create_delete_image(self):
        server_id = self.create_test_server(wait_until='ACTIVE')['id']

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

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

        original_image = self.client.show_image(self.image_ref)['image']

        # 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)
Exemple #7
0
    def test_create_delete_image(self):
        """An image for the provided server should be created"""
        server_name = rand_name('server')
        resp, server = self.servers_client.create_server(
            server_name, self.image_ref, self.flavor_ref)
        self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')

        # Create a new image
        name = rand_name('image')
        meta = {'image_type': 'test'}
        resp, body = self.client.create_image(server['id'], name, meta)
        image_id = parse_image_id(resp['location'])
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, 'ACTIVE')

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

        # Verify minRAM and minDisk values are the same as the original image
        resp, original_image = self.client.get_image(self.image_ref)
        self.assertEqual(original_image['minRam'], image['minRam'])
        self.assertEqual(original_image['minDisk'], image['minDisk'])

        # Teardown
        self.client.delete_image(image['id'])
        self.servers_client.delete_server(server['id'])
Exemple #8
0
 def __create_image__(self, server_id, name, meta=None):
     resp, body = self.client.create_image(server_id, name, meta)
     image_id = parse_image_id(resp['location'])
     self.client.wait_for_image_resp_code(image_id, 200)
     self.client.wait_for_image_status(image_id, 'ACTIVE')
     self.image_ids.append(image_id)
     return resp, body
Exemple #9
0
    def test_create_image_from_deleted_server(self):
        """An image should not be created if the server instance is removed """
        server_name = rand_name('server')
        resp, server = self.servers_client.create_server(
            server_name, self.image_ref, self.flavor_ref)
        self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')

        # Delete server before trying to create server
        self.servers_client.delete_server(server['id'])

        try:
            # Create a new image after server is deleted
            name = rand_name('image')
            meta = {'image_type': 'test'}
            resp, body = self.client.create_image(server['id'], name, meta)

        except:
            pass

        else:
            image_id = parse_image_id(resp['location'])
            self.client.wait_for_image_resp_code(image_id, 200)
            self.client.wait_for_image_status(image_id, 'ACTIVE')
            self.client.delete_image(image_id)
            self.fail("Should not create snapshot from deleted instance!")
Exemple #10
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')

        if cls._api_version == 2:
            resp, image = cls.images_client.create_image(server_id, name)
        elif cls._api_version == 3:
            resp, image = cls.servers_client.create_image(server_id, name)
        image_id = data_utils.parse_image_id(resp['location'])
        cls.images.append(image_id)

        if 'wait_until' in kwargs:
            cls.images_client.wait_for_image_status(image_id,
                                                    kwargs['wait_until'])
            if cls._api_version == 2:
                resp, image = cls.images_client.get_image(image_id)
            elif cls._api_version == 3:
                resp, image = cls.images_client.get_image_meta(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 resp, image
Exemple #11
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')

        if cls._api_version == 2:
            resp, image = cls.images_client.create_image(server_id, name)
        elif cls._api_version == 3:
            resp, image = cls.servers_client.create_image(server_id, name)
        image_id = data_utils.parse_image_id(resp['location'])
        cls.images.append(image_id)

        if 'wait_until' in kwargs:
            cls.images_client.wait_for_image_status(image_id,
                                                    kwargs['wait_until'])
            if cls._api_version == 2:
                resp, image = cls.images_client.get_image(image_id)
            elif cls._api_version == 3:
                resp, image = cls.images_client.get_image_meta(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 resp, image
    def test_create_delete_image(self):

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

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

        resp, 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
        resp, body = self.client.delete_image(image_id)
        self.assertEqual('204', resp['status'])
        self.client.wait_for_resource_deletion(image_id)
    def test_create_delete_image(self):

        # Create a new image
        name = rand_name('image')
        meta = {'image_type': 'test'}
        resp, body = self.client.create_image(self.server['id'], name, meta)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp['location'])
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, 'ACTIVE')

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

        # Verify minRAM and minDisk values are the same as the original image
        resp, original_image = self.client.get_image(self.image_ref)
        self.assertEqual(original_image['minRam'], image['minRam'])
        self.assertEqual(original_image['minDisk'], image['minDisk'])

        # Verify the image was deleted correctly
        resp, body = self.client.delete_image(image_id)
        self.assertEqual('204', resp['status'])
        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=name,
                                        metadata=meta)
        image_id = data_utils.parse_image_id(body.response['location'])
        waiters.wait_for_image_status(self.client, image_id, 'ACTIVE')

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

        original_image = self.client.show_image(self.image_ref)['image']

        # 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)
Exemple #15
0
 def __create_image__(self, server_id, name, meta=None):
     resp, body = self.client.create_image(server_id, name, meta)
     image_id = parse_image_id(resp['location'])
     self.client.wait_for_image_resp_code(image_id, 200)
     self.client.wait_for_image_status(image_id, 'ACTIVE')
     self.image_ids.append(image_id)
     return resp, body
    def test_create_delete_image(self):
        """An image for the provided server should be created"""
        server_name = rand_name('server')
        resp, server = self.servers_client.create_server(server_name,
                                                         self.image_ref,
                                                         self.flavor_ref)
        self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')

        # Create a new image
        name = rand_name('image')
        meta = {'image_type': 'test'}
        resp, body = self.client.create_image(server['id'], name, meta)
        image_id = parse_image_id(resp['location'])
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, 'ACTIVE')

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

        # Verify minRAM and minDisk values are the same as the original image
        resp, original_image = self.client.get_image(self.image_ref)
        self.assertEqual(original_image['minRam'], image['minRam'])
        self.assertEqual(original_image['minDisk'], image['minDisk'])

        # Teardown
        self.client.delete_image(image['id'])
        self.servers_client.delete_server(server['id'])
    def test_create_delete_image(self):

        # Create a new image
        name = rand_name('image')
        meta = {'image_type': 'test'}
        resp, body = self.client.create_image(self.server['id'], name, meta)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp['location'])
        self.client.wait_for_image_status(image_id, 'ACTIVE')

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

        resp, 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
        resp, body = self.client.delete_image(image_id)
        self.assertEqual('204', resp['status'])
        self.client.wait_for_resource_deletion(image_id)
Exemple #18
0
    def test_create_image_from_deleted_server(self):
        # An image should not be created if the server instance is removed
        server_name = rand_name('server')
        resp, server = self.servers_client.create_server(server_name,
                                                         self.image_ref,
                                                         self.flavor_ref)
        self.servers_client.wait_for_server_status(server['id'], 'ACTIVE')

        # Delete server before trying to create server
        self.servers_client.delete_server(server['id'])

        try:
            # Create a new image after server is deleted
            name = rand_name('image')
            meta = {'image_type': 'test'}
            resp, body = self.client.create_image(server['id'], name, meta)

        except Exception:
            pass

        else:
            image_id = parse_image_id(resp['location'])
            self.client.wait_for_image_resp_code(image_id, 200)
            self.client.wait_for_image_status(image_id, 'ACTIVE')
            self.client.delete_image(image_id)
            self.fail("Should not create snapshot from deleted instance!")
    def setUpClass(cls):
        if not compute.MULTI_USER:
            msg = "Need >1 user"
            raise cls.skipException(msg)

        super(AuthorizationTest, cls).setUpClass()

        cls.client = cls.os.servers_client
        cls.images_client = cls.os.images_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.security_client = cls.os.security_groups_client

        if cls.config.compute.allow_tenant_isolation:
            creds = cls._get_isolated_creds()
            username, tenant_name, password = creds
            cls.alt_manager = clients.Manager(username=username,
                                              password=password,
                                              tenant_name=tenant_name)
        else:
            # Use the alt_XXX credentials in the config file
            cls.alt_manager = clients.AltManager()

        cls.alt_client = cls.alt_manager.servers_client
        cls.alt_images_client = cls.alt_manager.images_client
        cls.alt_keypairs_client = cls.alt_manager.keypairs_client
        cls.alt_security_client = cls.alt_manager.security_groups_client

        cls.alt_security_client._set_auth()
        name = rand_name('server')
        resp, server = cls.client.create_server(name, cls.image_ref,
                                                cls.flavor_ref)
        cls.client.wait_for_server_status(server['id'], 'ACTIVE')
        resp, cls.server = cls.client.get_server(server['id'])

        name = rand_name('image')
        resp, body = cls.client.create_image(server['id'], name)
        image_id = parse_image_id(resp['location'])
        cls.images_client.wait_for_image_resp_code(image_id, 200)
        cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
        resp, cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = rand_name('keypair')
        resp, keypair = \
            cls.keypairs_client.create_keypair(cls.keypairname)

        name = rand_name('security')
        description = rand_name('description')
        resp, cls.security_group = \
        cls.security_client.create_security_group(name, description)

        parent_group_id = cls.security_group['id']
        ip_protocol = 'tcp'
        from_port = 22
        to_port = 22
        resp, cls.rule =\
        cls.security_client.create_security_group_rule(
                                        parent_group_id,
                                        ip_protocol, from_port,
                                        to_port)
 def test_create_image_specify_multibyte_character_image_name(self):
     # prefix character is:
     # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
     utf8_name = data_utils.rand_name(u'\xF0\x9F\x92\xA9')
     resp, body = self.client.create_image(self.server_id, utf8_name)
     image_id = data_utils.parse_image_id(resp['location'])
     self.addCleanup(self.client.delete_image, image_id)
     self.assertEqual('202', resp['status'])
Exemple #21
0
    def setUpClass(cls):
        super(ListImageFiltersTestJSON, cls).setUpClass()
        cls.client = cls.images_client

        try:
            resp, cls.server1 = cls.create_server()
            resp, cls.server2 = cls.create_server(wait_until='ACTIVE')
            # NOTE(sdague) this is faster than doing the sync wait_util on both
            cls.servers_client.wait_for_server_status(cls.server1['id'],
                                                      'ACTIVE')

            # Create images to be used in the filter tests
            image1_name = rand_name('image')
            resp, body = cls.client.create_image(cls.server1['id'],
                                                 image1_name)
            cls.image1_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image1_id, 200)
            cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
            resp, cls.image1 = cls.client.get_image(cls.image1_id)

            # Servers have a hidden property for when they are being imaged
            # Performing back-to-back create image calls on a single
            # server will sometimes cause failures
            image3_name = rand_name('image')
            resp, body = cls.client.create_image(cls.server2['id'],
                                                 image3_name)
            cls.image3_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image3_id, 200)
            cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
            resp, cls.image3 = cls.client.get_image(cls.image3_id)

            image2_name = rand_name('image')
            resp, body = cls.client.create_image(cls.server1['id'],
                                                 image2_name)
            cls.image2_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image2_id, 200)
            cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
            resp, cls.image2 = cls.client.get_image(cls.image2_id)
        except Exception:
            cls.clear_servers()
            cls.client.delete_image(cls.image1_id)
            cls.client.delete_image(cls.image2_id)
            cls.client.delete_image(cls.image3_id)
            raise
Exemple #22
0
 def _create_snapshot(cls, name, image_id, flavor, **kwargs):
     _, server = cls.servers_client.create_server(name, image_id, flavor,
                                                  **kwargs)
     cls.servers.append(server)
     cls.servers_client.wait_for_server_status(server['id'], 'ACTIVE')
     resp, _ = cls.servers_client.create_image(server['id'], name)
     image_id = data_utils.parse_image_id(resp['location'])
     cls.created_images.append(image_id)
     cls.client.wait_for_image_status(image_id, 'active')
     return 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, name=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, name=utf8_name)
        image_id = data_utils.parse_image_id(body.response['location'])
        self.addCleanup(self.client.delete_image, image_id)
Exemple #25
0
    def setUpClass(cls):
        if not compute.MULTI_USER:
            msg = "Need >1 user"
            raise SkipTest(msg)

        super(AuthorizationTest, cls).setUpClass()

        cls.client = cls.os.servers_client
        cls.images_client = cls.os.images_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.security_client = cls.os.security_groups_client
        cls.console_outputs_client = cls.os.console_outputs_client

        if cls.config.compute.allow_tenant_isolation:
            creds = cls._get_isolated_creds()
            username, tenant_name, password = creds
            cls.alt_manager = openstack.Manager(username=username, password=password, tenant_name=tenant_name)
        else:
            # Use the alt_XXX credentials in the config file
            cls.alt_manager = openstack.AltManager()

        cls.alt_client = cls.alt_manager.servers_client
        cls.alt_images_client = cls.alt_manager.images_client
        cls.alt_keypairs_client = cls.alt_manager.keypairs_client
        cls.alt_security_client = cls.alt_manager.security_groups_client
        cls.alt_console_outputs_client = cls.alt_manager.console_outputs_client

        cls.alt_security_client._set_auth()
        name = rand_name("server")
        resp, server = cls.client.create_server(name, cls.image_ref, cls.flavor_ref)
        cls.client.wait_for_server_status(server["id"], "ACTIVE")
        resp, cls.server = cls.client.get_server(server["id"])

        name = rand_name("image")
        resp, body = cls.client.create_image(server["id"], name)
        image_id = parse_image_id(resp["location"])
        cls.images_client.wait_for_image_resp_code(image_id, 200)
        cls.images_client.wait_for_image_status(image_id, "ACTIVE")
        resp, cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = rand_name("keypair")
        resp, keypair = cls.keypairs_client.create_keypair(cls.keypairname)

        name = rand_name("security")
        description = rand_name("description")
        resp, cls.security_group = cls.security_client.create_security_group(name, description)

        parent_group_id = cls.security_group["id"]
        ip_protocol = "tcp"
        from_port = 22
        to_port = 22
        resp, cls.rule = cls.security_client.create_security_group_rule(
            parent_group_id, ip_protocol, from_port, to_port
        )
    def setUpClass(cls):
        super(ListImageFiltersTestJSON, cls).setUpClass()
        if not cls.config.service_available.glance:
            skip_msg = ("%s skipped as glance is not available" % cls.__name__)
            raise cls.skipException(skip_msg)
        cls.client = cls.images_client
        cls.image_ids = []

        try:
            resp, cls.server1 = cls.create_server()
            resp, cls.server2 = cls.create_server(wait_until='ACTIVE')
            # NOTE(sdague) this is faster than doing the sync wait_util on both
            cls.servers_client.wait_for_server_status(cls.server1['id'],
                                                      'ACTIVE')

            # Create images to be used in the filter tests
            resp, body = cls.create_image_from_server(cls.server1['id'])
            cls.image1_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image1_id, 200)
            cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
            resp, cls.image1 = cls.client.get_image(cls.image1_id)

            # Servers have a hidden property for when they are being imaged
            # Performing back-to-back create image calls on a single
            # server will sometimes cause failures
            resp, body = cls.create_image_from_server(cls.server2['id'])
            cls.image3_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image3_id, 200)
            cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
            resp, cls.image3 = cls.client.get_image(cls.image3_id)

            resp, body = cls.create_image_from_server(cls.server1['id'])
            cls.image2_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image2_id, 200)

            cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
            resp, cls.image2 = cls.client.get_image(cls.image2_id)
        except Exception as exc:
            LOG.exception(exc)
            cls.tearDownClass()
            raise
    def setUpClass(cls):
        super(ListImageFiltersTestJSON, cls).setUpClass()
        if not cls.config.service_available.glance:
            skip_msg = ("%s skipped as glance is not available" % cls.__name__)
            raise cls.skipException(skip_msg)
        cls.client = cls.images_client
        cls.image_ids = []

        try:
            resp, cls.server1 = cls.create_server()
            resp, cls.server2 = cls.create_server(wait_until='ACTIVE')
            # NOTE(sdague) this is faster than doing the sync wait_util on both
            cls.servers_client.wait_for_server_status(cls.server1['id'],
                                                      'ACTIVE')

            # Create images to be used in the filter tests
            resp, body = cls.create_image_from_server(cls.server1['id'])
            cls.image1_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image1_id, 200)
            cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
            resp, cls.image1 = cls.client.get_image(cls.image1_id)

            # Servers have a hidden property for when they are being imaged
            # Performing back-to-back create image calls on a single
            # server will sometimes cause failures
            resp, body = cls.create_image_from_server(cls.server2['id'])
            cls.image3_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image3_id, 200)
            cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
            resp, cls.image3 = cls.client.get_image(cls.image3_id)

            resp, body = cls.create_image_from_server(cls.server1['id'])
            cls.image2_id = parse_image_id(resp['location'])
            cls.client.wait_for_image_resp_code(cls.image2_id, 200)

            cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
            resp, cls.image2 = cls.client.get_image(cls.image2_id)
        except Exception as exc:
            LOG.exception(exc)
            cls.tearDownClass()
            raise
 def test_create_image_specify_multibyte_character_image_name(self):
     if self.__class__._interface == "xml":
         # NOTE(sdague): not entirely accurage, but we'd need a ton of work
         # in our XML client to make this good
         raise self.skipException("Not testable in XML")
     # prefix character is:
     # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
     utf8_name = data_utils.rand_name(u'\xF0\x9F\x92\xA9')
     resp, body = self.client.create_image(self.server_id, utf8_name)
     image_id = data_utils.parse_image_id(resp['location'])
     self.addCleanup(self.client.delete_image, image_id)
     self.assertEqual('202', resp['status'])
 def _create_snapshot(cls, name, image_id, flavor, **kwargs):
     _, server = cls.servers_client.create_server(
         name, image_id, flavor, **kwargs)
     cls.servers.append(server)
     cls.servers_client.wait_for_server_status(
         server['id'], 'ACTIVE')
     resp, _ = cls.servers_client.create_image(server['id'], name)
     image_id = data_utils.parse_image_id(resp['location'])
     cls.created_images.append(image_id)
     cls.client.wait_for_image_status(image_id,
                                      'active')
     return image_id
    def setUpClass(cls):
        if not compute.MULTI_USER:
            msg = "Need >1 user"
            raise cls.skipException(msg)

        super(AuthorizationTestJSON, cls).setUpClass()

        cls.client = cls.os.servers_client
        cls.images_client = cls.os.images_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.security_client = cls.os.security_groups_client

        if cls.config.compute.allow_tenant_isolation:
            creds = cls.isolated_creds.get_alt_creds()
            username, tenant_name, password = creds
            cls.alt_manager = clients.Manager(username=username,
                                              password=password,
                                              tenant_name=tenant_name)
        else:
            # Use the alt_XXX credentials in the config file
            cls.alt_manager = clients.AltManager()

        cls.alt_client = cls.alt_manager.servers_client
        cls.alt_images_client = cls.alt_manager.images_client
        cls.alt_keypairs_client = cls.alt_manager.keypairs_client
        cls.alt_security_client = cls.alt_manager.security_groups_client

        cls.alt_security_client._set_auth()
        resp, server = cls.create_server(wait_until='ACTIVE')
        resp, cls.server = cls.client.get_server(server['id'])

        name = rand_name('image')
        resp, body = cls.client.create_image(server['id'], name)
        image_id = parse_image_id(resp['location'])
        cls.images_client.wait_for_image_resp_code(image_id, 200)
        cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
        resp, cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = rand_name('keypair')
        resp, keypair = \
            cls.keypairs_client.create_keypair(cls.keypairname)

        name = rand_name('security')
        description = rand_name('description')
        resp, cls.security_group = cls.security_client.create_security_group(
            name, description)

        parent_group_id = cls.security_group['id']
        ip_protocol = 'tcp'
        from_port = 22
        to_port = 22
        resp, cls.rule = cls.security_client.create_security_group_rule(
            parent_group_id, ip_protocol, from_port, to_port)
 def test_create_image_specify_multibyte_character_image_name(self):
     if self.__class__._interface == "xml":
         # NOTE(sdague): not entirely accurage, but we'd need a ton of work
         # in our XML client to make this good
         raise self.skipException("Not testable in XML")
     # prefix character is:
     # http://www.fileformat.info/info/unicode/char/1F4A9/index.htm
     utf8_name = data_utils.rand_name(u'\xF0\x9F\x92\xA9')
     resp, body = self.client.create_image(self.server_id, utf8_name)
     image_id = data_utils.parse_image_id(resp['location'])
     self.addCleanup(self.client.delete_image, image_id)
     self.assertEqual('202', resp['status'])
Exemple #32
0
    def test_delete_image_of_another_tenant(self):
        # Return an error while trying to delete another tenant's image
        self.servers_client.wait_for_server_status(self.server["id"], "ACTIVE")
        snapshot_name = rand_name("test-snap-")
        resp, body = self.client.create_image(self.server["id"], snapshot_name)
        image_id = parse_image_id(resp["location"])
        self.image_ids.append(image_id)
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, "ACTIVE")

        # Delete image
        self.assertRaises(exceptions.NotFound, self.alt_client.delete_image, image_id)
    def setUpClass(cls):
        # No network resources required for this test
        cls.set_network_resources()
        super(AuthorizationTestJSON, cls).setUpClass()
        if not cls.multi_user:
            msg = "Need >1 user"
            raise cls.skipException(msg)
        cls.client = cls.os.servers_client
        cls.images_client = cls.os.images_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.security_client = cls.os.security_groups_client

        if cls.config.compute.allow_tenant_isolation:
            creds = cls.isolated_creds.get_alt_creds()
            username, tenant_name, password = creds
            cls.alt_manager = clients.Manager(username=username,
                                              password=password,
                                              tenant_name=tenant_name)
        else:
            # Use the alt_XXX credentials in the config file
            cls.alt_manager = clients.AltManager()

        cls.alt_client = cls.alt_manager.servers_client
        cls.alt_images_client = cls.alt_manager.images_client
        cls.alt_keypairs_client = cls.alt_manager.keypairs_client
        cls.alt_security_client = cls.alt_manager.security_groups_client

        cls.alt_security_client._set_auth()
        resp, server = cls.create_test_server(wait_until='ACTIVE')
        resp, cls.server = cls.client.get_server(server['id'])

        name = data_utils.rand_name('image')
        resp, body = cls.client.create_image(server['id'], name)
        image_id = data_utils.parse_image_id(resp['location'])
        cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
        resp, cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = data_utils.rand_name('keypair')
        resp, keypair = \
            cls.keypairs_client.create_keypair(cls.keypairname)

        name = data_utils.rand_name('security')
        description = data_utils.rand_name('description')
        resp, cls.security_group = cls.security_client.create_security_group(
            name, description)

        parent_group_id = cls.security_group['id']
        ip_protocol = 'tcp'
        from_port = 22
        to_port = 22
        resp, cls.rule = cls.security_client.create_security_group_rule(
            parent_group_id, ip_protocol, from_port, to_port)
Exemple #34
0
    def test_delete_image_of_another_tenant(self):
        # Return an error while trying to delete another tenant's image
        self.servers_client.wait_for_server_status(self.server['id'], 'ACTIVE')
        snapshot_name = rand_name('test-snap-')
        resp, body = self.client.create_image(self.server['id'], snapshot_name)
        image_id = parse_image_id(resp['location'])
        self.image_ids.append(image_id)
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, 'ACTIVE')

        # Delete image
        self.assertRaises(exceptions.NotFound, self.alt_client.delete_image,
                          image_id)
    def setUpClass(cls):
        cls.client = cls.images_client

        name = rand_name('server')
        resp, cls.server1 = cls.servers_client.create_server(name,
                                                             cls.image_ref,
                                                             cls.flavor_ref)
        name = rand_name('server')
        resp, cls.server2 = cls.servers_client.create_server(name,
                                                             cls.image_ref,
                                                             cls.flavor_ref)
        cls.servers_client.wait_for_server_status(cls.server1['id'], 'ACTIVE')
        cls.servers_client.wait_for_server_status(cls.server2['id'], 'ACTIVE')

        # Create images to be used in the filter tests
        image1_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server1['id'], image1_name)
        cls.image1_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image1_id, 200)
        cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
        resp, cls.image1 = cls.client.get_image(cls.image1_id)

        # Servers have a hidden property for when they are being imaged
        # Performing back-to-back create image calls on a single
        # server will sometimes cause failures
        image3_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server2['id'], image3_name)
        cls.image3_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image3_id, 200)
        cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
        resp, cls.image3 = cls.client.get_image(cls.image3_id)

        image2_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server1['id'], image2_name)
        cls.image2_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image2_id, 200)
        cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
        resp, cls.image2 = cls.client.get_image(cls.image2_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, name=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.show_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.show_image, image_id)
    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-")
        resp, body = self.servers_client.create_image(self.server_id, snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = data_utils.parse_image_id(resp["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(exceptions.Conflict, self.servers_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, name=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, name=alt_snapshot_name)
Exemple #40
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 = rand_name("test-snap-")
        resp, body = self.client.create_image(self.server["id"], snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp["location"])
        self.image_ids.append(image_id)

        # Create second snapshot
        alt_snapshot_name = rand_name("test-snap-")
        self.assertRaises(exceptions.Duplicate, self.client.create_image, self.server["id"], alt_snapshot_name)
        self.client.wait_for_image_status(image_id, "ACTIVE")
    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, name=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, name=alt_snapshot_name)
Exemple #42
0
    def setUpClass(cls):
        super(ListImageFiltersTest, cls).setUpClass()
        cls.client = cls.images_client

        name = rand_name('server')
        resp, cls.server1 = cls.servers_client.create_server(
            name, cls.image_ref, cls.flavor_ref)
        name = rand_name('server')
        resp, cls.server2 = cls.servers_client.create_server(
            name, cls.image_ref, cls.flavor_ref)
        cls.servers_client.wait_for_server_status(cls.server1['id'], 'ACTIVE')
        cls.servers_client.wait_for_server_status(cls.server2['id'], 'ACTIVE')

        # Create images to be used in the filter tests
        image1_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server1['id'], image1_name)
        cls.image1_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image1_id, 200)
        cls.client.wait_for_image_status(cls.image1_id, 'ACTIVE')
        resp, cls.image1 = cls.client.get_image(cls.image1_id)

        # Servers have a hidden property for when they are being imaged
        # Performing back-to-back create image calls on a single
        # server will sometimes cause failures
        image3_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server2['id'], image3_name)
        cls.image3_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image3_id, 200)
        cls.client.wait_for_image_status(cls.image3_id, 'ACTIVE')
        resp, cls.image3 = cls.client.get_image(cls.image3_id)

        image2_name = rand_name('image')
        resp, body = cls.client.create_image(cls.server1['id'], image2_name)
        cls.image2_id = parse_image_id(resp['location'])
        cls.client.wait_for_image_resp_code(cls.image2_id, 200)
        cls.client.wait_for_image_status(cls.image2_id, 'ACTIVE')
        resp, cls.image2 = cls.client.get_image(cls.image2_id)
Exemple #43
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 = rand_name('test-snap-')
        resp, body = self.client.create_image(self.server['id'], snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp['location'])
        self.image_ids.append(image_id)

        # Create second snapshot
        alt_snapshot_name = rand_name('test-snap-')
        self.assertRaises(exceptions.Duplicate, self.client.create_image,
                          self.server['id'], alt_snapshot_name)
        self.client.wait_for_image_status(image_id, 'ACTIVE')
    def test_delete_image_of_another_tenant(self):
        """Return an error while trying to delete another tenant's image"""

        server = self.create_server()

        snapshot_name = rand_name('test-snap-')
        resp, body = self.client.create_image(server['id'], snapshot_name)
        image_id = parse_image_id(resp['location'])
        self.image_ids.append(image_id)
        self.client.wait_for_image_resp_code(image_id, 200)
        self.client.wait_for_image_status(image_id, 'ACTIVE')

        # Delete image
        self.assertRaises(exceptions.NotFound,
                          self.alt_client.delete_image, image_id)
Exemple #45
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-')
        resp, body = self.client.create_image(self.server_id, snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = data_utils.parse_image_id(resp['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(exceptions.Conflict, self.client.create_image,
                          self.server_id, alt_snapshot_name)
Exemple #46
0
    def create_image_from_server(cls, server_id, **kwargs):
        """Wrapper utility that returns a test server."""
        name = rand_name(cls.__name__ + "-image")
        if "name" in kwargs:
            name = kwargs.pop("name")

        resp, image = cls.images_client.create_image(server_id, name)
        image_id = parse_image_id(resp["location"])
        cls.images.append(image_id)

        if "wait_until" in kwargs:
            cls.images_client.wait_for_image_status(image_id, kwargs["wait_until"])
            resp, image = cls.images_client.get_image(image_id)

        return resp, image
    def test_delete_image_that_is_not_yet_active(self):
        # Return an error while trying to delete an image what is creating

        snapshot_name = rand_name('test-snap-')
        resp, body = self.client.create_image(self.server['id'], snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp['location'])
        self.image_ids.append(image_id)

        # Do not wait, attempt to delete the image, ensure it's successful
        resp, body = self.client.delete_image(image_id)
        self.assertEqual('204', resp['status'])
        self.image_ids.remove(image_id)

        self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
Exemple #48
0
    def test_delete_image_that_is_not_yet_active(self):
        # Return an error while trying to delete an image what is creating

        snapshot_name = rand_name('test-snap-')
        resp, body = self.client.create_image(self.server['id'], snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = parse_image_id(resp['location'])
        self.image_ids.append(image_id)

        # Do not wait, attempt to delete the image, ensure it's successful
        resp, body = self.client.delete_image(image_id)
        self.assertEqual('204', resp['status'])
        self.image_ids.remove(image_id)

        self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
    def setUpClass(cls):
        # No network resources required for this test
        cls.set_network_resources()
        super(AuthorizationTestJSON, cls).setUpClass()
        if not cls.multi_user:
            msg = "Need >1 user"
            raise cls.skipException(msg)
        cls.client = cls.os.servers_client
        cls.images_client = cls.os.images_client
        cls.keypairs_client = cls.os.keypairs_client
        cls.security_client = cls.os.security_groups_client

        if CONF.compute.allow_tenant_isolation:
            creds = cls.isolated_creds.get_alt_creds()
            cls.alt_manager = clients.Manager(credentials=creds)
        else:
            # Use the alt_XXX credentials in the config file
            cls.alt_manager = clients.AltManager()

        cls.alt_client = cls.alt_manager.servers_client
        cls.alt_images_client = cls.alt_manager.images_client
        cls.alt_keypairs_client = cls.alt_manager.keypairs_client
        cls.alt_security_client = cls.alt_manager.security_groups_client

        resp, server = cls.create_test_server(wait_until='ACTIVE')
        resp, cls.server = cls.client.get_server(server['id'])

        name = data_utils.rand_name('image')
        resp, body = cls.images_client.create_image(server['id'], name)
        image_id = data_utils.parse_image_id(resp['location'])
        cls.images_client.wait_for_image_status(image_id, 'ACTIVE')
        resp, cls.image = cls.images_client.get_image(image_id)

        cls.keypairname = data_utils.rand_name('keypair')
        resp, keypair = \
            cls.keypairs_client.create_keypair(cls.keypairname)

        name = data_utils.rand_name('security')
        description = data_utils.rand_name('description')
        resp, cls.security_group = cls.security_client.create_security_group(
            name, description)

        parent_group_id = cls.security_group['id']
        ip_protocol = 'tcp'
        from_port = 22
        to_port = 22
        resp, cls.rule = cls.security_client.create_security_group_rule(
            parent_group_id, ip_protocol, from_port, to_port)
    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-')
        resp, body = self.client.create_image(self.server_id,
                                              snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = data_utils.parse_image_id(resp['location'])
        self.image_ids.append(image_id)

        # Create second snapshot
        alt_snapshot_name = data_utils.rand_name('test-snap-')
        self.assertRaises(exceptions.Conflict, self.client.create_image,
                          self.server_id, alt_snapshot_name)
        self.client.wait_for_image_status(image_id, 'ACTIVE')
    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-")
        resp, body = self.servers_client.create_image(self.server_id, snapshot_name)
        self.assertEqual(202, resp.status)
        image_id = data_utils.parse_image_id(resp["location"])
        self.image_ids.append(image_id)
        self.addCleanup(self._reset_server)

        # Do not wait, attempt to delete the image, ensure it's successful
        resp, body = self.client.delete_image(image_id)
        self.assertEqual("200", resp["status"])
        self.image_ids.remove(image_id)

        self.assertRaises(exceptions.NotFound, self.client.get_image, image_id)
Exemple #52
0
    def create_image_from_server(cls, server_id, **kwargs):
        """Wrapper utility that returns a test server."""
        name = rand_name(cls.__name__ + "-image")
        if 'name' in kwargs:
            name = kwargs.pop('name')

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

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

        return resp, image
    def test_create_image_specify_multibyte_character_image_name(self):
        if self.__class__._interface == "xml":
            # NOTE(sdague): not entirely accurage, but we'd need a ton of work
            # in our XML client to make this good
            raise self.skipException("Not testable in XML")
        # 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')
        resp, body = self.client.create_image(self.server_id, utf8_name)
        image_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.client.delete_image, image_id)
        self.assertEqual('202', resp['status'])
Exemple #54
0
    def test_create_image_from_invalid_server(self):
        """An image should not be created with invalid server id"""
        try:
            # Create a new image with invalid server id
            name = rand_name('image')
            meta = {'image_type': 'test'}
            resp = {}
            resp['status'] = None
            resp, body = self.client.create_image('!@#$%^&*()', name, meta)

        except exceptions.NotFound:
            pass

        finally:
            if (resp['status'] != None):
                image_id = parse_image_id(resp['location'])
                resp, _ = self.client.delete_image(image_id)
                self.fail("An image should not be created"
                          " with invalid server id")
Exemple #55
0
    def test_create_second_image_when_first_image_is_being_saved(self):
        """Disallow creating another image when first image is being saved"""
        server = self.create_server()

        try:
            # Create first snapshot
            snapshot_name = rand_name('test-snap-')
            resp, body = self.client.create_image(server['id'], snapshot_name)
            image_id = parse_image_id(resp['location'])
            self.image_ids.append(image_id)

            # Create second snapshot
            alt_snapshot_name = rand_name('test-snap-')
            self.client.create_image(server['id'], alt_snapshot_name)
        except exceptions.Duplicate:
            pass

        else:
            self.fail("Should allow creating an image when another image of"
                      "the server is still being saved")
    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.compute_images_client.create_image(server_id, name=name)
        image_id = data_utils.parse_image_id(image.response['location'])
        cls.images.append(image_id)

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

            if kwargs['wait_until'] == 'ACTIVE':
                if kwargs.get('wait_for_server', True):
                    waiters.wait_for_server_status(cls.servers_client,
                                                   server_id, 'ACTIVE')
        return image
Exemple #57
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.compute_images_client.create_image(server_id, name=name)
        image_id = data_utils.parse_image_id(image.response['location'])
        cls.images.append(image_id)

        if 'wait_until' in kwargs:
            try:
                waiters.wait_for_image_status(cls.compute_images_client,
                                              image_id, kwargs['wait_until'])
            except lib_exc.NotFound:
                if kwargs['wait_until'].upper() == 'ACTIVE':
                    # If the image is not found after create_image returned
                    # that means the snapshot failed in nova-compute and nova
                    # deleted the image. There should be a compute fault
                    # recorded with the server in that case, so get the server
                    # and dump some details.
                    server = (
                        cls.servers_client.show_server(server_id)['server'])
                    if 'fault' in server:
                        raise exceptions.SnapshotNotFoundException(
                            server['fault'], image_id=image_id)
                    else:
                        raise exceptions.SnapshotNotFoundException(
                            image_id=image_id)
                else:
                    raise
            image = cls.compute_images_client.show_image(image_id)['image']

            if kwargs['wait_until'] == 'ACTIVE':
                if kwargs.get('wait_for_server', True):
                    waiters.wait_for_server_status(cls.servers_client,
                                                   server_id, 'ACTIVE')
        return image
Exemple #58
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.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')
        waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
        resp = self.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')['images']
        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')
        waiters.wait_for_server_status(self.client, self.server_id, 'ACTIVE')
        resp = self.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
        waiters.wait_for_server_status(self.client, 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')['images']
        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']))
    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)
        oldest_backup_exist = True

        # the oldest one should be deleted automatically in this test
        def _clean_oldest_backup(oldest_backup):
            if oldest_backup_exist:
                self.os.image_client.delete_image(oldest_backup)

        image1_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(_clean_oldest_backup, image1_id)
        self.assertEqual(202, resp.status)
        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)
        image2_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image2_id)
        self.assertEqual(202, resp.status)
        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,
        }
        resp, image_list = self.os.image_client.image_list_detail(
            properties, status='active', sort_key='created_at', sort_dir='asc')
        self.assertEqual(200, resp.status)
        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)
        image3_id = data_utils.parse_image_id(resp['location'])
        self.addCleanup(self.os.image_client.delete_image, image3_id)
        self.assertEqual(202, resp.status)
        # 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
        resp, image_list = self.os.image_client.image_list_detail(
            properties, status='active', sort_key='created_at', sort_dir='asc')
        self.assertEqual(200, resp.status)
        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']))