Пример #1
0
def restart_test_instance(_instance_id, _port, _profile, response_encoder, configurations):
    config_module = create_module_string(configurations,
                                         _port,
                                         get_base_url(_port),
                                         conf=CONF)
    config_file_path = get_config_file_path(_port, CONF.OPRP_DIR_PATH)
    try:
        write_config_file(config_file_path, config_module, _port, oprp_dir_path=CONF.OPRP_DIR_PATH)
        LOGGER.debug("Written configuration to file: %s" % config_file_path)
    except IOError as ioe:
        error_message = "write configurations file (%s) to disk." % config_file_path
        return handle_exception(ioe, response_encoder, failed_to_message=error_message)
    try:
        save_config_info_in_database(_port, configurations)
        LOGGER.debug(
            'Configurations for the test instance using instance ID '
            '"%s" which should be using port %s to has been saved in the database' % (
                _instance_id, _port))
    except Exception as ex:
        return handle_exception(ex, response_encoder,
                                failed_to_message="store configurations in database")
    try:
        kill_existing_process_on_port(_port, get_base_url(_port))
    except Exception as ex:
        return handle_exception(ex, response_encoder,
                                failed_to_message="restart existing test instance")
    config_file_name = os.path.basename(config_file_path)
    config_module = config_file_name.split(".")[0]
    start_rp_process(_port, [CONF.OPRP_PATH, "-p", _profile, "-t",
                             CONF.OPRP_TEST_FLOW, config_module], CONF.OPRP_DIR_PATH)
    return response_encoder.return_json(
        json.dumps({"oprp_url": str(get_base_url(_port))}))
Пример #2
0
def restart_test_instance(_instance_id, _port, _profile, response_encoder, configurations):
    config_module = create_module_string(configurations,
                                         _port,
                                         get_base_url(_port),
                                         conf=CONF)
    config_file_path = get_config_file_path(_port, CONF.OPRP_DIR_PATH)
    try:
        write_config_file(config_file_path, config_module, _port, oprp_dir_path=CONF.OPRP_DIR_PATH)
        LOGGER.debug("Written configuration to file: %s" % config_file_path)
    except IOError as ioe:
        error_message = "write configurations file (%s) to disk." % config_file_path
        return handle_exception(ioe, response_encoder, failed_to_message=error_message)
    try:
        save_config_info_in_database(_port, configurations)
        LOGGER.debug(
            'Configurations for the test instance using instance ID '
            '"%s" which should be using port %s to has been saved in the database' % (
                _instance_id, _port))
    except Exception as ex:
        return handle_exception(ex, response_encoder,
                                failed_to_message="store configurations in database")
    try:
        kill_existing_process_on_port(_port, get_base_url(_port))
    except Exception as ex:
        return handle_exception(ex, response_encoder,
                                failed_to_message="restart existing test instance")
    config_file_name = os.path.basename(config_file_path)
    config_module = config_file_name.split(".")[0]
    start_rp_process(_port, [CONF.OPRP_PATH, "-p", _profile, "-t",
                             CONF.OPRP_TEST_FLOW, config_module], CONF.OPRP_DIR_PATH)
    return response_encoder.return_json(
        json.dumps({"oprp_url": str(get_base_url(_port))}))
Пример #3
0
 def _restore_config_file(database, full_config_file_path, port):
     config_dict = database.get_row(port)[CONFIG_FILE_COLUMN]
     module_content = create_module_string(config_dict,
                                           port,
                                           config_dict['base_url'],
                                           ssl_module=OPRP_SSL_MODULE)
     with open(full_config_file_path, "w") as _file:
         _file.write(module_content)
Пример #4
0
 def _restore_config_file(database, full_config_file_path, port):
     config_dict = database.get_row_by_port(port)[CONFIG_FILE_COLUMN]
     module_content = create_module_string(config_dict,
                                           port,
                                           config_dict['base_url'],
                                           ssl_module=OPRP_SSL_MODULE)
     with open(full_config_file_path, "w") as _file:
         _file.write(module_content)
