increase tempest timeout
[integration/test.git] / csit / suites / openstack / securitygroup / 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    OpenStackOperations.OpenStack Suite Teardown
6 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
7 Test Teardown     OpenStackOperations.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}    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_API}    /restconf/config/neutron:neutron/security-groups/
25 ${SEC_RULE_API}    /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 @{NETWORKS}       sgs_net_1
28 @{SUBNETS}        sgs_sub_1
29 @{IP_SUBNETS}     61.2.1.0/24
30 @{PORTS}          sgs_port_1    sgs_port_2
31 ${SECURITY_GROUPS}    --security-group
32 @{SGS}            sgs_sg_1    sgs_sg_2    sgs_sg_3    sgs_sg_4
33 ${SG_UPDATED}     SSH_UPDATED
34 ${ADD_ARG_SSH5}    --direction ingress --ethertype IPv4 --port_range_max 20 --port_range_min 25 --protocol tcp
35 @{ADD_PARAMS}     ingression    IPv4    20    25    tcp
36 ${ADD_ARG_SSH6}    --direction ingress --ethertype IPv4 --port_range_max 25 --port_range_min -1 --protocol tcp
37 ${ADD_ARG_SSH7}    --direction ingress --ethertype IPv4 --port_range_max -1 --port_range_min 20 --protocol tcp
38 ${PORT_RANGE_ERROR}    For TCP/UDP protocols, port_range_min must be <= port_range_max
39 ${INVALID_PORT_RANGE_MIN}    Invalid value for port
40
41 *** Testcases ***
42 TC01_Update Security Group description and Name
43     [Documentation]    This test case validates the security group creation with optional parameter description, Update Security Group description and name
44     [Tags]    Regression
45     ${sg_id} =    BuiltIn.Run Keyword    Create Security Group and Validate    ${SGS[0]}
46     Create Security Rule and Validate    ${SGS[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]}
47     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
48     Neutron Setup Creation    ${NETWORKS[0]}    ${SUBNETS[0]}    ${IP_SUBNETS[0]}    ${PORTS[0]}    ${PORTS[1]}    ${SECURITY_GROUPS}
49     ...    ${sg_id}
50     Security group verification on Neutron port    ${PORTS[0]}    ${sg_id}
51     Security group verification on Neutron port    ${PORTS[1]}    ${sg_id}
52     Update Security Group Description and Verification    ${sg_id}    ${DESCRIPTION}    ${VERIFY_DESCRIPTION}
53     Update Security Group Name and Verification    ${sg_id}    ${NAME_UPDATE}    ${VERIFY_NAME}
54
55 TC02_Create Security Rule with port_range_min > port_range_max
56     [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
57     [Tags]    Regression
58     Create Security Group and Validate    ${SGS[1]}
59     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
60     Neutron Rule Creation With Invalid Parameters    ${SGS[1]}    ${ADD_ARG_SSH5}    ${PORT_RANGE_ERROR}
61
62 TC03_Create Security Rule with port_range_min = -1
63     [Documentation]    This test case validates the security group and rule creation with optional parameters, Create Security Rule with port_range_min = -1
64     [Tags]    Regression
65     Create Security Group and Validate    ${SGS[2]}
66     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
67     Neutron Rule Creation With Invalid Parameters    ${SGS[2]}    ${ADD_ARG_SSH6}    ${INVALID_PORT_RANGE_MIN}
68
69 TC04_Create Security Rule with port_range_max = -1
70     [Documentation]    This test case validates the security group and rule creation with optional parameters, Create Security Rule with port_range_max = -1
71     [Tags]    Regression
72     Create Security Group and Validate    ${SGS[3]}
73     Get Flows    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
74     Neutron Rule Creation With Invalid Parameters    ${SGS[3]}    ${ADD_ARG_SSH7}    ${INVALID_PORT_RANGE_MIN}
75
76 *** Keywords ***
77 Get Flows
78     [Arguments]    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
79     [Documentation]    Get the Flows from DPN1 and DPN2
80     ${resp} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_1_IP}    sudo ovs-ofctl dump-flows br-int -O OpenFlow13
81     ${resp} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_1_IP}    sudo ovs-ofctl dump-groups br-int -OOpenflow13
82     ${resp} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_2_IP}    sudo ovs-ofctl dump-flows br-int -O OpenFlow13
83     ${resp} =    Utils.Run Command On Remote System And Log    ${OS_COMPUTE_2_IP}    sudo ovs-ofctl dump-groups br-int -OOpenflow13
84
85 Create Security Group and Validate
86     [Arguments]    ${sg_ssh}
87     ${output}    ${sg_id} =    OpenStackOperations.Neutron Security Group Create    ${sg_ssh}
88     ${sec_groups} =    BuiltIn.Create List    ${sg_ssh}
89     BuiltIn.Wait Until Keyword Succeeds    10s    2s    Utils.Check For Elements At URI    ${SEC_GROUP_API}    ${sec_groups}
90     [Return]    ${sg_id}
91
92 Create Security Rule and Validate
93     [Arguments]    ${sg_ssh}    &{Kwargs}
94     ${output}    ${rule_id} =    OpenStackOperations.Neutron Security Group Rule Create    ${sg_ssh}
95     ${rule_ids} =    BuiltIn.Create List    ${rule_id}
96     BuiltIn.Wait Until Keyword Succeeds    10s    2s    Utils.Check For Elements At URI    ${SEC_RULE_API}    ${rule_ids}
97
98 Neutron Setup Creation
99     [Arguments]    ${network}    ${subnet}    ${ip_subnet}    ${port1}    ${port2}    ${sg_groups}
100     ...    ${sg_id}
101     ${net_id} =    OpenStackOperations.Create Network    ${network}
102     ${subnet_id} =    OpenStackOperations.Create SubNet    ${network}    ${subnet}    ${ip_subnet}
103     ${add_args} =    BuiltIn.Set Variable    ${sg_groups} ${sg_id}
104     ${port_id}    OpenStackOperations.Create Neutron Port With Additional Params    ${network}    ${port1}    ${add_args}
105     ${port_id}    OpenStackOperations.Create Neutron Port With Additional Params    ${network}    ${port2}    ${add_args}
106
107 Security group verification on Neutron port
108     [Arguments]    ${port}    ${sg_id}
109     ${port_show} =    OpenStackOperations.Neutron Port Show    ${port}
110     BuiltIn.Should Contain    ${port_show}    ${sg_id}
111
112 Update Security Group Description and Verification
113     [Arguments]    ${sg_id}    ${description}    ${verify_description}
114     OpenStackOperations.Neutron Security Group Update    ${sg_id}    ${description}
115     ${output} =    OpenStackOperations.Neutron Security Group Show    ${sg_id}
116     BuiltIn.Should Contain    ${output}    ${verify_description}
117
118 Update Security Group Name and Verification
119     [Arguments]    ${sg_id}    ${name_update}    ${verify_name}
120     OpenStackOperations.Neutron Security Group Update    ${sg_id}    ${name_update}
121     ${output} =    OpenStackOperations.Neutron Security Group Show    ${sg_id}
122     Should Contain    ${output}    ${verify_name}
123     ${resp}    RequestsLibrary.Get Request    session    ${SEC_GROUP_API}
124     BuiltIn.Log    ${resp.content}
125     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE_200}
126     BuiltIn.Should Contain    ${resp.content}    ${verify_name}
127
128 Neutron Rule Creation With Invalid Parameters
129     [Arguments]    ${sg_name}    ${additional_args}    ${expected_error}
130     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    neutron security-group-rule-create ${sg_name} ${additional_args}
131     BuiltIn.Log    ${output}
132     BuiltIn.Should Contain    ${output}    ${expected_error}
133     SSHLibrary.Close Connection