Example #1
0
def create_image():
    image_format = uforge.ImageFormat()
    image_format.name = "aws"

    target_format = uforge.TargetFormat()
    target_format.name = "aws"
    target_format.format = image_format

    image = uforge.Image()
    image.targetFormat = target_format

    image.name = "test image"
    image.dbId = 1
    image.version = "1"
    image.revision = "2"
    image.uri = "users/14/appliances/102/images/1"
    image.fileSize = 1000
    image.compress = True
    image.created = datetime.datetime.now()

    status = uforge.OpStatus()
    status.message = "message"
    status.complete = True
    image.status = status

    return image
Example #2
0
    def test_retrieve_publish_image_return_the_publish_image_created(self):
        # given
        target_format = uforge.TargetFormat()
        image_format = uforge.ImageFormat()
        image_format.name = "vcenter"
        target_format.format = image_format

        builder = {
            "displayName": "vcenter-vm-name",
            "esxHost": "esxhost_vcenter",
            "datastore": "datastore_vcenter",
            "network": "network_vcenter"
        }

        # when
        publish_image_retrieved = migration_utils.retrieve_publish_image(
            builder, target_format)

        # then
        self.assertEqual(publish_image_retrieved.displayName,
                         builder["displayName"])
        self.assertEqual(publish_image_retrieved.esxHost, builder["esxHost"])
        self.assertEqual(publish_image_retrieved.datastore,
                         builder["datastore"])
        self.assertEqual(publish_image_retrieved.network, builder["network"])
Example #3
0
    def test_retrieve_image_raise_exception_when_format_name_not_found(
            self, mock_remove_special_chars):
        # given
        api = Api("url",
                  username="******",
                  password="******",
                  headers=None,
                  disable_ssl_certificate_validation=False,
                  timeout=constants.HTTP_TIMEOUT)
        target_format = uforge.TargetFormat()
        image_format = uforge.ImageFormat()
        image_format.name = "vcenter"
        target_format.format = image_format

        builder = {"hardwareSettings": {"memory": 512, "hwType": 4}}

        mock_remove_special_chars.return_value = "vcenternotfound"

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.retrieve_image(builder, target_format, api,
                                           "login")

        # then
        self.assertTrue(
            "TargetFormat type is unsupported: vcenter" in e.exception)
Example #4
0
    def create_target_format(self, image_format_name):
        image_format = uforge.ImageFormat()
        image_format.name = image_format_name

        target_format = uforge.TargetFormat()
        target_format.format = image_format

        return target_format
Example #5
0
    def create_image(self, target_format_name):
        image_format = uforge.ImageFormat()
        image_format.name = target_format_name

        target_format = uforge.TargetFormat()
        target_format.name = target_format_name
        target_format.format = image_format

        image = uforge.Image()
        image.targetFormat = target_format
        return image
Example #6
0
    def test_retrieve_publish_image_raise_exception_when_format_name_not_found(self, mock_remove_special_chars):
        # given
        target_format = uforge.TargetFormat()
        image_format = uforge.ImageFormat()
        image_format.name = "vcenter"
        target_format.format = image_format

        builder = {
            "displayName": "vcenter-vm-name",
            "esxHost": "esxhost_vcenter",
            "datastore": "datastore_vcenter",
            "network": "network_vcenter"
        }

        mock_remove_special_chars.return_value = "vcenternotfound"

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.retrieve_publish_image(builder, target_format)

        # then
        self.assertTrue("TargetFormat type is unsupported: vcenter" in e.exception)
Example #7
0
    def test_retrieve_image_return_the_image_created(self):
        # given
        api = Api("url",
                  username="******",
                  password="******",
                  headers=None,
                  disable_ssl_certificate_validation=False,
                  timeout=constants.HTTP_TIMEOUT)
        target_format = uforge.TargetFormat()
        image_format = uforge.ImageFormat()
        image_format.name = "vcenter"
        target_format.format = image_format

        builder = {"hardwareSettings": {"memory": 512, "hwType": 4}}

        # when
        image_retrieved = migration_utils.retrieve_image(
            builder, target_format, api, "login")

        # then
        self.assertEqual(image_retrieved.installProfile.memorySize, 512)
        self.assertEqual(image_retrieved.installProfile.hwType, "4")
        self.assertFalse(image_retrieved.compress)