Update call-home integration tests 40/90940/16
authorOleksii Mozghovyi <oleksii.mozghovyi@pantheon.tech>
Tue, 7 Jul 2020 01:22:07 +0000 (04:22 +0300)
committerLuis Gomez <ecelgp@gmail.com>
Sun, 27 Dec 2020 21:43:53 +0000 (21:43 +0000)
- Replace outdated netopeer with a netopeer2-server
- Configuration of the ODL controller is done from tests(previous
  implementation used shell scripts inside the container)
- Templates for ODL requests are now stored separately
- Host key generation outside of the container
- Netopeer2 container plays only the role of netconf device

JIRA: NETCONF-5
Change-Id: I536b3c8a66cc3e92f376cb2451b888316c8a82bd
Signed-off-by: Oleksii Mozghovyi <oleksii.mozghovyi@pantheon.tech>
Signed-off-by: Vladyslav Marchenko <vladyslav.marchenko@pantheon.tech>
12 files changed:
csit/libraries/NetconfCallHome.robot
csit/suites/netconf/callhome/callhome.robot
csit/variables/netconf/callhome/configuration-files/ssh/ietf-keystore.xml [new file with mode: 0644]
csit/variables/netconf/callhome/configuration-files/ssh/ietf-netconf-server.xml [new file with mode: 0644]
csit/variables/netconf/callhome/credentials_set.sh [deleted file]
csit/variables/netconf/callhome/datastore-server.xml [deleted file]
csit/variables/netconf/callhome/docker-compose.yaml
csit/variables/netconf/callhome/init_configuration.sh [new file with mode: 0644]
csit/variables/netconf/callhome/json/apiv1/create_device.json [new file with mode: 0644]
csit/variables/netconf/callhome/json/apiv1/create_device_hostkey_only.json [new file with mode: 0644]
csit/variables/netconf/callhome/json/apiv1/create_global_credentials.json [new file with mode: 0644]
csit/variables/netconf/callhome/whitelist_add.sh [deleted file]

index 8b5fd4bebeb6ea47b3190d29d48c5effd441d223..eabe799fd637eef5137eb87a255292a4ddcf8b46 100644 (file)
@@ -8,41 +8,61 @@ Resource          ../variables/Variables.robot
 ${mount_point_url}    /restconf/operational/network-topology:network-topology/topology/topology-netconf/
 ${device_status}    /restconf/operational/odl-netconf-callhome-server:netconf-callhome-server
 ${whitelist}      /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices
+${global_config_url}    /restconf/config/odl-netconf-callhome-server:netconf-callhome-server/global/credentials
 ${substring1}     "netconf-node-topology:connection-status":"connected"
-${substring2}     "node-id":"netopeer"
+${substring2}     "node-id":"netopeer2"
 ${substring3}     "netconf-node-topology:available-capabilities"
 
 *** Keywords ***
 Check Device status
-    [Arguments]    ${status}    ${id}=netopeer
+    [Arguments]    ${status}    ${id}=netopeer2
     [Documentation]    Checks the operational device status.
     @{expectedValues}    Create List    "unique-id":"${id}"    "callhome-status:device-status":"${status}"
     Run Keyword If    '${status}'=='FAILED_NOT_ALLOWED' or '${status}'=='FAILED_AUTH_FAILURE'    Remove Values From List    ${expectedValues}    "unique-id":"${id}"
     Utils.Check For Elements At URI    ${device_status}    ${expectedValues}
 
