Migrate Get Requests invocations(libraries)
[integration/test.git] / csit / suites / netconf / KeyAuth / keyauth.robot
1 *** Settings ***
2 Documentation     Test suite to verify the device mount using public key based auth.
3 Suite Setup       Suite Setup
4 Suite Teardown    Suite Teardown
5 Library           SSHLibrary
6 Library           RequestsLibrary
7 Resource          ../../../libraries/SSHKeywords.robot
8 Resource          ../../../libraries/ClusterManagement.robot
9 Resource          ../../../variables/Variables.robot
10 Resource          ${CURDIR}/../../../libraries/NetconfKeywords.robot
11 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
12 Resource          ${CURDIR}/../../../libraries/TemplatedRequests.robot
13 Resource          ${CURDIR}/../../../libraries/CompareStream.robot
14 Resource          ${CURDIR}/../../../variables/Variables.robot
15
16 *** Variables ***
17 ${directory_with_keyauth_template}    ${CURDIR}/../../../variables/netconf/KeyAuth
18 ${pkPassphrase}    topsecret
19 ${device_name}    netconf-test-device
20 ${device_type_passw}    full-uri-device
21 ${device_type_key}    full-uri-device-key
22 ${netopeer_port}    830
23 ${netopeer_user}    root
24 ${netopeer_pwd}    wrong
25 ${netopeer_key}    device-key
26 ${USE_NETCONF_CONNECTOR}    ${False}
27
28 *** Test Cases ***
29 Check_Device_Is_Not_Configured_At_Beginning
30     [Documentation]    Sanity check making sure our device is not there. Fail if found.
31     Wait Until Keyword Succeeds    5x    20    NetconfKeywords.Check_Device_Has_No_Netconf_Connector    ${device_name}
32
33 Configure_Device_On_Netconf
34     [Documentation]    Make request to configure netconf netopeer with wrong password. Correct auth is root/root
35     ...    ODL should connect to device using public key auth as password auth will fail.
36     NetconfKeywords.Configure_Device_In_Netconf    ${device_name}    device_type=${device_type}    http_timeout=2    device_user=${netopeer_user}    device_password=${netopeer_pwd}    device_port=${netopeer_port}
37     ...    device_key=${netopeer_key}
38
39 Wait_For_Device_To_Become_Connected
40     [Documentation]    Wait until the device becomes available through Netconf.
41     NetconfKeywords.Wait_Device_Connected    ${device_name}
42
43 Deconfigure_Device_From_Netconf
44     [Documentation]    Make request to deconfigure the testtool device on Netconf connector.
45     [Setup]    SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
46     NetconfKeywords.Remove_Device_From_Netconf    ${device_name}
47
48 Check_Device_Going_To_Be_Gone_After_Deconfiguring
49     [Documentation]    Check that the device is really going to be gone. Fail
50     ...    if found after one minute. This is an expected behavior as the
51     ...    delete request is sent to the config subsystem which then triggers
52     ...    asynchronous destruction of the netconf connector referring to the
53     ...    device and the device's data. This test makes sure this
54     ...    asynchronous operation does not take unreasonable amount of time
55     ...    by making sure that both the netconf connector and the device's
56     ...    data is gone before reporting success.
57     [Tags]    critical
58     NetconfKeywords.Wait_Device_Fully_Removed    ${device_name}
59
60 *** Keywords ***
61 Run Netopeer Docker Container
62     [Documentation]    Start a new docker container for netopeer server.
63     ${netopeer_conn_id} =    SSHKeywords.Open_Connection_To_Tools_System
64     SSHLibrary.Put File    ${CURDIR}/../../../variables/netconf/KeyAuth/datastore.xml    .
65     SSHLibrary.Put File    ${CURDIR}/../../../variables/netconf/KeyAuth/sb-rsa-key.pub    .
66     Builtin.Set Suite Variable    ${netopeer_conn_id}
67     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker run -dt -p ${netopeer_port}:830 -v ${USER_HOME}/datastore.xml:/usr/local/etc/netopeer/cfgnetopeer/datastore.xml -v ${USER_HOME}/sb-rsa-key.pub:/root/RSA.pub sdnhub/netopeer netopeer-server -v 3    return_stdout=True    return_stderr=True
68     ...    return_rc=True
69     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker ps    return_stdout=True    return_stderr=True
70     ...    return_rc=True
71     Log    ${stdout}
72
73 Configure ODL with Key config
74     [Documentation]    Configure the ODL with the Southbound key configuration file containing details about private key path and passphrase
75     SSHKeywords.Open_Connection_To_ODL_System
76     Log    Bundle folder ${WORKSPACE}/${BUNDLEFOLDER}/etc
77     SSHLibrary.Put File    ${CURDIR}/../../../variables/netconf/KeyAuth/org.opendaylight.netconf.topology.sb.keypair.cfg    ${WORKSPACE}/${BUNDLEFOLDER}/etc/
78     SSHLibrary.Put File    ${CURDIR}/../../../variables/netconf/KeyAuth/sb-rsa-key    ${WORKSPACE}/${BUNDLEFOLDER}/etc/    400
79     ${stdout}=    SSHLibrary.Execute Command    ls -l ${WORKSPACE}/${BUNDLEFOLDER}/etc/    return_stdout=True
80     Log    ${stdout}
81     Restart Controller
82
83 Add Netconf Key
84     [Documentation]    Add Netconf Southbound key containing details about device private key and passphrase
85     ${mapping}=    BuiltIn.Create_dictionary    DEVICE_KEY=${netopeer_key}
86     TemplatedRequests.Post_As_Xml_Templated    folder=${directory_with_keyauth_template}    mapping=${mapping}
87
88 Restart Controller
89     [Documentation]    Controller restart is needed in order the new shiro.ini config takes effect
90     ClusterManagement.ClusterManagement_Setup
91     Wait Until Keyword Succeeds    5x    20    Stop_Single_Member    1
92     Start_Single_Member    1    wait_for_sync=False    timeout=120
93     Wait Until Keyword Succeeds    30x    5s    Get Controller Modules
94
95 Get Controller Modules
96     [Documentation]    Get the restconf modules, check 200 status and ietf-restconf presence
97     ${resp} =    RequestsLibrary.Get_Request    default    ${MODULES_API}
98     BuiltIn.Log    ${resp.content}
99     BuiltIn.Should_Be_Equal    ${resp.status_code}    ${200}
100     BuiltIn.Should_Contain    ${resp.content}    ietf-restconf
101
102 Suite Teardown
103     [Documentation]    Tearing down the setup.
104     RequestsLibrary.Delete_All_Sessions
105     SSHLibrary.Close_All_Connections
106
107 Suite Setup
108     [Documentation]    Get the suite ready for callhome test cases.
109     SetupUtils.Setup_Utils_For_Setup_And_Teardown
110     NetconfKeywords.Setup_Netconf_Keywords
111     ${device_type_passw}=    BuiltIn.Set_Variable_If    """${USE_NETCONF_CONNECTOR}""" == """True"""    default    ${device_type_passw}
112     ${device_type}    CompareStream.Set_Variable_If_At_Most_Nitrogen    ${device_type_passw}    ${device_type_key}
113     BuiltIn.Set_Suite_Variable    ${device_type}
114     Run Netopeer Docker Container
115     CompareStream.Run_Keyword_If_At_Most_Nitrogen    Configure ODL with Key config
116     CompareStream.Run_Keyword_If_At_Least_Oxygen    Add Netconf Key