Removed duplicate code for entity ownership
[integration/test.git] / csit / suites / netconf / clustering / entity.robot
1 *** Settings ***
2 Documentation     Test suite for netconf device entity ownership handling during outages.
3 ...
4 ...               Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
5 ...
6 ...               This program and the accompanying materials are made available under the
7 ...               terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...               and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...
11 ...               Perform basic operations (Create, Read, Update and Delete or CRUD) on device
12 ...               data mounted onto a netconf connector and see if they work.
13 ...
14 ...               The suite recognizes 3 nodes, "CONFIGURER" (the node that configures the
15 ...               device at the beginning and then deconfigures it at the end), "SETTER" (the
16 ...               node that manipulates the data on the device) and "CHECKER" (the node that
17 ...               checks the data on the device). The configured device and the results of each
18 ...               data operation on it is expected to be visible on all nodes so after each
19 ...               operation three test cases make sure they can see the result on their
20 ...               respective nodes.
21 ...
22 ...               The 3 nodes are configured by placing "node1", "node2" or "node3" into the
23 ...               ${NODE_CONFIGURER}, ${NODE_SETTER} and ${NODE_CHECKER} to make the node
24 ...               a "CONFIGURER", "SETTER" and "CHECKER" respectively. The "nodeX" name refers
25 ...               to the node with its IP address configured with the ${ODL_SYSTEM_X_IP}
26 ...               variable where the "X" is 1, 2 or 3.
27 ...
28 ...               The suite checks the integrity of the presence of the device and the data
29 ...               seen on the device only for nodes that have at least one of the roles
30 ...               ("CONFIGURER", "SETTER" and "CHECKER") assigned. A better design would have
31 ...               a "checker list" of sorts and have only one checking test case that runs
32 ...               through the check list and performs the test on each node listed. However
33 ...               this currently has fairly low priority due to Beryllium delivery date so
34 ...               it was left out.
35 Suite Setup       Setup_Everything
36 Suite Teardown    Teardown_Everything
37 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
38 Library           Collections
39 Library           RequestsLibrary
40 Library           OperatingSystem
41 Library           String
42 Library           SSHLibrary    timeout=10s
43 Resource          ${CURDIR}/../../../libraries/ClusterKeywords.robot
44 Resource          ${CURDIR}/../../../libraries/ClusterManagement.robot
45 Resource          ${CURDIR}/../../../libraries/FailFast.robot
46 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
47 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
48 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
49 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
50 Resource          ${CURDIR}/../../../libraries/Utils.robot
51 Variables         ${CURDIR}/../../../variables/Variables.py
52
53 *** Variables ***
54 ${DEVICE_CHECK_TIMEOUT}    60s
55 ${DEVICE_BOOT_TIMEOUT}    100s
56 ${CLUSTER_RECOVERY_TIMEOUT}    120s
57 ${DEVICE_NAME}    netconf-test-device
58
59 *** Test Cases ***
60 Start_Testtool
61     [Documentation]    Deploy and start test tool, then wait for all its devices to become online.
62     NetconfKeywords.Install_And_Start_Testtool    device-count=1    schemas=${CURDIR}/../../../variables/netconf/CRUD/schemas
63
64 Check_Device_Is_Not_Mounted_At_Beginning
65     [Documentation]    Sanity check making sure our device is not there. Fail if found.
66     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${DEVICE_NAME}    session=node1
67     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${DEVICE_NAME}    session=node2
68     NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${DEVICE_NAME}    session=node3
69
70 Configure_Device_On_Netconf
71     [Documentation]    Use node 1 to configure a testtool device on Netconf connector.
72     NetconfKeywords.Configure_Device_In_Netconf    ${DEVICE_NAME}    device_type=configure-via-topology    session=node1
73     [Teardown]    Utils.Report_Failure_Due_To_Bug    5089
74
75 Wait_For_Device_To_Become_Visible_For_All_Nodes
76     [Documentation]    Wait for the whole cluster to see the device.
77     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}    session=node1
78     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}    session=node2
79     NetconfKeywords.Wait_Device_Connected    ${DEVICE_NAME}    session=node3
80
81 Check_Config_Data_Before_Data_Creation
82     [Documentation]    Check if there really is no data present on none of the nodes
83     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node1    ${empty_data}
84     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node2    ${empty_data}
85     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node3    ${empty_data}
86
87 Create_Device_Data
88     [Documentation]    Create some data on the device and propagate it throughout the cluster.
89     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${DEVICE_NAME}'}
90     TemplatedRequests.Post_As_Xml_Templated    ${directory_with_template_folders}${/}dataorig    ${template_as_string}    session=node2
91
92 Check_Config_Data_After_Data_Creation
93     [Documentation]    Check if the data we just added into the cluster is really there
94     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node1    ${original_data}
95     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node2    ${original_data}
96     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node3    ${original_data}
97
98 Find_And_Shutdown_Device_Entity_Owner
99     [Documentation]    Simulate a failure of the owner of the entity that represents the device.
100     ${owner}    ${followers}=    ClusterKeywords.Get Device Entity Owner And Followers Indexes    node1    netconf    ${DEVICE NAME}
101     Log    ${followers}
102     Length Should Be    ${followers}    2    Wrong count of followers returned
103     BuiltIn.Set_Suite_Variable    ${original_device_owner}    ${owner}
104     BuiltIn.Set_Suite_Variable    ${follower1}    @{followers}[0]
105     BuiltIn.Set_Suite_Variable    ${follower2}    @{followers}[1]
106     ClusterManagement.Kill_Single_Member    ${owner}
107
108 Wait_For_New_Owner_To_Appear
109     [Documentation]    Wait for the cluster to recover from the failure and choose a new owner for the entity.
110     [Tags]    critical
111     BuiltIn.Wait_Until_Keyword_Succeeds    ${CLUSTER_RECOVERY_TIMEOUT}    1s    Check_Owner_Reconfigured
112
113 Check_Config_Data_Before_Modification_With_Original_Owner_Down
114     [Documentation]    Check if data is present and retrievable from follower nodes
115     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node${follower1}    ${original_data}
116     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node${follower2}    ${original_data}
117     [Teardown]    Utils.Report_Failure_Due_To_Bug    6067
118
119 Modify_Device_Data_When_Original_Owner_Is_Down
120     [Documentation]    Attempt to modify the data on the device after recovery and see if it still works.
121     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${DEVICE_NAME}'}
122     TemplatedRequests.Put_As_Xml_Templated    ${directory_with_template_folders}${/}datamod1    ${template_as_string}    session=node${follower1}
123     [Teardown]    Utils.Report_Failure_Due_To_Bug    4968
124
125 Check_Config_Data_After_Modification_With_Original_Owner_Down
126     [Documentation]    Check if data is written correctly when original owner is shut down
127     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node${follower1}    ${modified_data}
128     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node${follower2}    ${modified_data}
129     [Teardown]    Utils.Report_Failure_Due_To_Bug    6067
130
131 Restart_Original_Entity_Owner
132     [Documentation]    Restart the original entity owner and see if it can still see the device and the new data on it.
133     ClusterManagement.Start_Single_Member    ${original_device_owner}
134
135 Check_Config_Data_After_Original_Owner_Restart
136     [Documentation]    Sanity check if we still can retrieve our data from the original device owner (node${original_device_owner}).
137     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node${original_device_owner}    ${modified_data}
138     [Teardown]    Utils.Report_Failure_Due_To_Bug    5761
139
140 Modify_Device_Data_With_Original_Owner
141     [Documentation]    Check that the original owner of the entity is still able to modify the data on the device
142     ${template_as_string}=    BuiltIn.Set_Variable    {'DEVICE_NAME': '${DEVICE_NAME}'}
143     TemplatedRequests.Put_As_Xml_Templated    ${directory_with_template_folders}${/}datamod2    ${template_as_string}    session=node${original_device_owner}
144     [Teardown]    Utils.Report_Failure_Due_To_Bug    5761
145
146 Check_Config_Data_After_Modification_With_Original_Owner_Up
147     [Documentation]    Check if data has really been written as we expect. Fails if Modify_Device_Data_With_Original_Owner fails.
148     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node1    ${modified_data_2}
149     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node2    ${modified_data_2}
150     BuiltIn.Wait_Until_Keyword_Succeeds    ${DEVICE_CHECK_TIMEOUT}    1s    Check_Config_Data    node3    ${modified_data_2}
151
152 Deconfigure_Device_In_Netconf
153     [Documentation]    Make request to deconfigure the device on Netconf connector and see if it works.
154     [Tags]    critical
155     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
156     NetconfKeywords.Remove_Device_From_Netconf    ${DEVICE_NAME}    session=node1
157     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}    session=node1
158     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}    session=node2
159     NetconfKeywords.Wait_Device_Fully_Removed    ${DEVICE_NAME}    session=node3
160
161 *** Keywords ***
162 Setup_Everything
163     [Documentation]    Setup everything needed for the test cases.
164     # Setup resources used by the suite.
165     SetupUtils.Setup_Utils_For_Setup_And_Teardown
166     ClusterManagement.ClusterManagement_Setup
167     NetconfKeywords.Setup_Netconf_Keywords    create_session_for_templated_requests=False
168     ClusterKeywords.Create_Controller_Sessions
169     # TODO: Refactor the suite to use ClusterManagement.Resolve_Http_Session_For_Member instead of these 3 "hardcoded" sessions.
170     RequestsLibrary.Create_Session    node1    http://${ODL_SYSTEM_1_IP}:${RESTCONFPORT}    headers=${HEADERS_XML}    auth=${AUTH}
171     RequestsLibrary.Create_Session    node2    http://${ODL_SYSTEM_2_IP}:${RESTCONFPORT}    headers=${HEADERS_XML}    auth=${AUTH}
172     RequestsLibrary.Create_Session    node3    http://${ODL_SYSTEM_3_IP}:${RESTCONFPORT}    headers=${HEADERS_XML}    auth=${AUTH}
173     # Constants that are not meant to be overriden by the users
174     BuiltIn.Set_Suite_Variable    ${directory_with_template_folders}    ${CURDIR}/../../../variables/netconf/CRUD
175     BuiltIn.Set_Suite_Variable    ${empty_data}    <data xmlns="${ODL_NETCONF_NAMESPACE}"></data>
176     ${cont}=    BuiltIn.Set_Variable    <data xmlns="${ODL_NETCONF_NAMESPACE}"><cont xmlns="urn:opendaylight:test:netconf:crud"><l>
177     ${contend}=    BuiltIn.Set_Variable    </l></cont></data>
178     BuiltIn.Set_Suite_Variable    ${original_data}    ${cont}Content${contend}
179     BuiltIn.Set_Suite_Variable    ${modified_data}    ${cont}Modified Content${contend}
180     BuiltIn.Set_Suite_Variable    ${modified_data_2}    ${cont}Another Modified Content${contend}
181
182 Teardown_Everything
183     [Documentation]    Teardown the test infrastructure, perform cleanup and release all resources.
184     RequestsLibrary.Delete_All_Sessions
185     NetconfKeywords.Stop_Testtool
186
187 Check_Config_Data
188     [Arguments]    ${node}    ${expected}    ${contains}=False
189     [Documentation]    Check that the data on the device matches the specified expectations.
190     ...    TODO: Needs to be extracted into a suitable Resource as there is
191     ...    the same code in at least two other suites (CRUD and clustered
192     ...    CRUD).
193     ${url}=    Builtin.Set_Variable    ${CONFIG_API}/network-topology:network-topology/topology/topology-netconf/node/${DEVICE_NAME}/yang-ext:mount
194     ${data}=    TemplatedRequests.Get_As_Xml_From_Uri    ${url}    session=${node}
195     BuiltIn.Run_Keyword_Unless    ${contains}    BuiltIn.Should_Be_Equal_As_Strings    ${data}    ${expected}
196     BuiltIn.Run_Keyword_If    ${contains}    BuiltIn.Should_Contain    ${data}    ${expected}
197
198 Check_Owner_Reconfigured
199     [Documentation]    Check whether the entity owner changed. Fail if not or no owner found.
200     Log    Original Owner Index: ${original_device_owner}
201     Log    Follower 1: node${follower1}
202     Log    Follower 2: node${follower2}
203     ${owner}    ${candidates}=    ClusterKeywords.Get_Device_Entity_Owner_And_Candidates_Indexes    node${follower1}    netconf    ${DEVICE_NAME}
204     BuiltIn.Should_Not_Be_Equal_As_Integers    ${owner}    ${original_device_owner}