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
44Verify All Configured IP And Netmask
45    [Documentation]  Verify all configured IP and netmask on BMC.
46    [Tags]  Verify_All_Configured_IP_And_Netmask
47
48    : FOR  ${network_configuration}  IN  @{network_configurations}
49    \  Verify IP And Netmask On BMC  ${network_configuration['Address']}
50    ...  ${network_configuration['SubnetMask']}
51
52*** Keywords ***
53
54Test Setup Execution
55    [Documentation]  Test setup execution.
56
57    Redfish.Login
58
59    @{network_configurations}=  Get Network Configuration
60    Set Test Variable  @{network_configurations}
61
62    # Get BMC IP address and prefix length.
63    ${ip_data}=  Get BMC IP Info
64    Set Test Variable  ${ip_data}
65
66
67Get Network Configuration
68    [Documentation]  Get network configuration.
69
70    # Sample output:
71    #{
72    #  "@odata.context": "/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
73    #  "@odata.id": "/redfish/v1/Managers/bmc/EthernetInterfaces/eth0",
74    #  "@odata.type": "#EthernetInterface.v1_2_0.EthernetInterface",
75    #  "Description": "Management Network Interface",
76    #  "IPv4Addresses": [
77    #    {
78    #      "Address": "169.254.xx.xx",
79    #      "AddressOrigin": "IPv4LinkLocal",
80    #      "Gateway": "0.0.0.0",
81    #      "SubnetMask": "255.255.0.0"
82    #    },
83    #    {
84    #      "Address": "xx.xx.xx.xx",
85    #      "AddressOrigin": "Static",
86    #      "Gateway": "xx.xx.xx.1",
87    #      "SubnetMask": "xx.xx.xx.xx"
88    #    }
89    #  ],
90    #  "Id": "eth0",
91    #  "MACAddress": "xx:xx:xx:xx:xx:xx",
92    #  "Name": "Manager Ethernet Interface",
93    #  "SpeedMbps": 0,
94    #  "VLAN": {
95    #    "VLANEnable": false,
96    #    "VLANId": 0
97    #  }
98
99    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH0_URI}
100    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4Addresses
101    [Return]  @{network_configurations}
102
103
104Verify IP On BMC
105    [Documentation]  Verify IP on BMC.
106    [Arguments]  ${ip}
107
108    # Description of the argument(s):
109    # ip  IP address to be verified.
110
111    # Get IP address details on BMC using IP command.
112    @{ip_data}=  Get BMC IP Info
113    Should Contain Match  ${ip_data}  ${ip}/*
114    ...  msg=IP address does not exist.
115
116
117Verify Netmask On BMC
118    [Documentation]  Verify netmask on BMC.
119    [Arguments]  ${netmask}
120
121    # Description of the argument(s):
122    # netmask  netmask value to be verified.
123
124    ${prefix_length}=  Netmask Prefix Length  ${netmask}
125
126    Should Contain Match  ${ip_data}  */${prefix_length}
127    ...  msg=Prefix length does not exist.
128
129Verify Gateway On BMC
130    [Documentation]  Verify gateway on BMC.
131    [Arguments]  ${gateway_ip}=0.0.0.0
132
133    # Description of argument(s):
134    # gateway_ip  Gateway IP address.
135
136    ${route_info}=  Get BMC Route Info
137
138    # If gateway IP is empty or 0.0.0.0 it will not have route entry.
139
140    Run Keyword If  '${gateway_ip}' == '0.0.0.0'
141    ...      Pass Execution  Gateway IP is "0.0.0.0".
142    ...  ELSE
143    ...      Should Contain  ${route_info}  ${gateway_ip}
144    ...      msg=Gateway IP address not matching.
145
146Verify IP And Netmask On BMC
147    [Documentation]  Verify IP and netmask on BMC.
148    [Arguments]  ${ip}  ${netmask}
149
150    # Description of the argument(s):
151    # ip       IP address to be verified.
152    # netmask  netmask value to be verified.
153
154    ${prefix_length}=  Netmask Prefix Length  ${netmask}
155    @{ip_data}=  Get BMC IP Info
156
157    ${ip_with_netmask}=  Catenate  ${ip}/${prefix_length}
158    Should Contain  ${ip_data}  ${ip_with_netmask}
159    ...  msg=IP and netmask pair does not exist.
160
161Test Teardown Execution
162    [Documentation]  Test teardown execution.
163
164    FFDC On Test Case Fail
165    Redfish.Logout
166