示例#1
0
    def test_retrieve_target_format_raise_exception_when_the_target_format_not_found(self, mock_get_target_format_object):
        # given
        api = Api("url", username="******", password="******", headers=None,
                  disable_ssl_certificate_validation=False, timeout=constants.HTTP_TIMEOUT)
        mock_get_target_format_object.return_value = None

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.retrieve_target_format(api, "login", "targetFormatName")

        # then
        self.assertTrue("TargetFormat type unknown: targetFormatName" in e.exception)
示例#2
0
    def test_retrieve_target_format_return_the_target_format_found(self, mock_get_target_format_object):
        # given
        api = Api("url", username="******", password="******", headers=None,
                  disable_ssl_certificate_validation=False, timeout=constants.HTTP_TIMEOUT)
        target_format = uforge.TargetFormat()
        mock_get_target_format_object.return_value = target_format


        # when
        target_format_retrieved = migration_utils.retrieve_target_format(api, "login", "targetFormatName")

        # then
        self.assertEqual(target_format_retrieved, target_format)
示例#3
0
    def do_launch(self, args):
        try:
            # add arguments
            do_parser = self.arg_launch()
            do_args = do_parser.parse_args(shlex.split(args))

            # if the help command is called, parse_args returns None object
            if not do_args:
                return 2

            try:
                uforge_password = self.password
            except AttributeError:
                printer.out("Using API keys with command 'hammr migration launch' is not yet supported. Please use password.", printer.ERROR)
                return 2

            migration_config = migration_utils.retrieve_migration_configuration(do_args.file)
            target_format = migration_utils.retrieve_target_format(self.api, self.login, migration_config["target"]["builder"]["type"])
            image = migration_utils.retrieve_image(migration_config["target"]["builder"], target_format, self.api, self.login)
            if image is None:
                return 2
            cred_account = migration_utils.retrieve_account(self.api, self.login, migration_config["target"]["builder"]["account"]["name"])
            publish_image = migration_utils.build_publish_image(migration_config["target"]["builder"], target_format, cred_account)
            if publish_image is None:
                return 2

            migration = self.create_migration(migration_config["name"], migration_config["os"], target_format.name, image, publish_image)
            self.api.Users(self.login).Migrations.Create(body=migration, element_name="ns1:migration")

            local_uforge_migration_path = hammr_utils.download_binary_in_local_temp_dir(self.api, constants.TMP_WORKING_DIR, constants.URI_MIGRATION_BINARY, constants.MIGRATION_BINARY_NAME)

            self.upload_and_launch_migration_binary(self.login, uforge_password, migration_config, local_uforge_migration_path, self.api.getUrl())

            # delete temp dir
            shutil.rmtree(constants.TMP_WORKING_DIR)

            printer.out("Migration launched successfully, please go to the platform to follow steps of the migration.", printer.OK)

        except ArgumentParserError as e:
            printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
            self.help_launch()
        except Exception as e:
            if hammr_utils.is_uforge_exception(e):
                return hammr_utils.handle_uforge_exception(e)
            printer.out(str(e), printer.ERROR)

        return 0
示例#4
0
    def do_launch(self, args):
        try:
            # add arguments
            do_parser = self.arg_launch()
            do_args = do_parser.parse_args(shlex.split(args))

            # if the help command is called, parse_args returns None object
            if not do_args:
                return 2

            try:
                uforge_password = self.password
            except AttributeError:
                printer.out(
                    "Using API keys with command 'hammr migration launch' is not yet supported. Please use password.",
                    printer.ERROR)
                return 2

            migration_config = migration_utils.retrieve_migration_configuration(
                do_args.file)
            target_format = migration_utils.retrieve_target_format(
                self.api, self.login,
                migration_config["target"]["builder"]["type"])
            image = migration_utils.retrieve_image(
                migration_config["target"]["builder"], target_format, self.api,
                self.login)
            if image is None:
                return 2
            cred_account = migration_utils.retrieve_account(
                self.api, self.login,
                migration_config["target"]["builder"]["account"]["name"])
            publish_image = migration_utils.build_publish_image(
                migration_config["target"]["builder"], target_format,
                cred_account)
            if publish_image is None:
                return 2

            migration = self.create_migration(migration_config["name"],
                                              migration_config["os"],
                                              target_format.name, image,
                                              publish_image)
            self.api.Users(self.login).Migrations.Create(
                body=migration, element_name="ns1:migration")

            local_uforge_migration_path = hammr_utils.download_binary_in_local_temp_dir(
                self.api, constants.TMP_WORKING_DIR,
                constants.URI_MIGRATION_BINARY,
                constants.MIGRATION_BINARY_NAME)

            self.upload_and_launch_migration_binary(
                self.login, uforge_password, migration_config,
                local_uforge_migration_path, self.api.getUrl())

            # delete temp dir
            shutil.rmtree(constants.TMP_WORKING_DIR)

            printer.out(
                "Migration launched successfully, please go to the platform to follow steps of the migration.",
                printer.OK)

        except ArgumentParserError as e:
            printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
            self.help_launch()
        except Exception as e:
            if hammr_utils.is_uforge_exception(e):
                return hammr_utils.handle_uforge_exception(e)
            printer.out(str(e), printer.ERROR)

        return 0