Example #1
0
 def _key_value_verify(self, key: str, phase: str):
     """Verify if there exists a corresponding value for given key."""
     value = Conf.get(self.index, key)
     if not value:
         Log.debug("Validation failed for %s in %s phase" % (key ,phase))
         raise Exception("Validation failed for %s in %s phase" % (key ,phase))
     else:
         if ((Conf.get(self.prov, 'CONFIG>OPENLDAP_BASE_DN') == key) and (not bool(re.match("^dc=[a-zA-Z0-9]+(,dc=[a-zA-Z0-9]+)+[a-zA-Z0-9]$", value)))):
             Log.debug("Validation failed for %s in %s phase" % (key ,phase))
             raise Exception("Validation failed for %s in %s phase" % (key ,phase))
         elif (key.endswith("hostname")):
             try:
                 NetworkV().validate('connectivity',[value])
             except Exception:
                 Log.debug("Validation failed for %s in %s phase" % (key,  phase))
                 raise Exception("Validation failed for %s in %s phase" % (key, phase))
         elif (key.endswith("server_nodes")):
             if isinstance(value, str):
                 value = literal_eval(value)
             for node_machine_id in value:
                 host_name = Conf.get(self.index, f'server_node>{node_machine_id}>hostname')
                 try:
                     NetworkV().validate('connectivity',[host_name])
                 except Exception:
                     Log.debug("Validation failed for %s in %s phase" % (key, phase))
                     raise Exception("Validation failed for %s in %s phase" % (key, phase))
 def validate(self):
     """Check for required packages are installed."""
     # RPM dependency
     rpm_deps = {"cortx-sspl-test": None}
     # python 3rd party package dependency
     pip3_3ps_packages_test = {"Flask": "1.1.1"}
     pkg_validator = PkgV()
     pkg_validator.validate_pip3_pkgs(host=socket.getfqdn(),
                                      pkgs=pip3_3ps_packages_test,
                                      skip_version_check=False)
     pkg_validator.validate_rpm_pkgs(host=socket.getfqdn(),
                                     pkgs=rpm_deps,
                                     skip_version_check=True)
     # Load global, sspl and test configs
     Conf.load(SSPL_CONFIG_INDEX, sspl_config_path)
     Conf.load(SSPL_TEST_CONFIG_INDEX, sspl_test_config_path)
     # Take copy of supplied config passed to sspl_test and load it
     with open(self.sspl_test_gc_copy_file, "w") as f:
         f.write("")
     self.sspl_test_gc_copy_url = "yaml://%s" % self.sspl_test_gc_copy_file
     Conf.load(SSPL_TEST_GLOBAL_CONFIG, self.sspl_test_gc_copy_url)
     Conf.load("global_config", self.sspl_test_gc_url)
     Conf.copy("global_config", SSPL_TEST_GLOBAL_CONFIG)
     # Validate input configs
     machine_id = Utility.get_machine_id()
     self.node_type = Conf.get(SSPL_TEST_GLOBAL_CONFIG,
                               "server_node>%s>type" % machine_id)
     enclosure_id = Conf.get(
         SSPL_TEST_GLOBAL_CONFIG,
         "server_node>%s>storage>enclosure_id" % machine_id)
     self.enclosure_type = Conf.get(
         SSPL_TEST_GLOBAL_CONFIG,
         "storage_enclosure>%s>type" % enclosure_id)
Example #3
0
 def test_conf_store_get_with_wrong_key(self):
     """Test by getting the invalid wrong key."""
     load_config('set_local_7', 'json:///tmp/file1.json')
     try:
         Conf.get('set_local_7', 'bridge>lte_type[2]>..>location')
     except Exception as err:
         self.assertEqual('Invalid key name ', err.desc)