-Get Netopeer Ready
-    [Documentation]    Pulls the netopeer image from the docker repository. Points ODL(CallHome Server) IP in the files used by netopeer(CallHome Client).
-    ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker pull sdnhub/netopeer    return_stdout=True    return_stderr=True
+Apply SSH-based Call-Home configuration
+    [Documentation]    Upload netopeer2 configuration files needed for SSH transport
+    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/configuration-files/ssh/ietf-netconf-server.xml
+    ...    configuration-files/ietf-netconf-server.xml
+    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/configuration-files/ssh/ietf-keystore.xml
+    ...    configuration-files/ietf-keystore.xml
+
+Register global credentials for SSH call-home devices (APIv1)
+    [Arguments]    ${username}    ${password}
+    [Documentation]    Set global credentials for SSH call-home devices
+    ${template}    OperatingSystem.Get File    ${CREATE_GLOBAL_CREDENTIALS_REQ}
+    ${body}    Replace String    ${template}    {username}    ${username}
+    ${body}    Replace String    ${body}    {password}    ${password}
+    ${resp}    RequestsLibrary.Put Request    session    ${global_config_url}    data=${body}    headers=${HEADERS}
+    Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
+
+Register SSH call-home device in ODL controller (APIv1)
+    [Arguments]    ${device_name}    ${hostkey}    ${username}=${EMPTY}    ${password}=${EMPTY}
+    [Documentation]    Registration call-home device with SSH transport
+    Run Keyword If    '${username}' == '${EMPTY}' or '${password}' == '${EMPTY}'    Get create device request without credentials template (APIv1)
+    ...    ELSE    Get create device request template (APIv1)
+    ${body}    Replace String    ${template}    {device_name}    ${device_name}
+    ${body}    Replace String    ${body}    {username}    ${username}
+    ${body}    Replace String    ${body}    {password}    ${password}
+    ${body}    Replace String    ${body}    {hostkey}    ${hostkey}
+    ${resp}    RequestsLibrary.Post Request    session    ${whitelist}    data=${body}    headers=${HEADERS}
+    Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
+
+Get create device request template (APIv1)
+    ${template}    OperatingSystem.Get File    ${CREATE_SSH_DEVICE_REQ_V1}
+    Set Test Variable    ${template}
+
+Get create device request without credentials template (APIv1)
+    ${template}    OperatingSystem.Get File    ${CREATE_SSH_DEVICE_REQ_V1_HOST_KEY_ONLY}
+    Set Test Variable    ${template}
+
+Pull Netopeer2 Docker Image
+    [Documentation]    Pulls the netopeer image from the docker repository.
+    ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker pull sysrepo/sysrepo-netopeer2:latest    return_stdout=True    return_stderr=True
     ...    return_rc=True
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker images    return_stdout=True    return_stderr=True
     ...    return_rc=True
-    Reset Docker Compose Configuration
-
-Reset Docker Compose Configuration
-    [Documentation]    Resets the docker compose configurations.
-    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/docker-compose.yaml    .
-    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/datastore-server.xml    .
-    SSHLibrary.Execute_Command    sed -i -e 's/ODL_SYSTEM_IP/${ODL_SYSTEM_IP}/g' docker-compose.yaml
-    SSHLibrary.Execute_Command    sed -i -e 's/ODL_SYSTEM_IP/${ODL_SYSTEM_IP}/g' datastore-server.xml
-
-Get Environment Ready
-    [Documentation]    Get the scripts ready to set credentials and control whitelist maintained by the CallHome server.
-    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/whitelist_add.sh    .
-    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/credentials_set.sh    .
-    SSHLibrary.Execute_Command    chmod +x whitelist_add.sh
-    SSHLibrary.Execute_Command    chmod +x credentials_set.sh
-    SSHLibrary.Execute_Command    sed -i -e 's/ODL_SYSTEM_IP/${ODL_SYSTEM_IP}/g' credentials_set.sh
-    SSHLibrary.Execute_Command    sed -i -e 's/ODL_SYSTEM_IP/${ODL_SYSTEM_IP}/g' whitelist_add.sh
 
 Install Docker Compose on tools system
     [Documentation]    Install docker-compose on tools system.
@@ -58,11 +78,13 @@ Uninstall Docker Compose on tools system
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    pip uninstall docker-compose    return_stdout=True    return_stderr=True
     ...    return_rc=True
 
