def _create_test_config_file(self, base_dir_sys_path: str, **extra_conf_vals) -> str: """ Create a temporary conf file just for this test. :param base_dir_sys_path: Sys path of the base app dir :param extra_conf_vals: Optional; additional values to set in the conf file :return: The path to the conf file """ # Copy default conf file to tmp location self._conf_template_path = join(self._clusterrunner_repo_dir, 'conf', 'default_clusterrunner.conf') # Create the conf file inside base dir so we can clean up the test at the end just by removing the base dir test_conf_file_path = tempfile.NamedTemporaryFile( dir=base_dir_sys_path).name shutil.copy(self._conf_template_path, test_conf_file_path) os.chmod(test_conf_file_path, ConfigFile.CONFIG_FILE_MODE) conf_file = ConfigFile(test_conf_file_path) # Set custom conf file values for this test conf_values_to_set = { 'secret': Secret.get(), 'base_directory': base_dir_sys_path, 'max_log_file_size': 1024 * 5, 'database_name': TEST_DB_NAME, 'database_url': TEST_DB_URL } conf_values_to_set.update(extra_conf_vals) for conf_key, conf_value in conf_values_to_set.items(): conf_file.write_value(conf_key, conf_value, BASE_CONFIG_FILE_SECTION) return test_conf_file_path
def _create_test_config_file(self, base_dir_sys_path): """ Create a temporary conf file just for this test. :param base_dir_sys_path: Sys path of the base app dir :type base_dir_sys_path: unicode :return: The path to the conf file :rtype: str """ # Copy default conf file to tmp location self._conf_template_path = join(self._clusterrunner_repo_dir, 'conf', 'default_clusterrunner.conf') # Create the conf file inside base dir so we can clean up the test at the end just by removing the base dir test_conf_file_path = tempfile.NamedTemporaryFile(dir=base_dir_sys_path).name shutil.copy(self._conf_template_path, test_conf_file_path) os.chmod(test_conf_file_path, ConfigFile.CONFIG_FILE_MODE) conf_file = ConfigFile(test_conf_file_path) # Set custom conf file values for this test conf_values_to_set = { 'secret': Secret.get(), 'base_directory': base_dir_sys_path, 'max_log_file_size': 1024 * 5, } for conf_key, conf_value in conf_values_to_set.items(): conf_file.write_value(conf_key, conf_value, BASE_CONFIG_FILE_SECTION) return test_conf_file_path
def _set_secret(config_filename): if 'secret' in Configuration and Configuration['secret'] is not None: secret = Configuration['secret'] else: # No secret found, generate one and persist it secret = hashlib.sha512().hexdigest() conf_file = ConfigFile(config_filename) conf_file.write_value('secret', secret, BASE_CONFIG_FILE_SECTION) Secret.set(secret)
def _set_secret(config_filename): if 'secret' in Configuration and Configuration['secret'] is not None: secret = Configuration['secret'] else: # No secret found, generate one and persist it secret_length = 128 chars = string.ascii_lowercase + string.digits secret = ''.join(random.SystemRandom().choice(chars) for _ in range(secret_length)) conf_file = ConfigFile(config_filename) conf_file.write_value('secret', secret, BASE_CONFIG_FILE_SECTION) Secret.set(secret)
def _create_test_config_file(self, conf_values_to_set=None): """ Create a temporary conf file just for this test. :return: The path to the conf file :rtype: str """ # Copy default conf file to tmp location repo_dir = path.dirname(path.dirname(path.dirname(path.realpath(__file__)))) self._conf_template_path = path.join(repo_dir, 'conf', 'default_clusterrunner.conf') test_conf_file_path = tempfile.NamedTemporaryFile().name shutil.copy(self._conf_template_path, test_conf_file_path) os.chmod(test_conf_file_path, ConfigFile.CONFIG_FILE_MODE) conf_file = ConfigFile(test_conf_file_path) # Set custom conf file values for this test conf_values_to_set = conf_values_to_set or {} for conf_key, conf_value in conf_values_to_set.items(): conf_file.write_value(conf_key, conf_value, BASE_CONFIG_FILE_SECTION) return test_conf_file_path
def _create_test_config_file(self, conf_values_to_set=None): """ Create a temporary conf file just for this test. :return: The path to the conf file :rtype: str """ # Copy default conf file to tmp location repo_dir = path.dirname( path.dirname(path.dirname(path.dirname(path.realpath(__file__))))) self._conf_template_path = path.join(repo_dir, 'conf', 'default_clusterrunner.conf') test_conf_file_path = tempfile.NamedTemporaryFile().name shutil.copy(self._conf_template_path, test_conf_file_path) os.chmod(test_conf_file_path, ConfigFile.CONFIG_FILE_MODE) conf_file = ConfigFile(test_conf_file_path) # Set custom conf file values for this test conf_values_to_set = conf_values_to_set or {} for conf_key, conf_value in conf_values_to_set.items(): conf_file.write_value(conf_key, conf_value, BASE_CONFIG_FILE_SECTION) return test_conf_file_path