Esempio n. 1
0
    def wait_until_rados_ready(self, *args, **kwargs):
        banner("PCC.Wait Until Rados Gateway Ready")
        self._load_kwargs(kwargs)
        print("Kwargs" + str(kwargs))

        if self.name == None:
            return None
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        gateway_ready = False
        timeout = time.time() + PCCSERVER_TIMEOUT
        ceph_cluster_id = str(
            easy.get_ceph_cluster_id_by_name(conn,
                                             Name=self.ceph_cluster_name))
        while gateway_ready == False:
            response = pcc.get_ceph_rgws(conn, ceph_cluster_id)
            for data in get_response_data(response):
                if str(data['name']).lower() == str(self.name).lower():
                    print("Response To Look :-" + str(data))
                    trace("  Waiting until %s is Ready, current status: %s" %
                          (str(data['name']), str(data['deploy_status'])))
                    if data['deploy_status'] == "completed":
                        return "OK"
                    elif re.search("failed", str(data['deploy_status'])):
                        return "Error"
                    else:
                        break
            if time.time() > timeout:
                raise Exception("[PCC.Ceph Wait Until Rgw Ready] Timeout")
            time.sleep(5)
        return "OK"
 def get_ceph_state_nodes(self, *args, **kwargs):
     self._load_kwargs(kwargs)
     banner("PCC.Ceph Get State Nodes: {}".format(self.state))
     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))
     nodes = []
     nodes_name = []
     response = pcc.get_ceph_clusters_state(conn, str(cluster_id),
                                            str(self.state))
     trace("Response:" + str(response))
     if self.state.lower() == 'mds':
         for val in get_response_data(response)['nodes']:
             if self.state_status:
                 if re.search(self.state_status, val['state']):
                     nodes_name.append(val['name'])
                     nodes.append(easy.get_hostip_by_name(
                         conn, val['name']))
             else:
                 nodes_name.append(val['name'])
                 nodes.append(easy.get_hostip_by_name(conn, val['name']))
     else:
         for data in get_response_data(response):
             print("Data:" + str(data))
             nodes_name.append(data['server'])
             nodes.append(easy.get_hostip_by_name(conn, data['server']))
     nodes = list(set(nodes))
     print("{} Nodes Host IP's: {}".format(self.state, str(nodes)))
     print("{} Nodes Name: {}".format(self.state, str(nodes_name)))
     trace("{} Nodes: {}".format(self.state, str(nodes)))
     return nodes
    def get_ceph_version(self, *args, **kwargs):
        banner("Get Ceph Version")
        self._load_kwargs(kwargs)
        try:
            print("Kwargs are: {}".format(kwargs))
            # Get Ceph Version
            #cmd = "ceph -v"
            #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))
            #return status

            banner("PCC.Get Ceph Version [Name=%s]" % self.name)
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
            print("conn is {}".format(conn))
            ceph_ID = easy.get_ceph_cluster_id_by_name(conn, self.name)
            print("ceph_ID is {}".format(ceph_ID))

            ceph_node_list = pcc.get_ceph_version_list(conn, str(ceph_ID))
            print("ceph_node_list is {}".format(ceph_node_list))
            '''
            "ceph_version":"ceph version 14.2.20 (36274af6eb7f2a5055f2d53ad448f2694e9046a0) nautilus (stable)",
            "hostname":"qa-clusterhead-10"
            '''

            ceph_ver_list = {}
            for node_data in ceph_node_list["Result"]["Data"]:
                print("ceph_version of hostname {} is {} ".format(
                    node_data["hostname"], node_data["ceph_version"]))
                ceph_ver_list[
                    node_data["hostname"]] = node_data["ceph_version"]
            print("ceph_ver_list is {}".format(ceph_ver_list))
            return ceph_ver_list

        except Exception as e:
            trace("Error in getting ceph version: {}".format(e))
    def get_ceph_cluster_id_by_name(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get Cluster Id")

        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)
        return cluster_id
Esempio n. 5
0
    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 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 operation_to_perform_on_all_osds_daemons_of_node(
            self, *args, **kwargs):
        banner("PCC.Operation to perform on All OSD Daemons Of Node")
        self._load_kwargs(kwargs)
        print("Kwargs are: {}".format(kwargs))
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
        try:
            if "operation_to_perform" not in kwargs:
                self.operation_to_perform = None

            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_name = easy.get_hostname_by_ip(conn, Hostip=self.hostip)
            osd_ids = [
                data['osd'] for data in get_response_data(response)
                if data['server'] == host_name
            ]

            for osd_id in osd_ids:
                if self.operation_to_perform:
                    cmd = "sudo systemctl {} ceph-osd@{}".format(
                        self.operation_to_perform.lower(), osd_id)
                    status = cli_run(cmd=cmd,
                                     host_ip=self.hostip,
                                     linux_user=self.user,
                                     linux_password=self.password)
                    print("Status is: {}".format(status))
                    time.sleep(2)
                    trace("Command: {} executed successfully".format(cmd))
                else:
                    return "Please provide a valid operation to perform. Choose from 'Start', 'Stop', 'Status'"

            return "OK"

        except Exception as e:
            trace("Error in stop_all_osds_daemons_of_node: {}".format(e))
Esempio n. 8
0
    def wait_until_rados_deleted(self, *args, **kwargs):
        banner("PCC.Wait Until Rados Gateway Deleted")
        self._load_kwargs(kwargs)

        if self.name == None:
            return {
                "Error":
                "[PCC.Wait Until Rados Gateway Deleted]: Name of the Rgw is not specified."
            }

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

        Id_found_in_list_of_rgws = True
        timeout = time.time() + PCCSERVER_TIMEOUT
        ceph_cluster_id = easy.get_ceph_cluster_id_by_name(
            conn, self.ceph_cluster_name)
        while Id_found_in_list_of_rgws == True:
            Id_found_in_list_of_rgws = False
            response = get_response_data(
                pcc.get_ceph_rgws(conn, ceph_cluster_id))
            print("Response:" + str(response))
            if response != None:
                for data in response:
                    if str(data['name']) == str(self.name):
                        Id_found_in_list_of_rgws = True
                    if time.time() > timeout:
                        raise Exception(
                            "[PCC.Wait Until Rados Gateway Deleted] Timeout")
                    if Id_found_in_list_of_rgws:
                        trace(
                            "  Waiting until Rgws: %s is deleted. Timeout in %.1f seconds."
                            % (data['name'], timeout - time.time()))
            time.sleep(5)
        return "OK"