Onap normatives are imported always
[sdc.git] / catalog-be / sdc-backend-init / chef-repo / cookbooks / sdc-catalog-be-setup / recipes / 3_import_Normatives.rb
1 cookbook_file "/tmp/normatives.tar.gz" do
2       source "normatives.tar.gz"
3    end
4
5 be_ip=node['Nodes'][:BE]
6
7 bash "excuting-import_Normatives" do
8    code <<-EOH
9      set -x
10      cd /tmp
11      tar xvfz /tmp/normatives.tar.gz
12      cd /tmp/normatives/scripts/import/tosca/
13      /bin/chmod +x *.py
14
15      # executing the normatives
16      # add --debug=true to the importNormativeAll.py arguments to enable debug
17
18      check_normative="/tmp/check_normative.out"
19      status_code=$(curl -s -o ${check_normative} -w "%{http_code}\\n" -X GET -H 'Content-Type: application/json;charset=UTF-8' -H 'USER_ID: jh0003' -H 'X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090' "http://#{be_ip}:8080/sdc2/rest/v1/screen")
20      if [ "$status_code" != 200 ] ; then
21         exit "$status_code"
22      fi
23
24      #curl -s -X GET -H "Content-Type: application/json;charset=UTF-8" -H "USER_ID: jh0003" -H "X-ECOMP-RequestID: cbe744a0-037b-458f-aab5-df6e543c4090" "http://#{be_ip}:8080/sdc2/rest/v1/screen" > ${check_normative}
25
26      resources_len=`cat ${check_normative}| jq '.["resources"]|length'`
27      mkdir -p /var/lib/jetty/logs
28      if [ $resources_len -eq 0 ] ; then
29         python importONAPNormativeAll.py -i #{be_ip} > /var/lib/jetty/logs/importNormativeAll.log
30             rc=$?
31             if [[ $rc != 0 ]]; then exit $rc; fi
32      else
33         python upgradeONAPNormative.py -i #{be_ip} > /var/lib/jetty/logs/upgradeNormative.log
34             rc=$?
35             if [[ $rc != 0 ]]; then exit $rc; fi
36      fi
37    EOH
38 end