Example #4
0
    def reset(config_path: str):
        """Remove/Delete all the data/logs that was created by user/testing."""
        from cortx.utils.message_bus.error import MessageBusError
        try:
            # use gconf to deregister IEM
            from cortx.utils.message_bus import MessageBusAdmin, MessageBus
            from cortx.utils.message_bus import MessageProducer
            Conf.load(GCONF_INDEX, config_path, skip_reload=True)
            message_bus_backend = Conf.get('config', MSG_BUS_BACKEND_KEY)
            message_server_endpoints = Conf.get('config',\
                f'{EXTERNAL_KEY}>{message_bus_backend}>endpoints')
            MessageBus.init(message_server_endpoints)
            mb = MessageBusAdmin(admin_id='reset')
            message_types_list = mb.list_message_types()
            if message_types_list:
                for message_type in message_types_list:
                    producer = MessageProducer(producer_id=message_type,\
                        message_type=message_type, method='sync')
                    producer.delete()

        except MessageBusError as e:
            raise SetupError(e.rc, "Can not reset Message Bus. %s", e)
        except Exception as e:
            raise SetupError(
                errors.ERR_OP_FAILED, "Internal error, can not \
                reset Message Bus. %s", e)
        return 0
Example #5
0
    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
Example #6
0
    def get_nodelist(self, fetch_from: str = None) -> list:
        """
        Get nodelist from provisioner or confstore

        Args:
            fetch_from (str): Options from where to fetch.

        Returns:
            list: List of nodes.
        """
        nodelist: list = []
        fetch_from = Cmd.HA_CONFSTORE if fetch_from is None else fetch_from
        if fetch_from == Cmd.HA_CONFSTORE:
            cluster_nodes = self._confstore.get(
                const.CLUSTER_CONFSTORE_NODES_KEY)
            if cluster_nodes is None:
                return nodelist
            for key in cluster_nodes:
                nodelist.append(key.split('/')[-1])
        elif fetch_from == Cmd.PROV_CONFSTORE:
            nodes_schema = Conf.get(self._index, "server_node")
            machine_ids: list = list(nodes_schema.keys())
            for machine in machine_ids:
                nodelist.append(
                    Conf.get(
                        self._index,
                        f"server_node.{machine}.network.data.private_fqdn"))
        else:
            raise SetupError(
                f"Failed to get nodelist, Invalid options {fetch_from}")
        Log.info(
            f"Found total Nodes: {len(nodelist)}, Nodes: {nodelist}, in {fetch_from}"
        )
        return nodelist
Example #7
0
def main(argv: list):
    try:
        if sys.argv[1] == "post_install":
            Conf.init(delim='.')
            Conf.load(const.HA_GLOBAL_INDEX,
                      f"yaml://{const.SOURCE_CONFIG_FILE}")
            log_path = Conf.get(const.HA_GLOBAL_INDEX, "LOG.path")
            log_level = Conf.get(const.HA_GLOBAL_INDEX, "LOG.level")
            Log.init(service_name='ha_setup',
                     log_path=log_path,
                     level=log_level)
        else:
            ConfigManager.init("ha_setup")

        desc = "HA Setup command"
        command = Cmd.get_command(desc, argv[1:])
        command.process()

        sys.stdout.write(
            f"Mini Provisioning {sys.argv[1]} configured successfully.\n")
    except Exception as err:
        Log.error("%s\n" % traceback.format_exc())
        sys.stderr.write(
            f"Setup command:{argv[1]} failed for cortx-ha. Error: {err}\n")
        return errno.EINVAL
Example #8
0
    def validate(self):
        if not self.args:
            raise SetupError(
                errno.EINVAL,
                "%s - Argument validation failure. Global config is needed",
                self.name)
        if (len(self.args) != 2) or (self.args[0] != "--config"):
            raise SetupError(errno.EINVAL,
                             "%s - Argument validation failure. Check Usage.",
                             self.name)
        global_config = self.args[1]
        Conf.load('global_config', global_config)

        role = Conf.get('global_config', 'release>setup')
        if not role:
            raise SetupError(errno.EINVAL, "%s - validation failure. %s",
                             self.name,
                             "Role not found in %s" % (global_config))
        from cortx.sspl.bin.sspl_constants import setups
        if role not in setups:
            raise SetupError(errno.EINVAL, "%s - validataion failure. %s",
                             self.name,
                             "Role %s is not supported. Check Usage" % role)

        product = Conf.get('global_config', 'release>product')
        if not product:
            raise SetupError(errno.EINVAL, "%s - validation failure. %s",
                             self.name,
                             "Product not found in %s" % (global_config))
Example #9
0
    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
