Revised NIC CLI tests to account for agnostic policy formats.
[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     [Tags]    NIC
41     : FOR    ${intent}    IN    @{all_intents}
42     \    ${id}=    Add Intent    @{intent}
43     \    Append To List    ${all_intents_ids}    ${id}
44     ${size}=    Get Length    ${all_intents}
45     : FOR    ${index}    IN RANGE    ${size}
46     \    ${intent}=    Get From List    ${all_intents}    ${index}
47     \    ${intent_id}=    Get From List    ${all_intents_ids}    ${index}
48     \    Verify Intent Added    ${intent_id}    ${intent}
49     ${output}=    Issue Command On Karaf Console    intent:compile
50     ${size}=    Get Length    ${all_intent_validations}
51     : FOR    ${index}    IN RANGE    ${size}
52     \    ${compiled_intent_validation}=    Get From List    ${all_intent_validations}    ${index}
53     \    ${intent_validation_line}=    Get Lines Containing String    ${output}    ${compiled_intent_validation}
54     \    ${policy}=    Get From List    ${all_intent_validations_policies}    ${index}
55     \    Should Contain    ${intent_validation_line}    ${policy}
56     : FOR    ${intent_id}    IN    @{all_intents_ids}
57     \    Remove Intent    ${intent_id}
58     ${output}=    Issue Command On Karaf Console    intent:list -c
59     : FOR    ${intent_id}    IN    @{all_intents_ids}
60     \    Should Not Contain    ${output}    ${id}
61
62 *** Keywords ***
63 Setup NIC Console Environment
64     [Documentation]    Installing NIC Console related features (odl-nic-core, odl-nic-console)
65     Install a Feature    odl-nic-core
66     Install a Feature    odl-nic-console
67     Start Suite
68     Verify Feature Is Installed    odl-nic-core
69     Verify Feature Is Installed    odl-nic-console
70
71 Add Intent
72     [Arguments]    ${intent_from}    ${intent_to}    ${intent_permission}
73     [Documentation]    Adds an intent to the controller, and returns the id of the intent created.
74     ${output}=    Issue Command On Karaf Console    intent:add -f ${intent_from} -t ${intent_to} -a ${intent_permission}    timeout=60
75     Should Contain    ${output}    Intent created
76     ${output}=    Fetch From Left    ${output}    )
77     ${output_split}=    Split String    ${output}    ${SPACE}
78     ${id}=    Get From List    ${output_split}    3
79     [Return]    ${id}
80
81 Verify Intent Added
82     [Arguments]    ${id}    ${intent}
83     [Documentation]    This will check if the id exists via intent:list -c, then compares intent details with arguments passed in with Add Intent
84     ${output}=    Issue Command On Karaf Console    intent:list -c
85     Should Contain    ${output}    ${id}
86     ${output}=    Issue Command On Karaf Console    intent:show ${id}
87     ${out}=    Get Lines Containing String    ${output}    Value:
88     ${out_intent_from}=    Get Line    ${out}    0
89     ${out_intent_to}=    Get Line    ${out}    1
90     ${out_intent_permission}=    Get Line    ${out}    2
91     ${intent_from}=    Get From List    ${intent}    0
92     ${intent_to}=    Get From List    ${intent}    1
93     ${intent_permission}=    Get From List    ${intent}    2
94     Should Contain    ${out_intent_from}    ${intent_from}
95     Should Contain    ${out_intent_to}    ${intent_to}
96     Should Contain    ${out_intent_permission}    ${intent_permission}
97
98 Remove Intent
99     [Arguments]    ${id}
100     [Documentation]    Removes an intent from the controller via the provided intent id.
101     ${output}=    Issue Command On Karaf Console    intent:remove ${id}
102     Should Contain    ${output}    Intent successfully removed