Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / suites / nic / cli / console.robot
1 *** Settings ***
2 Documentation     Basic Tests for NIC Console Commands.
3 ...
4 ...               Copyright (c) 2015 Hewlett-Packard Development Company, L.P. 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 Suite Setup       Setup NIC Console Environment
10 Library           SSHLibrary
11 Library           Collections
12 Library           OperatingSystem
13 Library           ../../../libraries/Common.py
14 Resource          ../../../libraries/KarafKeywords.robot
15 Resource          ../../../libraries/Utils.robot
16 Variables         ../../../variables/Variables.py
17
18 *** Variables ***
19 @{intent1}        10.0.0.5    10.0.0.2,10.0.0.3    ALLOW
20 @{intent2}        10.0.0.5    10.0.0.2,10.0.0.10    BLOCK
21 @{intent3}        10.0.0.1,10.0.0.4    10.0.0.2    ALLOW
22 @{all_intents}    ${intent1}    ${intent2}    ${intent3}
23 @{all_intents_ids}
24 ${intent_validation1}    from [10.0.0.1, 10.0.0.4] to [10.0.0.2]
25 ${intent_validation2}    from [10.0.0.5] to [10.0.0.2]
26 ${intent_validation3}    from [10.0.0.5] to [10.0.0.3]
27 ${intent_validation4}    from [10.0.0.5] to [10.0.0.10]
28 ${intent_validation_policy1}    ALLOW
29 ${intent_validation_policy2}    BLOCK
30 ${intent_validation_policy3}    ALLOW
31 ${intent_validation_policy4}    BLOCK
32 @{all_intent_validations}    ${intent_validation1}    ${intent_validation2}    ${intent_validation3}    ${intent_validation4}
33 @{all_intent_validations_policies}    ${intent_validation_policy1}    ${intent_validation_policy2}    ${intent_validation_policy3}    ${intent_validation_policy4}
34
35 *** Test Cases ***
36 Verify NIC Command Add and Remove
37     [Documentation]    Verification of NIC Console command add and remove. It first creates the intents
38     ...    and stores the intent ids, then verifies that the intents were added. Finally, it compiles the intents
39     ...    to verify that intents were properly merged and also validates intents were removed at the end per the cleanup procedure.
40     ...    The command "Wait Until Keyword Succeeds" is used to poll for 10 minutes
41     ...    until the intent:add command is available for the test case to be run.
42     [Tags]    NIC
43     Wait Until Keyword Succeeds    1 min    5 sec    Verify Intent:Add Command is Available
44     FOR    ${intent}    IN    @{all_intents}
45         ${id}=    Add Intent    @{intent}
46         Append To List    ${all_intents_ids}    ${id}
47     END
48     ${size}=    Get Length    ${all_intents}
49     FOR    ${index}    IN RANGE    ${size}
50         ${intent}=    Get From List    ${all_intents}    ${index}
51         ${intent_id}=    Get From List    ${all_intents_ids}    ${index}
52         Verify Intent Added    ${intent_id}    ${intent}
53     END
54     ${output}=    Issue Command On Karaf Console    intent:compile
55     ${size}=    Get Length    ${all_intent_validations}
56     FOR    ${index}    IN RANGE    ${size}
57         ${compiled_intent_validation}=    Get From List    ${all_intent_validations}    ${index}
58         ${intent_validation_line}=    Get Lines Containing String    ${output}    ${compiled_intent_validation}
59         ${policy}=    Get From List    ${all_intent_validations_policies}    ${index}
60         Should Contain    ${intent_validation_line}    ${policy}
61     END
62     FOR    ${intent_id}    IN    @{all_intents_ids}
63         Remove Intent    ${intent_id}
64     END
65     ${output}=    Issue Command On Karaf Console    intent:list -c
66     FOR    ${intent_id}    IN    @{all_intents_ids}
67         Should Not Contain    ${output}    ${id}
68     END
69
70 *** Keywords ***
71 Setup NIC Console Environment
72     [Documentation]    Installing NIC Console related features (odl-nic-core-mdsal)
73     Start Mininet
74     Verify Feature Is Installed    odl-nic-core-mdsal
75
76 Add Intent
77     [Arguments]    ${intent_from}    ${intent_to}    ${intent_permission}
78     [Documentation]    Adds an intent to the controller, and returns the id of the intent created.
79     ${output}=    Issue Command On Karaf Console    intent:add -f ${intent_from} -t ${intent_to} -a ${intent_permission}
80     Should Contain    ${output}    Intent created
81     ${output}=    Fetch From Left    ${output}    )
82     ${output_split}=    Split String    ${output}    ${SPACE}
83     ${id}=    Get From List    ${output_split}    3
84     [Return]    ${id}
85
86 Verify Intent:Add Command is Available
87     [Documentation]    Verifies that intent:add command is available to be used.
88     ...    Should be used with the command "Wait Until Keyword Succeeds" to poll until command is available.
89     ${output}=    Issue Command On Karaf Console    intent:add
90     Should Not Contain    ${output}    Command not found
91
92 Verify Intent Added
93     [Arguments]    ${id}    ${intent}
94     [Documentation]    This will check if the id exists via intent:list -c, then compares intent details with arguments passed in with Add Intent
95     ${output}=    Issue Command On Karaf Console    intent:list -c
96     Should Contain    ${output}    ${id}
97     ${output}=    Issue Command On Karaf Console    intent:show ${id}
98     ${out}=    Get Lines Containing String    ${output}    Value:
99     ${out_intent_from}=    Get Line    ${out}    0
100     ${out_intent_to}=    Get Line    ${out}    1
101     ${out_intent_permission}=    Get Line    ${out}    2
102     ${intent_from}=    Get From List    ${intent}    0
103     ${intent_to}=    Get From List    ${intent}    1
104     ${intent_permission}=    Get From List    ${intent}    2
105     Should Contain    ${out_intent_from}    ${intent_from}
106     Should Contain    ${out_intent_to}    ${intent_to}
107     Should Contain    ${out_intent_permission}    ${intent_permission}
108
109 Remove Intent
110     [Arguments]    ${id}
111     [Documentation]    Removes an intent from the controller via the provided intent id.
112     ${output}=    Issue Command On Karaf Console    intent:remove ${id}
113     Should Contain    ${output}    Intent successfully removed