blob: 7946974b73b5be122d59931e8a40f5cd12ba6bbc [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
Michael Walsh1b0ceb22017-05-31 16:03:01 -05006
7*** Variables ***
8# MAC input from user.
9${MAC_ADDRESS} ${EMPTY}
10
11
12*** Keywords ***
13
Michael Walsh1b0ceb22017-05-31 16:03:01 -050014Check And Reset MAC
15 [Documentation] Update BMC with user input MAC address.
16 [Arguments] ${mac_address}=${MAC_ADDRESS}
17
18 # Description of argument(s):
19 # mac_address The mac address (e.g. 00:01:6c:80:02:28).
20
21 Should Not Be Empty ${mac_address}
22 Open Connection And Log In
23 ${bmc_mac_addr}= Execute Command On BMC cat /sys/class/net/eth0/address
24 Run Keyword If '${mac_address.lower()}' != '${bmc_mac_addr.lower()}'
25 ... Set MAC Address
26
Michael Walsh1b0ceb22017-05-31 16:03:01 -050027
Michael Walsh1b0ceb22017-05-31 16:03:01 -050028Set MAC Address
29 [Documentation] Update eth0 with input MAC address.
30 [Arguments] ${mac_address}=${MAC_ADDRESS}
31
32 # Description of argument(s):
33 # mac_address The mac address (e.g. 00:01:6c:80:02:28).
34
35 Write fw_setenv ethaddr ${mac_address}
36 OBMC Reboot (off)
Sunil Md1c4f272017-07-07 09:03:24 -050037
38 # Take SSH session post BMC reboot.
39 Open Connection And Log In
Michael Walsh1b0ceb22017-05-31 16:03:01 -050040 ${bmc_mac_addr}= Execute Command On BMC cat /sys/class/net/eth0/address
41 Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True
42
Prashanth Kattie79c5402017-06-08 07:40:49 -050043
44Get BMC IP Info
45 [Documentation] Get system IP address and prefix length.
46
47 Open Connection And Login
48
49 # Get system IP address and prefix length details using "ip addr"
50 # Sample Output of "ip addr":
51 # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000
52 # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
53 # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0
54
55 ${cmd_output}= Execute Command On BMC /sbin/ip addr | grep eth0
56
57 # Get line having IP address details.
58 ${lines}= Get Lines Containing String ${cmd_output} inet
59
60 # List IP address details.
61 @{ip_components}= Split To Lines ${lines}
62
63 @{ip_data}= Create List
64
65 # Get all IP addresses and prefix lengths on system.
66 :FOR ${ip_component} IN @{ip_components}
67 \ @{if_info}= Split String ${ip_component}
68 \ ${ip_n_prefix}= Get From List ${if_info} 1
69 \ Append To List ${ip_data} ${ip_n_prefix}
70
71 [Return] ${ip_data}
72
73Get BMC Route Info
74 [Documentation] Get system route info.
75
76 Open Connection And Login
77
78 # Sample output of "ip route":
79 # default via xx.xx.xx.x dev eth0
80 # xx.xx.xx.0/23 dev eth0 src xx.xx.xx.xx
81 # xx.xx.xx.0/24 dev eth0 src xx.xx.xx.xx
82
83 ${cmd_output}= Execute Command On BMC /sbin/ip route
84
85 [Return] ${cmd_output}
86
87Get BMC MAC Address
88 [Documentation] Get system MAC address.
89
90 Open Connection And Login
91
92 # Sample output of "ip addr | grep ether":
93 # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff
94
95 ${cmd_output}= Execute Command On BMC /sbin/ip addr | grep ether
96
Prashanth Katti9819b162017-12-12 05:38:59 -060097 # Split the line and return MAC address.
98 # Split list data:
99 # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff
100
101 @{words}= Split String ${cmd_output}
102
103 [Return] ${words[1]}
Prashanth Katti40fb8ca2017-07-25 06:47:23 -0500104
105Get BMC Hostname
106 [Documentation] Get BMC hostname.
107
108 # Sample output of "hostnamectl":
109 # Static hostname: xxyyxxyyxx
110 # Icon name: computer
111 # Machine ID: 6939927dc0db409ea09289d5b56eef08
112 # Boot ID: bb806955fd904d47b6aa4bc7c34df482
113 # Operating System: Phosphor OpenBMC (xxx xx xx) v1.xx.x-xx
114 # Kernel: Linux 4.10.17-d6ae40dc4c4dff3265cc254d404ed6b03fcc2206
115 # Architecture: arm
116
117 ${output}= Execute Command on BMC hostnamectl | grep hostname
118
119 [Return] ${output}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500120
121Get List Of IP Address Via REST
122 [Documentation] Get list of IP address via REST.
123 [Arguments] @{ip_uri_list}
124
125 # Description of argument(s):
126 # ip_uri_list List of IP objects.
127 # Example:
128 # "data": [
129 # "/xyz/openbmc_project/network/eth0/ipv4/e9767624",
130 # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b"
131 # ],
132
133 ${ip_list}= Create List
134
135 : FOR ${ip_uri} IN @{ip_uri_list}
136 \ ${ip_addr}= Read Attribute ${ip_uri} Address
137 \ Append To List ${ip_list} ${ip_addr}
138
139 [Return] @{ip_list}
140
141Delete IP And Object
142 [Documentation] Delete IP and object.
143 [Arguments] ${ip_addr} @{ip_uri_list}
144
145 # Description of argument(s):
146 # ip_addr IP address to be deleted.
147 # ip_uri_list List of IP object URIs.
148
149 # Find IP object having this IP address.
150
151 : FOR ${ip_uri} IN @{ip_uri_list}
152 \ ${ip_addr1}= Read Attribute ${ip_uri} Address
153 \ Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop
154
155 # If the given IP address is not configured, return.
156 # Otherwise, delete the IP and object.
157
158 Run Keyword And Return If '${ip_addr}' != '${ip_addr1}'
159 ... Pass Execution IP address to be deleted is not configured.
160
161 Run Keyword And Ignore Error OpenBMC Delete Request ${ip_uri}
162
163 # After any modification on network interface, BMC restarts network
164 # module, wait until it is reachable.
165
Prashanth Katti3690dc02017-11-22 07:21:24 -0600166 Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_RETRY_TIME}
167 ... ${NETWORK_TIMEOUT}
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500168
169 # Verify whether deleted IP address is removed from BMC system.
170
171 ${ip_data}= Get BMC IP Info
Prashanth Katti160faf62017-09-07 01:05:56 -0500172 Should Not Contain Match ${ip_data} ${ip_addr}*
Prashanth Katti90f9ff22017-08-11 06:17:12 -0500173 ... msg=IP address not deleted.
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600174
George Keishing58e47232018-02-12 10:35:15 -0600175Get First Non Pingable IP From Subnet
176 [Documentation] Find first non-pingable IP from the subnet and return it.
177 [Arguments] ${host}=${OPENBMC_HOST}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600178
179 # Description of argument(s):
George Keishing58e47232018-02-12 10:35:15 -0600180 # host Any valid host name or IP address
181 # (e.g. "machine1" or "9.xx.xx.31").
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600182
George Keishing58e47232018-02-12 10:35:15 -0600183 # Non-pingable IP is unused IP address in the subnet.
184 ${host_name} ${ip_addr}= Get Host Name IP
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600185
186 # Split IP address into network part and host part.
187 # IP address will have 4 octets xx.xx.xx.xx.
188 # Sample output after split:
189 # split_ip [xx.xx.xx, xx]
190
191 ${split_ip}= Split String From Right ${ip_addr} . 1
192 # First element in list is Network part.
193 ${network_part}= Get From List ${split_ip} 0
194
George Keishing58e47232018-02-12 10:35:15 -0600195 : FOR ${octet4} IN RANGE 1 255
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600196 \ ${new_ip}= Catenate ${network_part}.${octet4}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600197 \ ${status}= Run Keyword And Return Status Ping Host ${new_ip}
George Keishing58e47232018-02-12 10:35:15 -0600198 # If IP is non-pingable, return it.
199 \ Return From Keyword If '${status}' == 'False' ${new_ip}
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600200
George Keishing58e47232018-02-12 10:35:15 -0600201 Fail msg=No non-pingable IP could be found in subnet ${network_part}.
Prashanth Kattidf2e4fdf2018-02-07 07:04:13 -0600202