예제 #1
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))
예제 #2
0
 def validate(self):
     if not self.args:
         raise SetupError(
             1, "Validation failure. %s",
             "join_cluster requires comma separated node names as argument."
         )
     if (len(self.args) != 2) or (self.args[0] != "--nodes"):
         raise SetupError(1, "%s - Argument validation failure. %s",
                          self.name, "Check usage.")
예제 #3
0
 def validate(self):
     if not self.args:
         raise SetupError(1, "%s - Argument validation failure. %s",
                          self.name, "Post install requires global config.")
     if (len(self.args) != 2) or (self.args[0] != "--config"):
         raise SetupError(1, "%s - Argument validation failure. %s",
                          self.name, "Check usage.")
     global_config = self.args[1]
     Conf.load('global_config', global_config)
     product = Conf.get('global_config', 'release>product')
     if not product:
         raise SetupError(1, "%s - validation failure. %s", self.name,
                          "Product not found in %s" % (global_config))
예제 #4
0
 def process(self):
     args = ' '.join(self._args)
     sspl_bundle_generate = "%s/%s %s" % (self._script_dir, self.script,
                                          args)
     output, error, returncode = SimpleProcess(sspl_bundle_generate).run()
     if returncode != 0:
         raise SetupError(returncode, "%s - validation failure. %s",
                          self.name, error)
예제 #5
0
    def process(self):
        """Configure SSPL logs and service based on config."""
        PRODUCT_NAME = Conf.get('global_config', 'release>product')

        # Copy and load product specific sspl config
        if not os.path.exists(file_store_config_path):
            shutil.copyfile(
                "%s/conf/sspl.conf.%s.yaml" % (SSPL_BASE_DIR, PRODUCT_NAME),
                file_store_config_path)
        if not os.path.exists(sample_global_config):
            shutil.copyfile(
                "%s/conf/sample_global_cortx_config.yaml" % (SSPL_BASE_DIR),
                sample_global_config)
        Conf.load("sspl", "yaml://%s" % (file_store_config_path))

        environ = Conf.get("sspl", "SYSTEM_INFORMATION>environment")
        if environ == "DEV":
            self.ENVIRONMENT = environ

        # sspl_setup_consul script install consul in dev env and checks if consul process is running
        # on prod. For node replacement scenario consul will not be running on the new node. But,
        # there will be two instance of consul running on healthy node. When new node is configured
        # consul will be brought back on it. We are using VIP to connect to consul. So, if consul
        # is not running on new node, we dont need to error out. So, need to skip this step for
        # node replacement case
        # TODO: Need to avoid LDR in CORTX and check if we can use "CORTXr1"
        # Onward LR2, consul will be abstracted out and it won't exit as hard dependeny of SSPL
        if PRODUCT_NAME == "LDR_R1":
            # setup consul if not running already
            if not os.path.exists(REPLACEMENT_NODE_ENV_VAR_FILE):
                sspl_setup_consul = "%s/sspl_setup_consul -e %s" % (
                    self._script_dir, self.ENVIRONMENT)
                output, error, returncode = SimpleProcess(
                    sspl_setup_consul).run()
                if returncode != 0:
                    raise SetupError(returncode, error, sspl_setup_consul)

        # Install packages which are not available in YUM repo, from PIP
        pip_cmd = "python3 -m pip install -r %s/low-level/requirements.txt" % (
            SSPL_BASE_DIR)
        output, error, returncode = SimpleProcess(pip_cmd).run()
        if returncode != 0:
            raise SetupError(returncode, error, pip_cmd)
        # Splitting current function into 2 functions to reduce the complexity of the code.
        self.install_files(PRODUCT_NAME)
