CallHome Tests First draft.
[integration/test.git] / csit / variables / netconf / callhome / whitelist_add.sh
1 #!/bin/bash
2
3 # This script is called within the docker-compose to get the public RSA key of the
4 # device(callhome client) and provision the controller.
5
6 set -e
7
8 key3="$(cat /etc/ssh/ssh_host_rsa_key.pub)"
9 parts=($key3)
10 hostkey=${parts[1]}
11 id=$1
12 controller=ODL_SYSTEM_IP
13 echo "Adding key for ${id} to ${controller}"
14 echo "Found host key: ${hostkey}"
15
16 port=8181
17 basicauth="YWRtaW46YWRtaW4="
18
19 set +e
20 read -r -d '' payload << EOM
21 {
22     "device": [
23         {
24             "ssh-host-key": "${hostkey}",
25             "unique-id": "${id}"
26         }
27      ]
28 }
29 EOM
30 set -e
31
32 payload=$(echo "${payload}" | tr '\n' ' ' | tr -s " ")
33
34 url="http://${controller}:${port}/restconf/config/odl-netconf-callhome-server:netconf-callhome-server/allowed-devices"
35
36 echo "POST to whitelist"
37 res=$(curl -s -X POST -H "Authorization: Basic ${basicauth}" \
38       -H "Content-Type: application/json" \
39       -H "Cache-Control: no-cache" \
40       -H "Postman-Token: 656d7e0d-2f48-5135-3569-06b2a27a709d" \
41       --data "${payload}" \
42       ${url})
43 echo $res
44 if [[ $res == *"data-exists"* ]]; then
45   echo "Whitelist already has that entry."
46 fi