Example #1
0
 def check_node_exists(self, *args, **kwargs):
     """
     Check if node already exists and provision status is Ready
     [Args]
         (dict) conn: Connection dictionary obtained after logging in
         (str) IP: IP of the Node
     [Returns]
         (bool) True: if IP matches the node host in the list of nodes
             else False: if doesnot exists
         (dict) Error response: If Exception occured
     """
     self._load_kwargs(kwargs)
     banner("PCC.Check node exists")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     node_list = pcc.get_nodes(conn)['Result']['Data']
     print("node_list_status: {}".format(node_list))
     try:
         if node_list == None:
             return False
         for node in node_list:
             print("Node in check node exists: {}".format(node))
             if (str(node['Host']) == str(self.IP)) and (str(
                     node['provisionStatus']) == 'Ready'):
                 return True
         return False
     except Exception as e:
         print("In exception of check node exists" + str(e))
         return {"Error": str(e)}
 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)
Example #3
0
 def wait_until_node_ready(self, *args, **kwargs):
     """
     Wait Until Node Ready
     [Args]
         (dict) conn: Connection dictionary obtained after logging in
         (str) Name: Name of the Node 
     [Returns]
         (dict) Wait Time 
         (dict) Error response: If Exception occured
     """
     self._load_kwargs(kwargs)
     banner("PCC.Wait Until Node Ready")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     ready = False
     time.sleep(10)
     time_waited = 0
     PCC_TIMEOUT = 60 * 10  #10 minutes
     timeout = time.time() + PCC_TIMEOUT
     while not ready:
         ready = False
         node_list = pcc.get_nodes(conn)['Result']['Data']
         for node in node_list:
             if str(node['Name']) == str(self.Name):
                 if node['provisionStatus'] == 'Ready':
                     trace("Node:{} is ready".format(self.Name))
                     return "OK"
                 if "fail" in node['provisionStatus']:
                     return "Wait until node ready status - Failed. Node Status is {}".format(
                         node['provisionStatus'])
         if time.time() > timeout:
             return {"Error": "Timeout"}
         if not ready:
             trace("Node:{} is not yet ready".format(self.Name))
             time.sleep(5)
             time_waited += 5
Example #4
0
 def validate_tenant_assigned_to_node(self, *args, **kwargs):
     """
     Validate tenant assigned to Node
     [Args]
         (dict) conn: Connection dictionary obtained after logging in
         (str) Name: Name of the Node
         (str) Tenant_Name : Name of the tenant
     [Returns]
         "OK": If tenant assigned to Node
         else: "Not assigned" : If tenant not assigned to node
         
     """
     self._load_kwargs(kwargs)
     banner("Validate Tenant Assigned to Node")
     print("Kwargs are:{}".format(kwargs))
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     nodes_response = pcc.get_nodes(conn)['Result']['Data']
     try:
         for node in nodes_response:
             if str(node['Name']) == str(self.Name):
                 if node['tenant'] == str(self.Tenant_Name):
                     return "OK"
         return "Not assigned"
     except Exception as e:
         return {"Error": str(e)}
Example #5
0
 def wait_until_node_deleted(self, *args, **kwargs):
     """
     Wait Until Node Deleted
     [Args]
         (dict) conn: Connection dictionary obtained after logging in
         (str) Name: Name of the Node 
     [Returns]
         (dict) Wait time 
         (dict) Error response: If Exception occured
     """
     self._load_kwargs(kwargs)
     banner("PCC.Wait Until Node Deleted")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     found = True
     time_waited = 0
     timeout = time.time() + PCC_TIMEOUT
     try:
         while found:
             node_list = pcc.get_nodes(conn)['Result']['Data']
             if node_list == None:
                 return "OK"
             if re.search(self.Name, str(node_list)):
                 trace("Node:{} not yet deleted".format(self.Name))
                 time.sleep(3)
                 if time.time() > timeout:
                     return {"Error": "Timeout"}
             else:
                 return "OK"
     except Exception as e:
         return "Exception encountered: {}".format(e)
    def wait_until_PXE_booted_node_added(self, *args, **kwargs):
        banner("PCC.Wait until pxe booted node added to PCC")
        self._load_kwargs(kwargs)
        logger.console("Kwargs are: {}".format(kwargs))
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        notfound = True
        counter = 0
        while notfound:
            counter += 1
            node_list = pcc.get_nodes(conn)['Result']['Data']
            logger.console(
                "Counter {}: Pxe-booted server not added yet to PCC".format(
                    counter))
            if counter <= 300:
                time.sleep(5)
                for node in node_list:
                    if node['Name'] == self.Name:
                        notfound = False
                        logger.console("Pxe-booted server added to PCC")
                        return "OK"

            else:
                logger.console("Pxe-booted server not found")
                break
        return "Error: Pxe-booted server not found"
    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"
