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