xref: /openbmc/openbmc-test-automation/lib/xcat/xcat_utils.robot (revision 892422901270894aa8115a0579fa21b2c6cbae7a)
1*** Settings ***
2
3Resource    ../xcat/resource.robot
4Resource    ../../lib/resource.robot
5
6Library     SSHLibrary
7Library     OperatingSystem
8Library     String
9
10*** Keywords  ***
11
12Open Connection And Login To XCAT
13    [Documentation]  Open connection and login to xCAT server.
14    [Arguments]  ${xcat_host}=${XCAT_HOST}  ${xcat_port}=${XCAT_PORT}
15
16    # Description of argument(s):
17    # xcat_host  IP address of the XCAT server.
18    # xcat_port  Network port on which XCAT server accepts ssh session.
19
20    SSHLibrary.Open Connection  ${xcat_host}  port=${xcat_port}
21    SSHLibrary.Login  ${XCAT_USERNAME}  ${XCAT_PASSWORD}
22
23
24Execute Command On XCAT
25    [Documentation]  Execute command using XCAT.
26    [Arguments]  ${command}  ${command_option}=${EMPTY}
27    ...  ${node}=${OPENBMC_HOST}
28
29    # Description of argument(s):
30    # command         Command to be run(e.g. "rinv").
31    # command_option  Command's option to be run(e.g. "dimm").
32    # node            Name of the node(e.g. "node1").
33
34    ${xcat_cmd}=  Catenate  SEPARATOR=
35    ...  ${XCAT_DIR_PATH}/${command} ${node} ${command_option}
36    ${stdout}  ${stderr}=  Execute Command  ${xcat_cmd}  return_stderr=True
37    Should Be Empty  ${stderr}
38
39    RETURN  ${stdout}
40
41
42Get List Of BMC Nodes
43    [Documentation]  Get list of BMC nodes.
44    [Arguments]  ${node_cfg_file_path}=${NODE_CFG_FILE_PATH}
45
46    # Get the list of BMC nodes to be added.
47    # node_cfg_file_path    This keyword expects file having list of BMC nodes
48    #                       as an input.
49    #                       File should have IP addresses of BMC nodes.
50
51    OperatingSystem.File Should Exist  ${node_cfg_file_path}  msg=cfg file missing.
52    File Should Not Be Empty  ${node_cfg_file_path}  msg=Empty config file.
53
54    ${bmc_list}=  OperatingSystem.Get File  ${node_cfg_file_path}
55    RETURN  ${bmc_list}
56
57
58Add Nodes To XCAT
59    [Documentation]  Add nodes to XCAT configuration.
60    [Arguments]  ${node}  ${username}=${OPENBMC_USERNAME}
61    ...          ${password}=${OPENBMC_PASSWORD}
62
63    # Description of the argument(s):
64    # node         Name of the node to be added.
65    # username     User name to login.
66    # password     Password to login.
67
68    ${cmd_buf}=  Catenate  ${XCAT_DIR_PATH}/mkdef ${node} bmc=${node}
69    ...  bmcusername=${username} bmcpassword=${password} mgt=openbmc groups=all
70    Execute Command  ${cmd_buf}
71
72
73Validate Added Node
74    [Documentation]  Validate added node.
75    [Arguments]  ${node}
76
77    # Description of the argument(s):
78    # node  Name of the node.
79
80    ${stdout}  ${stderr}=  Execute Command  ${XCAT_DIR_PATH}/nodels
81    ...  return_stderr=True
82    Should Be Empty  ${stderr}
83    Should Contain  ${std_out}  ${node}  msg=Node is not added.
84
85Power On Via XCAT
86    [Documentation]  Power on via XCAT.
87    [Arguments]  ${node}
88
89    # Description of the argument(s):
90    # node  Name of the node.
91
92    ${stdout}  ${stderr}=  Execute Command  ${XCAT_DIR_PATH}/rpower ${node} on
93    ...  return_stderr=True
94    Should Be Empty  ${stderr}
95
96Power Off Via XCAT
97    [Documentation]  Power off via XCAT.
98    [Arguments]  ${node}
99
100    # Description of the argument(s):
101    # node  Name of the node.
102
103    ${stdout}  ${stderr}=  Execute Command  ${XCAT_DIR_PATH}/rpower ${node} off
104    ...  return_stderr=True
105    Should Be Empty  ${stderr}
106
107Get Power Status
108    [Documentation]  Get power status via XCAT.
109    [Arguments]  ${node}
110
111    # Description of the argument(s):
112    # node  Name of the node.
113
114    ${stdout}  ${stderr}=  Execute Command
115    ...  ${XCAT_DIR_PATH}/rpower ${node} state  return_stderr=True
116    Should Be Empty  ${stderr}
117
118    RETURN  ${stdout}
119
120Add Nodes To Group
121    [Documentation]  Add BMC nodes to group.
122    [Arguments]  ${node}  ${group}=${GROUP}
123
124    # Description of argument(s):
125    # node   Name of the node (e.g. "node1").
126    # group  Name of the group (e.g. "openbmc").
127
128    ${stdout}  ${stderr}=  Execute Command
129    ...  ${XCAT_DIR_PATH}/chdef ${node} groups=${group}  return_stderr=True
130    Should Be Empty  ${stderr}
131
132Get List Of Nodes In Group
133    [Documentation]  Get list of nodes in BMC.
134    [Arguments]  ${group}=${GROUP}
135
136    # Description of argument(s):
137    # group  Name of the group (e.g. "openbmc").
138
139    # Sample output of this keyword:
140    # XXX.XXX.XXX.XXX
141    # YYY.YYY.YYY.YYY
142    # ZZZ.ZZZ.ZZZ.ZZZ
143
144    ${stdout}  ${stderr}=  Execute Command
145    ...  ${XCAT_DIR_PATH}/nodels ${group}  return_stderr=True
146    Should Be Empty  ${stderr}
147
148    RETURN  ${stdout}
149
150Validate Node Added In Group
151    [Documentation]  Validate whether node is added in group.
152    [Arguments]  ${node}  ${group}
153
154    # Description of argument(s):
155    # node   Name of the node (e.g. "node1").
156    # group  Name of the group (e.g. "openbmc").
157
158    ${nodes_in_group}=  Get List Of Nodes In Group  ${group}
159    Should Contain  ${nodes_in_group}  ${node}
160    ...  msg=BMC node is not added in a group.
161
162Get Hardware Vitals Via XCAT
163    [Documentation]  Get hardware vitals via XCAT.
164    [Arguments]  ${node}  ${option}
165
166    # Description of argument(s):
167    # node    Name of the node (e.g. "node1").
168    # option  Hardware vitals option (e.g. "temp", "voltage", "fanspeed", etc.).
169
170    ${cmd_buf}=  Catenate  ${XCAT_DIR_PATH}/rvitals ${node} ${option}
171    ${stdout}  ${stderr}=  Execute Command  ${cmd_buf}  return_stderr=True
172    Should Be Empty  ${stderr}
173
174    RETURN  ${stdout}
175