コード例 #1
0
    def test_retrieve_migration_configuration_raise_exception_if_no_file_is_retrieved(self, mock_get_file):
        # given
        args_file = "file_no_present.json"
        mock_get_file.return_value = None

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.retrieve_migration_configuration(args_file)

        # then
        self.assertTrue("No such file or directory: " + args_file in e.exception)
コード例 #2
0
    def test_retrieve_migration_configuration_check_mandatory_migrate_if_file_contain_migration(self, mock_check_mandatory_migrate, mock_load_data, mock_get_file):
        # given
        args_file = "file_present.json"
        mock_get_file.return_value = "a file"
        data = self.get_migration_config()
        mock_load_data.return_value = data

        # when
        migration_utils.retrieve_migration_configuration(args_file)

        #  then
        mock_check_mandatory_migrate.assert_called_with(data["migration"])
コード例 #3
0
    def test_retrieve_migration_configuration_raise_exception_if_file_contain_no_migration(self, mock_load_data, mock_get_file):
        # given
        args_file = "file_present.json"
        mock_get_file.return_value = "a file"
        mock_load_data.return_value = self.get_migration_config(migration_key="noMigration")

        # when
        with self.assertRaises(Exception) as e:
            migration_utils.retrieve_migration_configuration(args_file)

        # then
        self.assertTrue("no migration section found" in e.exception)
コード例 #4
0
ファイル: migration.py プロジェクト: lqueiroga/hammr
    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
コード例 #5
0
ファイル: migration.py プロジェクト: paulcartier/hammr
    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