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