예제 #6
0
    def process(self):
        # stop sspl service
        Service('dbus').process('stop', 'sspl-ll.service')

        # Remove sspl_conf
        self.del_file(file_store_config_path)

        # Remove sspl-configured file
        self.del_file(SSPL_CONFIGURED)

        # Remove sspl data
        shutil.rmtree(DATA_PATH, ignore_errors=True)

        # Remove sspl-ll user if preset
        CMD = "id -u sspl-ll"
        output, error, returncode = SimpleProcess(CMD).run()
        if returncode != 0:
            raise SetupError(returncode, error + " CMD: %s", CMD)
        else:
            self.user_present=True

        if self.user_present:
            CMD="/usr/sbin/userdel sspl-ll"
            output, error, returncode = SimpleProcess(CMD).run()
            if returncode != 0:
                raise SetupError(returncode, error + " CMD: %s", CMD)

        # Remove log directories
        shutil.rmtree(f"/var/log/{PRODUCT_FAMILY}/sspl", ignore_errors=True)
        shutil.rmtree(f"/var/log/{PRODUCT_FAMILY}/iem", ignore_errors=True)

        # Remove rsyslog config files
        self.del_file("/etc/rsyslog.d/0-iemfwd.conf")
        self.del_file("/etc/rsyslog.d/1-ssplfwd.conf")

        # Remove logrotate config files
        self.del_file("/etc/logrotate.d/iem_messages")
        self.del_file("/etc/logrotate.d/sspl_logs")

        # Remove SSPL configuration files
        shutil.rmtree("/etc/sspl-ll", ignore_errors=True)
        self.del_file("/etc/sspl.conf.bak")
예제 #7
0
    def validate(self):
        if self.args:
            try:
                if "--config" in self.args:
                    conf_index = self.args.index("--config")
                    global_config = self.args[conf_index + 1]
                    # Provision for --config <global_config_url> for future use-case.
                    # Conf.load('global_config', global_config)
                if "--plan" in self.args:
                    plan_index = self.args.index("--plan")
                    if self.args[plan_index + 1] not in self.sspl_test_plans:
                        raise SetupError(
                            1,
                            "Invalid plan type specified. Please check usage")
            except Exception as ex:
                raise SetupError(1, "%s - validation failure. %s", self.name,
                                 str(ex))

        result = PkgV().validate("rpms", "sspl-test")
        if result == -1:
            raise SetupError(1, "'sspl-test' rpm pkg not found.")
 def _send_command(self, command, fail_on_error=True):
     """
     Execute command and retrun response
     Parameters:
         command: shell command to execute
         fail_on_error: Set to False will ignore command failure
     """
     print(f"Executing: {command}")
     output, error, returncode = SimpleProcess(command).run()
     if fail_on_error and returncode != 0:
         raise SetupError(returncode,
                          "ERROR: Command '%s' failed with error\n  %s",
                          command, error)
     return output.decode('utf-8')
예제 #9
0
    def validate(self):
        if self.args:
            try:
                if "--config" in self.args:
                    conf_index = self.args.index("--config")
                    global_config = self.args[conf_index + 1]
                    # Provision for --config <global_config_url> for future use-case.
                    # Conf.load('global_config', global_config)
                if "--type" in self.args:
                    type_index = self.args.index("--type")
                    if self.args[type_index + 1] not in ["hard", "soft"]:
                        raise SetupError(
                            1,
                            "Invalid reset type specified. Please check usage")
                else:
                    raise SetupError(
                        1, "SSPL Reset requires the type of reset(hard|soft).")
            except Exception as ex:
                raise SetupError(1, "%s - validation failure. %s", self.name,
                                 str(ex))
        else:
            raise SetupError(
                1, "%s - validation failure. %s", self.name,
                "SSPL Reset requires the type of reset(hard|soft).")

        for i in range(len(self.args)):
            try:
                if self.args[i] == "hard":
                    self.process_class = "HardReset"
                    break
                elif self.args[i] == "soft":
                    self.process_class = "SoftReset"
                    break
            except (IndexError, ValueError):
                raise SetupError(errno.EINVAL,
                                 "Invalid Argument for %s" % self.name)
예제 #10
0
 def process(self):
     # TODO: Need to convert run_tests.sh from shell to python
     test_plan = None
     sspl_test_plans = [
         "sanity", "alerts", "self_primary", "self_secondary"
     ]
     for i in range(len(self.args)):
         if self.args[i] in sspl_test_plans:
             test_plan = self.args[i]
     if test_plan is None:
         test_plan = "self_primary"
     CMD = f"{TEST_DIR}/run_tests.sh test {test_plan}"
     output, error, returncode = SimpleProcess(CMD).run(
         realtime_output=True)
     if returncode != 0:
         raise SetupError(returncode, error + " CMD: %s", CMD)
