Get rid of deprecation warnings
[integration/test.git] / csit / libraries / GBP / AssertionUtils.robot
1 *** Settings ***
2 Documentation       Utils for Restconf operations for GBP
3
4 Library             RequestsLibrary
5 Library             OperatingSystem
6 Library             String
7 Variables           ../../variables/Variables.py
8 Resource            ../../variables/gbp/Constants.robot
9 Resource            ../Utils.robot
10 Resource            RestconfUtils.robot
11
12
13 *** Keywords ***
14 Assert Subnet
15     [Documentation]    Checks name and ip prefix of given subnet and returns parent ID
16     [Arguments]    ${subnet_to_check}    ${subnet_name}    ${ip_prefix_to_check}
17     ${parent}    Assert Forwarding Domain    ${subnet_to_check}    ${subnet_name}    return_parent=TRUE
18     ${ip_prefix}    Get Ip Prefix of Subnet    ${subnet_to_check}
19     Should Be Equal As Strings    ${ip_prefix}    ${ip_prefix_to_check}
20     RETURN    ${parent}
21
22 Assert L2-Flood-Domain
23     [Documentation]    Checks name of given l2-flood-domain and returns parent ID
24     [Arguments]    ${l2_flood_domain_to_check}    ${l2_flood_domain_name}
25     ${parent}    Assert Forwarding Domain
26     ...    ${l2_flood_domain_to_check}
27     ...    ${l2_flood_domain_name}
28     ...    return_parent=TRUE
29     RETURN    ${parent}
30
31 Assert L2-Bridge-Domain
32     [Documentation]    Checks name of given l2-bridge-domain and returns parent ID
33     [Arguments]    ${l2_bridge_domain_to_check}    ${l2_bridge_domain_name}
34     ${parent}    Assert Forwarding Domain
35     ...    ${l2_bridge_domain_to_check}
36     ...    ${l2_bridge_domain_name}
37     ...    return_parent=TRUE
38     RETURN    ${parent}
39
40 Assert L3-Context
41     [Documentation]    Checks name of given l3-context
42     [Arguments]    ${l3_context_to_check}    ${l3_context_name}
43     ${parent}    Assert Forwarding Domain    ${l3_context_to_check}    ${l3_context_name}
44     RETURN    ${parent}
45
46 Assert Forwarding Domain
47     [Documentation]    Checks name of given l3-context
48     [Arguments]    ${domain_to_check}    ${domain_name}    ${return_parent}=FALSE
49     Check Name    ${domain_to_check}    ${domain_name}
50     IF    "${return_parent}" == "FALSE"    RETURN
51     ${parent}    Get Parent    ${domain_to_check}
52     RETURN    ${parent}
53
54 Check Name
55     [Documentation]    Checks correct format of a name field in JSON data
56     [Arguments]    ${data}    ${name}
57     Should Not Be Empty    ${data}
58     Should Match Regexp    ${data}    \"name\":\"${NAME_PATTERN}\"
59
60 Check CI Range Values
61     [Documentation]    Veriefies min and max values of range-value of classifier-instance in JSON format
62     [Arguments]    ${range_value_json}    ${min}    ${max}
63     Should Be Equal As Numbers    ${min}    ${range_value_json['min']}
64     Should Be Equal As Numbers    ${max}    ${range_value_json['max']}
65
66 Get Parent
67     [Documentation]    Returns 'parent' value of an JSON object. Can be applied to Subnet, L2-Flood-Domain or L2-Bridge-Domain
68     [Arguments]    ${data}
69     Should Not Be Empty    ${data}
70     ${parent_line}    Should Match Regexp    ${data}    \"parent\":\"${UUID_PATTERN}\"
71     ${parent_uuid}    Should Match Regexp    ${parent_line}    ${UUID_PATTERN}
72     RETURN    ${parent_uuid}
73
74 Check Endpoint
75     [Documentation]    Verifies parameters of given endpoint in JSON format
76     [Arguments]    ${endpoint}    ${ip_address}    ${epg}    ${l3-context}    ${network-containment}    ${tenant}
77     Should Contain    ${endpoint}    ofoverlay:port-name
78     @{ep_l3-addresses}    Get L3-Addresses of Endpoint    ${endpoint}
79     @{ep_endpoint_groups}    Get Groups of Endpoint    ${endpoint}
80     ${ep_network-containment}    Get Network Containment of Endpoint    ${endpoint}
81     ${ep_tenant}    Get Tenant of Endpoint    ${endpoint}
82     @{ep_endpoint_groups}    Get Groups of Endpoint    ${endpoint}
83     Should Be Equal As Strings    ${ep_network-containment}    ${network-containment}
84     Should Be Equal As Strings    ${ep_tenant}    ${tenant}
85     Check Group References    ${epg}    @{ep_endpoint_groups}
86     LOG    ${ep_l3-addresses}
87     FOR    ${l3}    IN    @{ep_l3-addresses}
88         LOG    ${l3-context}
89         LOG    ${ip_address}
90         LOG    ${l3['l3-context']}
91         LOG    ${l3['ip-address']}
92         IF    "${l3['l3-context']}" == "${l3-context}" and "${l3['ip-address']}" == "${ip_address}"
93             CONTINUE
94         END
95         Fail
96     END
97
98 Check Endpoint-L3
99     [Documentation]    Verifies parameters of registerd endpoint-l3 in JSON format
100     [Arguments]    ${endpoint-l3}    ${mac_address}    ${epg}    ${l2-context}    ${network-containment}    ${tenant}
101     Should Contain    ${endpoint-l3}    ofoverlay:port-name
102     ${ep_l2-context}    Get L2 Context of Endpoint-L3    ${endpoint-l3}
103     ${ep_mac_address}    Get Mac Address of Endpoint-L3    ${endpoint-l3}
104     ${ep_network-containment}    Get Network Containment of Endpoint-L3    ${endpoint-l3}
105     ${ep_tenant}    Get Tenant of Endpoint-L3    ${endpoint-l3}
106     @{ep_endpoint_groups}    Get Groups of Endpoint-L3    ${endpoint-l3}
107     Should Be Equal As Strings    ${ep_mac_address}    ${mac_address}
108     Should Be Equal As Strings    ${ep_l2-context}    ${l2-context}
109     Should Be Equal As Strings    ${network-containment}    ${network-containment}
110     Should Be Equal As Strings    ${tenant}    ${tenant}
111     Check Group References    ${epg}    @{ep_endpoint_groups}
112
113 Check Group References
114     [Documentation]    Verifies presence of endpoint group to which endpoint belongs and presence of network_client group
115     ...    among given endpoint groups
116     [Arguments]    ${epg_to_look_for}    @{endpoint_groups}
117     Should Not Be Empty    ${epg_to_look_for}
118     Should Not Be Empty    ${endpoint_groups}
119     FOR    ${epg}    IN    @{endpoint_groups}
120         IF    "${epg}" == "${epg_to_look_for}"            CONTINUE
121         IF    "${epg}" == "${NETWORK_CLIENT_GROUP}"            CONTINUE
122         Fail
123     END
124
125 Check Endpoint Group Name and Selector
126     [Documentation]    Verifies data generated by security group and security group rules
127     [Arguments]    ${epg_id}    ${epg_name}    ${tenant_id}    ${contract_id}    ${named-selector}
128     ${epg_path}    Get Endpoint Group Path    ${tenant_id}    ${epg_id}
129     ${endpoint_group}    Get Data From URI    session    ${epg_path}    headers=${headers}
130     Should Not Be Empty    ${endpoint_group}
131     Check Name    ${endpoint_group}    ${epg_name}
132     ${endpoint_group_json}    To Json    ${endpoint_group}
133     ${named_selectors}    Set Variable    ${endpoint_group_json['endpoint-group'][0]['${named-selector}']}
134     ${selector_found}    Set Variable    FALSE
135     FOR    ${selector}    IN    @{named_selectors}
136         IF    "${selector['contract'][0]}" == "${contract_id}"    RETURN
137     END
138     Fail