Ejemplo n.º 1
0
 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
Ejemplo n.º 2
0
    def delete_all_ipam_subnets(self, *args, **kwargs):
        banner("PCC.Ipam Subnet Delete All")
        self._load_kwargs(kwargs)

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
        
        failed_del=[]
        response = pcc.get_subnet_objs(conn)
        
        if not get_response_data(response):
            print("No subnet found for delete !!")
            return "OK"
            
        for data in get_response_data(response):
            print("Response To Look :-"+str(data))
            print("Subnet {} and id {} is deleting....".format(data['name'],data['id']))
            self.id=data['id']
            del_response=pcc.delete_subnet_obj_by_id(conn, str(self.id))
            if del_response['Result']['status']==200:
                continue
            else:
                print("Delete Response:"+str(del_response))
                failed_del.append(data['name'])
                continue
        if failed_del:
            print("Could not delete following Subnets: "+str(failed_del))
            return "Error"
        return "OK"
Ejemplo n.º 3
0
    def cleanup_features_associated_to_node(self, *args, **kwargs):
        """
        Cleanup features associated to Node
        [Args]
            (list) Names: List of Names of the Nodes to be deleted
            or
            Don't provide any arguments if you want to delete all nodes
            ...
        [Returns]
            (str) OK: Returns "OK" if all nodes are deleted successfully
            else: returns "Error"
        """

        banner("Cleanup features associated to Node")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        try:
            response = self.get_nodes()
            update_response_status = []
            node_names = []
            wait_until_node_ready_resp = []

            if get_response_data(response) == []:
                return "No nodes present on PCC"
            else:
                counter = 1
                for node in get_response_data(response):
                    print("Node:{} output - {}".format(counter, node))
                    counter += 1
                    node_names.append(node['Name'])

                    payload = {
                        "Id": node['Id'],
                        "ClusterId": 0,
                        "roles": [1],
                        "scopeId": int(self.scopeId)
                    }

                    update_resp = pcc.modify_node(conn, payload)
                    update_response_status.append(update_resp['StatusCode'])
                    print("update response status : {}".format(
                        update_response_status))
                update_result = len(update_response_status) > 0 and all(
                    elem == 200 for elem in update_response_status)
                banner("Node names : {}".format(node_names))
                for names in node_names:
                    resp = self.wait_until_node_ready(Name=names)
                    wait_until_node_ready_resp.append(resp)
                node_ready_result = len(
                    wait_until_node_ready_resp) > 0 and all(
                        elem == "OK" for elem in wait_until_node_ready_resp)

                if update_result and node_ready_result:
                    return "OK"
                return "Features not yet deleted ->  node update response is: {} and node ready status is {}".format(
                    update_response_status, wait_until_node_ready_resp)

        except Exception as e:
            return "Exception encountered: {}".format(e)
Ejemplo n.º 4
0
    def delete_all_node_groups(self, *args, **kwargs):
        """
        Validate Node Group assigned to Node
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            
    
        [Returns]
            "OK": If all node groups are deleted
            else "Error"
            
        """
        banner("Delete All Node groups")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        try:
            response = pcc.get_clusters(conn)
            list_id = []

            if get_response_data(response) == []:
                return "OK"
            else:
                for ids in get_response_data(response):
                    list_id.append(ids['id'])
                print("list of id:{}".format(list_id))
                for id_ in list_id:
                    response = pcc.delete_cluster_by_id(conn, str(id_))

            deletion_status = False
            counter = 0
            while deletion_status == False:
                counter += 1
                response = pcc.get_clusters(conn)
                if get_response_data(response) != []:
                    time.sleep(2)
                    banner("All Node groups not yet deleted")
                    if counter < 50:
                        banner("Counter: {}".format(counter))
                        continue
                    else:
                        logger.console("Error: ['Timeout']")
                        break
                elif get_response_data(response) == []:
                    deletion_status = True
                    banner("All Nodes groups deleted successfully")
                    return "OK"
                else:
                    banner("Entered into continuous loop")
                    return "Error"

        except Exception as e:
            logger.console(
                "Error in delete_all_node_groups status: {}".format(e))
    def get_Host_IP(self, *args, **kwargs):
        """
        Get Host IP used by Container Registry
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (str) Name: Name of the Container Registry who's Host IP is required (name=<Name>)
    
        [Returns]
            (str) Host IP: Host IP used by the Container Registry, or
                None: if no match found, or
            (dict) Error response: If Exception occured
        """

        banner("PCC.Get Host IP")
        self._load_kwargs(kwargs)
        try:
            server_id = self.get_CR_server_id(**kwargs)
            node_ids_response = Nodes().get_nodes(**kwargs)
            print("node_ids_response: {}".format(node_ids_response))

            for node in get_response_data(node_ids_response):
                if server_id == node['Id']:
                    return node['Host']
        except Exception as e:
            logger.console("Error in get_Host_IP: {}".format(e))