예제 #11
0
 def validate(self):
     # Common validator classes to check Cortx/system wide validator
     if not os.path.exists(self.SSPL_CONFIGURED):
         error = "SSPL is not configured. Run provisioner scripts in %s" % (
             self._script_dir)
         syslog.openlog(logoption=syslog.LOG_PID,
                        facility=syslog.LOG_LOCAL3)
         syslog.syslog(syslog.LOG_ERR, error)
         raise SetupError(1, "%s - validation failure. %s", self.name,
                          error)
     # Validate required services are running
     retry = 3
     while retry > 0:
         try:
             ServiceV().validate('isrunning', self.services)
         except VError:
             retry -= 1
             time.sleep(5)
         else:
             break
     ServiceV().validate('isrunning', self.services)
예제 #12
0
    def install_files(self, PRODUCT):
        """Configure required log files."""

        # Copy rsyslog configuration
        if not os.path.exists(self.RSYSLOG_CONF):
            shutil.copyfile(
                "%s/low-level/files/%s" % (SSPL_BASE_DIR, self.RSYSLOG_CONF),
                self.RSYSLOG_CONF)

        if not os.path.exists(self.RSYSLOG_SSPL_CONF):
            shutil.copyfile(
                "%s/low-level/files/%s" %
                (SSPL_BASE_DIR, self.RSYSLOG_SSPL_CONF),
                self.RSYSLOG_SSPL_CONF)

        # Create soft link for SINGLE product name service to existing LDR_R1, LR2 service
        # Instead of keeping separate service file for SINGLE product with same content.
        currentProduct = "%s/conf/sspl-ll.service.%s" % (SSPL_BASE_DIR,
                                                         PRODUCT)
        if (PRODUCT == "SINGLE" and not os.path.exists(currentProduct)) or \
                (PRODUCT == "DUAL" and not os.path.exists(currentProduct)):
            os.symlink("%s/conf/sspl-ll.service.%s" % (SSPL_BASE_DIR, PRODUCT),
                       currentProduct)

        if PRODUCT == "CLUSTER" and not os.path.exists(currentProduct):
            os.symlink("%s/conf/sspl-ll.service.LR2" % (SSPL_BASE_DIR),
                       currentProduct)

        # Copy sspl-ll.service file and enable service
        shutil.copyfile(currentProduct, "/etc/systemd/system/sspl-ll.service")
        Service('dbus').process('enable', 'sspl-ll.service')
        daemon_reload_cmd = "systemctl daemon-reload"
        output, error, returncode = SimpleProcess(daemon_reload_cmd).run()
        if returncode != 0:
            raise SetupError(returncode, error, daemon_reload_cmd)

        # Copy IEC mapping files
        os.makedirs("%s/iem/iec_mapping" % (PRODUCT_BASE_DIR), exist_ok=True)
        distutils.dir_util.copy_tree(
            "%s/low-level/files/iec_mapping/" % (SSPL_BASE_DIR),
            "%s/iem/iec_mapping" % (PRODUCT_BASE_DIR))

        # Skip this step if sspl is being configured for node replacement scenario as sspl configurations are
        # already available in consul on the healthy node
        # Running script for fetching the config using salt and feeding values to consul
        # Onward LR2, consul will be abstracted out and it won't exit as hard dependeny of SSPL
        if PRODUCT == "LDR_R1":
            if not os.path.exists(REPLACEMENT_NODE_ENV_VAR_FILE):
                config_from_salt = "%s/sspl_fetch_config_from_salt.py %s %s" % (
                    self._script_dir, self.ENVIRONMENT, PRODUCT)
                output, error, returncode = SimpleProcess(
                    config_from_salt).run()
                if returncode != 0:
                    raise SetupError(returncode, error, config_from_salt)

        # Skip this step if sspl is being configured for node replacement scenario as rabbitmq cluster is
        # already configured on the healthy node
        # Configure rabbitmq
        if not os.path.exists(REPLACEMENT_NODE_ENV_VAR_FILE):
            setup_rmq = Conf.get("sspl", "RABBITMQCLUSTER>setup_rmq")
            if setup_rmq:
                Service('dbus').process('start', 'rabbitmq-server.service')
                sspl_rabbitmq_reinit.main(PRODUCT)