Example #1
0
    def test_random_bytes(self):
        actual = data_utils.random_bytes()  # default size=1024
        self.assertIsInstance(actual, str)
        self.assertRegexpMatches(actual, "^[\x00-\xFF]{1024}")
        actual2 = data_utils.random_bytes()
        self.assertNotEqual(actual, actual2)

        actual = data_utils.random_bytes(size=2048)
        self.assertRegexpMatches(actual, "^[\x00-\xFF]{2048}")
    def test_random_bytes(self):
        actual = data_utils.random_bytes()  # default size=1024
        self.assertIsInstance(actual, str)
        self.assertRegexpMatches(actual, "^[\x00-\xFF]{1024}")
        actual2 = data_utils.random_bytes()
        self.assertNotEqual(actual, actual2)

        actual = data_utils.random_bytes(size=2048)
        self.assertRegexpMatches(actual, "^[\x00-\xFF]{2048}")
Example #3
0
 def test_admin_deactivate_reactivate_image(self):
     # Create image by non-admin tenant
     image_name = data_utils.rand_name('image')
     body = self.client.create_image(name=image_name,
                                     container_format='bare',
                                     disk_format='raw',
                                     visibility='private')
     image_id = body['id']
     self.addCleanup(self.client.delete_image, image_id)
     # upload an image file
     content = data_utils.random_bytes()
     image_file = moves.cStringIO(content)
     self.client.store_image_file(image_id, image_file)
     # deactivate image
     self.admin_client.deactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("deactivated", body['status'])
     # non-admin user unable to download deactivated image
     self.assertRaises(lib_exc.Forbidden, self.client.load_image_file,
                       image_id)
     # reactivate image
     self.admin_client.reactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("active", body['status'])
     # non-admin user able to download image after reactivation by admin
     body = self.client.load_image_file(image_id)
     self.assertEqual(content, body.data)
 def test_admin_deactivate_reactivate_image(self):
     # Create image by non-admin tenant
     image_name = data_utils.rand_name('image')
     body = self.client.create_image(name=image_name,
                                     container_format='bare',
                                     disk_format='raw',
                                     visibility='private')
     image_id = body['id']
     self.addCleanup(self.client.delete_image, image_id)
     # upload an image file
     content = data_utils.random_bytes()
     image_file = moves.cStringIO(content)
     self.client.store_image_file(image_id, image_file)
     # deactivate image
     self.admin_client.deactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("deactivated", body['status'])
     # non-admin user unable to download deactivated image
     self.assertRaises(lib_exc.Forbidden, self.client.show_image_file,
                       image_id)
     # reactivate image
     self.admin_client.reactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("active", body['status'])
     # non-admin user able to download image after reactivation by admin
     body = self.client.show_image_file(image_id)
     self.assertEqual(content, body.data)
Example #5
0
    def test_update_image(self):
        # Updates an image by image_id

        # Create image
        image_name = data_utils.rand_name('image')
        body = self.client.create_image(name=image_name,
                                        container_format='bare',
                                        disk_format='iso',
                                        visibility='private')
        self.addCleanup(self.client.delete_image, body['id'])
        self.assertEqual('queued', body['status'])
        image_id = body['id']

        # Now try uploading an image file
        image_file = moves.cStringIO(data_utils.random_bytes())
        self.client.store_image(image_id, image_file)

        # Update Image
        new_image_name = data_utils.rand_name('new-image')
        body = self.client.update_image(image_id, [
            dict(replace='/name', value=new_image_name)])

        # Verifying updating

        body = self.client.get_image(image_id)
        self.assertEqual(image_id, body['id'])
        self.assertEqual(new_image_name, body['name'])
Example #6
0
 def _create_image(self):
     image_file = moves.cStringIO(data_utils.random_bytes())
     image = self.create_image(container_format='bare',
                               disk_format='raw',
                               is_public=False,
                               data=image_file)
     image_id = image['id']
     return image_id
Example #7
0
 def _create_image(self):
     image_file = moves.cStringIO(data_utils.random_bytes())
     image = self.create_image(container_format='bare',
                               disk_format='raw',
                               is_public=False,
                               data=image_file)
     image_id = image['id']
     return image_id
