1*** Settings *** 2Documentation Test setting VLAN and its configuration. 3 4 5Resource ../lib/rest_client.robot 6Resource ../lib/ipmi_client.robot 7Resource ../lib/utils.robot 8Resource ../lib/common_utils.robot 9Resource ../lib/openbmc_ffdc.robot 10Resource ../lib/ipmi_client.robot 11Resource ../lib/bmc_network_utils.robot 12Resource ../lib/state_manager.robot 13Library ../lib/utilities.py 14Library ../lib/ipmi_utils.py 15Library ../lib/var_funcs.py 16Library ../lib/func_args.py 17Library Collections 18 19Suite Teardown Suite Teardown Execution 20 21 22*** Variables *** 23${vlan_id} ${53} 24@{vlan_ids} ${35} ${55} 25${invalid_vlan_id} abc 26${vlan_resource} ${NETWORK_MANAGER}action/VLAN 27${network_resource} xyz.openbmc_project.Network.IP.Protocol.IPv4 28${static_network_resource} xyz.openbmc_project.Network.IP.AddressOrigin.Static 29${ip} 10.6.6.10 30@{ip_addresses} 10.5.5.10 10.4.5.7 31${netmask} ${24} 32${gateway} 0.0.0.0 33${initial_vlan_config} @{EMPTY} 34 35 36*** Test Cases *** 37 38Add VLAN Via REST And Verify 39 [Documentation] Add VLAN via REST and verify it via REST and IPMI. 40 [Tags] Add_VLAN_Via_REST_And_Verify 41 [Setup] Test Setup Execution 42 [Teardown] Delete VLANs [${vlan_id}] 43 44 Create VLAN ${vlan_id} 45 Verify Existence Of VLAN ${vlan_id} 46 47 ${lan_config}= Get LAN Print Dict 48 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"] 49 50 51Add Invalid VLAN Via REST And Verify 52 [Documentation] Add Invalid VLAN via REST and verify. 53 [Tags] Add_Invalid_VLAN_Via_REST_And_Verify 54 55 Create VLAN ${invalid_vlan_id} expected_result=error 56 57 58Delete VLAN Via REST 59 [Documentation] Delete VLAN via REST and verify it via REST and IPMI. 60 [Tags] Delete_VLAN_Via_REST 61 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id} 62 63 Verify Existence Of VLAN ${vlan_id} 64 Delete VLANs [${vlan_id}] 65 Verify Existence Of VLAN ${vlan_id} expected_result=error 66 67 ${lan_config}= Get LAN Print Dict 68 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"] 69 70 71Configure Network Settings On VLAN Via REST 72 [Documentation] Configure IP on VLAN and verify it via REST and IPMI. 73 [Tags] Configure_Network_Settings_On_VLAN_Via_REST 74 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id} 75 [Teardown] Delete VLANs [${vlan_id}] 76 77 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask} 78 Get VLAN URI For IP ${vlan_id} ${ip} 79 80 ${lan_config}= Get LAN Print Dict 81 Valid Value lan_config['IP Address'] ["${ip}"] 82 83 84Delete IP On VLAN Via REST 85 [Documentation] Delete IP on VLAN and verify it via REST and IPMI. 86 [Tags] Delete_IP_On_VLAN_Via_REST 87 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id} 88 [Teardown] Delete VLANs [${vlan_id}] 89 90 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask} 91 ${lan_config}= Get LAN Print Dict 92 Valid Value lan_config['IP Address'] ["${ip}"] 93 94 ${vlan_ip_uri}= Get VLAN URI For IP ${vlan_id} ${ip} 95 Delete IP And Object ${ip} ${vlan_ip_uri} 96 97 Get VLAN URI For IP ${vlan_id} ${ip} expected_result=error 98 99 ${lan_config}= Get LAN Print Dict 100 Should Not Match ${lan_config['IP Address']} ${ip} 101 102 103Delete VLAN When IP Is Configured Via REST 104 [Documentation] Delete IP on VLAN and verify using IPMI. 105 [Tags] Delete_VLAN_When_IP_Is_Configured_Via_REST 106 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id} 107 [Teardown] Delete VLANs [${vlan_id}] 108 109 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask} 110 ${lan_config}= Get LAN Print Dict 111 Valid Value lan_config['IP Address'] ["${ip}"] 112 Delete VLANs [${vlan_id}] 113 114 Verify Existence Of VLAN ${vlan_id} expected_result=error 115 116 ${lan_config}= Get LAN Print Dict 117 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"] 118 119 120Configure VLAN And Check Persistency On Reboot 121 [Documentation] Create VLAN ID & IP , reboot and verify. 122 [Tags] Configure_VLAN_And_Check_Persistency_On_Reboot 123 [Setup] Test Setup Execution 124 [Teardown] Delete VLANs [${vlan_id}] 125 126 Create VLAN ${vlan_id} 127 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask} 128 ${lan_config}= Get LAN Print Dict 129 Valid Value lan_config['IP Address'] ["${ip}"] 130 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"] 131 132 Initiate BMC Reboot 133 134 Verify Existence Of VLAN ${vlan_id} 135 Get VLAN URI For IP ${vlan_id} ${ip} 136 137 ${lan_config}= Get LAN Print Dict 138 Valid Value lan_config['IP Address'] ["${ip}"] 139 Valid Value lan_config['802.1q VLAN ID'] ["${vlan_id}"] 140 141 142Add Multiple VLANs Via REST And Verify 143 [Documentation] Add multiple VLANs via REST and verify them via CLI. 144 [Tags] Add_Multiple_VLANs_Via_REST_And_Verify 145 [Setup] Test Setup Execution 146 [Teardown] Delete VLANs ${vlan_ids} 147 148 FOR ${vlan_id} IN @{vlan_ids} 149 Create VLAN ${vlan_id} 150 Verify Existence Of VLAN ${vlan_id} 151 END 152 153 ${lan_config}= Get LAN Print Dict 154 ${vlan_id_ipmi}= Convert To Integer ${lan_config["802.1q VLAN ID"]} 155 Valid List vlan_ids required_values=[${vlan_id_ipmi}] 156 157Delete Multiple IPs On VLAN And Verify 158 [Documentation] Delete multiple IPs on VLAN and verify each via REST and IPMI. 159 [Tags] Delete_Multiple_IP_On_VLAN_Via_REST 160 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id} 161 [Teardown] Delete VLANs [${vlan_id}] 162 163 FOR ${ip} IN @{ip_addresses} 164 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask} 165 ${vlan_ip_uri}= Get VLAN URI For IP ${vlan_id} ${ip} 166 Delete IP And Object ${ip} ${vlan_ip_uri} 167 168 Get VLAN URI For IP ${vlan_id} ${ip} expected_result=error 169 170 ${lan_config}= Get LAN Print Dict 171 Should Not Match ${lan_config['IP Address']} ${ip} 172 END 173 174Delete Multiple VLANs Via REST 175 [Documentation] Delete multiple VLANs via REST and verify each via REST and IPMI. 176 [Tags] Delete_Multiple_VLANs_Via_REST 177 [Setup] Test Setup Execution 178 179 FOR ${vlan_id} IN @{vlan_ids} 180 Create VLAN ${vlan_id} 181 END 182 183 Delete VLANs ${vlan_ids} 184 185 ${lan_config}= Get LAN Print Dict 186 Valid Value lan_config['802.1q VLAN ID'] ["Disabled"] 187 188Configure Multiple IPs On VLAN Via REST 189 [Documentation] Configure Multiple IPs on VLAN and verify each via REST. 190 [Tags] Configure_Multiple_IPs_On_VLAN_Via_REST 191 [Setup] Run Keywords Test Setup Execution AND Create VLAN ${vlan_id} 192 [Teardown] Delete VLANs [${vlan_id}] 193 194 FOR ${ip} IN @{ip_addresses} 195 Configure Network Settings On VLAN ${vlan_id} ${ip} ${netmask} 196 END 197 198 ${lan_config}= Get LAN Print Dict 199 Valid Value lan_config['IP Address'] ["${ip_addresses[0]}"] 200 201*** Keywords *** 202 203 204Test Setup Execution 205 [Documentation] Check and delete all previously created VLAN if any. 206 207 Printn 208 ${lan_config}= Get LAN Print Dict 209 Return From Keyword If '${lan_config['802.1q VLAN ID']}' == 'Disabled' 210 211 # Get all VLAN ID on interface eth0. 212 ${vlan_ids}= Get VLAN IDs 213 214 ${initial_vlan_config}= Create List 215 Set Suite Variable ${initial_vlan_config} 216 217 FOR ${vlan_id} IN @{vlan_ids} 218 ${vlan_records}= Read Properties 219 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1 220 ${vlan_record}= Filter Struct 221 ... ${vlan_records} [('Origin', '${static_network_resource}')] 222 223 ${id}= Convert To Integer ${vlan_id} 224 Set Initial VLAN Config ${vlan_record} ${id} 225 END 226 Rprint Vars initial_vlan_config 227 228 Delete VLANs ${vlan_ids} 229 230 231Set Initial VLAN Config 232 [Documentation] Set suite level list of Initial VLAN Config. 233 [Arguments] ${vlan_record} ${id} 234 235 # Description of argument(s): 236 # vlan_record Dictionary of IP configuration information of a VLAN. 237 # Example: 238 # /xyz/openbmc_project/network/eth0_55/ipv4/5fb2cfe6": { 239 # "Address": "x.x.x.x", 240 # "Gateway": "", 241 # "Origin": "xyz.openbmc_project.Network.IP.AddressOrigin.Static", 242 # "PrefixLength": 16, 243 # "Type": "xyz.openbmc_project.Network.IP.Protocol.IPv4"} 244 # 245 # id The VLAN ID corresponding to the IP Configuration records contained 246 # in the variable "vlan_record". 247 248 ${uris}= Get Dictionary Keys ${vlan_record} 249 250 FOR ${uri} IN @{uris} 251 Append To List ${initial_vlan_config} ${id} ${vlan_record['${uri}']['Address']} 252 ... ${vlan_record['${uri}']['PrefixLength']} 253 END 254 255 Run Keyword If @{uris} == @{EMPTY} 256 ... Append To List ${initial_vlan_config} ${id} ${EMPTY} ${EMPTY} 257 258 259Suite Teardown Execution 260 [Documentation] Restore VLAN configuration. 261 262 ${length}= Get Length ${initial_vlan_config} 263 Return From Keyword If ${length} == ${0} 264 265 ${previous_id}= Set Variable ${EMPTY} 266 FOR ${index} IN RANGE 0 ${length} 3 267 268 Run Keyword If '${initial_vlan_config[${index+1}]}' == '${EMPTY}' 269 ... Create VLAN ${initial_vlan_config[${index}]} 270 ... ELSE IF '${previous_id}' == '${initial_vlan_config[${index}]}' 271 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]} 272 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]} 273 ... ELSE Run Keywords Create VLAN ${initial_vlan_config[${index}]} AND 274 ... Configure Network Settings On VLAN ${initial_vlan_config[${index}]} 275 ... ${initial_vlan_config[${index+1}]} ${initial_vlan_config[${index+2}]} 276 277 ${previous_id}= Set Variable ${initial_vlan_config[${index}]} 278 END 279 280 281Delete VLANs 282 [Documentation] Delete one or more VLANs. 283 [Arguments] ${ids} ${interface}=eth0 284 285 # Description of argument(s): 286 # ids A list of VLAN IDs (e.g. ['53'] or ['53', '35', '12']). Note that the 287 # caller may simply pass a list variable or he/she may specify a 288 # python-like list specification (see examples below). 289 # interface The physical interface for the VLAN (e.g. 'eth0'). 290 291 # Example calls: 292 # Delete VLANs ${vlan_ids} 293 # Delete Vlans [53, 35] 294 295 # Allow for python-like list specifications (e.g. ids=['53']). 296 ${vlan_ids}= Source To Object ${ids} 297 298 FOR ${id} IN @{vlan_ids} 299 OpenBMC Delete Request ${NETWORK_MANAGER}${interface}_${id} 300 END 301 Run Key U Sleep \ ${NETWORK_TIMEOUT}s 302 303 304Get VLAN IDs 305 [Documentation] Return all VLAN IDs. 306 307 ${vlan_ids} ${stderr} ${rc}= BMC Execute Command 308 ... /sbin/ip addr | grep @eth0 | cut -f1 -d@ | cut -f2 -d. 309 ${vlan_ids}= Split String ${vlan_ids} 310 311 [Return] @{vlan_ids} 312 313 314Get VLAN URI For IP 315 [Documentation] Get and return the URI for a VLAN IP. 316 [Arguments] ${vlan_id} ${vlan_ip} ${expected_result}=valid 317 318 # Description of argument(s): 319 # vlan_id The VLAN ID (e.g. '53'). 320 # vlan_ip The VLAN IP (e.g. 'x.x.x.x'). 321 322 ${vlan_records}= Read Properties 323 ... ${NETWORK_MANAGER}eth0_${vlan_id}${/}enumerate quiet=1 324 ${vlan_record}= Filter Struct ${vlan_records} [('Address', '${vlan_ip}')] 325 ${num_vlan_records}= Get Length ${vlan_record} 326 ${status}= Run Keyword And Return Status Should Be True ${num_vlan_records} > 0 327 ... msg=Could not find a uri for vlan "${vlan_id}" with IP "${vlan_ip}". 328 329 Run Keyword If '${expected_result}' == 'valid' 330 ... Should Be Equal ${status} ${True} 331 ... msg=VLAN IP URI doesn't exist!. 332 ... ELSE 333 ... Should Be Equal ${status} ${False} 334 ... msg=VLAN IP URI exists!. 335 ${uris}= Get Dictionary Keys ${vlan_record} 336 Return From Keyword If @{uris} == @{EMPTY} 337 338 [Return] ${uris[${0}]} 339 340 341Verify Existence Of VLAN 342 [Documentation] Verify VLAN ID exists. 343 [Arguments] ${id} ${interface}=eth0 ${expected_result}=valid 344 345 # Description of argument(s): 346 # id The VLAN ID (e.g. id:'53'). 347 # interface Physical Interface on which the VLAN is defined. 348 # expected_result Expected status to check existence or non-existence of VLAN. 349 350 ${vlan_ids}= Get VLAN IDs 351 ${cli_status}= Run Keyword And Return Status 352 ... Valid List vlan_ids required_values=['${id}'] 353 354 ${network_records}= Read Properties ${NETWORK_MANAGER} 355 ${rest_status}= Run Keyword And Return Status Valid List network_records 356 ... required_values=['${NETWORK_MANAGER}${interface}_${id}'] 357 358 Should Be Equal ${rest_status} ${cli_status} 359 ... msg=REST and CLI Output are not the same. 360 Run Keyword If '${expected_result}' == 'valid' 361 ... Should Be Equal ${rest_status} ${True} 362 ... msg=VLAN ID doesn't exist!. 363 ... ELSE 364 ... Should Be Equal ${rest_status} ${False} 365 ... msg=VLAN ID exists!. 366