Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 1 | *** Settings *** |
| 2 | Resource ../lib/utils.robot |
| 3 | Resource ../lib/connection_client.robot |
| 4 | Resource ../lib/boot_utils.robot |
| 5 | |
| 6 | *** Variables *** |
| 7 | # MAC input from user. |
| 8 | ${MAC_ADDRESS} ${EMPTY} |
| 9 | |
| 10 | |
| 11 | *** Keywords *** |
| 12 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 13 | Check And Reset MAC |
| 14 | [Documentation] Update BMC with user input MAC address. |
| 15 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 16 | |
| 17 | # Description of argument(s): |
| 18 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 19 | |
| 20 | Should Not Be Empty ${mac_address} |
| 21 | Open Connection And Log In |
| 22 | ${bmc_mac_addr}= Execute Command On BMC cat /sys/class/net/eth0/address |
| 23 | Run Keyword If '${mac_address.lower()}' != '${bmc_mac_addr.lower()}' |
| 24 | ... Set MAC Address |
| 25 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 26 | |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 27 | Set MAC Address |
| 28 | [Documentation] Update eth0 with input MAC address. |
| 29 | [Arguments] ${mac_address}=${MAC_ADDRESS} |
| 30 | |
| 31 | # Description of argument(s): |
| 32 | # mac_address The mac address (e.g. 00:01:6c:80:02:28). |
| 33 | |
| 34 | Write fw_setenv ethaddr ${mac_address} |
| 35 | OBMC Reboot (off) |
Sunil M | d1c4f27 | 2017-07-07 09:03:24 -0500 | [diff] [blame] | 36 | |
| 37 | # Take SSH session post BMC reboot. |
| 38 | Open Connection And Log In |
Michael Walsh | 1b0ceb2 | 2017-05-31 16:03:01 -0500 | [diff] [blame] | 39 | ${bmc_mac_addr}= Execute Command On BMC cat /sys/class/net/eth0/address |
| 40 | Should Be Equal ${bmc_mac_addr} ${mac_address} ignore_case=True |
| 41 | |
Prashanth Katti | e79c540 | 2017-06-08 07:40:49 -0500 | [diff] [blame] | 42 | |
| 43 | Get BMC IP Info |
| 44 | [Documentation] Get system IP address and prefix length. |
| 45 | |
| 46 | Open Connection And Login |
| 47 | |
| 48 | # Get system IP address and prefix length details using "ip addr" |
| 49 | # Sample Output of "ip addr": |
| 50 | # 1: eth0: <BROADCAST,MULTIAST> mtu 1500 qdisc mq state UP qlen 1000 |
| 51 | # link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff |
| 52 | # inet xx.xx.xx.xx/24 brd xx.xx.xx.xx scope global eth0 |
| 53 | |
| 54 | ${cmd_output}= Execute Command On BMC /sbin/ip addr | grep eth0 |
| 55 | |
| 56 | # Get line having IP address details. |
| 57 | ${lines}= Get Lines Containing String ${cmd_output} inet |
| 58 | |
| 59 | # List IP address details. |
| 60 | @{ip_components}= Split To Lines ${lines} |
| 61 | |
| 62 | @{ip_data}= Create List |
| 63 | |
| 64 | # Get all IP addresses and prefix lengths on system. |
| 65 | :FOR ${ip_component} IN @{ip_components} |
| 66 | \ @{if_info}= Split String ${ip_component} |
| 67 | \ ${ip_n_prefix}= Get From List ${if_info} 1 |
| 68 | \ Append To List ${ip_data} ${ip_n_prefix} |
| 69 | |
| 70 | [Return] ${ip_data} |
| 71 | |
| 72 | Get BMC Route Info |
| 73 | [Documentation] Get system route info. |
| 74 | |
| 75 | Open Connection And Login |
| 76 | |
| 77 | # Sample output of "ip route": |
| 78 | # default via xx.xx.xx.x dev eth0 |
| 79 | # xx.xx.xx.0/23 dev eth0 src xx.xx.xx.xx |
| 80 | # xx.xx.xx.0/24 dev eth0 src xx.xx.xx.xx |
| 81 | |
| 82 | ${cmd_output}= Execute Command On BMC /sbin/ip route |
| 83 | |
| 84 | [Return] ${cmd_output} |
| 85 | |
| 86 | Get BMC MAC Address |
| 87 | [Documentation] Get system MAC address. |
| 88 | |
| 89 | Open Connection And Login |
| 90 | |
| 91 | # Sample output of "ip addr | grep ether": |
| 92 | # link/ether xx.xx.xx.xx.xx.xx brd ff:ff:ff:ff:ff:ff |
| 93 | |
| 94 | ${cmd_output}= Execute Command On BMC /sbin/ip addr | grep ether |
| 95 | |
Prashanth Katti | 9819b16 | 2017-12-12 05:38:59 -0600 | [diff] [blame] | 96 | # Split the line and return MAC address. |
| 97 | # Split list data: |
| 98 | # link/ether | xx:xx:xx:xx:xx:xx | brd | ff:ff:ff:ff:ff:ff |
| 99 | |
| 100 | @{words}= Split String ${cmd_output} |
| 101 | |
| 102 | [Return] ${words[1]} |
Prashanth Katti | 40fb8ca | 2017-07-25 06:47:23 -0500 | [diff] [blame] | 103 | |
| 104 | Get BMC Hostname |
| 105 | [Documentation] Get BMC hostname. |
| 106 | |
| 107 | # Sample output of "hostnamectl": |
| 108 | # Static hostname: xxyyxxyyxx |
| 109 | # Icon name: computer |
| 110 | # Machine ID: 6939927dc0db409ea09289d5b56eef08 |
| 111 | # Boot ID: bb806955fd904d47b6aa4bc7c34df482 |
| 112 | # Operating System: Phosphor OpenBMC (xxx xx xx) v1.xx.x-xx |
| 113 | # Kernel: Linux 4.10.17-d6ae40dc4c4dff3265cc254d404ed6b03fcc2206 |
| 114 | # Architecture: arm |
| 115 | |
| 116 | ${output}= Execute Command on BMC hostnamectl | grep hostname |
| 117 | |
| 118 | [Return] ${output} |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 119 | |
| 120 | Get List Of IP Address Via REST |
| 121 | [Documentation] Get list of IP address via REST. |
| 122 | [Arguments] @{ip_uri_list} |
| 123 | |
| 124 | # Description of argument(s): |
| 125 | # ip_uri_list List of IP objects. |
| 126 | # Example: |
| 127 | # "data": [ |
| 128 | # "/xyz/openbmc_project/network/eth0/ipv4/e9767624", |
| 129 | # "/xyz/openbmc_project/network/eth0/ipv4/31f4ce8b" |
| 130 | # ], |
| 131 | |
| 132 | ${ip_list}= Create List |
| 133 | |
| 134 | : FOR ${ip_uri} IN @{ip_uri_list} |
| 135 | \ ${ip_addr}= Read Attribute ${ip_uri} Address |
| 136 | \ Append To List ${ip_list} ${ip_addr} |
| 137 | |
| 138 | [Return] @{ip_list} |
| 139 | |
| 140 | Delete IP And Object |
| 141 | [Documentation] Delete IP and object. |
| 142 | [Arguments] ${ip_addr} @{ip_uri_list} |
| 143 | |
| 144 | # Description of argument(s): |
| 145 | # ip_addr IP address to be deleted. |
| 146 | # ip_uri_list List of IP object URIs. |
| 147 | |
| 148 | # Find IP object having this IP address. |
| 149 | |
| 150 | : FOR ${ip_uri} IN @{ip_uri_list} |
| 151 | \ ${ip_addr1}= Read Attribute ${ip_uri} Address |
| 152 | \ Run Keyword If '${ip_addr}' == '${ip_addr1}' Exit For Loop |
| 153 | |
| 154 | # If the given IP address is not configured, return. |
| 155 | # Otherwise, delete the IP and object. |
| 156 | |
| 157 | Run Keyword And Return If '${ip_addr}' != '${ip_addr1}' |
| 158 | ... Pass Execution IP address to be deleted is not configured. |
| 159 | |
| 160 | Run Keyword And Ignore Error OpenBMC Delete Request ${ip_uri} |
| 161 | |
| 162 | # After any modification on network interface, BMC restarts network |
| 163 | # module, wait until it is reachable. |
| 164 | |
Prashanth Katti | 3690dc0 | 2017-11-22 07:21:24 -0600 | [diff] [blame] | 165 | Wait For Host To Ping ${OPENBMC_HOST} ${NETWORK_RETRY_TIME} |
| 166 | ... ${NETWORK_TIMEOUT} |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 167 | |
| 168 | # Verify whether deleted IP address is removed from BMC system. |
| 169 | |
| 170 | ${ip_data}= Get BMC IP Info |
Prashanth Katti | 160faf6 | 2017-09-07 01:05:56 -0500 | [diff] [blame] | 171 | Should Not Contain Match ${ip_data} ${ip_addr}* |
Prashanth Katti | 90f9ff2 | 2017-08-11 06:17:12 -0500 | [diff] [blame] | 172 | ... msg=IP address not deleted. |