def validate_ceph_crush_map_from_backend(self, *args, **kwargs):
        banner("CLI.Validate CEPH Crush Map From Backend")
        self._load_kwargs(kwargs)
        try:
            print("Kwargs are: {}".format(kwargs))
            cmd = "sudo ceph osd tree|awk '/region|zone|datacenter|rack|host/ {print $4}'"
            status = cli_run(cmd=cmd,
                             host_ip=self.hostip,
                             linux_user=self.user,
                             linux_password=self.password)
            print("cmd: {} executed successfully and status is: {}".format(
                cmd, status))
            serialised_status = self._serialize_response(time.time(), status)

            cmd_output = str(serialised_status['Result']['stdout']).replace(
                '\n', '').strip()
            trace("Command output is:{}".format(cmd_output))
            validation_status = []
            for node_name, location in ast.literal_eval(
                    self.node_location).items():
                if node_name.lower() in cmd_output:
                    validation_status.append("OK")
                else:
                    validation_status.append(
                        "{} not present in from_backend".format(node_name))
                for loc in location:
                    if loc.lower() in cmd_output:
                        validation_status.append("OK")
                    else:
                        validation_status.append(
                            "{} not present in backend for node:{}".format(
                                loc, node_name))

            trace("validation_status: {}".format(validation_status))
            result = len(validation_status) > 0 and all(
                elem == "OK" for elem in validation_status)
            if result:
                return "OK"
            else:
                return "Validation unsuccessful for CEPH crush map. Validation status is:{}".format(
                    validation_status)

        except Exception as e:
            trace(
                "Error in validate_ceph_crush_map_from_backend: {}".format(e))
Exemple #2
0
    def disable_firewall(self, *args, **kwargs):
        """
        Disable Firewall
        [Args]
            (str) host_ip:
            (str) linux_password:
            (str) linux_user:
        [Returns]
            (str) OK if command successful, stderr output if there's an error
        """
        self._load_kwargs(kwargs)
        print("kwargs" + str(kwargs))
        banner("CLI.Disable Firewall ip=%s" % self.host_ip)

        OS_type = self.get_OS_version(host_ip=self.host_ip,
                                      linux_user=self.linux_user,
                                      linux_password=self.linux_password)

        if re.search("Ubuntu", str(OS_type)) or re.search(
                "Debian", str(OS_type)):
            cmd = "sudo ufw disable"
            cmd_output = cli_run(cmd=cmd,
                                 host_ip=self.host_ip,
                                 linux_user=self.linux_user,
                                 linux_password=self.linux_password)
            print("Command: {} executed successfully and output is :{}".format(
                cmd, cmd_output))
            return "OK"

        elif re.search("Red Hat", str(OS_type)) or re.search(
                "CentOS", str(OS_type)):
            cmd1 = "sudo systemctl stop firewalld"
            cmd2 = "sudo systemctl disable firewalld"

            resp1 = cli_run(cmd1, self.host_ip, self.linux_user,
                            self.linux_password)
            resp2 = cli_run(cmd2, self.host_ip, self.linux_user,
                            self.linux_password)
            print("Command executed successfully and Response1 is " +
                  str(resp1))
            print("Command executed successfully and Response2 is " +
                  str(resp2))
            return "OK"
        else:
            return "OS type not specified"
Exemple #3
0
    def verify_k8s_be(self, *args, **kwargs):
        cmd = "sudo kubectl get nodes"
        banner("PCC.K8s Verify BE")
        self._load_kwargs(kwargs)
        print("Kwargs:" + str(kwargs))

        for ip in eval(str(self.nodes_ip)):
            output = cli_run(cmd=cmd,
                             host_ip=ip,
                             linux_user=self.user,
                             linux_password=self.password)
            print("Output:" + str(output))
            if re.search("Ready", str(output)):
                continue
            else:
                print("Could not verify K8s on " + str(ip))
                return "Error"
        return "OK"
