1*** Settings ***
2Documentation  Network interface configuration and verification
3               ...  tests.
4
5Resource       ../../lib/bmc_redfish_resource.robot
6Resource       ../../lib/bmc_network_utils.robot
7Resource       ../../lib/openbmc_ffdc.robot
8Library        ../../lib/bmc_network_utils.py
9
10Test Setup     Test Setup Execution
11Test Teardown  Test Teardown Execution
12
13*** Test Cases ***
14
15Get IP Address And Verify
16    [Documentation]  Get IP Address And Verify.
17    [Tags]  Get_IP_Address_And_Verify
18
19    : FOR  ${network_configuration}  IN  @{network_configurations}
20    \  Verify IP On BMC  ${network_configuration['Address']}
21
22Get Netmask And Verify
23    [Documentation]  Get Netmask And Verify.
24    [Tags]  Get_Netmask_And_Verify
25
26    : FOR  ${network_configuration}  IN  @{network_configurations}
27    \  Verify Netmask On BMC  ${network_configuration['SubnetMask']}
28
29Get Gateway And Verify
30    [Documentation]  Get gateway and verify it's existence on the BMC.
31    [Tags]  Get_Gateway_And_Verify
32
33    : FOR  ${network_configuration}  IN  @{network_configurations}
34    \  Verify Gateway On BMC  ${network_configuration['Gateway']}
35
36Get MAC Address And Verify
37    [Documentation]  Get MAC address and verify it's existence on the BMC.
38    [Tags]  Get_MAC_Address_And_Verify
39
40    ${resp}=  redfish.Get  ${REDFISH_NW_ETH0_URI}
41    ${macaddr}=  Get From Dictionary  ${resp.dict}  MACAddress
42    Validate MAC On BMC  ${macaddr}
43
44*** Keywords ***
45
46Test Setup Execution
47    [Documentation]  Test setup execution.
48
49    redfish.Login
50
51    @{network_configurations}=  Get Network Configuration
52    Set Test Variable  @{network_configurations}
53
54    # Get BMC IP address and prefix length.
55    ${ip_data}=  Get BMC IP Info
56    Set Test Variable  ${ip_data}
57
58
59Get Network Configuration
60    [Documentation]  Get network configuration.
61
62    # Sample output:
63    #{
64    #  "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
65    #  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
66    #  "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
67    #  "Description": "Management Network Interface",
68    #  "IPv4Addresses": [
69    #    {
70    #      "Address": "169.254.xx.xx",
71    #      "AddressOrigin": "IPv4LinkLocal",
72    #      "Gateway": "0.0.0.0",
73    #      "SubnetMask": "255.255.0.0"
74    #    },
75    #    {
76    #      "Address": "xx.xx.xx.xx",
77    #      "AddressOrigin": "Static",
78    #      "Gateway": "xx.xx.xx.1",
79    #      "SubnetMask": "xx.xx.xx.xx"
80    #    }
81    #  ],
82    #  "Id": "eth0",
83    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
84    #  "Name": "Manager Ethernet Interface",
85    #  "SpeedMbps": 0,
86    #  "VLAN": {
87    #    "VLANEnable": false,
88    #    "VLANId": 0
89    #  }
90
91    ${resp}=  redfish.Get  ${REDFISH_NW_ETH0_URI}
92    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4Addresses
93    [Return]  @{network_configurations}
94
95
96Verify IP On BMC
97    [Documentation]  Verify IP on BMC.
98    [Arguments]  ${ip}
99
100    # Description of the argument(s):
101    # ip  IP address to be verified.
102
103    # Get IP address details on BMC using IP command.
104    @{ip_data}=  Get BMC IP Info
105    Should Contain Match  ${ip_data}  ${ip}/*
106    ...  msg=IP address does not exist.
107
108
109Verify Netmask On BMC
110    [Documentation]  Verify netmask on BMC.
111    [Arguments]  ${netmask}
112
113    # Description of the argument(s):
114    # netmask  netmask value to be verified.
115
116    ${prefix_length}=  Netmask Prefix Length  ${netmask}
117
118    Should Contain Match  ${ip_data}  */${prefix_length}
119    ...  msg=Prefix length does not exist.
120
121Verify Gateway On BMC
122    [Documentation]  Verify gateway on BMC.
123    [Arguments]  ${gateway_ip}=0.0.0.0
124
125    # Description of argument(s):
126    # gateway_ip  Gateway IP address.
127
128    ${route_info}=  Get BMC Route Info
129
130    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
131
132    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
133    ...      Pass Execution  Gateway IP is "0.0.0.0".
134    ...  ELSE
135    ...      Should Contain  ${route_info}  ${gateway_ip}
136    ...      msg=Gateway IP address not matching.
137
138Test Teardown Execution
139    [Documentation]  Test teardown execution.
140
141    FFDC On Test Case Fail
142    redfish.Logout
143