def test_confkeys_exist(self): """Check if keys exist.""" try: Conf.load(index, test_backend_url) ConfKeysV().validate('exists', index, ['bridge', 'bridge>name']) except Exception as e: self.fail(f"Unexpected exception: {e}")
def _get_kafka_server_list(conf_url): """ Reads the ConfStore and derives keys related to message bus """ from cortx.utils.conf_store import Conf Conf.load("cluster_config", conf_url) keylist = ["cortx>software>common>message_bus_type", "cortx>software>kafka>servers"] ConfKeysV().validate("exists", "cluster_config", keylist) msg_bus_type = Conf.get("cluster_config", \ "cortx>software>common>message_bus_type") if msg_bus_type != "kafka": raise SetupError(errno.EINVAL, \ "Message Bus do not support type %s" % msg_bus_type) # Read the required keys all_servers = Conf.get("cluster_config", \ "cortx>software>kafka>servers") no_servers = len(all_servers) kafka_server_list = [] port_list = [] for i in range(no_servers): # check if port is mentioned rc = all_servers[i].find(':') if rc == -1: port_list.append("9092") kafka_server_list.append(all_servers[i]) else: port_list.append(all_servers[i][rc + 1:]) kafka_server_list.append(all_servers[i][:rc]) if len(kafka_server_list) == 0: raise SetupError(errno.EINVAL, \ "No valid Kafka server info provided for Config Key \ 'cortx>software>kafka>servers' ") return kafka_server_list, port_list
def _get_kafka_server_list(conf_url: str): """ Reads the ConfStore and derives keys related to message bus """ Conf.load('cluster_config', conf_url) key_list = ['cortx>software>common>message_bus_type', \ 'cortx>software>kafka>servers'] ConfKeysV().validate('exists', 'cluster_config', key_list) msg_bus_type = Conf.get('cluster_config', key_list[0]) if msg_bus_type != 'kafka': raise SetupError(errno.EINVAL, "Message Bus do not support type \ %s", msg_bus_type) # Read the required keys all_servers = Conf.get('cluster_config', key_list[1]) no_servers = len(all_servers) kafka_server_list = [] port_list = [] for i in range(no_servers): # check if port is mentioned rc = all_servers[i].find(':') if rc == -1: port_list.append('9092') kafka_server_list.append(all_servers[i]) else: port_list.append(all_servers[i][rc + 1:]) kafka_server_list.append(all_servers[i][:rc]) if len(kafka_server_list) == 0: raise SetupError(errno.EINVAL, "No valid Kafka server info \ provided for config key: %s", key_list[1]) return kafka_server_list, port_list
def test_confkeys_not_exist(self): """Check if keys not exist.""" try: ConfKeysV().validate('exists', index, ['bridge', 'bridge>port_no']) except Exception as e: if "key missing" not in f"{e}": raise Exception(f"Unexpected exception: {e}") return self.fail("Unexpected test pass, this key should not be found.")
def _get_server_info(conf_url: str, machine_id: str) -> dict: """ Reads the ConfStore and derives keys related to Event Message """ Conf.load('server_info', conf_url) key_list = [f'server_node>{machine_id}'] ConfKeysV().validate('exists', 'server_info', key_list) server_info = Conf.get('server_info', key_list[0]) return server_info
def _get_server_info(conf_url_index: str, machine_id: str) -> dict: """Reads the ConfStore and derives keys related to Event Message. Args: conf_url_index (str): Index for loaded conf_url machine_id (str): Machine_id Returns: dict: Server Information """ key_list = [f'server_node>{machine_id}'] ConfKeysV().validate('exists', conf_url_index, key_list) server_info = Conf.get(conf_url_index, key_list[0]) return server_info
def get_server_list(cluster_conf_index: str) -> tuple: """Fetches info of nodes in cluster from passed template file. Args: cluster_conf_index (str): index for loaded input template file Raises: SetupError: if message bus type not kafka or missing required keys Returns: tuple: ([server_list], [port_list]) """ key_list = ['cortx>software>common>message_bus_type', \ 'cortx>software>kafka>servers'] ConfKeysV().validate('exists', cluster_conf_index, key_list) msg_bus_type = Conf.get(cluster_conf_index, key_list[0]) if msg_bus_type != 'kafka': Log.error(f"Message bus type {msg_bus_type} is not supported") raise SetupError(errno.EINVAL, \ "Message bus type %s is not supported", msg_bus_type) all_servers = Conf.get(cluster_conf_index, key_list[1]) message_server_list = [] port_list = [] for server in all_servers: # Value of server can be <server_fqdn:port> or <server_fqdn> if ':' in server: server_fqdn, port = server.split(':') message_server_list.append(server_fqdn) port_list.append(port) else: message_server_list.append(server) port_list.append('9092') # 90992 is default kafka server port if not message_server_list: Log.error(f"Missing config entry {key_list} in input file") raise SetupError(errno.EINVAL, \ "Missing config entry %s in config", key_list) # Read the default config config_file_path = '/etc/cortx/cortx.conf' Conf.load('mb_config', f'yaml:///{config_file_path}') config = Conf.get('mb_config', 'message_bus') return message_server_list, port_list, config
def post_install(post_install_template: str): """ Performs post install operations """ # check whether zookeeper and kafka are running ServiceV().validate('isrunning', ['kafka-zookeeper.service', \ 'kafka.service']) # Check required python packages install_path = Utils._get_from_conf_file('install_path') utils_path = install_path + '/cortx/utils' with open(f"{utils_path}/conf/python_requirements.txt") as file: req_pack = [] for package in file.readlines(): pack = package.strip().split('==') req_pack.append(f"{pack[0]} ({pack[1]})") try: with open(f"{utils_path}/conf/python_requirements.ext.txt" ) as extfile: for package in extfile.readlines(): pack = package.strip().split('==') req_pack.append(f"{pack[0]} ({pack[1]})") except Exception: Log.info("Not found: " + f"{utils_path}/conf/python_requirements.ext.txt") PkgV().validate(v_type='pip3s', args=req_pack) default_sb_path = '/var/log/cortx/support_bundle' Utils._set_to_conf_file('support>local_path', default_sb_path) os.makedirs(default_sb_path, exist_ok=True) post_install_template_index = 'post_install_index' Conf.load(post_install_template_index, post_install_template) machine_id = Conf.machine_id key_list = [ f'server_node>{machine_id}>hostname', f'server_node>{machine_id}>name' ] ConfKeysV().validate('exists', post_install_template_index, key_list) #set cluster nodename:hostname mapping to cluster.conf (needed for Support Bundle) Conf.load('cluster', 'json:///etc/cortx/cluster.conf', skip_reload=True) Utils._copy_cluster_map(post_install_template_index) return 0
def post_install(config_path: str): """Performs post install operations.""" default_sb_path = '/var/log/cortx/support_bundle' os.makedirs(default_sb_path, exist_ok=True) post_install_template_index = 'post_install_index' Conf.load(post_install_template_index, config_path) machine_id = Conf.machine_id key_list = [f'node>{machine_id}>hostname', f'node>{machine_id}>name'] ConfKeysV().validate('exists', post_install_template_index, key_list) #set cluster nodename:hostname mapping to cluster.conf (needed for Support Bundle) Utils._copy_cluster_map(config_path) Utils._copy_database_conf(config_path) return 0