3 Library RequestsLibrary
4 Resource SSHKeywords.robot
5 Resource ../variables/Variables.robot
8 ${mount_point_url} /restconf/operational/network-topology:network-topology/topology/topology-netconf/
9 ${device_status} /restconf/operational/odl-netconf-callhome-server:netconf-callhome-server
10 ${whitelist} /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices
11 ${global_config_url} /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/global/credentials
12 ${substring1} "netconf-node-topology:connection-status":"connected"
13 ${substring2} "node-id":"netopeer2"
14 ${substring3} "netconf-node-topology:available-capabilities"
18 [Arguments] ${status} ${id}=netopeer2
19 [Documentation] Checks the operational device status.
20 @{expectedValues} Create List "unique-id":"${id}" "callhome-status:device-status":"${status}"
21 Run Keyword If '${status}'=='FAILED_NOT_ALLOWED' or '${status}'=='FAILED_AUTH_FAILURE' Remove Values From List ${expectedValues} "unique-id":"${id}"
22 Utils.Check For Elements At URI ${device_status} ${expectedValues}
24 Apply SSH-based Call-Home configuration
25 [Documentation] Upload netopeer2 configuration files needed for SSH transport
26 SSHLibrary.Put File ${CURDIR}/../variables/netconf/callhome/configuration-files/ssh/ietf-netconf-server.xml
27 ... configuration-files/ietf-netconf-server.xml
28 SSHLibrary.Put File ${CURDIR}/../variables/netconf/callhome/configuration-files/ssh/ietf-keystore.xml
29 ... configuration-files/ietf-keystore.xml
31 Register global credentials for SSH call-home devices (APIv1)
32 [Arguments] ${username} ${password}
33 [Documentation] Set global credentials for SSH call-home devices
34 ${template} OperatingSystem.Get File ${CREATE_GLOBAL_CREDENTIALS_REQ}
35 ${body} Replace String ${template} {username} ${username}
36 ${body} Replace String ${body} {password} ${password}
37 ${resp} RequestsLibrary.Put Request session ${global_config_url} data=${body} headers=${HEADERS}
38 Should Contain ${ALLOWED_STATUS_CODES} ${resp.status_code}
40 Register SSH call-home device in ODL controller (APIv1)
41 [Arguments] ${device_name} ${hostkey} ${username}=${EMPTY} ${password}=${EMPTY}
42 [Documentation] Registration call-home device with SSH transport
43 Run Keyword If '${username}' == '${EMPTY}' or '${password}' == '${EMPTY}' Get create device request without credentials template (APIv1)
44 ... ELSE Get create device request template (APIv1)
45 ${body} Replace String ${template} {device_name} ${device_name}
46 ${body} Replace String ${body} {username} ${username}
47 ${body} Replace String ${body} {password} ${password}
48 ${body} Replace String ${body} {hostkey} ${hostkey}
49 ${resp} RequestsLibrary.Post Request session ${whitelist} data=${body} headers=${HEADERS}
50 Should Contain ${ALLOWED_STATUS_CODES} ${resp.status_code}
52 Get create device request template (APIv1)
53 ${template} OperatingSystem.Get File ${CREATE_SSH_DEVICE_REQ_V1}
54 Set Test Variable ${template}
56 Get create device request without credentials template (APIv1)
57 ${template} OperatingSystem.Get File ${CREATE_SSH_DEVICE_REQ_V1_HOST_KEY_ONLY}
58 Set Test Variable ${template}
60 Pull Netopeer2 Docker Image
61 [Documentation] Pulls the netopeer image from the docker repository.
62 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command docker pull sysrepo/sysrepo-netopeer2:latest return_stdout=True return_stderr=True
64 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command docker images return_stdout=True return_stderr=True
67 Install Docker Compose on tools system
68 [Documentation] Install docker-compose on tools system.
69 ${netopeer_conn_id} = SSHKeywords.Open_Connection_To_Tools_System
70 Builtin.Set Suite Variable ${netopeer_conn_id}
71 SSHLibrary.Write sudo curl -L "https://github.com/docker/compose/releases/download/1.11.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
72 ${output}= Wait Until Keyword Succeeds 30s 2s SSHLibrary.Read_Until_Prompt
73 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command sudo chmod +x /usr/local/bin/docker-compose return_stdout=True return_stderr=True
76 Uninstall Docker Compose on tools system
77 [Documentation] Uninstall docker-compose on tools system
78 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command pip uninstall docker-compose return_stdout=True return_stderr=True
82 [Documentation] Opens session towards ODL controller, set configuration folder, generates a new host key for the container
83 RequestsLibrary.Create_Session session http://${ODL_SYSTEM_IP}:${RESTCONFPORT} auth=${AUTH}
84 SSHLibrary.Execute_Command rm -rf ./configuration-files && mkdir configuration-files
85 SSHLibrary.Execute_Command ssh-keygen -q -t rsa -b 2048 -N '' -f ./configuration-files/ssh_host_rsa_key
86 ${public_key} SSHLibrary.Execute_Command cat configuration-files/ssh_host_rsa_key.pub | awk '{print $2}'
87 Set Test Variable ${NETOPEER_PUB_KEY} ${public_key}
90 [Documentation] Tears down the docker running netopeer and deletes entry from the whitelist.
91 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command docker-compose logs return_stdout=True return_stderr=True
94 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command docker-compose down return_stdout=True return_stderr=True
96 ${stdout} ${stderr} ${rc}= SSHLibrary.Execute Command docker ps -a return_stdout=True return_stderr=True
98 SSHLibrary.Execute_Command rm -rf ./configuration-files
99 ${resp} = RequestsLibrary.Delete_Request session ${whitelist}
102 [Documentation] Get the suite ready for callhome test cases.
103 Install Docker Compose on tools system
104 Pull Netopeer2 Docker Image
105 SSHLibrary.Put File ${CURDIR}/../variables/netconf/callhome/docker-compose.yaml .
106 SSHLibrary.Put File ${CURDIR}/../variables/netconf/callhome/init_configuration.sh .
107 SSHLibrary.Execute_Command sed -i -e 's/ODL_SYSTEM_IP/${ODL_SYSTEM_IP}/g' docker-compose.yaml
108 ${netconf_mount_expected_values} Create list ${substring1} ${substring2} ${substring3}
109 Set Suite Variable ${netconf_mount_expected_values}
110 Set Suite Variable ${CREATE_SSH_DEVICE_REQ_V1} ${CURDIR}/../variables/netconf/callhome/json/apiv1/create_device.json
111 Set Suite Variable ${CREATE_SSH_DEVICE_REQ_V1_HOST_KEY_ONLY} ${CURDIR}/../variables/netconf/callhome/json/apiv1/create_device_hostkey_only.json
112 Set Suite Variable ${CREATE_GLOBAL_CREDENTIALS_REQ} ${CURDIR}/../variables/netconf/callhome/json/apiv1/create_global_credentials.json
115 [Documentation] Tearing down the setup.
116 Uninstall Docker Compose on tools system
117 RequestsLibrary.Delete_All_Sessions
118 SSHLibrary.Close_All_Connections