Example #8
0
 def test_upload_image_negative(self):
     # Updates an image by image_id
     # Create image
     image_name = data_utils.rand_name('image')
     body = self.client.create_image(name=image_name,
                                     container_format='bare',
                                     disk_format='iso',
                                     visibility='private')
     image_id = body['id']
     # Now try uploading an image file
     image_file = StringIO.StringIO(data_utils.random_bytes())
     self.assertRaises(lib_exc.Forbidden, self.client.store_image,image_id, image_file)
Example #9
0
 def _create_standard_image(cls, name, container_format, disk_format, size):
     """
     Create a new standard image and return the ID of the newly-registered
     image. Note that the size of the new image is a random number between
     1024 and 4096
     """
     image_file = moves.cStringIO(data_utils.random_bytes(size))
     name = "New Standard Image %s" % name
     image = cls.create_image(
         name=name, container_format=container_format, disk_format=disk_format, is_public=False, data=image_file
     )
     image_id = image["id"]
     return image_id
 def test_upload_image_negative(self):
     # Updates an image by image_id
     # Create image
     image_name = data_utils.rand_name('image')
     body = self.client.create_image(name=image_name,
                                     container_format='bare',
                                     disk_format='iso',
                                     visibility='private')
     image_id = body['id']
     # Now try uploading an image file
     image_file = StringIO.StringIO(data_utils.random_bytes())
     self.assertRaises(lib_exc.Forbidden, self.client.store_image, image_id,
                       image_file)
Example #11
0
 def _create_standard_image(cls, name, container_format, disk_format, size):
     """
     Create a new standard image and return the ID of the newly-registered
     image.
     """
     image_file = moves.cStringIO(data_utils.random_bytes(size))
     name = 'New Standard Image %s' % name
     image = cls.create_image(name=name,
                              container_format=container_format,
                              disk_format=disk_format,
                              is_public=False,
                              data=image_file,
                              properties={'key1': 'value1'})
     image_id = image['id']
     return image_id
Example #12
0
 def _create_standard_image(cls, name, container_format, disk_format, size):
     """
     Create a new standard image and return the ID of the newly-registered
     image. Note that the size of the new image is a random number between
     1024 and 4096
     """
     image_file = moves.cStringIO(data_utils.random_bytes(size))
     name = 'New Standard Image %s' % name
     image = cls.create_image(name=name,
                              container_format=container_format,
                              disk_format=disk_format,
                              is_public=False,
                              data=image_file)
     image_id = image['id']
     return image_id
Example #13
0
 def _create_standard_image(cls, name, container_format,
                            disk_format, size):
     """
     Create a new standard image and return the ID of the newly-registered
     image.
     """
     image_file = moves.cStringIO(data_utils.random_bytes(size))
     name = 'New Standard Image %s' % name
     image = cls.create_image(name=name,
                              container_format=container_format,
                              disk_format=disk_format,
                              is_public=False, data=image_file,
                              properties={'key1': 'value1'})
     image_id = image['id']
     return image_id
Example #14
0
    def _create_standard_image(cls, container_format, disk_format):
        """
        Create a new standard image and return the ID of the newly-registered
        image. Note that the size of the new image is a random number between
        1024 and 4096
        """
        size = random.randint(1024, 4096)
        image_file = moves.cStringIO(data_utils.random_bytes(size))
        name = data_utils.rand_name('image')
        body = cls.create_image(name=name,
                                container_format=container_format,
                                disk_format=disk_format,
                                visibility='private')
        image_id = body['id']
        cls.client.store_image(image_id, data=image_file)

        return image_id
Example #15
0
    def test_register_then_upload(self):
        # Register, then upload an image
        properties = {"prop1": "val1"}
        body = self.create_image(
            name="New Name", container_format="bare", disk_format="raw", is_public=False, properties=properties
        )
        self.assertIn("id", body)
        image_id = body.get("id")
        self.assertEqual("New Name", body.get("name"))
        self.assertFalse(body.get("is_public"))
        self.assertEqual("queued", body.get("status"))
        for key, val in properties.items():
            self.assertEqual(val, body.get("properties")[key])

        # Now try uploading an image file
        image_file = moves.cStringIO(data_utils.random_bytes())
        body = self.client.update_image(image_id, data=image_file)
        self.assertIn("size", body)
        self.assertEqual(1024, body.get("size"))