Example #10
0
def configure_lnet(self):
    '''
       Get iface and /etc/modprobe.d/lnet.conf params from
       conf store. Configure lnet. Start lnet service
    '''
    try:
        iface = Conf.get(self._index,
        f'cluster>{self._server_id}')['network']['data']['private_interfaces']
        iface = iface[0]
    except:
        raise MotrError(errno.EINVAL, "private_interfaces[0] not found\n")

    sys.stdout.write(f"Validate private_interfaces[0]: {iface}\n")
    cmd = f"ip addr show {iface}"
    execute_command(self, cmd)

    try:
        iface_type = Conf.get(self._index,
            f'cluster>{self._server_id}')['network']['data']['interface_type']
    except:
        raise MotrError(errno.EINVAL, "interface_type not found\n")

    lnet_config = (f"options lnet networks={iface_type}({iface}) "
                  f"config_on_load=1  lnet_peer_discovery_disabled=1\n")
    sys.stdout.write(f"lnet config: {lnet_config}")

    with open(LNET_CONF_FILE, "w") as fp:
        fp.write(lnet_config)

    restart_services(self, ["lnet"])
Example #11
0
    def _register_for_resp(self):
        """
        Register to wait for a response to the sent request.
        """
        # Unique consumer_group for each actuator response
        self.consumer_group = self._uuid
        self.consumer_id = Conf.get(const.HA_GLOBAL_INDEX,
                                    f"ACTUATOR_MANAGER{_DELIM}consumer_id")
        self.resp_message_type = Conf.get(
            const.HA_GLOBAL_INDEX,
            f"ACTUATOR_MANAGER{_DELIM}resp_message_type")

        self.consumer = MessageBus.get_consumer(
            consumer_id=str(self.consumer_id),
            consumer_group=self.consumer_group,
            message_type=self.resp_message_type,
            callback=self.process_resp,
            offset="latest",
            timeout=ACTUATOR_MSG_WAIT_TIME)
        # Start the thread to listen to response
        self.consumer.start()

        Log.debug(
            f"Waiting to get response on message_type {self.resp_message_type}"
        )
    def get_config_entries(self):
        """Returns config that needs to add in elasticsearch.yml file."""
        # Read required config from provisioner config.
        srvnodes = []
        server_nodes_id = []
        machine_id = Conf.machine_id
        node_name = Conf.get(self.index, f'server_node>{machine_id}>name')
        # Total nodes in cluster.
        cluster_id = Conf.get(self.index,
                              f'server_node>{machine_id}>cluster_id')
        if cluster_id is None:
            raise ElasticsearchSetupError(errno.EINVAL, "cluster_id is none.")
        storage_set = Conf.get(self.index, f'cluster>{cluster_id}>storage_set')
        if storage_set:
            server_nodes_id = storage_set[0]["server_nodes"]
        if server_nodes_id:
            for machine_id in server_nodes_id:
                srvnodes.append(
                    Conf.get(self.index, f'server_node>{machine_id}>name'))

        # Config entries needs to add in elasticsearch.yml file.
        config_entries = [
            f"cluster.name: {self.elasticsearch_cluster_name}",
            f"node.name: {node_name}",
            f"network.bind_host: {['localhost', node_name]}",
            f"network.publish_host: {[node_name]}",
            f"discovery.seed_hosts: {srvnodes}",
            f"cluster.initial_master_nodes: {srvnodes}",
            f"http.port: {self.http_port}"
        ]
        return config_entries
Example #13
0
    def read_ldap_credentials(self):
        """Read ldap credentials (rootdn, sgiam) from the openldap_config file."""
        try:
            # Load the openldap config file
            index_id = 'openldap_config_file_read_index'
            Conf.load(index_id, f'yaml://{self.openldap_config_file}')

            # Read the cluster id from openldap_config file
            self.cluster_id = Conf.get(index_id, f'{self.cluster_id_key}')

            cipher_key = Cipher.generate_key(
                self.cluster_id,
                self.get_confkey('CONFSTORE_OPENLDAP_CONST_KEY'))

            # rootdn username/password
            self.ldap_root_user = Conf.get(index_id, f'{self.rootdn_user_key}')
            encrypted_rootdn_pass = Conf.get(index_id,
                                             f'{self.rootdn_pass_key}')
            if encrypted_rootdn_pass != None:
                self.rootdn_passwd = Cipher.decrypt(
                    cipher_key, bytes(str(encrypted_rootdn_pass), 'utf-8'))

        except Exception as e:
            Log.error(f'read ldap credentials failed, error: {e}')
            raise e
