Пример #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
Пример #2
0
    def test_create_migration_create_a_migration_with_all_stages(self):
        # given
        m = migration.Migration()
        data = {"migration": {"name": "myMigrationTest", "os": "linux"}}
        target_format = self.create_targetFormat("nameTargetFormat")
        cred_account = uforge.CredAccountVSphere()
        install_profile = uforge.InstallProfile()
        image = uforge.Image()
        image.installProfile = install_profile
        publish_image = uforge.PublishImageVSphere()
        publish_image.credAccount = cred_account

        # when
        my_migration = m.create_migration(data["migration"]["name"],
                                          data["migration"]["os"],
                                          target_format.name, image,
                                          publish_image)

        # then
        self.assertEqual(my_migration.name, "myMigrationTest")
        self.assertEqual(my_migration.stages.stage[0].family,
                         data["migration"]["os"])
        self.assertEqual(my_migration.stages.stage[1].image.targetFormat.name,
                         target_format.name)
        self.assertEqual(my_migration.stages.stage[1].image.installProfile,
                         install_profile)
        self.assertEqual(
            my_migration.stages.stage[2].publishImage.targetFormat.name,
            target_format.name)
        self.assertEqual(my_migration.stages.stage[2].publishImage.credAccount,
                         cred_account)
Пример #3
0
    def test_do_launch_succeed_when_all_parameters_are_ok(self, mock_rmtree, mock_out, mock_api_create, mock_upload_and_launch_migration_binary, mock_create_migration, mock_retrieve_account, mock_retrieve_publish_image, mock_retrieve_image, mock_retrieve_target_format, mock_retrieve_migration_configuration, mock_download_binary):
        # given
        m = migration.Migration()
        m.api = Api("url", username="******", password="******", headers=None,
                    disable_ssl_certificate_validation=False, timeout=constants.HTTP_TIMEOUT)
        m.login = "******"
        m.password = "******"

        mock_retrieve_migration_configuration.return_value = self.get_migration_config()
        mock_retrieve_target_format.return_value = self.create_targetFormat("targetFormatRetrieved")
        mock_retrieve_image.return_value = uforge.Image()
        mock_retrieve_publish_image.return_value = uforge.PublishImageVSphere()
        mock_retrieve_account.return_value = uforge.CredAccountVSphere()
        migration_to_create = uforge.migration()
        mock_create_migration.return_value = migration_to_create
        mock_upload_and_launch_migration_binary.return_value(0)

        # when
        m.do_launch("--file config.json")

        # then
        self.assertEquals(mock_api_create.call_count, 1)
        self.assertEquals(mock_download_binary.call_count, 1)
        self.assertEquals(mock_upload_and_launch_migration_binary.call_count, 1)
        self.assertEquals(mock_rmtree.call_count, 1)
        mock_out.assert_called_with("Migration launched successfully, please go to the platform to follow steps of the migration.", "OK")
Пример #4
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
Пример #5
0
def retrieve_image(builder, target_format, api, login):
    image_format_name = target_format.format.name
    check_mandatory_installation(image_format_name, builder)
    create_image_method = getattr(generate_utils, "generate_" + generics_utils.remove_special_chars(image_format_name), None)
    if create_image_method:
        install_profile = uforge.installProfile()
        install_profile.diskSize = 0
        image, install_profile = create_image_method(uforge.Image(), builder, install_profile, api, login)
        install_profile = set_install_profile_disk_size(install_profile, builder, image_format_name)
        image.installProfile = install_profile
        return image

    raise Exception("TargetFormat type is unsupported: " + target_format.format.name)