876b2a44a7421aba6bd7a27c46835ff5c75b7ce6
[integration/test.git] / csit / suites / openstack / securitygroup / neutron_security_group.robot
1 *** Settings ***
2 Documentation     Test Suite for Neutron Security Group
3 Suite Setup       OpenStackOperations.OpenStack Suite Setup
4 Suite Teardown    OpenStackOperations.OpenStack Suite Teardown
5 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
6 Test Teardown     OpenStackOperations.Get Test Teardown Debugs
7 Library           SSHLibrary
8 Library           OperatingSystem
9 Library           RequestsLibrary
10 Library           json
11 Resource          ../../../libraries/DevstackUtils.robot
12 Resource          ../../../libraries/OpenStackOperations.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     Neutron Setup Creation    ${NETWORKS[0]}    ${SUBNETS[0]}    ${IP_SUBNETS[0]}    ${PORTS[0]}    ${PORTS[1]}    ${SECURITY_GROUPS}
48     ...    ${sg_id}
49     Security group verification on Neutron port    ${PORTS[0]}    ${sg_id}
50     Security group verification on Neutron port    ${PORTS[1]}    ${sg_id}
51     Update Security Group Description and Verification    ${sg_id}    ${DESCRIPTION}    ${VERIFY_DESCRIPTION}
52     Update Security Group Name and Verification    ${sg_id}    ${NAME_UPDATE}    ${VERIFY_NAME}
53
54 TC02_Create Security Rule with port_range_min > port_range_max
55     [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
56     [Tags]    Regression
57     Create Security Group and Validate    ${SGS[1]}
58     Neutron Rule Creation With Invalid Parameters    ${SGS[1]}    ${ADD_ARG_SSH5}    ${PORT_RANGE_ERROR}
59
60 TC03_Create Security Rule with port_range_min = -1
61     [Documentation]    This test case validates the security group and rule creation with optional parameters, Create Security Rule with port_range_min = -1
62     [Tags]    Regression
63     Create Security Group and Validate    ${SGS[2]}
64     Neutron Rule Creation With Invalid Parameters    ${SGS[2]}    ${ADD_ARG_SSH6}    ${INVALID_PORT_RANGE_MIN}
65
66 TC04_Create Security Rule with port_range_max = -1
67     [Documentation]    This test case validates the security group and rule creation with optional parameters, Create Security Rule with port_range_max = -1
68     [Tags]    Regression
69     Create Security Group and Validate    ${SGS[3]}
70     Neutron Rule Creation With Invalid Parameters    ${SGS[3]}    ${ADD_ARG_SSH7}    ${INVALID_PORT_RANGE_MIN}
71
72 *** Keywords ***
73 Create Security Group and Validate
74     [Arguments]    ${sg_ssh}
75     ${output}    ${sg_id} =    OpenStackOperations.Neutron Security Group Create    ${sg_ssh}
76     ${sec_groups} =    BuiltIn.Create List    ${sg_ssh}
77     BuiltIn.Wait Until Keyword Succeeds    10s    2s    Utils.Check For Elements At URI    ${SEC_GROUP_API}    ${sec_groups}
78     [Return]    ${sg_id}
79
80 Create Security Rule and Validate
81     [Arguments]    ${sg_ssh}    &{Kwargs}
82     ${output}    ${rule_id} =    OpenStackOperations.Neutron Security Group Rule Create    ${sg_ssh}
83     ${rule_ids} =    BuiltIn.Create List    ${rule_id}
84     BuiltIn.Wait Until Keyword Succeeds    10s    2s    Utils.Check For Elements At URI    ${SEC_RULE_API}    ${rule_ids}
85
86 Neutron Setup Creation
87     [Arguments]    ${network}    ${subnet}    ${ip_subnet}    ${port1}    ${port2}    ${sg_groups}
88     ...    ${sg_id}
89     ${net_id} =    OpenStackOperations.Create Network    ${network}
90     ${subnet_id} =    OpenStackOperations.Create SubNet    ${network}    ${subnet}    ${ip_subnet}
91     ${add_args} =    BuiltIn.Set Variable    ${sg_groups} ${sg_id}
92     ${port_id}    OpenStackOperations.Create Neutron Port With Additional Params    ${network}    ${port1}    ${add_args}
93     ${port_id}    OpenStackOperations.Create Neutron Port With Additional Params    ${network}    ${port2}    ${add_args}
94
95 Security group verification on Neutron port
96     [Arguments]    ${port}    ${sg_id}
97     ${port_show} =    OpenStackOperations.Neutron Port Show    ${port}
98     BuiltIn.Should Contain    ${port_show}    ${sg_id}
99
100 Update Security Group Description and Verification
101     [Arguments]    ${sg_id}    ${description}    ${verify_description}
102     OpenStackOperations.Neutron Security Group Update    ${sg_id}    ${description}
103     ${output} =    OpenStackOperations.Neutron Security Group Show    ${sg_id}
104     BuiltIn.Should Contain    ${output}    ${verify_description}
105
106 Update Security Group Name and Verification
107     [Arguments]    ${sg_id}    ${name_update}    ${verify_name}
108     OpenStackOperations.Neutron Security Group Update    ${sg_id}    ${name_update}
109     ${output} =    OpenStackOperations.Neutron Security Group Show    ${sg_id}
110     Should Contain    ${output}    ${verify_name}
111     ${resp}    RequestsLibrary.Get Request    session    ${SEC_GROUP_API}
112     BuiltIn.Log    ${resp.content}
113     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    ${RESP_CODE_200}
114     BuiltIn.Should Contain    ${resp.content}    ${verify_name}
115
116 Neutron Rule Creation With Invalid Parameters
117     [Arguments]    ${sg_name}    ${additional_args}    ${expected_error}
118     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    neutron security-group-rule-create ${sg_name} ${additional_args}
119     BuiltIn.Log    ${output}
120     BuiltIn.Should Contain    ${output}    ${expected_error}