Example #14
0
    def __init__(self):
        """ Initialize a MessageBus and load its configurations """
        Conf.load('config_file', 'json:///etc/cortx/cortx.conf',
            skip_reload=True)

        # if Log.logger is already initialized by some parent process
        # the same file will be used to log all the messagebus related
        # logs, else standard message_bus.log will be used.
        if not Log.logger:
            log_level = Conf.get('config_file', 'utils>log_level', 'INFO')
            Log.init('message_bus', '/var/log/cortx/utils/message_bus', \
                level=log_level, backup_count=5, file_size_in_mb=5)

        try:
            Conf.load('message_bus', self.conf_file, skip_reload=True)
            self._broker_conf = Conf.get('message_bus', 'message_broker')
            broker_type = self._broker_conf['type']
            Log.info(f"MessageBus initialized as {broker_type}")
        except ConfError as e:
            Log.error(f"MessageBusError: {e.rc} Error while parsing" \
                f" configuration file {self.conf_file}. {e}.")
            raise MessageBusError(e.rc, "Error while parsing " + \
                "configuration file %s. %s.", self.conf_file, e)
        except Exception as e:
            Log.error(f"MessageBusError: {e.rc} Error while parsing" \
                f" configuration file {self.conf_file}. {e}.")
            raise MessageBusError(errno.ENOENT, "Error while parsing " + \
                "configuration file %s. %s.", self.conf_file, e)

        self._broker = MessageBrokerFactory.get_instance(broker_type, \
            self._broker_conf)
Example #15
0
def main():
    from cortx.utils.conf_store import Conf
    argv = sys.argv

    # Get the log path
    tmpl_file = argv[3]
    Conf.load(GCONF_INDEX, tmpl_file)
    log_dir = Conf.get(GCONF_INDEX, CLUSTER_CONF_LOG_KEY)
    utils_log_path = os.path.join(log_dir, f'utils/{Conf.machine_id}')

    # Get the log level
    log_level = Conf.get(GCONF_INDEX, 'utils>log_level', 'INFO')

    Log.init('utils_setup', utils_log_path, level=log_level, backup_count=5, \
        file_size_in_mb=5)
    try:
        desc = "CORTX Utils Setup command"
        Log.info(f"Starting utils_setup {argv[1]} ")
        command = Cmd.get_command(desc, argv[1:])
        rc = command.process()
    except SetupError as e:
        sys.stderr.write("error: %s\n\n" % str(e))
        sys.stderr.write("%s\n" % traceback.format_exc())
        Cmd.usage(argv[0])
        rc = e.rc
    except Exception as e:
        sys.stderr.write("error: %s\n\n" % str(e))
        sys.stderr.write("%s\n" % traceback.format_exc())
        rc = errno.EINVAL
    Log.info(f"Command {command} {argv[1]} finished with exit " \
        f"code {rc}")
Example #16
0
 def validate(self, phase: str):
     """Perform validations for phase."""
     try:
         Conf.load(phase, f'json://{self._preqs_conf_file}')
         prereqs_block = Conf.get(phase, f'{phase}')
         if prereqs_block:
             pip3s = Conf.get(phase, f'{phase}>pip3s')
             if pip3s:
                 PkgV().validate('pip3s', pip3s)
             rpms = Conf.get(phase, f'{phase}>rpms')
             if rpms:
                 PkgV().validate('rpms', rpms)
             services = Conf.get(phase, f'{phase}>services')
             if services:
                 for service in services:
                     pid = os.popen('pidof ' + service).read()
                     if pid is None:
                         Log.debug(
                             'Validation failed for service %s in %s phase'
                             % (service, phase))
                         raise Exception(
                             'Validation failed for service %s in %s phase'
                             % (service, phase))
             files = Conf.get(phase, f'{phase}>files')
             if files:
                 PathV().validate('exists', files)
         Log.debug("%s - pre-requisite validation complete" % phase)
     except Exception:
         Log.debug("%s - pre-requisite validation failed" % phase)
         raise Exception("prereqs validation failed")
     return 0
