Upgrade RF syntax for v3.2 compatibility
[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    ${ODL_SYSTEM_IP}
88     Wait Until Keyword Succeeds    60s    3s    Controller Down Check    ${ODL_SYSTEM_IP}
89     Start One Or More Controllers    ${ODL_SYSTEM_IP}
90     UtilLibrary.Wait For Controller Up    ${ODL_SYSTEM_IP}    ${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     END
130     [Return]    ${line}
131
132 Find Device Id
133     [Arguments]    ${device_ip}
134     [Documentation]    Find the device ID using its IP address
135     ${line}=    Find Line    ${device_ip}
136     ${id}=    Split String    ${line}    NetworkDevice{id=SerialNumber{value=
137     ${id}=    Get From List    ${id}    1
138     ${id}=    Fetch from Left    ${id}    }
139     [Return]    ${id}
140
141 Find Device Name
142     [Arguments]    ${device_ip}
143     [Documentation]    Find the device's name using its IP address
144     ${line}=    Find Line    ${device_ip}
145     ${line}=    Split String    ${line}    ,
146     ${line}=    Get From List    ${line}    -2
147     ${name}=    Split String    ${line}    friendlyName=
148     ${name}=    Get From List    ${name}    1
149     [Return]    ${name}
150
151 Find Device Location
152     [Arguments]    ${device_ip}    ${location}
153     [Documentation]    Find the device's location using its IP address
154     ${line}=    Find Line    ${device_ip}
155     ${line}=    Split String    ${line}    ,
156     ${line}=    Get From List    ${line}    3
157     ${name}=    Split String    ${line}    location=
158     ${name}=    Get From List    ${name}    1
159     [Return]    ${location}
160
161 Find User State
162     [Arguments]    ${output}
163     [Documentation]    Find the user's state
164     ${output}=    Split Value from String    ${output}    ,
165     ${data}=    Get From List    ${output}    4
166     ${data}=    Remove Space on String    ${data}
167     ${data}=    Split String    ${data}    }
168     [Return]    ${data}
169
170 Setup Persistence Test App Environment
171     [Documentation]    Installing Persistence Related features
172     Install a Feature    odl-persistence-all
173     Install a Feature    odl-persistence-test-app
174     Verify Feature Is Installed    odl-persistence-api
175     Verify Feature Is Installed    odl-persistence-jpa-impl
176     Verify Feature Is Installed    odl-persistence-test-app
177
178 Cleanup Persistence Test Database
179     [Documentation]    Clear the database and uninstall Persistence Test App
180     Uninstall a Feature    odl-persistence-api
181     Uninstall a Feature    odl-persistence-jpa-impl
182     Uninstall a Feature    odl-persistence-test-app
183     Verify Feature Is Not Installed    odl-persistence-api
184     Verify Feature Is Not Installed    odl-persistence-jpa-impl
185     Verify Feature Is Not Installed    odl-persistence-test-app