Exemple #4
0
    def cli_copy_pcc_logs(self, *args, **kwargs):
        """
        CLI Copy+ PCC Logs
        [Args]
            (str) host_ip:
            (str) linux_password:
            (str) linux_user:
            (str) remote_source
            (str) local_destination

        [Returns]
            (str) OK if command successful, stderr output if there's an error
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("CLI.Copy PCC Logs ip=%s" % self.host_ip)
        return cli_copy_pcc_logs(self.host_ip, self.linux_user,
                                 self.linux_password)
    def get_sub_enclosure_slot_id(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Get Sub-Enclosure Slot Id")

        print("kwargs in get sub enclosure slot id :-  {}".format(str(kwargs)))
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        try:
            sub_enclosures = self.get_SAS_enclosures(
            )['Data'][0]['subenclosures'][0]['slots']

            for slots in sub_enclosures:
                if str(slots['deviceName']) == str(self.slot_name):
                    trace("Slot name found")
                    return slots['slotID']
            trace("Slot not found")
            return "Error: Slot_name not found"
        except Exception as e:
            return {'Error': str(e)}
    def validate_ethtool(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("CLI.Validate Ethtool")
        try:
            for host_ip in ast.literal_eval(self.host_ips):
                trace("Host IP:{}".format(host_ip))
                cmd = 'sudo ethtool --version'
                cmd_op = cli_run(host_ip, self.linux_user, self.linux_password,
                                 cmd)
                trace("Command output:{}".format(cmd_op))
                if re.search("ethtool version", str(cmd_op)):
                    return "OK"
                else:
                    return "Error: Ethtool Not Found"

        except Exception as e:
            print("Exception encountered: {}".format(e))
            return "Exception encountered: " + str(e)
Exemple #7
0
    def delete_all_erasure_pools(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Delete All Erasure Pool")

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        response = pcc.get_erasure_ceph_pools(conn)
        for data in get_response_data(response):
            response = pcc.delete_erasure_ceph_pool_by_id(
                conn, str(data['id']))
            status = self.wait_until_erasure_pool_deleted(id=data['id'])
            if status != "OK":
                print("{} deletion failed".format(data['name']))
                return "Error"
        return "OK"
Exemple #8
0
    def get_openssh_key_id(self, *args, **kwargs):
        """
        Get OpenSSH Key Id
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (str) Name: Name of the OpenSSH Key who's id is required (name=<Name>)
    
        [Returns]
            (int) Id: Id of the OpenSSH Key, or
                None: if no match found, or
            (dict) Error response: If Exception occured
        """

        banner("PCC.Get OpenSSH Key Id")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        return easy.get_openssh_keys_id_by_name(conn, self.Name)
    def get_CR_server_id(self, *args, **kwargs):
        """
        Get Server Id used by Container Registry
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (str) Name: Name of the Container Registry who's server id is required (name=<Name>)
    
        [Returns]
            (int) Id: Server Id of the Container Registry, or
                None: if no match found, or
            (dict) Error response: If Exception occured
        """

        banner("PCC.Get CR_Server Id")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        return easy.get_server_id_used_by_portus(conn, self.Name)
Exemple #10
0
    def check_snmp_services_backend(self, **kwargs):
        banner("PCC.Check SNMP from backend")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        cmd_snmp1 = "sudo systemctl status snmpd"
        cmd_snmp2 = "sudo netstat -anp | grep snmpd"
        cmd_snmp3 = "sudo ps aux | grep snmpd"

        success_chk = []
        failed_chk = []
        for ip in ast.literal_eval(self.targetNodeIp):
            snmp_check1 = cli_run(ip, self.user, self.password, cmd_snmp1)
            print("Command_1 is: {}".format(cmd_snmp1))
            print("=========== SNMP_Check1 output ==========\n{}".format(
                snmp_check1))
            snmp_check2 = cli_run(ip, self.user, self.password, cmd_snmp2)
            print("Command_2 is: {}".format(cmd_snmp2))
            print("=========== SNMP_Check2 output ==========\n{}".format(
                snmp_check2))
            snmp_check3 = cli_run(ip, self.user, self.password, cmd_snmp3)
            print("Command_3 is: {}".format(cmd_snmp3))
            print("=========== SNMP_Check3 output ==========\n{}".format(
                snmp_check3))
            if re.search("snmpd", str(snmp_check1)) and re.search(
                    "running", str(snmp_check1)) and re.search(
                        "CONNECTED", str(snmp_check2)) and re.search(
                            "snmpd", str(snmp_check3)):
                print("SNMP Found")
                success_chk.append(ip)

            else:
                failed_chk.append(ip)
        print("Success chk status is : {}".format(success_chk))
        print("Failed chk status is : {}".format(failed_chk))
        if len(success_chk) == len(ast.literal_eval(self.targetNodeIp)):
            print("Backend verification successfuly done for : {}".format(
                success_chk))
            return "OK"

        if failed_chk:
            print("SNMP service are down for {}".format(failed_chk))
            return "Error: SNMP service are down for {}".format(failed_chk)
        else:
            return "OK"
    def validate_rsyslog_backend(self, *args, **kwargs):
        """
        Validate rsyslog from backend
        [Args]
            (str) host_ip: Host IP of the server
            (str) client names
        [Returns]
            (str) Response: Output of check repo list command
        """
        self._load_kwargs(kwargs)
        banner("CLI.Validate Rsyslog from backend")
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
        try:
            validation_status = []
            for node_name in ast.literal_eval(self.node_names):
                print("Node name: {}".format(node_name))
                date_cmd_op = self._serialize_response(time.time(), cli_run(self.host_ip,self.linux_user,self.linux_password,cmd="date"))
                output = str(date_cmd_op['Result']['stdout']).replace('\n', '').strip()
                current_date = output[4:10]
                current_time = output[11:16]
                print("Current_date: {}".format(current_date))
                print("Current_time: {}".format(current_time))

                cmd = '''sudo cat /var/log/messages|grep "{}"|grep "{}"|grep "{}"|wc -l'''.format(current_date,current_time,node_name)  
                print("============== cmd is : {} ==========".format(cmd))
                cmd_op=cli_run(self.host_ip,self.linux_user,self.linux_password,cmd)
                serialised_output = self._serialize_response(time.time(), cmd_op)
                output = str(serialised_output['Result']['stdout']).replace('\n', '').strip()
                print("command output is :{}".format(output))
                if int(output)>0:
                    print("I am here inside if")
                    validation_status.append("OK")
                else:
                    validation_status.append("{}: Failed".format(node_name))
            result = len(validation_status) > 0 and all(elem == "OK" for elem in validation_status)
            if result:
                return "OK"
            else:
                return "Error: while validation of Rsyslog. Validation_status is: {}".format(validation_status)
        except Exception as e:
            return "Exception encountered while Validating Rsyslog client {}".format(e)
Exemple #12
0
    def wait_until_interface_ready(self, *args, **kwargs):
        banner("PCC.Wait Until Interface Ready")
        self._load_kwargs(kwargs)
        print("Kwargs:-" + str(kwargs))
        if self.node_name == None:
            return None
        if self.interface_name == None:
            return None
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        inf_ready = False
        timeout = time.time() + PCCSERVER_TIMEOUT
        counter = 0
        while inf_ready == False:
            counter += 1
            if counter == 15 or counter == 20 or counter == 26:
                print(
                    "Interface stucked in updating state, Refreshing interface UI ..."
                )
                refresh = self.interface_apply()
                print("Refresh:" + str(refresh))
            node_id = easy.get_node_id_by_name(conn, self.node_name)
            response = pcc.get_node_by_id(conn, str(node_id))['Result']['Data']
            interfaces = eval(str(response))['interfaces']
            timeout_response = None
            for data in interfaces:
                if str(data['interface']["name"]) == str(self.interface_name):
                    timeout_response = data
                    if str(data['interface']["intfState"]).lower() == "ready":
                        print(str(data))
                        inf_ready = True
                    elif re.search("failed",
                                   str(data['interface']["intfState"])):
                        print(str(data))
                        return "Error"
            if time.time() > timeout:
                print("Response Before Time Out: " + str(timeout_response))
                raise Exception("[PCC.Wait Until Interface Ready] Timeout")
            trace("  Waiting until Interface : is Ready .....")
            time.sleep(20)
        return "OK"
    def delete_ceph_rgw_by_id(self, *args, **kwargs):
        banner("PCC.Ceph Delete Cluster")
        self._load_kwargs(kwargs)

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        if self.ID == None and self.name == None:
            return {
                "Error":
                "[PCC.Ceph Delete Cluster]: Id of the cluster is not specified."
            }

        self.ID = easy.get_ceph_rgw_id_by_name(
            conn, Name=self.name, Ceph_cluster_name=self.ceph_cluster_name)

        return pcc.delete_ceph_rgw_by_id(conn, str(self.ID))
Exemple #14
0
    def get_profile_id(self, *args, **kwargs):
        """
        Get Authentication Profile Id
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (str) Name: Name of the Auth Profile who's id is required (name=<name>)
    
        [Returns]
            (int) Id: Id of the Authentication Profile, or
                None: if no match found, or
            (dict) Error response: If Exception occured
        """

        self._load_kwargs(kwargs)
        banner("PCC.Get Id [Name=%s]" % self.Name)

        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        return easy.get_profile_id_by_name(conn, Name=self.Name)
 def ceph_node_osd_architecture_validation(self, *args, **kwargs):
     banner("PCC.Ceph Nodes OSDs Architecture Validation")
     self._load_kwargs(kwargs)
     if self.name == None:
         return "Please provide Ceph cluster name"
     try:
         conn = BuiltIn().get_variable_value("${PCC_CONN}")
     except Exception as e:
         raise e
     cluster_id = self.get_ceph_cluster_id_by_name(conn, self.name)
     response = pcc.get_ceph_clusters_state(conn,
                                            id=str(cluster_id),
                                            state='osds')
     response_data = get_response_data(response)
     servers = list(set([x['server'] for x in response_data]))
     trace("Servers are:{}".format(servers))
     temp_dict = {}
     for server in servers:
         temp_osd_ids = []
         for data in response_data:
             if data['server'] == server:
                 temp_osd_ids.append(data['osd'])
         temp_dict[server] = temp_osd_ids
     architecture_from_pcc = temp_dict
     trace("architecture_from_pcc:{}".format(architecture_from_pcc))
     cmd = 'sudo ceph node ls osd -f json-pretty'
     status = cli_run(cmd=cmd,
                      host_ip=self.hostip,
                      linux_user=self.user,
                      linux_password=self.password)
     print("cmd: {} executed successfully and status is: {}".format(
         cmd, status))
     serialised_status = self._serialize_response(time.time(), status)
     trace("serialised_status: {}".format(serialised_status))
     cmd_output = str(serialised_status['Result']['stdout']).replace(
         '\n', '').strip()
     architecture_from_backend = json.loads(cmd_output)
     trace("architecture_from_backend:{}".format(architecture_from_backend))
     if architecture_from_pcc == architecture_from_backend:
         return "OK"
     else:
         return "Architecture of Node and OSDs doesn't match -- architecture_from_pcc :{} and architecture_from_backend : {}".format(
             architecture_from_pcc, architecture_from_backend)
    def add_role(self, *args, **kwargs):
        """
        Add Role

        [Args]
            (str) Name: Name of the Role
            (str) description: of the Role
            (list) groupOperations: List of dictionaries containing ids of ops
            (int) owner

        [Returns]
            (dict) Response: Add Role response (includes any errors)
        """
        self._load_kwargs(kwargs)
        banner("PCC.Add Role [Name=%s]" % self.Name)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        print("conn is {}".format(conn))
        return easy.add_role(conn, self.Name, self.Description, self.owner,
                             self.groupOperations)
Exemple #17
0
    def get_app_id_from_policies(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Get App Id from Policies")
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
            logger.console("kwargs are : {}".format(kwargs))
            data = pcc.get_policy_enabled_apps(conn)['Result']['Data']

            for i in eval(str(data)):
                app_list = [
                    str(x).lower() for x in i.values() if type(x) != int
                ]
                if self.Name.lower() in app_list:
                    app_id_from_policy = i['id']
                    logger.console(
                        "app_id_from_policy: {}".format(app_id_from_policy))
        except Exception as e:
            return "Error in get_app_id_from_policies: {}".format(e)
        return app_id_from_policy
    def wait_for_CR_updation(self, *args, **kwargs):
        """
        Wait for updation of Container Registry
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (str) Name: Name of the Container Registry to wait for(name=<Name>)
    
        [Returns]
            (str) OK: OK if Container Registry has been updated on PCC, else
            Error
                
        """

        banner("PCC.CR Wait For Updation")
        self._load_kwargs(kwargs)
        self.CR_ID = self.get_CR_id(**kwargs)
        if self.CR_ID != None:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        else:
            return "Object with {} not found".format(self.Name)

        for i in range(1, 60):
            time.sleep(10)
            banner("Loop: {}".format(i))
            response = pcc.get_portus_by_id(conn, id=str(self.CR_ID))
            print("Response is:{}".format(response))

            node = get_response_data(response)
            try:
                if node['name'] == self.Name:
                    self.availability = node["available"]
                    print("availability status: ", self.availability)
                    banner("availability is: {}".format(self.availability))
                    if self.availability == True:
                        if node.get("portusInfo") != None:
                            self.running = node["portusInfo"]["running"]
                            print("running status: ", self.running)
                            banner("running is: {}".format(self.running))
                            if self.running == True:
                                return "OK"
                            else:
                                continue
                    else:
                        continue  # continue for loop if availability is false
                if i >= 49:
                    return {
                        "Error: Timeout while updating Container Registry: {}".
                        format(self.Name)
                    }
            except Exception as e:
                print("Error in updating CR: {}".format(self.Name))
                return "Error in updating CR: {}".format(self.Name)
    def remove_dummy_file(self, *args, **kwargs):
        banner("Remove dummy file")
        self._load_kwargs(kwargs)
        try:
            print("Kwargs are: {}".format(kwargs))
            print("username is '{}' and password is: '{}'".format(
                self.user, self.password))
            cmd = "sudo rm -rf /home/pcc/{}".format(self.dummy_file_name)
            status = cli_run(cmd=cmd,
                             host_ip=self.hostip,
                             linux_user=self.user,
                             linux_password=self.password)
            print("cmd3: {} executed successfully and status is : {}".format(
                cmd, status))

            return "OK"

        except Exception as e:
            trace("Error in removing dummy file: {}".format(e))
 def make_ceph_osds_up(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     banner("PCC.Ceph Make Osds Up : {}".format(self.name))
     print("Kwargs:" + str(kwargs))
     try:
         conn = BuiltIn().get_variable_value("${PCC_CONN}")
     except Exception as e:
         raise e
     cluster_id = easy.get_ceph_cluster_id_by_name(conn, self.name)
     print("Cluster Name: {} Id: {}".format(self.name, cluster_id))
     response = pcc.get_ceph_clusters_state(conn, str(cluster_id), 'osds')
     host_ip = None
     for data in get_response_data(response):
         print("Data:" + str(data))
         trace("Data:" + str(data))
         print("Server:" + str(data['server']))
         print("Osd Id:" + str(data['osd']))
         host_ip = easy.get_hostip_by_name(conn, data['server'])
         print("Host Ip:" + str(host_ip))
         cmd = "sudo systemctl -f restart ceph-osd@{}".format(data['osd'])
         cmd_exec = cli_run(host_ip, self.user, self.password, cmd)
         print("cmd:" + str(cmd))
         print("cmd output:" + str(cmd_exec))
         time.sleep(10)
         cmd_verify = "sudo ceph osd tree|grep osd.{} |grep up|wc -l".format(
             data['osd'])
         cmd_verify_exec = cli_run(host_ip, self.user, self.password,
                                   cmd_verify)
         serialise_output = self._serialize_response(
             time.time(), cmd_verify_exec)['Result']['stdout']
         print("cmd:" + str(cmd_verify))
         print("cmd output:" + str(cmd_verify_exec))
         print("Serialise Output:" + str(serialise_output))
         if int(serialise_output) == 1:
             print("{} ods id {} up sucessfully !!!".format(
                 data['server'], data['osd']))
             continue
         else:
             print("Command execution could not make osd id {} up".format(
                 data['osd']))
             return "Error"
     return "OK"
    def delete_all_tenants(self, *args, **kwargs):
        """
        Delete All Tenants
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (list) tenants: Tenants list to be deleted

        [Returns]
            "OK": If all Tenants are deleted
            else "Error"

        """
        banner("Delete All Tenants")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        banner("Kwargs are: {}".format(kwargs))
        try:
            tenant_list = self.get_tenant_list(conn)['Result']
            trace(tenant_list)
            tenant_names = [tenant['name'] for tenant in tenant_list]
            trace("tenant_names: {}".format(tenant_names))
            if tenant_names == ['ROOT']:
                return "OK"
            elif tenant_names == ['ROOT']:
                return "OK"
            else:
                tenants_to_be_deleted = set(tenant_names) - set(['ROOT'])
                trace(
                    "tenants_to_be_deleted: {}".format(tenants_to_be_deleted))
                for tenant in list(tenants_to_be_deleted):
                    trace("Deleting tenant: {}".format(tenant))
                    tenant_id = self.get_tenant_id(Name=tenant)
                    response = self.delete_tenant(Id=str(tenant_id))
                    print("tenant name : {}".format(tenant))
                    print("Response : {}".format(response))
                    if response['StatusCode'] == 200:
                        continue
                    else:
                        return "Error"
                return "OK"
        except Exception as e:
            return {"Error: {}".format(e)}
Exemple #22
0
    def verify_node_back_end_after_deletion(self, *args, **kwargs):
        banner("PCC.Node Verify Back End After Deletion")
        self._load_kwargs(kwargs)
        print("Kwargs:{}".format(kwargs))

        pcc_agent_cmd = "sudo systemctl status pccagent"
        sys_cllector_cmd = "sudo systemctl status systemCollector"
        frr_cmd = "sudo service frr status|head -10"

        failed_host = []

        if self.host_ips:
            for host_ip in eval(str(self.host_ips)):
                logger.console(
                    "Verifying services for host {} .....".format(host_ip))
                pcc_agent_output = cli_run(host_ip, self.user, self.password,
                                           pcc_agent_cmd)
                sys_collector_output = cli_run(host_ip, self.user,
                                               self.password, sys_cllector_cmd)
                logger.console("Pcc Agent Output: {}".format(pcc_agent_output))
                logger.console(
                    "System Collector Output: {}".format(sys_collector_output))
                #frr_output=cli_run(host_ip,self.user,self.password,frr_cmd)
                #logger.console("Frr Service Output: {}".format(frr_output))
                #if re.search("running",str(pcc_agent_output)) and re.search("running",str(sys_collector_output) and re.search("running",str(frr_output))):
                if re.search("running", str(pcc_agent_output)) and re.search(
                        "running", str(sys_collector_output)):
                    continue
                else:

                    failed_host.append(host_ip)
                    continue
        else:
            print(
                "Host list is empty, please provide the host ip in a list for eg. host_ips=['000.00.0.00']"
            )

        if failed_host:
            print("Service are down for {}".format(failed_host))
            return "Error"
        else:
            return "OK"
    def delete_all_rgws(self, *args, **kwargs):
        banner("PCC.Rados Gateway Delete All")
        self._load_kwargs(kwargs)
        print("Kwargs:" + str(kwargs))

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
        ceph_cluster_id = str(
            easy.get_ceph_cluster_id_by_name(conn,
                                             Name=self.ceph_cluster_name))
        if ceph_cluster_id == "None":
            return "OK"
        response = pcc.get_ceph_rgws(conn, ceph_cluster_id)
        print("Rgw Response:" + str(response))
        if not get_response_data(response):
            print("No Rgw found for delete")
            return "OK"
        for data in get_response_data(response):
            print("Response To Look :-" + str(data))
            print("Rados Gateway {} and id {} is deleting....".format(
                data['name'], data['ID']))
            self.ID = data['ID']
            self.name = data['name']
            del_response = pcc.delete_ceph_rgw_by_id(conn, str(self.ID))
            if del_response['Result']['status'] == 200:
                del_check = self.wait_until_rados_deleted()
                if del_check == "OK":
                    print("Rados Gateway {} is deleted sucessfully".format(
                        data['name']))
                    return "OK"
                else:
                    print("Rados Gateway {} unable to delete".format(
                        data['name']))
                    return "Error"
            else:
                print("Delete Response:" + str(del_response))
                print("Issue: Not getting 200 response back")
                return "Error"

        return "OK"
    def get_topologies_(self, *args, **kwargs):
        banner("PCC.Find management interface")
        self._load_kwargs(kwargs)

        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        ## Interfaces from Topology
        topology_response = pcc.get_topologies(conn)['Result']['Data']

        interface_list = []
        for interfaces in topology_response:
            if interfaces['NodeName'] == self.Node_name:
                for link in interfaces['links']:
                    interface_list.append(link['interface_name'])
        print("Interface list from Topology: {}".format(interface_list))

        ## Interfaces from node properties
        node_details = pcc.get_node_by_id(conn, id=str(
            self.Id))['Result']['Data']['HardwareInventory']['Network']

        li = []
        interface_dict = {}
        for interfaces in node_details.values():
            name = interfaces['name']
            status = interfaces["link"]
            interface_dict[name] = status
        print("Interface dict from node properties: {}".format(interface_dict))

        list_of_online_interfaces = [
            key for (key, value) in interface_dict.items() if value == 'yes'
        ]

        ## Finding the available online interfaces which will be set as Management Interface
        list_of_online_interfaces = set(list_of_online_interfaces)
        interface_list = set(interface_list)

        management_interfaces = list_of_online_interfaces - interface_list
        print("Management interfaces: {}".format(management_interfaces))

        for management_interface in management_interfaces:
            logger.console(management_interface)
            return management_interface
Exemple #25
0
 def backend_verification_after_restore(self, *args, **kwargs):
     banner("CLI.Backend Verification After Restore")
     self._load_kwargs(kwargs)
     trace("Kwargs are: " + str(kwargs))
     failed_features = []
     key_cmd = "sudo sha1sum /home/pcc/platina-home/platina-system/conf/keys/system/key|cut -d ' ' -f1 > /tmp/after_restore.txt"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, key_cmd)
     key_cmd1 = "sudo sha1sum /home/pcc/platina-home/platina-system/conf/keys/system/key.pub|cut -d ' ' -f1 >>/tmp/after_restore.txt"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, key_cmd1)
     cert_cmd = "sudo sha1sum /home/pcc/platina-home/platina-system/conf/certs/server.crt|cut -d ' ' -f1 >> /tmp/after_restore.txt"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, cert_cmd)
     cert_cmd1 = "sudo sha1sum /home/pcc/platina-home/platina-system/conf/certs/server.key|cut -d ' ' -f1 >> /tmp/after_restore.txt"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, cert_cmd1)
     monitor_cmd = "sudo test -d /home/pcc/platina-home/platina-system/volumes/monitor-parquet && echo 'True' || echo 'False'"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, monitor_cmd)
     if re.search("True", str(cmd_out)):
         print("Monitor backup verified !!!")
         trace("Monitor backup verified !!!")
     else:
         failed_features.append("Monitor")
     env_cmd_verify = "sudo docker ps -a |grep key"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, env_cmd_verify)
     if re.search("v1.6.2", str(cmd_out)):
         failed_features.append("Env")
     shasum_verify_cmd = "sudo cmp /tmp/before_restore.txt /tmp/after_restore.txt"
     cmd_out = cli_run(self.backup_hostip, self.linux_user,
                       self.linux_password, shasum_verify_cmd)
     if re.search("differ", str(cmd_out)):
         failed_features.append("Key")
         failed_features.append(("Cert"))
     if failed_features:
         return "Folloeing feature verification failed {}".format(
             failed_features)
     else:
         return "OK"
     return "OK"
Exemple #26
0
    def set_interface_down(self, *args, **kwargs):
        banner("PCC.Set Interface Down")
        self._load_kwargs(kwargs)

        cmd = "sudo ip link set down {}".format(self.interface_name)
        interface_down = cli_run(self.host_ip, self.user, self.password, cmd)
        print("Interface Status:" + str(interface_down))
        check_cmd = "sudo ip addr sh {}".format(self.interface_name)
        interface_status = cli_run(self.host_ip, self.user, self.password,
                                   check_cmd)
        status = str(
            self._serialize_response(
                time.time(), interface_status)['Result']['stdout']).strip()
        print("Interface Status Serialize:" + str(status))
        if re.search("DOWN", str(status)):
            return "OK"
        else:
            return "Error"

        return "OK"
    def verify_tenant_buckets(self,*args,**kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Verify Tenant Buckets")

        print("kwargs in Verify Tenant Buckets :-  "+str(kwargs))        
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        ####  cmd ---- '''PGPASSWORD=plat1na psql -h 172.17.2.213 -U jwtuser jwt -c "SELECT * from tenants where name='platina';"'''
        
        cmd = '''PGPASSWORD={} psql -h {} -U jwtuser jwt -c "SELECT * from tenants where name='{}';"'''.format(self.pgpassword, self.setup_ip, self.tenant_name)
        
        
        output=cli_run(cmd=cmd, host_ip=self.setup_ip, linux_user=self.user, linux_password=self.password)
        
        serialise_output=json.loads(self._serialize_response(time.time(),output)['Result']['stdout'])
        print("Serialize Output:"+str(serialise_output))
        trace("Serialize Output:- %s " % (serialise_output))
        
        if serialise_output['status']==200 and serialise_output['error']=="":
            return serialise_output
        return "Error"
    def add_node_group(self, *args, **kwargs):
        """
        Add Node Group to PCC
        [Args]
            (str) Name: Name of the group
            (int) owner: Tenant Id for the new group
            (str) Description: Description of the group
        [Returns]
            (dict) Response: Add Node Group response (includes any errors)
        """
        self._load_kwargs(kwargs)
        banner("PCC.Add Node Group [Name=%s]" % self.Name)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        payload = {
            "Name": self.Name,
            "Description": self.Description,
            "owner": self.owner
        }

        return pcc.add_cluster(conn, payload)
 def pull_from_docker_registry(self, *args, **kwargs):
     self._load_kwargs(kwargs)        
     print("kwargs are: {}".format(kwargs))
     try:
         self.cmd = "docker pull {}".format(self.image_name)
         pull_command_execution = cli_run(cmd=self.cmd,host_ip=self.hostip, linux_user=self.username,linux_password=self.password)
         
         serialised_pull_command_execution = self._serialize_response(time.time(), pull_command_execution)
         print("serialised_pull_command_execution is:{}".format(serialised_pull_command_execution))
         
         self.cmd_output = str(serialised_pull_command_execution['Result']['stdout']).replace('\n', '').strip()
         
         print("pull_image_cmd executed successfully: {}".format(self.cmd_output))
         if "Downloaded newer image for {}".format(self.image_name) in self.cmd_output:
             banner("Image downloaded from docker successfully")
             return "OK"
         else:
             return "Error"
     except Exception as e:
         logger.console("Error in pull from docker registry: " + str(e))
 def ceph_rgw_upload_file_bucket(self, **kwargs):
     banner("PCC.Ceph Rgw Upload File To Bucket ")
     self._load_kwargs(kwargs)
     cmd = 'sudo dd if=/dev/zero of={} bs=10MiB count=1'.format(
         self.fileName)
     file_create = cli_run(self.pcc, self.user, self.password, cmd)
     cmd = 'sudo s3cmd put {} s3://BUCKET/{} -c /home/pcc/.s3cfg'.format(
         self.fileName, self.fileName)
     print("Command:" + str(cmd))
     trace("Command:" + str(cmd))
     data = cli_run(self.pcc, self.user, self.password, cmd)
     if re.search("upload", str(data)):
         print("File is uploaded to bucket")
         cmd = 'sudo rm {}'.format(self.fileName)
         file_del = cli_run(self.pcc, self.user, self.password, cmd)
         return "OK"
     else:
         print("File is not uploaded")
         return "Error"
     return