Example #17
0
    def cleanup(pre_factory: bool, config_path: str):
        """Remove/Delete all the data that was created after post install."""

        # delete message_types
        from cortx.utils.message_bus.error import MessageBusError
        try:
            # use gconf to clean and delete all message type in messagebus
            from cortx.utils.message_bus import MessageBus, MessageBusAdmin
            Conf.load(GCONF_INDEX, config_path, skip_reload=True)
            message_bus_backend = Conf.get(GCONF_INDEX, MSG_BUS_BACKEND_KEY)
            message_server_endpoints = Conf.get(GCONF_INDEX,\
                f'{EXTERNAL_KEY}>{message_bus_backend}>endpoints')
            MessageBus.init(message_server_endpoints)
            mb = MessageBusAdmin(admin_id='cleanup')
            message_types_list = mb.list_message_types()
            if message_types_list:
                mb.deregister_message_type(message_types_list)
        except MessageBusError as e:
            raise SetupError(e.rc, "Can not cleanup Message Bus. %s", e)
        except Exception as e:
            raise SetupError(
                errors.ERR_OP_FAILED, "Can not cleanup Message  \
                Bus. %s", e)

        return 0
Example #18
0
    def process(*args):
        """Process input parameters"""
        if len(args) < 2:
            raise CortxProvisionerError(
                errno.EINVAL, 'Please provide solution_config and conf_store '
                'url as input parameters.')
        elif len(args) >= 2:
            solution_conf_url = args[0]
            cortx_conf_url = args[1]

        ConfigValidator.load_config(solution_conf_url, cortx_conf_url)

        if Conf.get(ConfigValidator._solution_index, 'cluster') is not None:
            ConfigValidator()._check_storage_sets()
            ConfigValidator()._check_number_of_nodes()
            ConfigValidator()._validate_components()
        if Conf.get(ConfigValidator._solution_index, 'cortx') is not None:
            ConfigValidator()._check_external_services()

        # if cluster/cortx both keys are not present in file means file is
        # empty or file doesn't have required config.
        if (Conf.get(ConfigValidator._solution_index, 'cluster') is None and
                Conf.get(ConfigValidator._solution_index, 'cortx') is None):
            raise CortxProvisionerError(
                errno.EINVAL,
                'File is empty OR Cluster config and cortx config is not present in file.'
            )
Example #19
0
    def upgrade(config_path: str, change_set_path: str):
        """Perform upgrade steps."""

        Conf.load(DELTA_INDEX, change_set_path)
        Conf.load(GCONF_INDEX, config_path, skip_reload=True)
        delta_keys = Conf.get_keys(DELTA_INDEX)

        # if message_bus_backend changed, add new and delete old msg bus entries
        if CHANGED_PREFIX + MSG_BUS_BACKEND_KEY in delta_keys:
            new_msg_bus_backend = Conf.get(
                DELTA_INDEX,
                CHANGED_PREFIX + MSG_BUS_BACKEND_KEY).split('|')[1]
            Conf.set(GCONF_INDEX, MSG_BUS_BACKEND_KEY, new_msg_bus_backend)
            for key in delta_keys:
                if NEW_PREFIX + EXTERNAL_KEY + new_msg_bus_backend in key:
                    new_key = key.split(NEW_PREFIX)[1]
                    new_val = Conf.get(DELTA_INDEX, key).split('|')[1]
                    Conf.set(GCONF_INDEX, new_key, new_val)
                if DELETED_PREFIX + EXTERNAL_KEY + new_msg_bus_backend in key:
                    delete_key = key.split(DELETED_PREFIX)[1]
                    Conf.delete(GCONF_INDEX, delete_key)

        # update existing messagebus parameters
        else:
            msg_bus_backend = Conf.get(GCONF_INDEX, MSG_BUS_BACKEND_KEY)
            for key in delta_keys:
                if CHANGED_PREFIX + EXTERNAL_KEY + msg_bus_backend in key:
                    new_val = Conf.get(DELTA_INDEX, key).split('|')[1]
                    change_key = key.split(CHANGED_PREFIX)[1]
                    Conf.set(GCONF_INDEX, change_key, new_val)

        Conf.save(GCONF_INDEX)
        Utils.init(config_path)
        return 0
