def create_directories_and_ownership(self): """Create ras persistent cache directory and state file. Assign ownership recursively on the configured directory. The created state file will be used later by SSPL resourse agent(HA). """ # Extract the data path sspldp = Utility.get_config_value(consts.SSPL_CONFIG_INDEX, "SYSTEM_INFORMATION>data_path") if not sspldp: raise SetupError(errno.EINVAL, "Data path not set in sspl.conf") sspl_uid = Utility.get_uid(consts.USER) sspl_gid = Utility.get_gid(consts.USER) if sspl_uid == -1 or sspl_gid == -1: msg = "No user found with name : %s" % (consts.USER) logger.error(msg) raise SetupError(errno.EINVAL, msg) # Create sspl data directory if not exists os.makedirs(sspldp, exist_ok=True) # Create state file under sspl data directory if not os.path.exists(self.state_file): file = open(self.state_file, "w") file.close() # Create SSPL log and bundle directories os.makedirs(consts.SSPL_LOG_PATH, exist_ok=True) os.makedirs(consts.SSPL_BUNDLE_PATH, exist_ok=True) # set ownership for SSPL dirs list_root_dir = [consts.SSPL_CONFIGURED_DIR, consts.SSPL_LOG_PATH] Utility.set_ownership_recursively(list_root_dir, sspl_uid, sspl_gid) # Create /tmp/dcs/hpi if required. Not required for '<product>' role if self.setup != "cortx": os.makedirs(consts.HPI_PATH, mode=0o777, exist_ok=True) zabbix_uid = Utility.get_uid("zabbix") if zabbix_uid != -1: os.chown(consts.HPI_PATH, zabbix_uid, -1) # Create mdadm.conf to set ACL on it. with open(consts.MDADM_PATH, 'a'): os.utime(consts.MDADM_PATH) os.chmod(consts.MDADM_PATH, mode=0o666) os.chown(consts.MDADM_PATH, sspl_uid, -1)
def validate_user_existence(self): max_retry = 3 for i in range(max_retry): sspl_uid = Utility.get_uid(consts.USER) if sspl_uid != -1: break else: if i == (max_retry - 1): msg = "No user found with name : %s" % (consts.USER) logger.error(msg) raise SetupError(errno.EINVAL, msg) time.sleep(1)
def process(self): """Configure sensor monitoring and log level setting.""" # Update sspl.conf with provisioner supplied input config copy Conf.set(consts.SSPL_CONFIG_INDEX, "SYSTEM_INFORMATION>global_config_copy_url", consts.global_config_path) Conf.save(consts.SSPL_CONFIG_INDEX) if os.path.isfile(consts.SSPL_CONFIGURED): os.remove(consts.SSPL_CONFIGURED) os.makedirs(consts.SSPL_CONFIGURED_DIR, exist_ok=True) with open(consts.SSPL_CONFIGURED, 'a'): os.utime(consts.SSPL_CONFIGURED) sspl_uid = Utility.get_uid(consts.USER) sspl_gid = Utility.get_gid(consts.USER) Utility.set_ownership_recursively([consts.SSPL_CONFIGURED], sspl_uid, sspl_gid) # Get the types of server and storage we are currently running on and # enable/disable sensor groups in the conf file accordingly. update_sensor_info(consts.SSPL_CONFIG_INDEX, self.node_type, self.enclosure_type) # Message bus topic creation self.create_message_types() # Skip this step if sspl is being configured for node replacement # scenario as consul data is already # available on healthy node # Updating build requested log level if not os.path.exists(consts.REPLACEMENT_NODE_ENV_VAR_FILE): with open(f"{consts.SSPL_BASE_DIR}/low-level/files/opt/seagate" + \ "/sspl/conf/build-requested-loglevel") as f: log_level = f.read().strip() if not log_level: log_level = "INFO" if log_level in ["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"]: Conf.set(consts.SSPL_CONFIG_INDEX, "SYSTEM_INFORMATION>log_level", log_level) Conf.save(consts.SSPL_CONFIG_INDEX) else: msg = "Unexpected log level is requested, '%s'" % (log_level) logger.error(msg) raise SetupError(errno.EINVAL, msg)
def validate(self): """Check for below requirement. 1. Validate if sspl-ll user exists 2. Validate input keys """ # Check sspl-ll user exists sspl_uid = Utility.get_uid(self.user) if sspl_uid == -1: msg = "User %s doesn't exist. Please add user." % self.user logger.error(msg) raise SetupError(errno.EINVAL, msg) # Check input/provisioner configs machine_id = Utility.get_machine_id() cluster_id = Utility.get_config_value( consts.PRVSNR_CONFIG_INDEX, "server_node>%s>cluster_id" % machine_id) Utility.get_config_value(consts.PRVSNR_CONFIG_INDEX, "cluster>%s>name" % cluster_id) Utility.get_config_value(consts.PRVSNR_CONFIG_INDEX, "cluster>%s>site_count" % cluster_id) storage_set_count = int( Utility.get_config_value( consts.PRVSNR_CONFIG_INDEX, "cluster>%s>site>storage_set_count" % cluster_id)) for i in range(storage_set_count): Utility.get_config_value( consts.PRVSNR_CONFIG_INDEX, "cluster>%s>storage_set[%s]>name" % (cluster_id, i)) Utility.get_config_value( consts.PRVSNR_CONFIG_INDEX, "cluster>%s>storage_set[%s]>server_nodes" % (cluster_id, i)) Utility.get_config_value( consts.PRVSNR_CONFIG_INDEX, "cluster>%s>storage_set[%s]>storage_enclosures" % (cluster_id, i))