Пример #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 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)
Пример #4
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,
                        )
Пример #5
0
    def prompt_user_for_config_file_restoration(self, database, removed_config_file_ports):
        for port in removed_config_file_ports:
            full_config_file_path = get_config_file_path(port, self.config_file_path)

            msg = 'The configuration file: %s has been remove but could be restored from ' \
                  'the database. If not restored it will be removed permanently ' \
                  'from the database. Do you want to restore it?' % full_config_file_path

            user_input = raw_input("%s (y/N) " % msg).lower()

            if user_input == 'y':
                self._restore_config_file(database, full_config_file_path, port)
            elif user_input == 'n':
                database.remove_row(port)
            else:
                sys.stdout.write("\nPlease respond with 'Y' or 'N' \n\n")
                return self.prompt_user_for_config_file_restoration(database,
                                                                    removed_config_file_ports)
 def _create_config_files(self, folder, ports, file_content=""):
     for port in ports:
         config_file_name = get_config_file_path(port, folder)
         with open(config_file_name, "w") as _file:
             _file.write(file_content)
 def _remove_config_files(self, folder, ports):
     for port in ports:
         config_file_name = get_config_file_path(port, folder)
         os.remove(config_file_name)
 def _create_config_files(self, folder, ports, file_content=""):
     for port in ports:
         config_file_name = get_config_file_path(port, folder)
         with open(config_file_name, "w") as _file:
             _file.write(file_content)
 def _remove_config_files(self, folder, ports):
     for port in ports:
         config_file_name = get_config_file_path(port, folder)
         os.remove(config_file_name)