Example #20
0
 def _get_cluster_data(config_path):
     Conf.load('cluster_conf', config_path)
     message_bus_backend = Conf.get('cluster_conf',\
         'cortx>utils>message_bus_backend')
     message_server_endpoints = Conf.get('cluster_conf',\
         f'cortx>external>{message_bus_backend}>endpoints')
     cluster_id = Conf.get('cluster_conf', 'cluster>id')
     return message_server_endpoints, cluster_id
Example #21
0
 def test_conf_store_get_null_index(self):
     """Test by getting the null index key."""
     load_config('set_local_5', 'json:///tmp/file1.json')
     try:
         Conf.get('set_local_5', 'bridge>lte_type[]')
     except Exception as err:
         self.assertEqual('Invalid key index for the key lte_type',
                          err.desc)
Example #22
0
def update_sensor_info(config_index):

    key = 'monitor'

    sensors = dict()
    sensors["REALSTORSENSORS"] = "true"
    sensors["NODEHWSENSOR"] = "true"
    sensors["DISKMONITOR"] = "true"
    sensors["SERVICEMONITOR"] = "true"
    sensors["RAIDSENSOR"] = "true"
    sensors["SASPORTSENSOR"] = "true"
    sensors["MEMFAULTSENSOR"] = "true"
    sensors["CPUFAULTSENSOR"] = "true"

    try:
        with open("/etc/machine-id") as f:
            machine_id = f.read().strip("\n")
    except Exception as err:
        raise SetupError(1, "Failed to get machine-id. - %s" % (err))

    srvnode = Conf.get(GLOBAL_CONFIG_INDEX,
                       "cluster>server_nodes>%s" % (machine_id))
    enclosure_id = Conf.get(GLOBAL_CONFIG_INDEX,
                            "cluster>%s>storage>enclosure_id" % (srvnode))
    node_key_id = Conf.get(GLOBAL_CONFIG_INDEX,
                           'cluster>server_nodes>%s' % (machine_id))

    storage_type = Conf.get(GLOBAL_CONFIG_INDEX,
                            'storage>%s>type' % enclosure_id)
    if storage_type and storage_type.lower() in ["virtual", "jbod"]:
        sensors["REALSTORSENSORS"] = "false"

    server_type = Conf.get(GLOBAL_CONFIG_INDEX,
                           'cluster>%s>node_type' % (node_key_id))
    if server_type and server_type.lower() in ["virtual"]:
        sensors["NODEHWSENSOR"] = "false"
        sensors["SASPORTSENSOR"] = "false"
        sensors["MEMFAULTSENSOR"] = "false"
        sensors["CPUFAULTSENSOR"] = "false"
        sensors["RAIDSENSOR"] = "false"

    # Onward LDR_R2, consul will be abstracted out and it won't exit as hard dependeny of SSPL
    # Note: SSPL has backward compatibility to LDR_R1 and there consul is a dependency of SSPL.
    if SSPL_STORE_TYPE == "consul":
        host = os.getenv('CONSUL_HOST', CONSUL_HOST)
        port = os.getenv('CONSUL_PORT', CONSUL_PORT)
        try:
            consul_conn = consul.Consul(host=host, port=port)
            for sect, value in sensors.items():
                consul_conn.kv.put("sspl/config/%s/monitor" % sect, value)
        except Exception as cerror:
            print("Error in connecting with consul: {}".format(cerror))

    # Update sensor information in config
    for sect, value in sensors.items():
        Conf.set(config_index, '%s>%s' % (sect, key), value)

    Conf.save(config_index)
Example #23
0
 def __init__(self):
     """
     Init method.
     """
     super(ClusterResourceParser, self).__init__()
     self.cluster_id = Conf.get(const.HA_GLOBAL_INDEX, f"COMMON_CONFIG{_DELIM}cluster_id")
     self.site_id = Conf.get(const.HA_GLOBAL_INDEX, f"COMMON_CONFIG{_DELIM}site_id")
     self.rack_id = Conf.get(const.HA_GLOBAL_INDEX, f"COMMON_CONFIG{_DELIM}rack_id")
     Log.info("ClusterResource Parser is initialized ...")