-Suite Teardown
-    [Documentation]    Tearing down the setup.
-    Uninstall Docker Compose on tools system
-    RequestsLibrary.Delete_All_Sessions
-    SSHLibrary.Close_All_Connections
+Test Setup
+    [Documentation]    Opens session towards ODL controller, set configuration folder, generates a new host key for the container
+    RequestsLibrary.Create_Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
+    SSHLibrary.Execute_Command    rm -rf ./configuration-files && mkdir configuration-files
+    SSHLibrary.Execute_Command    ssh-keygen -q -t rsa -b 2048 -N '' -f ./configuration-files/ssh_host_rsa_key
+    ${public_key}    SSHLibrary.Execute_Command    cat configuration-files/ssh_host_rsa_key.pub | awk '{print $2}'
+    Set Test Variable    ${NETOPEER_PUB_KEY}    ${public_key}
 
 Test Teardown
     [Documentation]    Tears down the docker running netopeer and deletes entry from the whitelist.
@@ -73,13 +95,24 @@ Test Teardown
     ...    return_rc=True
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker ps -a    return_stdout=True    return_stderr=True
     ...    return_rc=True
+    SSHLibrary.Execute_Command    rm -rf ./configuration-files
     ${resp} =    RequestsLibrary.Delete_Request    session    ${whitelist}
 
 Suite Setup
     [Documentation]    Get the suite ready for callhome test cases.
-    RequestsLibrary.Create_Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
     Install Docker Compose on tools system
-    Get Environment Ready
-    Get Netopeer Ready
+    Pull Netopeer2 Docker Image
+    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/docker-compose.yaml    .
+    SSHLibrary.Put File    ${CURDIR}/../variables/netconf/callhome/init_configuration.sh    .
+    SSHLibrary.Execute_Command    sed -i -e 's/ODL_SYSTEM_IP/${ODL_SYSTEM_IP}/g' docker-compose.yaml
     ${netconf_mount_expected_values}    Create list    ${substring1}    ${substring2}    ${substring3}
     Set Suite Variable    ${netconf_mount_expected_values}
+    Set Suite Variable    ${CREATE_SSH_DEVICE_REQ_V1}    ${CURDIR}/../variables/netconf/callhome/json/apiv1/create_device.json
+    Set Suite Variable    ${CREATE_SSH_DEVICE_REQ_V1_HOST_KEY_ONLY}    ${CURDIR}/../variables/netconf/callhome/json/apiv1/create_device_hostkey_only.json
+    Set Suite Variable    ${CREATE_GLOBAL_CREDENTIALS_REQ}    ${CURDIR}/../variables/netconf/callhome/json/apiv1/create_global_credentials.json
+
+Suite Teardown
+    [Documentation]    Tearing down the setup.
+    Uninstall Docker Compose on tools system
+    RequestsLibrary.Delete_All_Sessions
+    SSHLibrary.Close_All_Connections
index 2d85791a28a1bb1bbcbc3ac673102d4958a3a153..501ee7c7a07e1f367155c0d72f0c43efbfda3b0e 100644 (file)
@@ -1,17 +1,20 @@
 *** Settings ***
-Documentation     Test suite to verify callhome functionality where the Call Home Server(CONTROLLER) is provisioned with device
-...               certificates when docker-compose is invoked. Every test case does a SED operation to search and replace words
-...               to cover the happy path and negative scenarios.
+Documentation     Test suite to verify callhome functionality over SSH transport protocol. Registration in OpenDaylight
+...               Controller happens via restconf interface. Netopeer2-server docker container plays a role of the
+...               netconf device with call-home feature. Docker-compose file is used to configure netopeer2 docker
+...               container(netconf configuration templates, host-key).
 Suite Setup       Suite Setup
 Suite Teardown    Suite Teardown
-Test Setup        Reset Docker Compose Configuration
+Test Setup        Test Setup
 Test Teardown     Test Teardown
 Resource          ../../../libraries/NetconfCallHome.robot
 
 *** Test Cases ***
 CallHome with Incorrect global Credentials
     [Documentation]    Incorrect global credentials should result to mount failure. FAILED_AUTH_FAILURE should be the device status.