Пример #5
0
    def sync_database_information(self, database, module):
        try:
            file_config_info = self.get_config_file_dict(module)
        except Exception as ex:
            print(ex.message)
        else:
            port = self.get_port(module)
            issuer = self.get_issuer(file_config_info)
            instance_id = self.get_instance_id(file_config_info, port)
            port_type = self.get_port_type(file_config_info)

            try:
                database_config_info = database.get_row(
                    port)[CONFIG_FILE_COLUMN]
            except TypeError:
                database.upsert(port=port,
                                issuer=issuer,
                                instance_id=instance_id,
                                port_type=port_type,
                                config_file=file_config_info)
            else:
                if not database_config_info:
                    database.upsert(port=port,
                                    issuer=issuer,
                                    instance_id=instance_id,
                                    port_type=port_type,
                                    config_file=file_config_info)
                    database_config_info = file_config_info

                database_config_info_as_unicode = self.convert_dict_to_unicode(
                    database_config_info)
                file_config_info_as_unicode = self.convert_dict_to_unicode(
                    file_config_info)
                if database_config_info_as_unicode != file_config_info_as_unicode:
                    selected_config_version = self.prompt_user_for_selecting_db_or_file_config(
                        database_config_info_as_unicode,
                        file_config_info_as_unicode, module)
                    if selected_config_version == DATABASE_SELECTED:
                        module_content = create_module_string(
                            database_config_info,
                            port,
                            base_url=database_config_info['base_url'],
                            ssl_module=OPRP_SSL_MODULE)
                        with open(
                                get_config_file_path(port,
                                                     self.config_file_path),
                                "w") as _file:
                            _file.write(module_content)
                    elif selected_config_version == CONFIG_FILE_SELECTED:
                        database.upsert(port=port,
                                        issuer=issuer,
                                        instance_id=instance_id,
                                        port_type=port_type,
                                        config_file=file_config_info)
Пример #6
0
    def sync_database_information(self, database, module):
        try:
            file_config_info = self.get_config_file_dict(module)
        except Exception as ex:
            print(ex.message)
        else:
            port = self.get_port(module)
            issuer = self.get_issuer(file_config_info)
            instance_id = self.get_instance_id(file_config_info, port)
            port_type = self.get_port_type(file_config_info)

            try:
                database_config_info = database.get_row(port)[CONFIG_FILE_COLUMN]
            except TypeError:
                database.upsert(
                    port=port, issuer=issuer, instance_id=instance_id, port_type=port_type, config_file=file_config_info
                )
            else:
                if not database_config_info:
                    database.upsert(
                        port=port,
                        issuer=issuer,
                        instance_id=instance_id,
                        port_type=port_type,
                        config_file=file_config_info,
                    )
                    database_config_info = file_config_info

                database_config_info_as_unicode = self.convert_dict_to_unicode(database_config_info)
                file_config_info_as_unicode = self.convert_dict_to_unicode(file_config_info)
                if database_config_info_as_unicode != file_config_info_as_unicode:
                    selected_config_version = self.prompt_user_for_selecting_db_or_file_config(
                        database_config_info_as_unicode, file_config_info_as_unicode, module
                    )
                    if selected_config_version == DATABASE_SELECTED:
                        module_content = create_module_string(
                            database_config_info,
                            port,
                            base_url=database_config_info["base_url"],
                            ssl_module=OPRP_SSL_MODULE,
                        )
                        with open(get_config_file_path(port, self.config_file_path), "w") as _file:
                            _file.write(module_content)
                    elif selected_config_version == CONFIG_FILE_SELECTED:
                        database.upsert(
                            port=port,
                            issuer=issuer,
                            instance_id=instance_id,
                            port_type=port_type,
                            config_file=file_config_info,
                        )