Ejemplo n.º 6
0
 def validate_apps_on_pcc(self, *args, **kwargs):
     """
     PCC.Validate Applications Present on PCC
     [Args]
         None
     [Returns]
         (dict) List of Applications from PCC
     """
     banner("PCC.Validate Applications Present on PCC")
     self._load_kwargs(kwargs)
     print("Kwargs are: {}".format(kwargs))
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     response = pcc.get_templates(conn)
     #return response
     
     temp_app_list = []
     for data in get_response_data(response):
         print(data)
         temp_app_list.append(data['longName'])
     print("app list from PCC: {}".format(temp_app_list))        
     if "app_list" in kwargs:
         self.app_list= ast.literal_eval(self.app_list)
     
     print("app list from user: {}".format(self.app_list)) 
     result = (set(self.app_list).issubset(set(temp_app_list)))
     print("Result is: {}".format(result))
     if result:
         return "OK"
     else:
         return "App doesnot exists: {}".format(list(set(self.app_list) - set(temp_app_list)))
Ejemplo n.º 7
0
 def verify_node_roles_on_nodes(self, *args, **kwargs):
     """
     Verify node role on Nodes
     [Args]
         (list) nodes: name of pcc nodes
         (list) roles: name of roles
     [Returns]
         (dict) Response: OK if node role exists on the node (includes any errors)
     """
     self._load_kwargs(kwargs)
     print("kwargs:-"+str(kwargs))
     banner("PCC.Verify Node Role On Nodes")
     
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     node_role_id = self.get_node_role_id(conn,Name= self.Name)
     for node in ast.literal_eval(self.nodes):
         print("Node from user is: {}".format(node))
         response = pcc.get_nodes(conn)
         for data in get_response_data(response):
             self.Id=data['Id']
             self.Host=data['Host']
             print("node name from pcc: {}".format(data['Name']).lower())
             if str(data['Name']).lower() == str(node).lower():
                 if data['roles'] == None:
                     return "No roles present on node"
                 if node_role_id in data['roles']:
                     return "OK"
                 else:
                     return "Node role {} not present on node: {}".format(self.Name, node)
    def add_and_verify_tags_on_nodes(self, *args, **kwargs):
        """
        Add Roles and Verify Tags to Nodes
        [Args]
            (list) nodes: name of pcc nodes
            (list) tags: name of tags
        [Returns]
            (dict) Response: Add Node tags response (includes any errors)
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("PCC.Add and Verify Tags On Nodes")

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

        for node in eval(str(self.nodes)):
            response = pcc.get_nodes(conn)
            for data in get_response_data(response):
                self.Id = data['Id']
                self.Host = data['Host']
                if str(data['Name']).lower() == str(node).lower():
                    payload = {
                        "Id": self.Id,
                        "Host": self.Host,
                        "tags": eval(str(self.tags))
                    }
                    print("Payload:-" + str(payload))
                    api_response = pcc.modify_node(conn, payload)
                    print("API Response:-" + str(api_response))
                    if api_response['Result']['status'] == 200:
                        continue
                    else:
                        return api_response
        return "OK"
Ejemplo n.º 9
0
    def wait_until_cluster_ready(self, *args, **kwargs):
        banner("PCC.Ceph Wait Until Cluster Ready")
        self._load_kwargs(kwargs)

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

        cluster_ready = False
        timeout = time.time() + PCCSERVER_TIMEOUT
        capture_data = ""

        while cluster_ready == False:
            response = pcc.get_ceph_clusters(conn)
            for data in get_response_data(response):
                if str(data['name']).lower() == str(self.name).lower():
                    capture_data = data
                    if data['progressPercentage'] == 100 or data[
                            'deploy_status'].lower() == "completed":
                        print("Response To Look :-" + str(data))
                        cluster_ready = True
                    elif re.search("failed", str(data['deploy_status'])):
                        print("Response:-" + str(data))
                        return "Error"
            if time.time() > timeout:
                print("Response:-" + str(capture_data))
                raise Exception("[PCC.Ceph Wait Until Cluster Ready] Timeout")
            trace("  Waiting until cluster: %s is Ready, currently: %s" %
                  (data['name'], data['progressPercentage']))
            time.sleep(5)
        return "OK"
Ejemplo n.º 10
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"
Ejemplo n.º 11
0
    def verify_ipam_subnet_updated(self, *args, **kwargs):
        banner("PCC.Verify Ipam Subnet Updated")
        self._load_kwargs(kwargs)
        print("Kwargs:"+str(kwargs))

        if self.name == None:
            print("Name is Empty, Please provide valid name.")
            return "Error"
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        timeout = time.time() + PCCSERVER_TIMEOUT
  
        response = pcc.get_subnet_objs(conn)
        for data in get_response_data(response):
            if str(data['name']).lower() == str(self.name).lower():
                print("Data to Look:"+str(data))
                for key in kwargs:
                    if data[key]==kwargs[key]:
                        continue
                    else:
                        print("Not Updated Propery, there is mismatch {}!={}".format(data[key],kwargs[key]))
                        return "Error"        
        return "OK"                
Ejemplo n.º 12
0
    def validate_storage_and_cache_pool_relation(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Validate storage and cache pool relation")

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
        validation = []
        get_all_pools_response = pcc.get_ceph_pools_by_cluster_id(
            conn, str(self.ceph_cluster_id))
        trace("get_all_pools_response: {}".format(get_all_pools_response))
        for data in get_response_data(get_all_pools_response):
            if (data['name']
                    == self.data_pool_name) and (data['cachePool']['name']
                                                 == self.cache_pool_name):
                validation.append("OK")
            if (data['name']
                    == self.cache_pool_name) and (data['storagePool']['name']
                                                  == self.data_pool_name):
                validation.append("OK")
        trace("Validation status: {}".format(validation))
        if (len(validation) == 2) and (len(validation) > 0
                                       and all(elem == "OK"
                                               for elem in validation)):
            return "OK"
        else:
            return "Validation failed for datapool- {} and cache_pool- {}".format(
                self.data_pool_name, self.cache_pool_name)
Ejemplo n.º 13
0
    def get_ceph_rgw_secret_key(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get Rgw Secret Key")

        if self.name == None:
            print("Ceph Rgw name is empty!!")
            return "Error"

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

        rados_id = easy.get_ceph_rgw_id_by_name(
            conn, Name=self.name, Ceph_cluster_name=self.ceph_cluster_name)
        key_data = get_response_data(
            pcc.get_profiles_with_additional_data_for_specific_application(
                conn, "ceph", str(rados_id)))
        print("Response:" + str(key_data))
        print("Secret Key:" + str(key_data[0]['profile']["secretKey"]))
        if key_data[0]['profile']["secretKey"]:
            return key_data[0]['profile']["secretKey"]
        else:
            print("Can't extract Secret Key")
            return "Error"
        return None
Ejemplo n.º 14
0
    def alert_delete_all_rule(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Alert Delete All Rule")
        print("kwargs:-" + str(kwargs))

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

        default_alerts = ["memory high usage", "cpu high temp"]
        response = pcc.get_alert_rules(conn)
        for data in get_response_data(response):
            self.id = data["id"]
            self.name = data["name"]
            print("Alert Rule Id:-" + str(self.id))
            print("Alert Rule Name:-" + str(self.name))
            if self.id and data["name"].lower() not in default_alerts:
                tmp = self.alert_delete_rule()
                time.sleep(3)
                if self.alert_get_rule_id(id=self.id):
                    print("Alert {} and id {} is not deleted:".format(
                        self.name, self.id))
                    return "Error"
        return "OK"
Ejemplo n.º 15
0
    def wait_until_pool_ready(self, *args, **kwargs):
        banner("PCC.Ceph Wait Until Pool Ready")
        self._load_kwargs(kwargs)

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

        pool_ready = False
        timeout = time.time() + PCCSERVER_TIMEOUT

        while pool_ready == False:
            response = pcc.get_ceph_pools(conn)
            if time.time() > timeout:
                return "[PCC.Ceph Wait Until Pool Ready] Timeout"
            for data in get_response_data(response):
                if str(data['name']).lower() == str(self.name).lower():
                    print(str(data))
                    if data['deploy_status'] == "completed":
                        pool_ready = True
                        return "OK"
                    if data['deploy_status'] == "failed":
                        return "Error"
                    else:
                        trace(
                            " Waiting until pool : %s is Ready, currently: %s"
                            % (data['name'], data['progressPercentage']))
                        time.sleep(5)
Ejemplo n.º 16
0
    def wait_until_pool_deleted(self, *args, **kwargs):
        banner("PCC.Ceph Wait Until Pool Deleted")

        self._load_kwargs(kwargs)

        if self.id == None:
            # pool doesn't exist, nothing to wait for
            return "OK"
        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e

        Id_found_in_list_of_pools = True
        timeout = time.time() + PCCSERVER_TIMEOUT

        while Id_found_in_list_of_pools == True:
            Id_found_in_list_of_pools = False
            response = pcc.get_ceph_pools(conn)
            for pool in get_response_data(response):
                if str(pool['id']) == str(self.id):
                    name = pool["name"]
                    Id_found_in_list_of_pools = True
            if time.time() > timeout:
                raise Exception("[PCC.Wait Until Pool Deleted] Timeout")
            if Id_found_in_list_of_pools:
                trace(
                    "Waiting until node: %s is deleted. Timeout in %.1f seconds."
                    % (name, timeout - time.time()))
                time.sleep(5)
            else:
                trace("Pool deleted!")
        time.sleep(10)
        return "OK"
Ejemplo n.º 17
0
    def wait_until_rbd_deleted(self, *args, **kwargs):
        banner("PCC.Ceph Wait Until Rbd Deleted")
        self._load_kwargs(kwargs)

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

        Id_found_in_list_of_rbd = True
        timeout = time.time() + PCCSERVER_TIMEOUT

        while Id_found_in_list_of_rbd == True:
            Id_found_in_list_of_rbd = False
            response = pcc.get_ceph_rbds(conn)
            for data in get_response_data(response):
                print(data)
                if str(data['id']) == str(self.id):
                    Id_found_in_list_of_rbd = True
            if time.time() > timeout:
                raise Exception("[PCC.Ceph Wait Until Rbd Deleted] Timeout")
            if Id_found_in_list_of_rbd:
                trace("  Waiting until rbd: %s is deleted. Timeout in %.1f seconds." % 
                       (data['name'], timeout-time.time()))
                time.sleep(5)
        time.sleep(10)
        return "OK"
Ejemplo n.º 18
0
    def delete_ceph_all_fs(self, *args, **kwargs):
        banner("PCC.Ceph Delete All Fs")
        self._load_kwargs(kwargs)

        try:
            conn = BuiltIn().get_variable_value("${PCC_CONN}")
        except Exception as e:
            raise e
            
        response = pcc.get_ceph_fs(conn)
        for data in get_response_data(response):
            print("Response To Look :-"+str(data))
            print("Ceph Fs {} and id {} is deleting....".format(data['name'],data['id']))
            self.id=data['id']
            del_response=pcc.delete_ceph_fs_by_id(conn, str(self.id))
            if del_response['Result']['status']==200:
                del_check=self.wait_until_fs_deleted()
                if del_check=="OK":
                    print("Ceph Fs {} is deleted sucessfully".format(data['name']))
                    return "OK"
                else:
                    print("Ceph Fs {} 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"
Ejemplo n.º 19
0
    def modify_ceph_clusters(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        print("Kwargs:" + str(kwargs))
        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        time.sleep(60)
        tmp_node = []
        payload_nodes = []

        for node_name in eval(str(self.nodes)):
            node_id = easy.get_node_id_by_name(conn, node_name)
            tmp_node.append(node_id)

        self.nodes = []
        response = pcc.get_ceph_clusters(conn)
        for data in get_response_data(response):
            if str(data['name']).lower() == str(self.name).lower():
                payload_nodes = eval(str(data['nodes']))
                if not self.tags:
                    self.tags = data['tags']
                if not self.name:
                    self.name = data['name']
                if not self.networkClusterName:
                    self.networkClusterId = data['networkClusterId']
                else:
                    self.networkClusterId = easy.get_network_clusters_id_by_name(
                        conn, self.networkClusterName)

        for id in tmp_node:
            count = 0
            for data in payload_nodes:
                if int(data['id']) == int(id):
                    self.nodes.append(data)
                    count = 1
            if count == 0:
                self.nodes.append({"id": int(id)})

        if self.tags:
            self.tags = eval(str(self.tags))

        try:
            payload = {
                "id": self.id,
                "name": self.name,
                "nodes": self.nodes,
                "tags": self.tags,
                "networkClusterId": self.networkClusterId
            }

            print("Payload:-" + str(payload))

        except Exception as e:
            trace("[update_cluster] EXCEPTION: %s" % str(e))
            raise Exception(e)

        return pcc.modify_ceph_clusters(conn, payload)
Ejemplo n.º 20
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"
Ejemplo n.º 21
0
    def get_ceph_all_cache_pools_data(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get All Cache Pools Data")

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

        response = get_response_data(pcc.get_ceph_pool_caches(conn))
        return response
Ejemplo n.º 22
0
    def get_erasure_ceph_erasure_coded_profiles(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get All Erasure Coded Profiles")

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

        response = get_response_data(pcc.get_all_erasure_code_profile(conn))
        return response
Ejemplo n.º 23
0
    def clean_all_authprofile(self, *args, **kwargs):
        """
        Delete All Authentication Profiles
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            
        [Returns]
            (bool) OK: OK if All Authentication Profiles are deleted (includes any errors)
        """

        banner("PCC.Clean all AuthProfile")
        self._load_kwargs(kwargs)

        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        response = pcc.get_profiles(conn)
        print("Response is :{}".format(response))

        list_id = []
        if get_response_data(response) == []:
            print("No auth profile available")
            return "OK"
        else:
            try:
                for ids in get_response_data(response):
                    list_id.append(ids['id'])
                print("list of id:{}".format(list_id))
            except Exception as e:
                logger.console("Error in clean_all_AuthProfile: {}".format(e))
            response_code_list = []
            try:
                for id_ in list_id:
                    response = pcc.delete_profile_by_id(conn, id=str(id_))
                    response_code_list.append(str(response['StatusCode']))
                result = len(response_code_list) > 0 and all(
                    elem == response_code_list[0]
                    for elem in response_code_list)
                if result == True:
                    return "OK"
            except Exception as e:
                logger.console("Error in clean_all_AuthProfile: {}".format(e))
    def clean_all_CR(self, *args, **kwargs):
        """
        Delete All Container Registry
    
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            
        [Returns]
            (str) OK: OK if All Container Registry are deleted (includes any errors)
        """

        banner("PCC.Clean all CR")
        self._load_kwargs(kwargs)
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        response = pcc.get_portus(conn)

        list_id = []
        if get_response_data(response) == []:
            return "OK"
        else:
            try:
                for ids in get_response_data(response):
                    list_id.append(ids['id'])
                print("list of id:{}".format(list_id))
            except Exception as e:
                logger.console("Error: {}".format(e))
            response_code_list = []
            try:
                for id_ in list_id:
                    response = pcc.delete_portus_by_id(conn, id=str(id_))
                    print()
                    response_code_list.append(response['StatusCode'])
                result = len(response_code_list) > 0 and all(
                    elem == response_code_list[0]
                    for elem in response_code_list)
                if result:
                    return "OK"
                else:
                    return "Error"
            except Exception as e:
                logger.console("Error in clean all CR: {}".format(e))
Ejemplo n.º 25
0
    def get_ceph_cache_pool_by_cache_pool_id(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Get Cache Pool By Cache Pool Id")

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

        response = get_response_data(
            pcc.get_ceph_cache_pool_by_cache_id(conn, self.id))
        return response
Ejemplo n.º 26
0
    def delete_ceph_cache_pool(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Delete Cache Pool")

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

        response = get_response_data(
            pcc.delete_ceph_cache_pool_by_id(conn, str(id)))
        return response
    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)
Ejemplo n.º 28
0
    def add_and_verify_roles_on_nodes(self, *args, **kwargs):
        """
        Add Roles and Verify to Nodes
        [Args]
            (list) nodes: name of pcc nodes
            (list) roles: name of roles
        [Returns]
            (dict) Response: Add Node Role response (includes any errors)
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("PCC.Add and Verify Roles On Nodes")

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

        payload = None
        tmp_id = None

        for node in eval(str(self.nodes)):
            role_ids = []
            response = pcc.get_nodes(conn)
            for data in get_response_data(response):
                self.Id = data['Id']
                self.Host = data['Host']
                if str(data['Name']).lower() == str(node).lower():
                    for role in eval(str(self.roles)):
                        tmp_id = easy.get_node_role_id_by_name(conn, str(role))
                        print("Role-Id:-" + str(role) + "-" + str(tmp_id))
                        role_ids.append(tmp_id)
                    trace("role_ids : {}".format(role_ids))
                    if "scopeId" not in kwargs:
                        trace("Node id is :{}".format(str(data['Id'])))
                        get_node_response = pcc.get_node_by_id(
                            conn, str(data['Id']))
                        trace("get_node_response: {}".format(
                            str(get_node_response)))
                        self.scopeId = int(
                            get_node_response['Result']['Data']["scopeId"])
                    payload = {
                        "Id": self.Id,
                        "Host": self.Host,
                        "roles": role_ids,
                        "scopeId": self.scopeId
                    }
                    print("Payload:-" + str(payload))
                    api_response = pcc.modify_node(conn, payload)
                    print("API Response:-" + str(api_response))
                    if api_response['Result']['status'] == 200:
                        continue
                    else:
                        return api_response

        return "OK"