-    SSHLibrary.Execute_Command    sed -i -e 's/global root/global incorrect/g' docker-compose.yaml
+    Apply SSH-based Call-Home configuration
+    Register global credentials for SSH call-home devices (APIv1)    incorrect    root
+    Register SSH call-home device in ODL controller (APIv1)    netopeer2    ${NETOPEER_PUB_KEY}
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker-compose up -d    return_stdout=True    return_stderr=True
     ...    return_rc=True
     Wait Until Keyword Succeeds    90s    2s    NetconfCallHome.Check Device Status    FAILED_AUTH_FAILURE
@@ -20,7 +23,8 @@ CallHome with Incorrect global Credentials
 
 CallHome with Incorrect per-device Credentials
     [Documentation]    Incorrect per-device credentials should result to mount failure. FAILED_AUTH_FAILURE should be the device status.
-    SSHLibrary.Execute_Command    sed -i -e 's/global root/per-device netopeer incorrect/g' docker-compose.yaml
+    Apply SSH-based Call-Home configuration
+    Register SSH call-home device in ODL controller (APIv1)    netopeer2    ${NETOPEER_PUB_KEY}    root    incorrect
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker-compose up -d    return_stdout=True    return_stderr=True
     ...    return_rc=True
     Wait Until Keyword Succeeds    90s    2s    NetconfCallHome.Check Device Status    FAILED_AUTH_FAILURE
@@ -29,7 +33,9 @@ CallHome with Incorrect per-device Credentials
 
 CallHome with Incorrect Node-id
     [Documentation]    CallHome from device that does not have an entry in per-device credential with result to mount point failure.
-    SSHLibrary.Execute_Command    sed -i -e 's/global/per-device incorrect_hostname/g' docker-compose.yaml    return_rc=True
+    Apply SSH-based Call-Home configuration
+    Register SSH call-home device in ODL controller (APIv1)    incorrect_hostname    ${EMPTY}    root    root
+    Register SSH call-home device in ODL controller (APIv1)    netopeer2    ${NETOPEER_PUB_KEY}
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker-compose up -d    return_stdout=True    return_stderr=True
     ...    return_rc=True
     Wait Until Keyword Succeeds    90s    2s    NetconfCallHome.Check Device Status    DISCONNECTED
@@ -39,7 +45,8 @@ CallHome with Incorrect Node-id
 CallHome with Rogue Devices
     [Documentation]    A Rogue Device will fail to callhome and wont be able to mount because the keys are not added in whitelist.
     ...    FAILED_NOT_ALLOWED should be the device status.
-    SSHLibrary.Execute_Command    sed -i -e 's,\/root\/whitelist_add.sh \$\$\{HOSTNAME\}\;,,g' docker-compose.yaml
+    Apply SSH-based Call-Home configuration
+    Register SSH call-home device in ODL controller (APIv1)    netopeer2    incorrect-key-value    root    root
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker-compose up -d    return_stdout=True    return_stderr=True
     ...    return_rc=True
     # Next line is commented due to https://jira.opendaylight.org/browse/NETCONF-574
@@ -50,6 +57,9 @@ CallHome with Rogue Devices
 Successful CallHome with correct global credentials
     [Documentation]    Device being in whitelist of the Call Home server along with correct global credentials will result to successful mount.
     ...    CONNECTED should be the device status.
+    Apply SSH-based Call-Home configuration
+    Register global credentials for SSH call-home devices (APIv1)    root    root
+    Register SSH call-home device in ODL controller (APIv1)    netopeer2    ${NETOPEER_PUB_KEY}
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker-compose up -d    return_stdout=True    return_stderr=True
     ...    return_rc=True
     Wait Until Keyword Succeeds    90s    2s    NetconfCallHome.Check Device Status    CONNECTED
@@ -58,7 +68,8 @@ Successful CallHome with correct global credentials
 Successful CallHome with correct per-device credentials
     [Documentation]    Device being in whitelist of the Call Home server along with correct per-device credentials will result to successful mount.
     ...    CONNECTED should be the device status.
