Step 2: Move test folder to root
[integration/test.git] / csit / suites / persistence / basic / test_app.robot
1 *** Settings ***
2 Documentation     Basic Tests for Persistence Test APP.
3 ...
4 ...               Copyright (c) 2015 Hewlett-Packard Development Company, L.P. and others. All rights reserved.
5 Suite Setup       Setup Persistence Test App Environment
6 Suite Teardown    Cleanup Persistence Test Database
7 Library           SSHLibrary
8 Library           Collections
9 Library           ../../../libraries/UtilLibrary.py
10 Resource          ../../../libraries/KarafKeywords.robot
11 Resource          ../../../libraries/Utils.robot
12 Variables         ../../../variables/Variables.py
13
14 *** Variables ***
15 ${username}       user1
16 ${password}       user1
17 ${email_addr}     user1@example.com
18 ${location1}      BUILDING_1_FIRST_FLOOR
19 ${location2}      BUILDING_2_FIRST_FLOOR
20 ${device1_name}    node1
21 ${device1_ip}     10.1.1.10
22 ${device2_name}    node2
23 ${device2_ip}     10.1.1.20
24
25 *** Test Cases ***
26 Verify User Test App
27     [Documentation]    Verify the User functionality of the Persistence Test App
28     ...    This test case performs the following:
29     ...    1. Create a user
30     ...    2. Verify user is created and can be fetched
31     ...    3. Verify user is created with correct user name and email address
32     ...    4. Verify unknown user cannot be authenticated
33     ...    5. Disable the user
34     ...    6. Verify disabled user can be fetched
35     [Tags]    Persistence    TestApp
36     Issue Command On Karaf Console    user:sign-up ${username} ${password} ${email_addr}
37     ${output}=    Issue Command On Karaf Console    user:get-enabled
38     ${string}=    Extract String To Validate    ${output}    User{username=Username{value=    0
39     Should Match    ${string}    ${username}
40     ${string}=    Extract String To Validate    ${output}    email=Email{value=    2
41     Should Match    ${string}    ${email_addr}
42     ${unknown_user}=    Set Variable    random
43     ${output}=    Issue Command On Karaf Console    user:sign-in ${unknown_user} ${password}
44     Should Contain    ${output}    Error executing command:
45     Issue Command On Karaf Console    user:disable ${username}
46     ${output}=    Issue Command On Karaf Console    user:get-disabled
47     ${user_dstate}=    Set Variable    isEnabled=false
48     ${data}=    Find User State    ${output}
49     Should Contain    ${data}    ${user_dstate}
50
51 Verify Network Device Test App
52     [Documentation]    Verify the Network Device functionality of the Persistence Test App
53     ...    This test case performs the following:
54     ...    1. Add a device
55     ...    2. Verify device can be discovered
56     ...    3. Assign a name to the device
57     ...    4. Verify device name
58     ...    5. Configure a location
59     ...    6. Verify device location
60     [Tags]    Persistence    TestApp
61     Issue Command On Karaf Console    networkdevice:discover ${device1_ip}
62     ${output}=    Issue Command On Karaf Console    networkdevice:get-reachable
63     ${string}=    Extract String To Validate    ${output}    ipAddress=IpAddress{value=    2
64     Should Match    ${string}    ${device1_ip}
65     ${device_id}    Find Device Id    ${device1_ip}
66     Issue Command On Karaf Console    networkdevice:set-friendly-name ${device_id} ${device1_name}
67     ${data}=    Find Device Name    ${device1_ip}
68     Should Match    ${data}    ${device1_name}
69     Issue Command On Karaf Console    networkdevice:set-location ${device_id} ${location1}
70     ${data}=    Find Device Location    ${device1_ip}    ${location1}
71     Should Match    ${data}    ${location1}
72
73 Verify Data Persistency
74     [Documentation]    Verify that the data that is generated by Persistence Test App can be persisted
75     ...    This test case performs the following:
76     ...    1. Create a user
77     ...    2. Add a device and configure name and location
78     ...    3. Restart the controller
79     ...    4. Verify user name, email address and state are persisted
80     ...    5. Verify device name and location are persisted
81     [Tags]    Persistence    TestApp
82     Issue Command On Karaf Console    user:sign-up ${username} ${password} ${email_addr}
83     Issue Command On Karaf Console    networkdevice:discover ${device2_ip}
84     ${device_id}    Find Device Id    ${device2_ip}
85     Issue Command On Karaf Console    networkdevice:set-location ${device_id} ${location2}
86     Issue Command On Karaf Console    networkdevice:set-friendly-name ${device_id} ${device2_name}
87     Stop One Or More Controllers    ${CONTROLLER}
88     Wait Until Keyword Succeeds    60s    3s    Controller Down Check    ${CONTROLLER}
89     Start One Or More Controllers    ${CONTROLLER}
90     UtilLibrary.Wait For Controller Up    ${CONTROLLER}    ${RESTCONFPORT}
91     ${output}=    Issue Command On Karaf Console    user:get-enabled
92     ${string}=    Extract String To Validate    ${output}    User{username=Username{value=    0
93     Should Match    ${string}    ${username}
94     ${string}=    Extract String To Validate    ${output}    email=Email{value=    2
95     Should Match    ${string}    ${email_addr}
96     ${data}=    Find User State    ${output}
97     ${user_estate}=    Set Variable    isEnabled=true
98     Should Contain    ${data}    ${user_estate}
99     ${data}=    Find Device Name    ${device2_ip}
100     Should Match    ${data}    ${device2_name}
101     ${data}=    Find Device Location    ${device2_ip}    ${location2}
102     Should Match    ${data}    ${location2}
103
104 *** Keywords ***
105 Extract String To Validate
106     [Arguments]    ${output}    ${splitter}    ${index}
107     [Documentation]    Take the output of a content, the string to be splitted and the
108     ...    index of the data from the output, parse the strin and return the data that includes
109     ...    user's name, user's email address, device's IP address
110     ${output}=    Split Value from String    ${output}    }
111     ${string}=    Get From List    ${output}    ${index}
112     ${string}=    Split Value from String    ${string}    ${splitter}
113     ${string}=    Get From List    ${string}    1
114     [Return]    ${string}
115
116 Find Line
117     [Arguments]    ${device_ip}
118     [Documentation]    Take the output of networkdevice:get-reachable, find the line
119     ...    with the give IP with the given IP address and return the line
120     ${output}=    Issue Command On Karaf Console    networkdevice:get-reachable
121     ${output}=    Split To Lines    ${output}
122     ${length}=    Get Length    ${output}
123     : FOR    ${INDEX}    IN RANGE    0    ${length}
124     \    ${line}=    Get From List    ${output}    ${INDEX}
125     \    ${data}=    Fetch From Right    ${line}    ipAddress=IpAddress{value=
126     \    ${data}=    Split String    ${data}    },
127     \    ${data}=    Get From List    ${data}    0
128     \    Run Keyword If    '${data}' == '${device_ip}'    Exit For Loop
129     [Return]    ${line}
130
131 Find Device Id
132     [Arguments]    ${device_ip}
133     [Documentation]    Find the device ID using its IP address
134     ${line}=    Find Line    ${device_ip}
135     ${id}=    Split String    ${line}    NetworkDevice{id=SerialNumber{value=
136     ${id}=    Get From List    ${id}    1
137     ${id}=    Fetch from Left    ${id}    }
138     [Return]    ${id}
139
140 Find Device Name
141     [Arguments]    ${device_ip}
142     [Documentation]    Find the device's name using its IP address
143     ${line}=    Find Line    ${device_ip}
144     ${line}=    Split String    ${line}    ,
145     ${line}=    Get From List    ${line}    -2
146     ${name}=    Split String    ${line}    friendlyName=
147     ${name}=    Get From List    ${name}    1
148     [Return]    ${name}
149
150 Find Device Location
151     [Arguments]    ${device_ip}    ${location}
152     [Documentation]    Find the device's location using its IP address
153     ${line}=    Find Line    ${device_ip}
154     ${line}=    Split String    ${line}    ,
155     ${line}=    Get From List    ${line}    3
156     ${name}=    Split String    ${line}    location=
157     ${name}=    Get From List    ${name}    1
158     [Return]    ${location}
159
160 Find User State
161     [Arguments]    ${output}
162     [Documentation]    Find the user's state
163     ${output}=    Split Value from String    ${output}    ,
164     ${data}=    Get From List    ${output}    4
165     ${data}=    Remove Space on String    ${data}
166     ${data}=    Split String    ${data}    }
167     [Return]    ${data}
168
169 Setup Persistence Test App Environment
170     [Documentation]    Installing Persistence Related features
171     Install a Feature    odl-persistence-all
172     Install a Feature    odl-persistence-test-app
173     Verify Feature Is Installed    odl-persistence-api
174     Verify Feature Is Installed    odl-persistence-jpa-impl
175     Verify Feature Is Installed    odl-persistence-test-app
176
177 Cleanup Persistence Test Database
178     [Documentation]    Clear the database and uninstall Persistence Test App
179     Uninstall a Feature    odl-persistence-api
180     Uninstall a Feature    odl-persistence-jpa-impl
181     Uninstall a Feature    odl-persistence-test-app
182     Verify Feature Is Not Installed    odl-persistence-api
183     Verify Feature Is Not Installed    odl-persistence-jpa-impl
184     Verify Feature Is Not Installed    odl-persistence-test-app