Example #24
0
 def get_changed_keys(self):
     """Get flattened dict of {old_key:key_key}."""
     changed_keys = {}
     if Conf.get(NEW_CONF, CHANGED):
         for changed_key in Conf.get(NEW_CONF, CHANGED):
             changed_key_payload = KvPayload(changed_key)
             key = changed_key_payload.get_keys()[0]
             changed_keys[key] = changed_key_payload.get(key)
     return changed_keys
Example #25
0
    def _validate_provisioning_status(_conf_idx: str, node_id: str, apply_phase: str):
        """Validate provisioning."""
        ret_code = 0
        recent_phase = Conf.get(_conf_idx, f'node>{node_id}>provisioning>phase')
        recent_status = Conf.get(_conf_idx, f'node>{node_id}>provisioning>status')
        msg = f'Recent phase for this node is {recent_phase} and ' + \
                f'recent status is {recent_status}. '
        # {apply_phase: {recent_phase: {recent_status: [boolean_result,rc]}}}
        validations_checks = {
            ProvisionerStages.DEPLOYMENT.value: {
                ProvisionerStages.DEPLOYMENT.value: {
                    ProvisionerStatus.DEFAULT.value: [True, 0],
                    ProvisionerStatus.ERROR.value: [True, 0],
                    ProvisionerStatus.PROGRESS.value: [True, 0],
                    ProvisionerStatus.SUCCESS.value: [False, 0]
                },
                ProvisionerStages.UPGRADE.value: {
                    ProvisionerStatus.DEFAULT.value: [True, 0],
                    ProvisionerStatus.ERROR.value: [True, 0],
                    ProvisionerStatus.PROGRESS.value: [True, 0],
                    ProvisionerStatus.SUCCESS.value: [True, 0]
                }},
            ProvisionerStages.UPGRADE.value: {
                ProvisionerStages.DEPLOYMENT.value: {
                    ProvisionerStatus.DEFAULT.value: [False, 1],
                    ProvisionerStatus.ERROR.value: [False, 1],
                    ProvisionerStatus.PROGRESS.value: [False, 1],
                    ProvisionerStatus.SUCCESS.value: [True, 0]
                },
                ProvisionerStages.UPGRADE.value: {
                    ProvisionerStatus.DEFAULT.value: [True, 0],
                    ProvisionerStatus.ERROR.value: [True, 0],
                    ProvisionerStatus.PROGRESS.value: [True, 0],
                    ProvisionerStatus.SUCCESS.value: [True, 0]
                }
            }}
        if recent_phase is None and recent_status is None:
            Log.info(msg + f'Performing {apply_phase} on this node.')
            return True, ret_code

        if (not validations_checks.get(apply_phase) or
            not validations_checks.get(apply_phase).get(recent_phase) or
            not validations_checks.get(apply_phase).get(recent_phase).get(recent_status)):
            Log.error('Invalid phase or status.')
            ret_code = 1
            return False, ret_code

        validate_result = validations_checks.get(apply_phase).get(recent_phase).get(recent_status)
        if validate_result[1] != 0:
            Log.error(msg + f'{apply_phase} is not possible on this node.')
            if apply_phase == ProvisionerStages.UPGRADE.value:
                # Reset status.
                recent_status = Conf.set(_conf_idx, f'node>{node_id}>provisioning>status',
                    ProvisionerStatus.DEFAULT.value)
        else:
            Log.info(msg)
        return validate_result[0], validate_result[1]
Example #26
0
 def __init__(self):
     """Init method for sspl setup config."""
     self._script_dir = os.path.dirname(os.path.abspath(__file__))
     # Load sspl and global configs
     Conf.load(consts.SSPL_CONFIG_INDEX, consts.sspl_config_path)
     global_config_url = Conf.get(
         consts.SSPL_CONFIG_INDEX, "SYSTEM_INFORMATION>global_config_copy_url")
     Conf.load(consts.GLOBAL_CONFIG_INDEX, global_config_url)
     self.product = Conf.get(consts.GLOBAL_CONFIG_INDEX, 'release>product')