-    SSHLibrary.Execute_Command    sed -i -e 's/global/per-device netopeer/g' docker-compose.yaml
+    Apply SSH-based Call-Home configuration
+    Register SSH call-home device in ODL controller (APIv1)    netopeer2    ${NETOPEER_PUB_KEY}    root    root
     ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    docker-compose up -d    return_stdout=True    return_stderr=True
     ...    return_rc=True
     Wait Until Keyword Succeeds    90s    2s    NetconfCallHome.Check Device Status    CONNECTED
diff --git a/csit/variables/netconf/callhome/configuration-files/ssh/ietf-keystore.xml b/csit/variables/netconf/callhome/configuration-files/ssh/ietf-keystore.xml
new file mode 100644 (file)
index 0000000..c17d384
--- /dev/null
@@ -0,0 +1,10 @@
+<keystore xmlns="urn:ietf:params:xml:ns:yang:ietf-keystore">
+    <asymmetric-keys>
+        <asymmetric-key>
+            <name>genkey</name>
+            <algorithm>rsa2048</algorithm>
+            <public-key>$NP_PUBKEY</public-key>
+            <private-key>$NP_PRIVKEY</private-key>
+        </asymmetric-key>
+    </asymmetric-keys>
+</keystore>
diff --git a/csit/variables/netconf/callhome/configuration-files/ssh/ietf-netconf-server.xml b/csit/variables/netconf/callhome/configuration-files/ssh/ietf-netconf-server.xml
new file mode 100644 (file)
index 0000000..d726f3e
--- /dev/null
@@ -0,0 +1,77 @@
+<netconf-server xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server">
+    <listen>
+        <endpoint>
+            <name>default-ssh</name>
+            <ssh>
+                <tcp-server-parameters>
+                    <local-address>0.0.0.0</local-address>
+                    <keepalives>
+                        <idle-time>1</idle-time>
+                        <max-probes>10</max-probes>
+                        <probe-interval>5</probe-interval>
+                    </keepalives>
+                </tcp-server-parameters>
+                <ssh-server-parameters>
+                    <server-identity>
+                        <host-key>
+                            <name>default-key</name>
+                            <public-key>
+                                <keystore-reference>genkey</keystore-reference>
+                            </public-key>
+                        </host-key>
+                    </server-identity>
+                    <client-authentication>
+                        <supported-authentication-methods>
+                            <publickey/>
+                            <passsword/>
+                            <other>interactive</other>
+                        </supported-authentication-methods>
+                        <users/>
+                    </client-authentication>
+                </ssh-server-parameters>
+            </ssh>
+        </endpoint>
+    </listen>
+    <call-home>
+        <netconf-client>
+            <name>default-client</name>
+            <endpoints>
+                <endpoint>
+                    <name>default-ssh</name>
+                    <ssh>
+                        <tcp-client-parameters>
+                            <remote-address>$CALL_HOME_SERVER_IP</remote-address>
+                            <remote-port>$CALL_HOME_SSH_PORT</remote-port>
+                            <keepalives>
+                                <idle-time>1</idle-time>
+                                <max-probes>10</max-probes>
+                                <probe-interval>5</probe-interval>
+                            </keepalives>
+                        </tcp-client-parameters>
+                        <ssh-server-parameters>
+                            <server-identity>
+                                <host-key>
+                                    <name>default-key</name>
+                                    <public-key>
+                                        <keystore-reference>genkey</keystore-reference>
+                                    </public-key>
+                                </host-key>
+                            </server-identity>
+                            <client-authentication>
+                                <supported-authentication-methods>
+                                    <publickey/>
+                                    <passsword/>
+                                    <other>interactive</other>
+                                </supported-authentication-methods>
+                                <users/>
+                            </client-authentication>
+                        </ssh-server-parameters>
+                    </ssh>
+                </endpoint>
+            </endpoints>
+            <connection-type>
+                <persistent/>
+            </connection-type>
+        </netconf-client>
+    </call-home>
+</netconf-server>
diff --git a/csit/variables/netconf/callhome/credentials_set.sh b/csit/variables/netconf/callhome/credentials_set.sh
deleted file mode 100755 (executable)
index fd80f20..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/bin/bash
-
-# This script is called within the docker-compose to provision the controller with either
-# the global or per-device credentials.
-
-stderr() { echo "$@" 1>&2; }
-
-[ $# -eq 0 ] && { stderr "Usage: $0 ( -global | -per-device id ) username password(s)"; exit 1; }
-
-: ${1?"Usage: $0 -global | -per-device"}
-
-option=${1};
-
-if [[ "${option}" == "-per-device" ]]; then
-  : ${2?"Usage: $0 Device Id"}
-  : ${3?"Usage: $0 Device Username"}
-  : ${4?"Usage: $0 Device Password"}
-  devid=${2}
-  user=${3}
-  shift; shift; shift
-  pwds="$@"
-elif [[ "${option}" == "-global" ]]; then
-  : ${2?"Usage: $0 Global Username"}
-  : ${3?"Usage: $0 Global Password"}
-  devid=""
-  user=${2}
-  shift; shift
-  pwds="$@"
-else
-  stderr "$0: must supply -global or -per-device command line argument for global password changes, not '${option}''"
-  exit 1
-fi
-
-pwdsjson=""
-
-for pwd in $pwds; do
-  if [[ ! -z "$pwdsjson" ]]; then
-    pwdsjson+=","
-  fi
-  pwdsjson+="'$pwd'"
-done
-
-set -e
-controller=ODL_SYSTEM_IP
-port=8181
-basicauth="YWRtaW46YWRtaW4="
-
-baseurl="http://${controller}:${port}/restconf/config/odl-netconf-callhome-server:netconf-callhome-server"
-
-if [[ "${option}" == "-global" ]]; then
-  url="${baseurl}/global/credentials"
-else
-  url="${baseurl}/allowed-devices/device/${devid}/credentials"
-fi
-
-set +e
-read -r -d '' payload << EOM
-{
-    "credentials": {
-       "username": "${user}",
-         "passwords": [${pwdsjson}]
-    }
-}
-EOM
-set -e
-
-payload=$(echo "${payload}" | tr '\n' ' ' | tr -s " ")
-
-echo "PUT of user (${user}) and pwd (${pwd})"
-res=$(curl -s -X PUT \
-      -H "Authorization: Basic ${basicauth}" \
-      -H "Content-Type: application/json" \
-      -H "Cache-Control: no-cache" \
-      --data "${payload}" \
-      ${url})
-
-if [[ $res == *"error-message"* ]]; then
-  stderr "$0: ${res}"
-  exit 1
-fi
-
-echo "Getting user/pwd ..."
-
-res=$(curl -s -X GET \
-      -H "Authorization: Basic ${basicauth}" \
-      -H "Cache-Control: no-cache" \
-      ${url})
-echo ${res}
diff --git a/csit/variables/netconf/callhome/datastore-server.xml b/csit/variables/netconf/callhome/datastore-server.xml
deleted file mode 100644 (file)
index 8762a29..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<datastores xmlns="urn:cesnet:tmc:datastores:file">
-  <running lock="">
-    <netconf xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server">
-      <ssh>
-        <call-home>
-          <applications>
-            <application>
-              <name>test</name>
-              <servers>
-                <server>
-                  <address>ODL_SYSTEM_IP</address>
-                  <port>6666</port>
-                </server>
-              </servers>
-              <host-keys>
-                <host-key>
-                  <name>localhost</name>
-                </host-key>
-              </host-keys>
-            </application>
-          </applications>
-        </call-home>
-      </ssh>
-    </netconf>
-  </running>
-  <startup lock="">
-    <netconf xmlns="urn:ietf:params:xml:ns:yang:ietf-netconf-server">
-      <ssh>
-        <call-home>
-          <applications>
-            <application>
-              <name>test</name>
-              <servers>
-                <server>
-                  <address>ODL_SYSTEM_IP</address>
-                  <port>6666</port>
-                </server>
-              </servers>
-              <host-keys>
-                <host-key>
-                  <name>localhost</name>
-                </host-key>
-              </host-keys>
-            </application>
-          </applications>
-        </call-home>
-      </ssh>
-    </netconf>
-  </startup>
-  <candidate modified="false" lock=""/>
-</datastores>
index 6eb1e78c07548eb9ead7a59f867019f8f6362681..00e6c97e9b8a348bd43a3e4fabd6321d1e680cec 100644 (file)
@@ -1,17 +1,13 @@
-# Controller needs to be provisoned with the unique-id of the device(netopeer) and public key.
-# The way this is done with docker compose is:
-# 1. A new docker instance is spawned and public key is generated.
-# 2. We create new pair of keys to ensure it is different than the snapshot of the image.
-# 3. Execute script to send REST to provision netopeer unique-id + public key + credentials in controller.
-# 4. Start netopeer.
-
-netopeer:
-  image: sdnhub/netopeer
-  hostname: netopeer
-  command: sh -c "apt-get update;apt-get install curl --force-yes -y;echo -e 'y/n' | ssh-keygen -q -N '' -f /etc/ssh/ssh_host_rsa_key;/root/whitelist_add.sh $${HOSTNAME};/root/credentials_set.sh -global root root;/root/netopeer/server/netopeer-server -v 3"
+netopeer2-server:
+  image: sysrepo/sysrepo-netopeer2:latest
+  hostname: netopeer2
+  command: sh -c "
+      /root/init_configuration.sh &&
+      exec netopeer2-server -d -v3"
   environment:
-     - controller_ip=ODL_SYSTEM_IP
+     - CALL_HOME_SERVER_IP=ODL_SYSTEM_IP
+     - CALL_HOME_SSH_PORT=6666
+     - CALL_HOME_TLS_PORT=4335
   volumes:
-    - ./datastore-server.xml:/usr/local/etc/netopeer/cfgnetopeer/datastore-server.xml
-    - ./whitelist_add.sh:/root/whitelist_add.sh
-    - ./credentials_set.sh:/root/credentials_set.sh
+    - ./configuration-files:/root/configuration-files
+    - ./init_configuration.sh:/root/init_configuration.sh
diff --git a/csit/variables/netconf/callhome/init_configuration.sh b/csit/variables/netconf/callhome/init_configuration.sh
new file mode 100644 (file)
index 0000000..6ea5c21
--- /dev/null
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# This scripts is called within a docker-compose to initialize configuration for netopeer2-server
+#
+
+set -e
+
+# Configuration files path. Used to store certificates, keys, and configuration data that might be used by netopeer2.
+CONFIG_PATH='/root/configuration-files'
+
+# Configuration from the following modules will be imported to the sysrepo datastore.
+# 1. Each module's configuration file should be placed under the $CONFIG_PATH folder with .xml extension, e.g. ietf-truststore.xml.
+# 2. Script will replace all variable placeholders with corresponding environment variables, e.g. $CALL_HOME_SERVER_IP.
+# Please, note that following environment variables will be set according to the provided keys(under the $CONFIG_PATH folder):
+#  - $NP_PRIVKEY
+#  - $NP_PUBKEY
+# 3. Modules must be provided in the correct order.
+MODULES_LIST=("ietf-keystore" "ietf-netconf-server")
+
+import_module()
+{
+  local MODULE_NAME=$1
+
+  # do not import anything if the corresponding configuration file doesn't exist
+  if [ ! -f $CONFIG_PATH/$MODULE_NAME.xml ]; then
+    return 0
+  fi
+
+  # Replace placeholders in templates with ENV variables
+  envsubst < $CONFIG_PATH/$MODULE_NAME.xml > $MODULE_NAME.tmp
+  cat $MODULE_NAME.tmp > $CONFIG_PATH/$MODULE_NAME.xml
+  rm $MODULE_NAME.tmp
+
+  # Import configuration into both datastores
+  sysrepocfg --import=$CONFIG_PATH/$MODULE_NAME.xml -m $MODULE_NAME --datastore=startup
+  sysrepocfg --import=$CONFIG_PATH/$MODULE_NAME.xml -m $MODULE_NAME --datastore=running
+
+  echo "Configuration file $CONFIG_PATH/$MODULE_NAME.xml has been imported"
+}
+
+### Main script starts here ###
+
+# Remove existing host keys and import new one
+rm -f /etc/ssh/ssh_host_*
+cp $CONFIG_PATH/ssh_host_rsa_key /etc/ssh/ssh_host_rsa_key
+cp $CONFIG_PATH/ssh_host_rsa_key.pub /etc/ssh/ssh_host_rsa_key.pub
+
+# These variables will replace corresponding placeholders inside configuration templates
+SAVEIFS=$IFS
+IFS=
+export NP_PRIVKEY=`cat /etc/ssh/ssh_host_rsa_key | sed -u '1d; $d'`
+export NP_PUBKEY=`openssl rsa -in /etc/ssh/ssh_host_rsa_key -pubout | sed -u '1d; $d'`
+IFS=$SAVEIFS
+
+# Import all provided configuration files for netopeer
+for module_name in "${MODULES_LIST[@]}"; do
+    import_module "$module_name"
+done
+
+unset NP_PRIVKEY
+unset NP_PUBKEY
+
+echo "Netopeer2-server initial configuration completed"
+exit 0
diff --git a/csit/variables/netconf/callhome/json/apiv1/create_device.json b/csit/variables/netconf/callhome/json/apiv1/create_device.json
new file mode 100644 (file)
index 0000000..2dd7d3a
--- /dev/null
@@ -0,0 +1,10 @@
+{
+    "device": {
+        "unique-id": "{device_name}",
+        "credentials": {
+            "username": "{username}",
+            "passwords": [ "{password}" ]
+        },
+        "ssh-host-key": "{hostkey}"
+    }
+}
diff --git a/csit/variables/netconf/callhome/json/apiv1/create_device_hostkey_only.json b/csit/variables/netconf/callhome/json/apiv1/create_device_hostkey_only.json
new file mode 100644 (file)
index 0000000..01582b3
--- /dev/null
@@ -0,0 +1,6 @@
+{
+    "device": {
+        "unique-id": "{device_name}",
+        "ssh-host-key": "{hostkey}"
+    }
+}
diff --git a/csit/variables/netconf/callhome/json/apiv1/create_global_credentials.json b/csit/variables/netconf/callhome/json/apiv1/create_global_credentials.json
new file mode 100644 (file)
index 0000000..ec18cc9
--- /dev/null
@@ -0,0 +1,6 @@
+{
+  "credentials": {
+    "username": "{username}",
+    "passwords": [ "{password}" ]
+  }
+}
diff --git a/csit/variables/netconf/callhome/whitelist_add.sh b/csit/variables/netconf/callhome/whitelist_add.sh
deleted file mode 100755 (executable)
index ef569aa..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/bin/bash
-
-# This script is called within the docker-compose to get the public RSA key of the
-# device(callhome client) and provision the controller.
-
-set -e
-
-key3="$(cat /etc/ssh/ssh_host_rsa_key.pub)"
-parts=($key3)
-hostkey=${parts[1]}
-id=$1
-controller=ODL_SYSTEM_IP
-echo "Adding key for ${id} to ${controller}"
-echo "Found host key: ${hostkey}"
-
-port=8181
-basicauth="YWRtaW46YWRtaW4="
-
-set +e
-read -r -d '' payload << EOM
-{
-    "device": [
-        {
-            "ssh-host-key": "${hostkey}",
-            "unique-id": "${id}"
-        }
-     ]
-}
-EOM
-set -e
-
-payload=$(echo "${payload}" | tr '\n' ' ' | tr -s " ")
-
-url="http://${controller}:${port}/restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices"
-
-echo "POST to whitelist"
-res=$(curl -s -X POST -H "Authorization: Basic ${basicauth}" \
-      -H "Content-Type: application/json" \
-      -H "Cache-Control: no-cache" \
-      -H "Postman-Token: 656d7e0d-2f48-5135-3569-06b2a27a709d" \
-      --data "${payload}" \
-      ${url})
-echo $res
-if [[ $res == *"data-exists"* ]]; then
-  echo "Whitelist already has that entry."
-fi