Example #8
0
 def get_nodes(self, *args, **kwargs):
     """
     Get Nodes
     [Args]
         None
     [Returns]
         (dict) Response: Get Node response (includes any errors)
     """
     self._load_kwargs(kwargs)
     banner("PCC.Get Nodes ")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     return pcc.get_nodes(conn)
    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"
    def assign_node_group_to_node(self, *args, **kwargs):
        """
        Assign Node Group to Node
        [Args]
            (int) Id : Node group Id
        [Returns]
            (dict) Response: Get Node response after Node group is assigned (includes any errors)
        """
        self._load_kwargs(kwargs)
        banner("PCC.Assign Node Group to Node")
        node_payload = {"ClusterId": int(self.Id), "Id": int(self.node_id)}

        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        response = pcc.modify_node(conn, data=node_payload)
        return pcc.get_nodes(conn)
    def check_provision_ready_status(self, *args, **kwargs):

        banner("PCC.Check Provision Ready Status")
        self._load_kwargs(kwargs)

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

        node_list = pcc.get_nodes(conn)['Result']['Data']
        try:
            for node in node_list:
                if str(node['Name']) == str(self.Name):
                    return node['ready']
            return None
        except Exception as e:
            return {"Error": str(e)}
Example #12
0
def get_host_name_by_ip(conn: dict, ip: str) -> str:
    """
    Get HostName by IP
    [Args]
        (dict) conn: Connection dictionary obtained after logging in
        (str) Ip: IP of the Host Node 
    [Returns]
        (dict) Error response: If Exception occured
    """
    node_list = pcc.get_nodes(conn)['Result']['Data']
    try:
        for node in node_list:
            if str(node['Host']) == str(ip):
                return node['Name']
        return None
    except Exception as e:
        return {"Error": str(e)}
Example #13
0
def get_node_id_by_name(conn: dict, Name: str) -> int:
    """
    Get Node Id by Name
    [Args]
        (dict) conn: Connection dictionary obtained after logging in
        (str) Name: Name of the Node 
    [Returns]
        (int) Id: Id of the matchining Node, or
            None: if no match found, or
        (dict) Error response: If Exception occured
    """
    node_list = pcc.get_nodes(conn)['Result']['Data']
    try:
        for node in node_list:
            if str(node['Name']) == str(Name):
                return node['Id']
        return None
    except Exception as e:
        return {"Error": str(e)}
    def wait_until_node_ready(self, *args, **kwargs):
        """
        Wait Until Node Ready
        [Args]
            (str) Name: Name of the Node 
        [Returns]
            (str) Ok 
            (str) Error response: If Exception occured
        """
        self._load_kwargs(kwargs)
        print("kwargs:-" + str(kwargs))
        banner("PCC.Wait Until Roles Ready On Nodes")

        ready = False
        status = None

        timeout = time.time() + PCC_TIMEOUT
        conn = BuiltIn().get_variable_value("${PCC_CONN}")
        time.sleep(10)
        while not ready:
            ready = False
            node_list = pcc.get_nodes(conn)['Result']['Data']
            tmp_response = None
            for node in node_list:
                if str(node['Name']).lower() == str(self.node_name).lower():
                    tmp_response = node
                    status = node['provisionStatus']
                    if node['provisionStatus'] == 'Ready':
                        print("Node Response:-" + str(node))
                        ready = True
                        return "OK"
                    elif re.search("failed", str(node['provisionStatus'])):
                        print("Node Response:-" + str(node))
                        return "Failed"
            if time.time() > timeout:
                print("Node Response:" + str(tmp_response))
                return {"Error": "Timeout"}
            if not ready:
                trace("Waiting until node: %s is Ready, currently status: %s" %
                      (self.node_name, status))
                time.sleep(5)
 def validate_node_group_assigned_to_node(self, *args, **kwargs):
     """
     Validate Node Group assigned to Node
     [Args]
         (dict) conn: Connection dictionary obtained after logging in
         (str) Name: Name of the Node
         (str) Id : Id of the node group
     [Returns]
         "OK": If node group assigned to Node
         else: "Not assigned" : If node group not assigned to node
         
     """
     self._load_kwargs(kwargs)
     banner("PCC.Validate Node Group Assigned to Node")
     conn = BuiltIn().get_variable_value("${PCC_CONN}")
     nodes_response = pcc.get_nodes(conn)['Result']['Data']
     try:
         for node in nodes_response:
             if str(node['Name']) == str(self.Name):
                 if node['ClusterId'] == int(self.Id):
                     return "OK"
         return "Not assigned"
     except Exception as e:
         return {"Error": str(e)}