Example #16
0
 def test_admin_deactivate_reactivate_image(self):
     # Create image by non-admin tenant
     image_name = data_utils.rand_name("image")
     body = self.client.create_image(
         name=image_name, container_format="bare", disk_format="raw", visibility="private"
     )
     image_id = body["id"]
     self.addCleanup(self.client.delete_image, image_id)
     # upload an image file
     image_file = moves.cStringIO(data_utils.random_bytes())
     self.client.store_image_file(image_id, image_file)
     # deactivate image
     self.admin_client.deactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("deactivated", body["status"])
     # reactivate image
     self.admin_client.reactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("active", body["status"])
Example #17
0
 def test_admin_deactivate_reactivate_image(self):
     # Create image by non-admin tenant
     image_name = data_utils.rand_name('image')
     body = self.client.create_image(name=image_name,
                                     container_format='bare',
                                     disk_format='raw',
                                     visibility='private')
     image_id = body['id']
     self.addCleanup(self.client.delete_image, image_id)
     # upload an image file
     image_file = moves.cStringIO(data_utils.random_bytes())
     self.client.store_image_file(image_id, image_file)
     # deactivate image
     self.admin_client.deactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("deactivated", body['status'])
     # reactivate image
     self.admin_client.reactivate_image(image_id)
     body = self.client.show_image(image_id)
     self.assertEqual("active", body['status'])
Example #18
0
    def test_register_then_upload(self):
        # Register, then upload an image
        properties = {'prop1': 'val1'}
        body = self.create_image(name='New Name',
                                 container_format='bare',
                                 disk_format='raw',
                                 is_public=False,
                                 properties=properties)
        self.assertIn('id', body)
        image_id = body.get('id')
        self.assertEqual('New Name', body.get('name'))
        self.assertFalse(body.get('is_public'))
        self.assertEqual('queued', body.get('status'))
        for key, val in properties.items():
            self.assertEqual(val, body.get('properties')[key])

        # Now try uploading an image file
        image_file = moves.cStringIO(data_utils.random_bytes())
        body = self.client.update_image(image_id, data=image_file)
        self.assertIn('size', body)
        self.assertEqual(1024, body.get('size'))
Example #19
0
    def test_register_then_upload(self):
        # Register, then upload an image
        properties = {'prop1': 'val1'}
        body = self.create_image(name='New Name',
                                 container_format='bare',
                                 disk_format='raw',
                                 is_public=False,
                                 properties=properties)
        self.assertIn('id', body)
        image_id = body.get('id')
        self.assertEqual('New Name', body.get('name'))
        self.assertFalse(body.get('is_public'))
        self.assertEqual('queued', body.get('status'))
        for key, val in properties.items():
            self.assertEqual(val, body.get('properties')[key])

        # Now try uploading an image file
        image_file = moves.cStringIO(data_utils.random_bytes())
        body = self.client.update_image(image_id, data=image_file)
        self.assertIn('size', body)
        self.assertEqual(1024, body.get('size'))
Example #20
0
    def test_register_upload_get_image_file(self):

        """
        Here we test these functionalities - Register image,
        upload the image file, get image and get image file api's
        """

        uuid = '00000000-1111-2222-3333-444455556666'
        image_name = data_utils.rand_name('image')
        body = self.create_image(name=image_name,
                                 container_format='bare',
                                 disk_format='raw',
                                 visibility='private',
                                 ramdisk_id=uuid)
        self.assertIn('id', body)
        image_id = body.get('id')
        self.assertIn('name', body)
        self.assertEqual(image_name, body['name'])
        self.assertIn('visibility', body)
        self.assertEqual('private', body['visibility'])
        self.assertIn('status', body)
        self.assertEqual('queued', body['status'])

        # Now try uploading an image file
        file_content = data_utils.random_bytes()
        image_file = moves.cStringIO(file_content)
        self.client.store_image(image_id, image_file)

        # Now try to get image details
        body = self.client.get_image(image_id)
        self.assertEqual(image_id, body['id'])
        self.assertEqual(image_name, body['name'])
        self.assertEqual(uuid, body['ramdisk_id'])
        self.assertIn('size', body)
        self.assertEqual(1024, body.get('size'))

        # Now try get image file
        body = self.client.get_image_file(image_id)
        self.assertEqual(file_content, body.data)