1*** Settings ***
2
3Documentation       Test setting network address of host OS.
4
5Resource            ../lib/rest_client.robot
6Resource            ../lib/ipmi_client.robot
7Resource            ../lib/utils.robot
8Resource            ../lib/openbmc_ffdc.robot
9Library             ../lib/utilities.py
10
11Test Setup          Open Connection And Log In
12Test Teardown       Test Teardown Execution
13
14Test Tags          Host_Network
15
16*** Variables ***
17${SET_ADDR_PREFIX}  0x00 0x08 0x61 0x80 0x21 0x70 0x62 0x21 0x00 0x01 0x06 0x04
18${STATIC}           0x00 0x01                       #equivalent address type 1
19${DHCP}             0x00 0x00                       #equivalent address type 0
20${CLEAR_ADDR}       0x00 0x08 0x61 0x80 0x00 0x00 0x00 0x00
21
22
23*** Test Cases ***
24
25Set Static Host Network Address Via IPMI
26    [Documentation]  Set static host network address via IPMI and verify
27    ...  IP address set with REST.
28    [Tags]  Set_Static_Host_Network_Address_Via_IPMI
29
30    ${ip_address}=  utilities.random_ip
31    ${gateway_ip}=  utilities.random_ip
32    ${mac_address}=  utilities.random_mac
33    ${prefix_length}=  Evaluate  random.randint(0, 32)  modules=random
34
35    ${mac_address_hex}=  Mac Address To Hex String  ${mac_address}
36    ${ip_address_hex}=  IP Address To Hex String  ${ip_address}
37    ${gateway_hex}=  IP Address To Hex String  ${gateway_ip}
38    ${prefix_hex}=  Convert To Hex  ${prefix_length}  prefix=0x  lowercase=yes
39
40    ${ipmi_raw_cmd}=  Catenate  SEPARATOR=
41    ...  ${SET_ADDR_PREFIX}${SPACE}${mac_address_hex}${SPACE}${STATIC}${SPACE}
42    ...  ${ip_address_hex}${SPACE}${prefix_hex}${SPACE}${gateway_hex}
43
44    Run IPMI command  ${ipmi_raw_cmd}
45
46    ${data}=  Read Properties  ${NETWORK_MANAGER}host0/intf/addr
47    Should Contain  ${data["Origin"]}  Static
48    Should Be Equal  ${data["Address"]}  ${ip_address}
49    Should Be Equal  ${data["Gateway"]}  ${gateway_ip}
50
51    ${new_mac_address}=
52    ...  Read Attribute  ${NETWORK_MANAGER}host0/intf  MACAddress
53    Should Be Equal  ${new_mac_address}  ${mac_address}
54
55
56Set DHCP Host Address Via IPMI
57    [Documentation]  Set dhcp host network address via IPMI and verify
58    ...  IP address set with REST.
59    [Tags]  Set_DHCP_Host_Address_Via_IPMI
60
61    ${mac_address}=  utilities.random_mac
62    ${mac_address_hex}=  Mac Address To Hex String  ${mac_address}
63
64    ${ipmi_raw_cmd}=  Catenate  SEPARATOR=
65    ...  ${SET_ADDR_PREFIX}${SPACE}${mac_address_hex}${SPACE}${DHCP}
66    Run IPMI command  ${ipmi_raw_cmd}
67
68    ${origin}=  Read Attribute  ${NETWORK_MANAGER}host0/intf/addr  Origin
69    ${new_mac_address}=
70    ...  Read Attribute  ${NETWORK_MANAGER}host0/intf  MACAddress
71    Should Contain  ${origin}  DHCP
72    Should Be Equal  ${new_mac_address}  ${mac_address}
73
74
75*** Keywords ***
76
77Test Teardown Execution
78    [Documentation]  Do the post test teardown.
79
80    FFDC On Test Case Fail
81    Run IPMI command  ${CLEAR_ADDR}
82    Close All Connections
83