Example #16
0
    def wait_until_all_nodes_are_ready(self, *args, **kwargs):
        """
        Wait Until Node Ready
        [Args]
            (dict) conn: Connection dictionary obtained after logging in
            (str) Name: Name of the Node 
        [Returns]
            (dict) Wait Time 
            (dict) Error response: If Exception occured
        """
        self._load_kwargs(kwargs)
        banner("PCC.Wait Until All Nodes are Ready")
        conn = BuiltIn().get_variable_value("${PCC_CONN}")

        all_node_list = pcc.get_nodes(conn)['Result']['Data']
        node_ready_status = []
        try:
            for node_name in all_node_list:
                ready = False
                time_waited = 0
                PCC_TIMEOUT = 60 * 10  #10 minutes
                timeout = time.time() + PCC_TIMEOUT
                while not ready:
                    ready = False
                    node_list = pcc.get_nodes(conn)['Result']['Data']
                    for node in node_list:
                        if str(node['Name']) == str(node_name['Name']):
                            if node['provisionStatus'] == 'Ready':
                                trace("Node:{} is ready".format(
                                    node_name['Name']))
                                node_ready_status.append("OK")
                                ready = True
                                break
                            if "fail" in node['provisionStatus']:
                                node_ready_status.append("Failed:{}".format(
                                    node['Name']))
                                trace(
                                    "Wait until node ready status - Failed on node {}. Node Status is {}"
                                    .format(node_name['Name'],
                                            node['provisionStatus']))
                                print(
                                    "Wait until node ready status - Failed on node {}. Node Status is {}"
                                    .format(node_name['Name'],
                                            node['provisionStatus']))
                                ready = True
                                break
                            if time.time() > timeout:
                                print("Error: Timeout for node {}".format(
                                    node_name['Name']))
                                node_ready_status.append("Timeout: {}".format(
                                    node_name['Name']))
                                ready = True
                                break
                            if not ready:
                                trace("Node:{} is not yet ready".format(
                                    node_name['Name']))
                                time.sleep(5)
                                time_waited += 5
            node_ready_result = len(node_ready_status) > 0 and all(
                elem == "OK" for elem in node_ready_status)
            if node_ready_result:
                return "OK"
            else:
                return "Wait Until Node ready status is: {}".format(
                    node_ready_status)
        except Exception as e:
            return "Exception encountered: {}".format(e)
    def delete_and_verify_roles_on_nodes(self, *args, **kwargs):
        """
        Delete 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.Delete and Verify Roles On Nodes")

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

        payload = None
        tmp_id = None
        response_code_list = []
        for node in eval(str(self.nodes)):
            print(
                "*****************  On node from user: {} ********************"
                .format(node))
            response = pcc.get_nodes(conn)
            for data in get_response_data(response):
                self.Id = data['Id']
                role_ids = data['roles']
                print(
                    "***************** node from pcc: {} ********************".
                    format(data['Name'].lower()))
                if str(data['Name']).lower() == str(node).lower():

                    print("Role_Ids_On_Node:-" + str(role_ids))
                    if role_ids:
                        for role in eval(str(self.roles)):
                            tmp_id = easy.get_node_role_id_by_name(
                                conn, str(role))
                            print("Role-Id to Remove:-" + str(role) + "-" +
                                  str(tmp_id))
                            if tmp_id in eval(str(role_ids)):
                                role_ids.remove(tmp_id)
                        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,
                            "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['StatusCode'] == 200:
                            print("Required roles deleted for {}".format(node))
                            response_code_list.append(
                                str(api_response['StatusCode']))
                            continue
                        else:
                            return api_response
                    else:
                        print("No roles present of node: {}".format(node))
        result = len(response_code_list) > 0 and all(
            elem == "200" for elem in response_code_list)
        if result:
            return "OK"
        else:
            return "Error in removing node roles: {}".format(
                response_code_list)