blob: 8c0e2ef2e90b58009a73ed5d68f632bf4bc8e37b [file] [log] [blame]
Michael Walsh1b0ceb22017-05-31 16:03:01 -05001*** Settings ***
2Resource ../lib/utils.robot
3Resource ../lib/connection_client.robot
4Resource ../lib/boot_utils.robot
George Keishing58e47232018-02-12 10:35:15 -06005Library ../lib/gen_misc.py
George Keishingbf724772018-02-21 08:57:16 -06006Library ../lib/utils.py
Michael Walsh1b0ceb22017-05-31 16:03:01 -05007
8*** Variables ***
9# MAC input from user.
10${MAC_ADDRESS} ${EMPTY}
11
12
13*** Keywords ***
14
Michael Walsh1b0ceb22017-05-31 16:03:01 -050015Check And Reset MAC
16 [Documentation] Update BMC with user input MAC address.
17 [Arguments] ${mac_address}=${MAC_ADDRESS}
18
19 # Description of argument(s):
20 # mac_address The mac address (e.g. 00:01:6c:80:02:28).
21
22 Should Not Be Empty ${mac_address}
23 Open Connection And Log In
24 ${bmc_mac_addr}= Execute Command On BMC cat /sys/class/net/eth0/address
25 Run Keyword If '${mac_address.lower()}' != '${bmc_mac_addr.lower()}'
26 ... Set MAC Address
27
Michael Walsh1b0ceb22017-05-31 16:03:01 -050028
Michael Walsh1b0ceb22017-05-31 16:03:01 -050029Set MAC Address
30 [Documentation] Update eth0 with input MAC address.
31 [Arguments] ${mac_address}=${MAC_ADDRESS}
32
33 # Description of argument(s):
34 # mac_address The mac address (e.g. 00:01:6c:80:02:28).
35
36 Write fw_setenv ethaddr ${mac_address}
37 OBMC Reboot (off)
Sunil Md1c4f272017-07-07 09:03:24 -050038
39 # Take SSH session post BMC reboot.
40 Open Connection And Log In
Michael Walsh1b0ceb22017-05-31 16:03:01 -050041 ${bmc_mac_addr}= Execute Command On BMC cat /sys/class/net/eth0/address
42 Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True
43
Prashanth Kattie79c5402017-06-08 07:40:49 -050044
45Get BMC IP Info
46 [Documentation] Get system IP address and prefix length.
47
48 Open Connection And Login
49
50 # Get system IP address and prefix length details using "ip addr"
51 # Sample Output of "ip addr":
52 # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000
53 # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
54 # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0
55
56 ${cmd_output}= Execute Command On BMC /sbin/ip addr | grep eth0
57
58 # Get line having IP address details.
59 ${lines}= Get Lines Containing String ${cmd_output} inet
60
61 # List IP address details.
62 @{ip_components}= Split To Lines ${lines}
63
64 @{ip_data}= Create List
65
66 # Get all IP addresses and prefix lengths on system.
67 :FOR ${ip_component} IN @{ip_components}
68 \ @{if_info}= Split String ${ip_component}
69 \ ${ip_n_prefix}= Get From List ${if_info} 1
70 \ Append To List ${ip_data} ${ip_n_prefix}
71
72 [Return] ${ip_data}
73
74Get BMC Route Info
75 [Documentation] Get system route info.
76
77 Open Connection And Login
78
79 # Sample output of "ip route":
80 # default via xx.xx.xx.x dev eth0
81 # xx.xx.xx.0/23 dev eth0 src xx.xx.xx.xx
82 # xx.xx.xx.0/24 dev eth0 src xx.xx.xx.xx
83
84 ${cmd_output}= Execute Command On BMC /sbin/ip route
85
86 [Return] ${cmd_output}
87
George Keishing02651f02018-04-11 02:07:16 -050088# TODO: openbmc/openbmc-test-automation#1331
Prashanth Kattie79c5402017-06-08 07:40:49 -050089Get BMC MAC Address
90 [Documentation] Get system MAC address.
91
92 Open Connection And Login
93
94 # Sample output of "ip addr | grep ether":
95 # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
96
97 ${cmd_output}= Execute Command On BMC /sbin/ip addr | grep ether
98
Prashanth Katti9819b162017-12-12 05:38:59 -060099 # Split the line and return MAC address.
100 # Split list data:
101 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
102
103 @{words}= Split String ${cmd_output}
104
105 [Return] ${words[1]}
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500106
George Keishing02651f02018-04-11 02:07:16 -0500107
108Get BMC MAC Address List
109 [Documentation] Get system MAC address
110
111 # Sample output of "ip addr | grep ether":
112 # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
113
114 ${cmd_output}= BMC Execute Command /sbin/ip addr | grep ether
115
116 # Split the line and return MAC address.
117 # Split list data:
118 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
119 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
120
121 ${mac_list}= Create List
122 @{lines}= Split To Lines ${cmd_output[0]}
123 :FOR ${line} IN @{lines}
124 \ @{words}= Split String ${line}
125 \ Append To List ${mac_list} ${words[1]}
126
127 [Return] ${mac_list}
128
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500129Get BMC Hostname
130 [Documentation] Get BMC hostname.
131
132 # Sample output of "hostnamectl":
133 # Static hostname: xxyyxxyyxx
134 # Icon name: computer
135 # Machine ID: 6939927dc0db409ea09289d5b56eef08
136 # Boot ID: bb806955fd904d47b6aa4bc7c34df482
137 # Operating System: Phosphor OpenBMC (xxx xx xx) v1.xx.x-xx
138 # Kernel: Linux 4.10.17-d6ae40dc4c4dff3265cc254d404ed6b03fcc2206
139 # Architecture: arm
140
141 ${output}= Execute Command on BMC hostnamectl | grep hostname
142
143 [Return] ${output}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500144
145Get List Of IP Address Via REST
146 [Documentation] Get list of IP address via REST.
147 [Arguments] @{ip_uri_list}
148
149 # Description of argument(s):
150 # ip_uri_list List of IP objects.
151 # Example:
152 # "data": [
153 # "/xyz/openbmc_project/network/eth0/ipv4/e9767624",
154 # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b"
155 # ],
156
157 ${ip_list}= Create List
158
159 : FOR ${ip_uri} IN @{ip_uri_list}
160 \ ${ip_addr}= Read Attribute ${ip_uri} Address
161 \ Append To List ${ip_list} ${ip_addr}
162
163 [Return] @{ip_list}
164
165Delete IP And Object
166 [Documentation] Delete IP and object.
167 [Arguments] ${ip_addr} @{ip_uri_list}
168
169 # Description of argument(s):
170 # ip_addr IP address to be deleted.
171 # ip_uri_list List of IP object URIs.
172
173 # Find IP object having this IP address.
174
175 : FOR ${ip_uri} IN @{ip_uri_list}
176 \ ${ip_addr1}= Read Attribute ${ip_uri} Address
177 \ Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop
178
179 # If the given IP address is not configured, return.
180 # Otherwise, delete the IP and object.
181
182 Run Keyword And Return If '${ip_addr}' != '${ip_addr1}'
183 ... Pass Execution IP address to be deleted is not configured.
184
185 Run Keyword And Ignore Error OpenBMC Delete Request ${ip_uri}
186
187 # After any modification on network interface, BMC restarts network
188 # module, wait until it is reachable.
189
Prashanth Katti3690dc02017-11-22 07:21:24 -0600190 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_RETRY_TIME}
191 ... ${NETWORK_TIMEOUT}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500192
193 # Verify whether deleted IP address is removed from BMC system.
194
195 ${ip_data}= Get BMC IP Info
Prashanth Katti160faf62017-09-07 01:05:56 -0500196 Should Not Contain Match ${ip_data} ${ip_addr}*
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500197 ... msg=IP address not deleted.
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600198
George Keishing58e47232018-02-12 10:35:15 -0600199Get First Non Pingable IP From Subnet
200 [Documentation] Find first non-pingable IP from the subnet and return it.
201 [Arguments] ${host}=${OPENBMC_HOST}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600202
203 # Description of argument(s):
George Keishing58e47232018-02-12 10:35:15 -0600204 # host Any valid host name or IP address
205 # (e.g. "machine1" or "9.xx.xx.31").
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600206
George Keishing58e47232018-02-12 10:35:15 -0600207 # Non-pingable IP is unused IP address in the subnet.
208 ${host_name} ${ip_addr}= Get Host Name IP
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600209
210 # Split IP address into network part and host part.
211 # IP address will have 4 octets xx.xx.xx.xx.
212 # Sample output after split:
213 # split_ip [xx.xx.xx, xx]
214
215 ${split_ip}= Split String From Right ${ip_addr} . 1
216 # First element in list is Network part.
217 ${network_part}= Get From List ${split_ip} 0
218
George Keishing58e47232018-02-12 10:35:15 -0600219 : FOR ${octet4} IN RANGE 1 255
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600220 \ ${new_ip}= Catenate ${network_part}.${octet4}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600221 \ ${status}= Run Keyword And Return Status Ping Host ${new_ip}
George Keishing58e47232018-02-12 10:35:15 -0600222 # If IP is non-pingable, return it.
223 \ Return From Keyword If '${status}' == 'False' ${new_ip}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600224
George Keishing58e47232018-02-12 10:35:15 -0600225 Fail msg=No non-pingable IP could be found in subnet ${network_part}.
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600226
George Keishingbf724772018-02-21 08:57:16 -0600227
228Validate MAC On BMC
229 [Documentation] Validate MAC on BMC.
230 [Arguments] ${mac_addr}
231
232 # Description of argument(s):
233 # mac_addr MAC address of the BMC.
234
235 ${system_mac}= Get BMC MAC Address
236
237 ${status}= Compare MAC Address ${system_mac} ${mac_addr}
238 Should Be True ${status}
239 ... msg=MAC address ${system_mac} does not match ${mac_addr}.
240