xref: /openbmc/openbmc-test-automation/lib/xcat/xcat_utils.robot (revision 409df05d4b10b9a8c81e282da8fef0199db5bdea)
11dcd5394SPrashanth Katti*** Settings ***
21dcd5394SPrashanth Katti
3839a0c27SSandhya SomashekarResource    ../xcat/resource.robot
4839a0c27SSandhya SomashekarResource    ../../lib/resource.robot
51dcd5394SPrashanth Katti
61dcd5394SPrashanth KattiLibrary     SSHLibrary
71dcd5394SPrashanth KattiLibrary     OperatingSystem
8477debc4SPrashanth KattiLibrary     String
91dcd5394SPrashanth Katti
101dcd5394SPrashanth Katti*** Keywords  ***
111dcd5394SPrashanth Katti
121dcd5394SPrashanth KattiOpen Connection And Login To XCAT
131dcd5394SPrashanth Katti    [Documentation]  Open connection and login to xCAT server.
141dcd5394SPrashanth Katti    [Arguments]  ${xcat_host}=${XCAT_HOST}  ${xcat_port}=${XCAT_PORT}
151dcd5394SPrashanth Katti
161dcd5394SPrashanth Katti    # Description of argument(s):
171dcd5394SPrashanth Katti    # xcat_host  IP address of the XCAT server.
181dcd5394SPrashanth Katti    # xcat_port  Network port on which XCAT server accepts ssh session.
191dcd5394SPrashanth Katti
2037c97bb5SGeorge Keishing    SSHLibrary.Open Connection  ${xcat_host}  port=${xcat_port}
211dcd5394SPrashanth Katti    Login  ${XCAT_USERNAME}  ${XCAT_PASSWORD}
221dcd5394SPrashanth Katti
2399c092f3SRahul Maheshwari
2499c092f3SRahul MaheshwariExecute Command On XCAT
2599c092f3SRahul Maheshwari    [Documentation]  Execute command using XCAT.
2699c092f3SRahul Maheshwari    [Arguments]  ${command}  ${command_option}=${EMPTY}
2799c092f3SRahul Maheshwari    ...  ${node}=${OPENBMC_HOST}
2899c092f3SRahul Maheshwari
2999c092f3SRahul Maheshwari    # Description of argument(s):
3099c092f3SRahul Maheshwari    # command         Command to be run(e.g. "rinv").
3199c092f3SRahul Maheshwari    # command_option  Command's option to be run(e.g. "dimm").
3299c092f3SRahul Maheshwari    # node            Name of the node(e.g. "node1").
3399c092f3SRahul Maheshwari
3499c092f3SRahul Maheshwari    ${xcat_cmd}=  Catenate  SEPARATOR=
3599c092f3SRahul Maheshwari    ...  ${XCAT_DIR_PATH}/${command} ${node} ${command_option}
3699c092f3SRahul Maheshwari    ${stdout}  ${stderr}=  Execute Command  ${xcat_cmd}  return_stderr=True
3799c092f3SRahul Maheshwari    Should Be Empty  ${stderr}
3899c092f3SRahul Maheshwari
39*409df05dSGeorge Keishing    RETURN  ${stdout}
4099c092f3SRahul Maheshwari
4199c092f3SRahul Maheshwari
421dcd5394SPrashanth KattiGet List Of BMC Nodes
431dcd5394SPrashanth Katti    [Documentation]  Get list of BMC nodes.
441dcd5394SPrashanth Katti    [Arguments]  ${node_cfg_file_path}=${NODE_CFG_FILE_PATH}
451dcd5394SPrashanth Katti
461dcd5394SPrashanth Katti    # Get the list of BMC nodes to be added.
471dcd5394SPrashanth Katti    # This keyword expects file having list of BMC nodes
481dcd5394SPrashanth Katti    # as an input.
491dcd5394SPrashanth Katti    # File should have IP addresses of BMC nodes.
501dcd5394SPrashanth Katti
511dcd5394SPrashanth Katti    OperatingSystem.File Should Exist  ${node_cfg_file_path}  msg=cfg file missing.
521dcd5394SPrashanth Katti    File Should Not Be Empty  ${node_cfg_file_path}  msg=Empty config file.
531dcd5394SPrashanth Katti
541dcd5394SPrashanth Katti    ${bmc_list}=  OperatingSystem.Get File  ${node_cfg_file_path}
55*409df05dSGeorge Keishing    RETURN  ${bmc_list}
56477debc4SPrashanth Katti
57477debc4SPrashanth KattiAdd Nodes To XCAT
58477debc4SPrashanth Katti    [Documentation]  Add nodes to XCAT configuration.
59477debc4SPrashanth Katti    [Arguments]  ${node}  ${username}=${OPENBMC_USERNAME}
60477debc4SPrashanth Katti    ...          ${password}=${OPENBMC_PASSWORD}
61477debc4SPrashanth Katti
62477debc4SPrashanth Katti    # Description of the argument(s):
63477debc4SPrashanth Katti    # node  Name of the node to be added.
64477debc4SPrashanth Katti
65477debc4SPrashanth Katti    ${cmd_buf}=  Catenate  ${XCAT_DIR_PATH}/mkdef ${node} bmc=${node}
66477debc4SPrashanth Katti    ...  bmcusername=${username} bmcpassword=${password} mgt=openbmc groups=all
67477debc4SPrashanth Katti    Execute Command  ${cmd_buf}
68477debc4SPrashanth Katti
69477debc4SPrashanth KattiValidate Added Node
70477debc4SPrashanth Katti    [Documentation]  Validate added node.
71477debc4SPrashanth Katti    [Arguments]  ${node}
72477debc4SPrashanth Katti
73477debc4SPrashanth Katti    # Description of the argument(s):
74477debc4SPrashanth Katti    # node  Name of the node.
75477debc4SPrashanth Katti
76477debc4SPrashanth Katti    ${stdout}  ${stderr}=  Execute Command  ${XCAT_DIR_PATH}/nodels
77477debc4SPrashanth Katti    ...  return_stderr=True
78477debc4SPrashanth Katti    Should Be Empty  ${stderr}
79477debc4SPrashanth Katti    Should Contain  ${std_out}  ${node}  msg=Node is not added.
80477debc4SPrashanth Katti
81477debc4SPrashanth KattiPower On Via XCAT
82477debc4SPrashanth Katti    [Documentation]  Power on via XCAT.
83477debc4SPrashanth Katti    [Arguments]  ${node}
84477debc4SPrashanth Katti
85477debc4SPrashanth Katti    # Description of the argument(s):
86477debc4SPrashanth Katti    # node  Name of the node.
87477debc4SPrashanth Katti
88477debc4SPrashanth Katti    ${stdout}  ${stderr}=  Execute Command  ${XCAT_DIR_PATH}/rpower ${node} on
89477debc4SPrashanth Katti    ...  return_stderr=True
90477debc4SPrashanth Katti    Should Be Empty  ${stderr}
91477debc4SPrashanth Katti
92477debc4SPrashanth KattiPower Off Via XCAT
93477debc4SPrashanth Katti    [Documentation]  Power off via XCAT.
94477debc4SPrashanth Katti    [Arguments]  ${node}
95477debc4SPrashanth Katti
96477debc4SPrashanth Katti    # Description of the argument(s):
97477debc4SPrashanth Katti    # node  Name of the node.
98477debc4SPrashanth Katti
99477debc4SPrashanth Katti    ${stdout}  ${stderr}=  Execute Command  ${XCAT_DIR_PATH}/rpower ${node} off
100477debc4SPrashanth Katti    ...  return_stderr=True
101477debc4SPrashanth Katti    Should Be Empty  ${stderr}
102477debc4SPrashanth Katti
103477debc4SPrashanth KattiGet Power Status
104477debc4SPrashanth Katti    [Documentation]  Get power status via XCAT.
105477debc4SPrashanth Katti    [Arguments]  ${node}
106477debc4SPrashanth Katti
107477debc4SPrashanth Katti    # Description of the argument(s):
108477debc4SPrashanth Katti    # node  Name of the node.
109477debc4SPrashanth Katti
110477debc4SPrashanth Katti    ${stdout}  ${stderr}=  Execute Command
111477debc4SPrashanth Katti    ...  ${XCAT_DIR_PATH}/rpower ${node} state  return_stderr=True
112477debc4SPrashanth Katti    Should Be Empty  ${stderr}
113477debc4SPrashanth Katti
114*409df05dSGeorge Keishing    RETURN  ${stdout}
115b974a747SPrashanth Katti
116b974a747SPrashanth KattiAdd Nodes To Group
117b974a747SPrashanth Katti    [Documentation]  Add BMC nodes to group.
118b974a747SPrashanth Katti    [Arguments]  ${node}  ${group}=${GROUP}
119b974a747SPrashanth Katti
120b974a747SPrashanth Katti    # Description of argument(s):
121b974a747SPrashanth Katti    # node   Name of the node (e.g. "node1").
122b974a747SPrashanth Katti    # group  Name of the group (e.g. "openbmc").
123b974a747SPrashanth Katti
124b974a747SPrashanth Katti    ${stdout}  ${stderr}=  Execute Command
125b974a747SPrashanth Katti    ...  ${XCAT_DIR_PATH}/chdef ${node} groups=${group}  return_stderr=True
126b974a747SPrashanth Katti    Should Be Empty  ${stderr}
127b974a747SPrashanth Katti
128b974a747SPrashanth KattiGet List Of Nodes In Group
129b974a747SPrashanth Katti    [Documentation]  Get list of nodes in BMC.
130b974a747SPrashanth Katti    [Arguments]  ${group}=${GROUP}
131b974a747SPrashanth Katti
132b974a747SPrashanth Katti    # Description of argument(s):
133b974a747SPrashanth Katti    # group  Name of the group (e.g. "openbmc").
134b974a747SPrashanth Katti
135b974a747SPrashanth Katti    # Sample output of this keyword:
136b974a747SPrashanth Katti    # XXX.XXX.XXX.XXX
137b974a747SPrashanth Katti    # YYY.YYY.YYY.YYY
138b974a747SPrashanth Katti    # ZZZ.ZZZ.ZZZ.ZZZ
139b974a747SPrashanth Katti
140b974a747SPrashanth Katti    ${stdout}  ${stderr}=  Execute Command
141b974a747SPrashanth Katti    ...  ${XCAT_DIR_PATH}/nodels ${group}  return_stderr=True
142b974a747SPrashanth Katti    Should Be Empty  ${stderr}
143b974a747SPrashanth Katti
144*409df05dSGeorge Keishing    RETURN  ${stdout}
145b974a747SPrashanth Katti
146b974a747SPrashanth KattiValidate Node Added In Group
147b974a747SPrashanth Katti    [Documentation]  Validate whether node is added in group.
148b974a747SPrashanth Katti    [Arguments]  ${node}  ${group}
149b974a747SPrashanth Katti
150b974a747SPrashanth Katti    # Description of argument(s):
151b974a747SPrashanth Katti    # node   Name of the node (e.g. "node1").
152b974a747SPrashanth Katti    # group  Name of the group (e.g. "openbmc").
153b974a747SPrashanth Katti
154b974a747SPrashanth Katti    ${nodes_in_group}=  Get List Of Nodes In Group  ${group}
155b974a747SPrashanth Katti    Should Contain  ${nodes_in_group}  ${node}
156b974a747SPrashanth Katti    ...  msg=BMC node is not added in a group.
157b974a747SPrashanth Katti
15856cbd17fSPrashanth KattiGet Hardware Vitals Via XCAT
15956cbd17fSPrashanth Katti    [Documentation]  Get hardware vitals via XCAT.
16056cbd17fSPrashanth Katti    [Arguments]  ${node}  ${option}
16156cbd17fSPrashanth Katti
16256cbd17fSPrashanth Katti    # Description of argument(s):
16356cbd17fSPrashanth Katti    # node    Name of the node (e.g. "node1").
16456cbd17fSPrashanth Katti    # option  Hardware vitals option (e.g. "temp", "voltage", "fanspeed", etc.).
16556cbd17fSPrashanth Katti
16656cbd17fSPrashanth Katti    ${cmd_buf}=  Catenate  ${XCAT_DIR_PATH}/rvitals ${node} ${option}
16756cbd17fSPrashanth Katti    ${stdout}  ${stderr}=  Execute Command  ${cmd_buf}  return_stderr=True
16856cbd17fSPrashanth Katti    Should Be Empty  ${stderr}
16956cbd17fSPrashanth Katti
170*409df05dSGeorge Keishing    RETURN  ${stdout}
171