def update_sensor_info():

    key = 'monitor'

    sensors = dict()
    sensors["REALSTORSENSORS"] = "true"
    sensors["NODEHWSENSOR"] = "true"
    sensors["SYSTEMDWATCHDOG"] = "true"
    sensors["RAIDSENSOR"] = "true"
    sensors["SASPORTSENSOR"] = "true"
    sensors["MEMFAULTSENSOR"] = "true"
    sensors["CPUFAULTSENSOR"] = "true"

    try:
        with open("/etc/machine-id") as f:
            node_key_id = f.read().strip("\n")
    except Exception as err:
        print("Failed to get machine-id. - %s" % (err))

    storage_type = Conf.get('global_config', 'storage>enclosure_1>type')
    if storage_type and storage_type.lower() in ["virtual", "jbod"]:
        sensors["REALSTORSENSORS"] = "false"

    server_type = Conf.get('global_config',
                           'cluster>%s>node_type' % (node_key_id))
    if server_type and server_type.lower() in ["virtual"]:
        sensors["NODEHWSENSOR"] = "false"
        sensors["SASPORTSENSOR"] = "false"
        sensors["MEMFAULTSENSOR"] = "false"
        sensors["CPUFAULTSENSOR"] = "false"
        sensors["RAIDSENSOR"] = "false"

    for sect, value in sensors.items():
        Conf.set('sspl', '%s>%s' % (sect, key), value)

    Conf.save('sspl')

    # Onward LDR_R2, consul will be abstracted out and it won't exit as hard dependeny of SSPL
    # Note: SSPL has backward compatibility to LDR_R1 and there consul is a dependency of SSPL.
    if SSPL_STORE_TYPE == "consul":
        host = os.getenv('CONSUL_HOST', CONSUL_HOST)
        port = os.getenv('CONSUL_PORT', CONSUL_PORT)
        try:
            consul_conn = consul.Consul(host=host, port=port)
            for sect, value in sensors.items():
                consul_conn.kv.put("sspl/config/%s/monitor" % sect, value)
        except Exception as cerror:
            print("Error in connecting with consul: {}".format(cerror))

    # Update sensor information for sspl_test
    test_file_config_path = "/opt/seagate/%s/sspl/sspl_test/conf/sspl_tests.conf" % PRODUCT_FAMILY
    Conf.load('sspl_test', 'yaml://%s' % test_file_config_path)
    for sect, value in sensors.items():
        Conf.set('sspl_test', '%s>%s' % (sect, key), value)

    Conf.save('sspl_test')
Example #28
0
 def __init__(self):
     """initial variables and ConfStor setup."""
     self.role = None
     self.dp = True
     # Load sspl and global configs
     Conf.load(SSPL_CONFIG_INDEX, sspl_config_path)
     global_config_url = Conf.get(
         SSPL_CONFIG_INDEX, "SYSTEM_INFORMATION>global_config_copy_url")
     Conf.load(GLOBAL_CONFIG_INDEX, global_config_url)
     self.role = Conf.get(GLOBAL_CONFIG_INDEX, 'release>setup')
Example #29
0
 def test_json_message_kv_store(self):
     """Tests jsonmessage basic operation."""
     index = 'json_message_kv_store_index'
     Conf.load(index, 'jsonmessage:{"key1":"val1"}')
     self.assertEqual(Conf.get(index, 'key1'), 'val1')
     Conf.set(index, 'key2', 'val2')
     self.assertEqual(Conf.get_keys(index), ['key1', 'key2'])
     Conf.set(index, 'key2>key3>key4', 'val4')
     Conf.delete(index, 'key2>key3>key4')
     self.assertEqual(Conf.get(index, 'key2>key3>key4'), None)
Example #30
0
 def setUpClass(cls,
                cluster_conf_path: str = 'yaml:///etc/cortx/cluster.conf'):
     if TestMessage._cluster_conf_path:
         cls.cluster_conf_path = TestMessage._cluster_conf_path
     else:
         cls.cluster_conf_path = cluster_conf_path
     Conf.load('config', cls.cluster_conf_path, skip_reload=True)
     TestMessage._cluster_id = Conf.get('config', 'cluster>id')
     TestMessage._message_server_endpoints = Conf.get('config',\
         'cortx>external>kafka>endpoints')