aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorYang Xu <yang.xu3@huawei.com>2019-04-29 00:20:52 -0400
committerYang Xu <yang.xu3@huawei.com>2019-04-29 00:34:42 -0400
commitc52ed6e001b09f6e21f0e76cf173eda03fbf1f0e (patch)
tree3ac0714050c84986f5b4f7696ef7885d1059af6e /test
parent42dcb266339a26803074f3190d1d9576e9dd05b7 (diff)
Download vCPE service csar from SDC
Clean up import Change-Id: I1a1be9b0528858fc30106978153e0af132675f93 Issue-ID: INT-847 Signed-off-by: Yang Xu <yang.xu3@huawei.com>
Diffstat (limited to 'test')
-rw-r--r--test/vcpe/csar/.gitignore4
-rwxr-xr-xtest/vcpe/sdcutils.py54
-rwxr-xr-xtest/vcpe/vcpe.py6
-rwxr-xr-xtest/vcpe/vcpecommon.py12
4 files changed, 74 insertions, 2 deletions
diff --git a/test/vcpe/csar/.gitignore b/test/vcpe/csar/.gitignore
new file mode 100644
index 000000000..5e7d2734c
--- /dev/null
+++ b/test/vcpe/csar/.gitignore
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
diff --git a/test/vcpe/sdcutils.py b/test/vcpe/sdcutils.py
new file mode 100755
index 000000000..a93872149
--- /dev/null
+++ b/test/vcpe/sdcutils.py
@@ -0,0 +1,54 @@
+#! /usr/bin/python
+
+import sys
+import logging
+import requests
+import json
+from vcpecommon import *
+
+
+class SdcUtils:
+ def __init__(self, vcpecommon):
+ """
+ :param vcpecommon:
+ """
+ self.logger = logging.getLogger(__name__)
+ self.logger.setLevel(logging.DEBUG)
+ self.vcpecommon = vcpecommon
+
+ def get_service_list(self):
+ """
+ :return:
+ """
+
+ url = self.vcpecommon.sdc_service_list_url
+ self.logger.info(url)
+ r = requests.get(url, headers=self.vcpecommon.sdc_get_request_headers, auth=self.vcpecommon.sdc_get_request_userpass)
+ self.logger.debug(r)
+ data = r.json()
+
+ self.logger.debug('---------------------------------------------------------------')
+ self.logger.debug('------- Creation request submitted to SDC, got response --------')
+ self.logger.debug('response code = %s' % r.status_code )
+ self.logger.debug(json.dumps(data, indent=4, sort_keys=True))
+ self.logger.debug('---------------------------------------------------------------')
+
+ for service in data:
+ if service['name'].startswith('demoVCPE'):
+ self.logger.debug('service name = %s, url = %s' % (service['name'], service['toscaModelURL']))
+ self.download_file(self.vcpecommon.sdc_url_prefix + service['toscaModelURL'])
+
+ def get_filename_from_cd(self, cd):
+ """
+ cd: in the format of Content-Disposition: attachment; filename="service-Demovcpeinfra-csar.csar"
+ """
+ fname = re.findall('filename="(.+)"', cd)
+ self.logger.debug('fname = %s' % fname[0])
+ return fname[0]
+
+ def download_file(self, url):
+ self.logger.info(url)
+ response = requests.get(url, headers=self.vcpecommon.sdc_get_request_headers, auth=self.vcpecommon.sdc_get_request_userpass)
+ filename = 'csar/' + self.get_filename_from_cd(response.headers.get('Content-Disposition'))
+ open(filename, 'wb').write(response.content)
+
diff --git a/test/vcpe/vcpe.py b/test/vcpe/vcpe.py
index 8f888c6d5..f9c1778da 100755
--- a/test/vcpe/vcpe.py
+++ b/test/vcpe/vcpe.py
@@ -2,6 +2,7 @@
import sys
import logging
from vcpecommon import *
+import sdcutils
import soutils
from datetime import datetime
import preload
@@ -182,6 +183,10 @@ def init_so_sdnc():
vgw_vfmod_name_index= 0
vcpecommon.save_object(vgw_vfmod_name_index, vcpecommon.vgw_vfmod_name_index_file)
+def download_vcpe_service_templates():
+ vcpecommon = VcpeCommon()
+ sdc = sdcutils.SdcUtils(vcpecommon)
+ sdc.get_service_list()
def tmp_sniro():
logger = logging.getLogger(__name__)
@@ -217,6 +222,7 @@ if __name__ == '__main__':
elif sys.argv[1] == 'init':
if 'y' == raw_input('Ready to add customer service data to SDNC and SO DBs? This is needed only once.'
'y/n: ').lower():
+ download_vcpe_service_templates()
init_so_sdnc()
elif sys.argv[1] == 'infra':
if 'y' == raw_input('Ready to deploy infrastructure? y/n: ').lower():
diff --git a/test/vcpe/vcpecommon.py b/test/vcpe/vcpecommon.py
index 980092c82..77e362271 100755
--- a/test/vcpe/vcpecommon.py
+++ b/test/vcpe/vcpecommon.py
@@ -95,7 +95,7 @@ class VcpeCommon:
self.aai_query_port = '30233' if self.oom_mode else '8443'
self.sniro_port = '30288' if self.oom_mode else '8080'
- self.host_names = ['so', 'sdnc', 'robot', 'aai-inst1', self.dcae_ves_collector_name]
+ self.host_names = ['sdc', 'so', 'sdnc', 'robot', 'aai-inst1', self.dcae_ves_collector_name]
if extra_host_names:
self.host_names.extend(extra_host_names)
# get IP addresses
@@ -131,6 +131,14 @@ class VcpeCommon:
}
#############################################################################################
+ # SDC urls
+ self.sdc_get_request_userpass = 'vid','Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
+ self.sdc_get_request_headers = {'X-ECOMP-InstanceID': 'VID'}
+ self.sdc_port = '30205'
+ self.sdc_url_prefix = 'http://' + self.hosts['sdc'] + ':' + self.sdc_port
+ self.sdc_service_list_url = self.sdc_url_prefix + '/sdc/v1/catalog/services'
+
+ #############################################################################################
# SDNC urls
self.sdnc_userpass = 'admin', 'Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U'
self.sdnc_db_name = 'sdnctl'
@@ -425,7 +433,7 @@ class VcpeCommon:
def get_oom_onap_vm_ip(self, keywords):
vm_ip = {}
- onap_vm_list = set(['so', 'sdnc', 'aai-inst1', 'robot', self.dcae_ves_collector_name])
+ onap_vm_list = set(['sdc', 'so', 'sdnc', 'aai-inst1', 'robot', self.dcae_ves_collector_name])
for vm in keywords:
if vm in onap_vm_list:
vm_ip[vm] = self.oom_so_sdnc_aai_ip