Ejemplo n.º 29
0
    def verify_model_and_serial_number(self, *args, **kwargs):
        banner("PCC.Node Verify Model And Serial Number")
        self._load_kwargs(kwargs)
        print("Kwargs:{}".format(kwargs))
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        serial_cmd = "sudo dmidecode -s baseboard-serial-number"
        model_cmd = "sudo dmidecode -s baseboard-product-name"
        failed_host = []
        if self.Names:
            for name in ast.literal_eval(self.Names):
                node_id = self.get_node_id(Name=name)
                node_details = get_response_data(
                    pcc.get_node_summary_by_id(conn, str(node_id)))
                print("1. Node Summary:" + str(node_details))
                print("++++++++++++++++++++++++++++++++++++++++++++")
                print("2. Serial Number" + str(node_details['SN']))
                print("++++++++++++++++++++++++++++++++++++++++++++")
                print("3. Model Number" + str(node_details['Model']))
                print("++++++++++++++++++++++++++++++++++++++++++++")
                logger.console("Verifying services for host {} .....".format(
                    node_details['Host']))
                print("Verifying services for host {} .....".format(
                    node_details['Host']))
                serial_number = self._serialize_response(
                    time.time(),
                    cli_run(node_details['Host'], self.user, self.password,
                            serial_cmd))['Result']['stdout']
                model_number = self._serialize_response(
                    time.time(),
                    cli_run(node_details['Host'], self.user, self.password,
                            model_cmd))['Result']['stdout']
                print("Backend Serial Data:" + str(serial_number))
                print("Backend Model Data:" + str(model_number))
                if node_details['Model'] == str(
                        model_number.strip()) and node_details['SN'] == str(
                            serial_number.strip()):
                    continue
                else:

                    failed_host.append(name)
                    continue
        else:
            print(
                "Node names is empty, please provide the node name list for eg. Names=['sv124','sv125']"
            )
        if failed_host:
            print("Couldn't verify Serial and Model Number for {}".format(
                failed_host))
            return "Error"
        else:
            return "OK"
Ejemplo n.º 30
0
    def delete_all_pools(self, *args, **kwargs):
        self._load_kwargs(kwargs)
        banner("PCC.Ceph Delete All Pool")

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

        response = pcc.get_ceph_pools(conn)
        for data in get_response_data(response):
            response = pcc.delete_ceph_pool_by_id(conn, str(data['id']))
            status = self.wait_until_pool_deleted(id=data['id'])
            if status != "OK":
                print("{} deletion failed".format(data['name']))
                return "Error"
        return "OK"