1*** Settings ***
2Documentation   Test BMC multiple network interface functionalities.
3
4# User input BMC IP for the eth1.
5# Use can input as  -v OPENBMC_HOST_1:xx.xxx.xx from command line.
6Library         ../../lib/bmc_redfish.py  https://${OPENBMC_HOST_1}:${HTTPS_PORT}
7...             ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  WITH NAME  Redfish1
8
9Resource        ../../lib/resource.robot
10Resource        ../../lib/common_utils.robot
11Resource        ../../lib/connection_client.robot
12Resource        ../../lib/bmc_network_utils.robot
13Resource        ../../lib/openbmc_ffdc.robot
14Resource        ../../lib/bmc_ldap_utils.robot
15Resource        ../../lib/snmp/resource.robot
16Resource        ../../lib/snmp/redfish_snmp_utils.robot
17Library         ../../lib/jobs_processing.py
18
19Suite Setup     Suite Setup Execution
20Test Teardown   FFDC On Test Case Fail
21Suite Teardown  Run Keywords  Redfish1.Logout  AND  Redfish.Logout
22
23*** Test Cases ***
24
25Verify Both Interfaces BMC IP Addresses Accessible Via SSH
26    [Documentation]  Verify both interfaces (eth0, eth1) BMC IP addresses accessible via SSH.
27    [Tags]  Verify_Both_Interfaces_BMC_IP_Addresses_Accessible_Via_SSH
28
29    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  host=${OPENBMC_HOST}
30    Open Connection And Log In  ${OPENBMC_USERNAME}  ${OPENBMC_PASSWORD}  host=${OPENBMC_HOST_1}
31    Close All Connections
32
33
34Verify Redfish Works On Both Interfaces
35    [Documentation]  Verify access BMC with both interfaces (eth0, eth1) IP addresses via Redfish.
36    [Tags]  Verify_Redfish_Works_On_Both_Interfaces
37    [Teardown]  Run Keywords
38    ...  Configure Hostname  ${hostname}  AND  Validate Hostname On BMC  ${hostname}
39
40    Redfish1.Login
41    Redfish.Login
42
43    ${hostname}=  Redfish.Get Attribute  ${REDFISH_NW_PROTOCOL_URI}  HostName
44    ${data}=  Create Dictionary  HostName=openbmc
45    Redfish1.patch  ${REDFISH_NW_ETH_IFACE}eth1  body=&{data}
46    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
47
48    Validate Hostname On BMC  openbmc
49
50    ${resp1}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}eth0
51    ${resp2}=  Redfish1.Get  ${REDFISH_NW_ETH_IFACE}eth1
52    Should Be Equal  ${resp1.dict['HostName']}  ${resp2.dict['HostName']}
53
54
55Verify LDAP Login Works When Eth1 IP Is Not Configured
56    [Documentation]  Verify LDAP login works when eth1 IP is erased.
57    [Tags]  Verify_LDAP_Login_Works_When_Eth1_IP_Is_Not_Configured
58    [Setup]  Run Keywords  Set Test Variable  ${CHANNEL_NUMBER}  ${2}
59    ...  AND  Delete IP Address  ${OPENBMC_HOST_1}
60    [Teardown]  Run Keywords  Redfish.Login  AND
61    ...  Add IP Address  ${OPENBMC_HOST_1}  ${eth1_subnet_mask}  ${eth1_gateway}
62
63    Create LDAP Configuration
64    Redfish.Login  ${LDAP_USER}  ${LDAP_USER_PASSWORD}
65    Redfish.Logout
66
67
68Verify SNMP Works When Eth1 IP Is Not Configured
69    [Documentation]  Verify SNMP works when eth1 IP is not configured.
70    [Tags]  Verify_SNMP_Works_When_Eth1_IP_Is_Not_Configured
71    [Setup]  Run Keywords  Set Test Variable  ${CHANNEL_NUMBER}  ${2}
72    ...  AND  Delete IP Address  ${OPENBMC_HOST_1}
73    [Teardown]  Run Keywords  Redfish.Login  AND
74    ...  Add IP Address  ${OPENBMC_HOST_1}  ${eth1_subnet_mask}  ${eth1_gateway}
75
76    Create Error On BMC And Verify Trap
77
78
79Disable And Enable Eth0 Interface
80    [Documentation]  Disable and Enable eth0 ethernet interface via redfish.
81    [Tags]  Disable_And_Enable_Eth0_Interface
82    [Template]  Set BMC Ethernet Interfaces State
83
84    # interface_ip   interface  enabled
85    ${OPENBMC_HOST}   eth0      ${False}
86    ${OPENBMC_HOST}   eth0      ${True}
87
88
89Verify Both Interfaces Access Concurrently Via Redfish
90    [Documentation]  Verify both interfaces access conurrently via redfish.
91    [Tags]  Verify_Both_Interfaces_Access_Concurrently_Via_Redfish
92
93    Redfish.Login
94    Redfish1.Login
95
96    ${dict}=  Execute Process Multi Keyword  ${2}
97    ...  Redfish.Patch ${REDFISH_NW_ETH_IFACE}eth0 body={'DHCPv4':{'UseDNSServers':${True}}}
98    ...  Redfish1.Patch ${REDFISH_NW_ETH_IFACE}eth1 body={'DHCPv4':{'UseDNSServers':${True}}}
99
100    Dictionary Should Not Contain Value  ${dict}  False
101    ...  msg=One or more operations has failed.
102
103    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}eth0
104    ${resp1}=  Redfish1.Get  ${REDFISH_NW_ETH_IFACE}eth1
105
106    Should Be Equal  ${resp.dict["DHCPv4"]['UseDNSServers']}  ${True}
107    Should Be Equal  ${resp1.dict["DHCPv4"]['UseDNSServers']}  ${True}
108
109*** Keywords ***
110
111Get Network Configuration Using Channel Number
112    [Documentation]  Get ethernet interface.
113    [Arguments]  ${channel_number}
114
115    # Description of argument(s):
116    # channel_number   Ethernet channel number, 1 is for eth0 and 2 is for eth1 (e.g. "1").
117
118    ${active_channel_config}=  Get Active Channel Config
119    ${ethernet_interface}=  Set Variable  ${active_channel_config['${channel_number}']['name']}
120    ${resp}=  Redfish.Get  ${REDFISH_NW_ETH_IFACE}${ethernet_interface}
121
122    @{network_configurations}=  Get From Dictionary  ${resp.dict}  IPv4StaticAddresses
123    [Return]  @{network_configurations}
124
125
126Suite Setup Execution
127    [Documentation]  Do suite setup task.
128
129    Valid Value  OPENBMC_HOST_1
130
131    # Check both interfaces are configured and reachable.
132    Ping Host  ${OPENBMC_HOST}
133    Ping Host  ${OPENBMC_HOST_1}
134
135    ${network_configurations}=  Get Network Configuration Using Channel Number  ${2}
136    FOR  ${network_configuration}  IN  @{network_configurations}
137
138      Run Keyword If  '${network_configuration['Address']}' == '${OPENBMC_HOST_1}'
139      ...  Run Keywords  Set Suite Variable  ${eth1_subnet_mask}  ${network_configuration['SubnetMask']}
140      ...  AND  Set Suite Variable  ${eth1_gateway}  ${network_configuration['Gateway']}
141      ...  AND  Exit For Loop
142
143    END
144
145
146Set BMC Ethernet Interfaces State
147    [Documentation]  Set BMC ethernet interface state.
148    [Arguments]  ${interface_ip}  ${interface}  ${enabled}
149    [Teardown]  Redfish1.Logout
150
151    # Description of argument(s):
152    # interface_ip    IP address of ethernet interface.
153    # interface       The ethernet interface name (eg. eth0 or eth1).
154    # enabled         Indicates interface should be enabled (eg. True or False).
155
156    Redfish1.Login
157
158    ${data}=  Create Dictionary  InterfaceEnabled=${enabled}
159
160    Redfish1.patch  ${REDFISH_NW_ETH_IFACE}${interface}  body=&{data}
161    ...  valid_status_codes=[${HTTP_OK}, ${HTTP_NO_CONTENT}]
162
163    Sleep  ${NETWORK_TIMEOUT}s
164    ${interface_status}=   Redfish1.Get Attribute  ${REDFISH_NW_ETH_IFACE}${interface}  InterfaceEnabled
165    Should Be Equal  ${interface_status}  ${enabled}
166
167    ${status}=  Run Keyword And Return Status  Ping Host  ${interface_ip}
168
169    Run Keyword If  ${enabled} == ${True}  Should Be Equal  ${status}  ${True}
170    ...  ELSE  Should Be Equal  ${status}  ${False}
171