a61171cf5b2ab2027d5d29a643cd5c0dd3164a27
[integration/test.git] / csit / suites / openstack / NeutronSecurityGrp / Neutron_Security_Group.robot
1 *** Settings ***
2 Documentation     Test Suite for Neutron Security Group
3 Suite Setup       BuiltIn.Run Keywords    SetupUtils.Setup_Utils_For_Setup_And_Teardown
4 ...               AND    DevstackUtils.Devstack Suite Setup
5 Suite Teardown    Close All Connections
6 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
7 Test Teardown     Get Test Teardown Debugs
8 Library           SSHLibrary
9 Library           OperatingSystem
10 Library           RequestsLibrary
11 Library           json
12 Resource          ../../../libraries/DevstackUtils.robot
13 Resource          ../../../libraries/SetupUtils.robot
14 Resource          ../../../variables/Variables.robot
15
16 *** Variables ***
17 ${RESP_CODE}      200
18 ${DESCRIPTION}    --description "new security group 1"
19 ${VERIFY_DESCRIPTION}    new security group 1
20 ${VERIFY_NAME}    SSH_UPDATED
21 ${NAME_UPDATE}    --name SSH_UPDATED
22 ${SECURITY_FALSE}    --port-security-enabled false
23 ${SECURITY_TRUE}    --port-security-enabled true
24 ${SEC_GROUP}      /restconf/config/neutron:neutron/security-groups/
25 ${SEC_RULE}       /restconf/config/neutron:neutron/security-rules/
26 ${ADD_ARG_SSH}    --direction ingress --ethertype IPv4 --port_range_max 22 --port_range_min 22 --protocol tcp
27 @{NETWORK}        net1    net2    net3    net4    net5    net6    net7
28 ...               net8    net9    net10
29 @{SUBNET}         sub1    sub2    sub3    sub4    sub5    sub6    sub7
30 ...               sub8    sub9    sub10
31 @{IP_SUBNET}      20.2.1.0/24    20.2.2.0/24    20.2.3.0/24    20.2.4.0/24    20.2.5.0/24    20.2.6.0/24
32 @{PORT}           port01    port02    port03    port04    port05    port06    port07
33 ...               port08    port09    port10
34 ${SECURITY_GROUPS}    --security-group
35 @{SGP_SSH}        SSH1    SSH2    SSH3    SSH4    SSH5    SSH6    SSH7
36 ...               SSH8    SSH9    SSH10
37 ${ADD_ARG_SSH5}    --direction ingress --ethertype IPv4 --port_range_max 20 --port_range_min 25 --protocol tcp
38 @{ADD_PARAMS}     ingression    IPv4    20    25    tcp
39 ${ADD_ARG_SSH6}    --direction ingress --ethertype IPv4 --port_range_max 25 --port_range_min -1 --protocol tcp
40 ${ADD_ARG_SSH7}    --direction ingress --ethertype IPv4 --port_range_max -1 --port_range_min 20 --protocol tcp
41 ${PORT_RANGE_ERROR}    For TCP/UDP protocols, port_range_min must be <= port_range_max
42 ${INVALID_PORT_RANGE_MIN}    Invalid value for port
43
44 *** Testcases ***
45 TC01_Update Security Group description and Name
46     [Documentation]    This test case validates the security group creation with optional parameter description, Update Security Group description and name
47     [Tags]    Regression
48     Log    "Creating security Group and verification"
49     Create Security Group and Validate    ${SGP_SSH[0]}
50     Log    "Creating security Rule and verification"
51     Create Security Rule and Validate    ${SGP_SSH[0]}    direction=${ADD_PARAMS[0]}    ethertype=${ADD_PARAMS[1]}    port_range_max=${ADD_PARAMS[3]}    port_range_min=${ADD_PARAMS[2]}    protocol=${ADD_PARAMS[4]}
52     Log    "Fetching the flows from DPN1 and DPN2"
53     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
54     Log    "Creating neutron setup as network subnet port"
55     Neutron Setup Creation    ${NETWORK[0]}    ${SUBNET[0]}    ${IP_SUBNET[0]}    ${PORT[0]}    ${PORT[1]}    ${SECURITY_GROUPS}
56     ...    ${SGP_ID}
57     Log    "Security group verification on Neutron port"
58     Security group verification on Neutron port    ${PORT[0]}    ${SGP_ID}
59     Security group verification on Neutron port    ${PORT[1]}    ${SGP_ID}
60     Log    "Update Security Group Description and Verification"
61     Update Security Group Description and Verification    ${SGP_ID}    ${DESCRIPTION}    ${VERIFY_DESCRIPTION}
62     Log    "Update Security Group Name and Verification"
63     Update Security Group Name and Verification    ${SGP_ID}    ${NAME_UPDATE}    ${VERIFY_NAME}
64
65 TC02_Create Security Rule with port_range_min > port_range_max
66     [Documentation]    This test case validates the security group and rule creation with optional parameters Create Security Rule with port_range_min greater than port_range_max
67     [Tags]    Regression
68     Log    "Creating security Group and verification"
69     Create Security Group and Validate    ${SGP_SSH[1]}
70     Log    "Fetching the flows from DPN1 and DPN2"
71     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
72     Log    "Neutron Rule Creation With Port Range Min Grt Port Range Max and Validation"
73     Neutron Rule Creation With Invalid Parameters    ${SGP_SSH[1]}    ${ADD_ARG_SSH5}    ${PORT_RANGE_ERROR}
74
75 TC03_Create Security Rule with port_range_min = -1
76     [Documentation]    This test case validates the security group and rule creation with optional parameters, Create Security Rule with port_range_min = -1
77     [Tags]    Regression
78     Log    "Creating security Group and verification"
79     Create Security Group and Validate    ${SGP_SSH[2]}
80     Log    "Fetching the flows from DPN1 and DPN2"
81     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
82     Log    "Neutron Rule Creation With Port Range Min Grt Port Range Max and Validation"
83     Neutron Rule Creation With Invalid Parameters    ${SGP_SSH[2]}    ${ADD_ARG_SSH6}    ${INVALID_PORT_RANGE_MIN}
84
85 TC04_Create Security Rule with port_range_max = -1
86     [Documentation]    This test case validates the security group and rule creation with optional parameters, Create Security Rule with port_range_max = -1
87     [Tags]    Regression
88     Log    "Creating security Group and verification"
89     Create Security Group and Validate    ${SGP_SSH[3]}
90     Log    "Fetching the flows from DPN1 and DPN2"
91     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
92     Log    "Neutron Rule Creation With Port Range Min Grt Port Range Max and Validation"
93     Neutron Rule Creation With Invalid Parameters    ${SGP_SSH[3]}    ${ADD_ARG_SSH7}    ${INVALID_PORT_RANGE_MIN}
94
95 *** Keywords ***
96 Get Flows
97     [Arguments]    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
98     [Documentation]    Get the Flows from DPN1 and DPN2
99     Log    "Fetching the flows from DPN1"
100     ${resp}=    Run Command On Remote System    ${OS_COMPUTE_1_IP}    sudo ovs-ofctl dump-flows br-int -O OpenFlow13
101     Log    ${resp}
102     Log    "Fetching the Groups from DPN1"
103     ${resp}=    Run Command On Remote System    ${OS_COMPUTE_1_IP}    sudo ovs-ofctl dump-groups br-int -OOpenflow13
104     Log    ${resp}
105     Log    "Fetching the flows from DPN2"
106     ${resp}=    Run Command On Remote System    ${OS_COMPUTE_2_IP}    sudo ovs-ofctl dump-flows br-int -O OpenFlow13
107     Log    ${resp}
108     Log    "Fetching the Groups from DPN2"
109     ${resp}=    Run Command On Remote System    ${OS_COMPUTE_2_IP}    sudo ovs-ofctl dump-groups br-int -OOpenflow13
110     Log    ${resp}
111
112 Create Security Group and Validate
113     [Arguments]    ${SGP_SSH}
114     [Documentation]    Create Security Group and Validate
115     Log    "Creating security Group"
116     ${OUTPUT}    ${SGP_ID}    Neutron Security Group Create    ${SGP_SSH}
117     Set Global Variable    ${SGP_ID}
118     Log    ${OUTPUT}
119     Log    ${SGP_ID}
120     Log    "Verifying the security group"
121     ${resp}    RequestsLibrary.Get Request    session    ${SEC_GROUP}
122     Log    ${resp.content}
123     Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE}
124     Should Contain    ${resp.content}    ${SGP_SSH}
125
126 Create Security Rule and Validate
127     [Arguments]    ${SGP_SSH}    &{Kwargs}
128     [Documentation]    Create Security Rule and Validate
129     Log    "Creating the Rules for SSH groups"
130     ${OUTPUT}    ${RULE_ID}    Neutron Security Group Rule Create    ${SGP_SSH}
131     Log    ${OUTPUT}
132     Log    ${RULE_ID}
133     Set Global Variable    ${RULE_ID}
134     Log    "Verifying the security Rule"
135     ${resp}    RequestsLibrary.Get Request    session    ${SEC_RULE}
136     Log    ${resp.content}
137     Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE}
138     Should Contain    ${resp.content}    ${RULE_ID}
139
140 Neutron Setup Creation
141     [Arguments]    ${NETWORK}    ${SUBNET}    ${IP_SUBNET}    ${PORT1}    ${PORT2}    ${SECURITY_GROUPS}
142     ...    ${SGP_ID}
143     [Documentation]    Neutron Setup Creation
144     Log    "Creating networks"
145     ${net_id}    Create Network    ${NETWORK}
146     Log    ${net_id}
147     Set Global Variable    ${net_id}
148     Log    "Creating subnets"
149     ${subnet_id}    Create SubNet    ${NETWORK}    ${SUBNET}    ${IP_SUBNET}
150     Log    ${subnet_id}
151     Set Global Variable    ${subnet_id}
152     ${ADD_ARGMS}=    Set Variable    ${SECURITY_GROUPS} ${SGP_ID}
153     ${port_id}    Create Neutron Port With Additional Params    ${NETWORK}    ${PORT1}    ${ADD_ARGMS}
154     Log    ${port_id}
155     Log    "Creating ports"
156     ${port_id}    Create Neutron Port With Additional Params    ${NETWORK}    ${PORT2}    ${ADD_ARGMS}
157     Log    ${port_id}
158
159 Security group verification on Neutron port
160     [Arguments]    ${PORT}    ${SGP_ID}
161     [Documentation]    Security group verification on Neutron port
162     Log    "security group verification"
163     ${PORT_SHOW}    Neutron Port Show    ${PORT}
164     Log    ${PORT_SHOW}
165     Should Contain    ${PORT_SHOW}    ${SGP_ID}
166
167 Update Security Group Description and Verification
168     [Arguments]    ${SGP_ID}    ${DESCRIPTION}    ${VERIFY_DESCRIPTION}
169     [Documentation]    Update Security Group Description and Verification
170     Log    "Update Security Group Description"
171     ${output}    Neutron Security Group Update    ${SGP_ID}    ${DESCRIPTION}
172     Log    "Verification of Description"
173     ${output}    Neutron Security Group Show    ${SGP_ID}
174     Log    ${output}
175     Should Contain    ${output}    ${VERIFY_DESCRIPTION}
176
177 Update Security Group Name and Verification
178     [Arguments]    ${SGP_ID}    ${NAME_UPDATE}    ${VERIFY_NAME}
179     [Documentation]    Update Security Group Name and Verification
180     Log    "Update Security Group Name"
181     ${output}    Neutron Security Group Update    ${SGP_ID}    ${NAME_UPDATE}
182     Log    "Verification of Updated Name"
183     ${output}    Neutron Security Group Show    ${SGP_ID}
184     Log    ${output}
185     Should Contain    ${output}    ${VERIFY_NAME}
186     Log    "Verification of Updated Name via Rest"
187     ${resp}    RequestsLibrary.Get Request    session    ${SEC_GROUP}
188     Log    ${resp.content}
189     Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE}
190     Should Contain    ${resp.content}    ${VERIFY_NAME}
191
192 Neutron Rule Creation With Invalid Parameters
193     [Arguments]    ${SecurityGroupName}    ${additional_args}    ${EXPECTED_ERROR}
194     [Documentation]    Neutron Rule Creation With Null Protocol
195     ${cmd}=    Set Variable    neutron security-group-rule-create ${SecurityGroupName} ${additional_args}
196     Log    ${cmd}
197     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
198     Log    ${output}
199     Log    ${rc}
200     Should Contain    ${output}    ${EXPECTED_ERROR}
201     Close Connection
202     [Return]    ${output}