summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog/packages/nf_package.py7
-rw-r--r--catalog/packages/ns_package.py5
-rw-r--r--catalog/packages/tests/test_nf.py27
-rw-r--r--catalog/packages/tests/test_ns.py32
-rw-r--r--catalog/pub/msapi/sdc.py30
-rw-r--r--catalog/pub/utils/restcall.py3
-rw-r--r--catalog/pub/utils/toscaparser/basemodel.py6
-rw-r--r--catalog/pub/utils/toscaparser/dataentityext.py1
-rw-r--r--catalog/samples/views.py6
-rw-r--r--tox.ini2
10 files changed, 62 insertions, 57 deletions
diff --git a/catalog/packages/nf_package.py b/catalog/packages/nf_package.py
index 20ad9b8f..4907e552 100644
--- a/catalog/packages/nf_package.py
+++ b/catalog/packages/nf_package.py
@@ -113,9 +113,8 @@ class NfDistributeThread(threading.Thread):
artifact = sdc.get_artifact(sdc.ASSETTYPE_RESOURCES, self.csar_id)
local_path = os.path.join(CATALOG_ROOT_PATH, self.csar_id)
csar_name = "%s.csar" % artifact.get("name", self.csar_id)
- local_file_name = sdc.download_artifacts(artifact["toscaModelURL"],
- local_path, csar_name)
-
+ local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], local_path, csar_name)
+
vnfd_json = toscaparser.parse_vnfd(local_file_name)
vnfd = json.JSONDecoder().decode(vnfd_json)
@@ -205,7 +204,7 @@ class NfPackage(object):
"vnfdId": nf_pkg.vnfdId
})
return [0, csars]
-
+
def get_csar(self, csar_id):
pkg_info = {}
nf_pkg = VnfPackageModel.objects.filter(vnfPackageId=csar_id)
diff --git a/catalog/packages/ns_package.py b/catalog/packages/ns_package.py
index d22f0a5f..cc261d41 100644
--- a/catalog/packages/ns_package.py
+++ b/catalog/packages/ns_package.py
@@ -116,9 +116,8 @@ class NsPackage(object):
artifact = sdc.get_artifact(sdc.ASSETTYPE_SERVICES, csar_id)
local_path = os.path.join(CATALOG_ROOT_PATH, csar_id)
csar_name = "%s.csar" % artifact.get("name", csar_id)
- local_file_name = sdc.download_artifacts(artifact["toscaModelURL"],
- local_path, csar_name)
-
+ local_file_name = sdc.download_artifacts(artifact["toscaModelURL"], local_path, csar_name)
+
nsd_json = toscaparser.parse_nsd(local_file_name)
nsd = json.JSONDecoder().decode(nsd_json)
diff --git a/catalog/packages/tests/test_nf.py b/catalog/packages/tests/test_nf.py
index 709ec5cb..30c7e02c 100644
--- a/catalog/packages/tests/test_nf.py
+++ b/catalog/packages/tests/test_nf.py
@@ -254,7 +254,7 @@ class TestNfPackage(TestCase):
"vimIds": ["1"]
}, format='json')
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
-
+
def test_nf_pkg_distribute_when_csar_already_exist(self):
VnfPackageModel(vnfPackageId="1", vnfdId="vcpe_vfw_zte_1_0").save()
NfDistributeThread(csar_id="1",
@@ -280,7 +280,7 @@ class TestNfPackage(TestCase):
lab_vim_id="",
job_id="2").run()
self.assert_job_result("2", 255, "NFD(zte-hss-1.0) already exists.")
-
+
@mock.patch.object(restcall, 'call_req')
@mock.patch.object(sdc, 'download_artifacts')
@mock.patch.object(toscaparser, 'parse_vnfd')
@@ -304,7 +304,7 @@ class TestNfPackage(TestCase):
def test_nf_pkg_delete_normal(self, mock_run):
resp = self.client.delete("/api/catalog/v1/vnfpackages/1")
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
-
+
def test_nf_pkg_normal_delete(self):
VnfPackageModel(vnfPackageId="2", vnfdId="vcpe_vfw_zte_1_0").save()
NfPkgDeleteThread(csar_id="2", job_id="2").run()
@@ -318,12 +318,13 @@ class TestNfPackage(TestCase):
self.assertEqual({"csars": [{"csarId":"3", "vnfdId": "4"}]}, resp.data)
def test_nf_pkg_get_one(self):
- VnfPackageModel(vnfPackageId="4", vnfdId="5", vnfVendor="6",
- vnfdVersion="7", vnfSoftwareVersion="8", vnfPackageUri="4.csar").save()
+ VnfPackageModel(vnfPackageId="4", vnfdId="5", vnfVendor="6",
+ vnfdVersion="7", vnfSoftwareVersion="8", vnfPackageUri="4.csar").save()
resp = self.client.get("/api/catalog/v1/vnfpackages/4")
self.assertEqual(resp.status_code, status.HTTP_200_OK)
- self.assertEqual({"csarId": "4",
+ expect_data = {
+ "csarId": "4",
"packageInfo": {
"vnfdId": "5",
"vnfdProvider": "6",
@@ -331,8 +332,10 @@ class TestNfPackage(TestCase):
"vnfVersion": "8",
"csarName": "4.csar",
"downloadUrl": "http://127.0.0.1:8806/static/catalog/4/4.csar"
- },
- "imageInfo": []}, resp.data)
+ },
+ "imageInfo": []
+ }
+ self.assertEqual(expect_data, resp.data)
###############################################################################################################
@@ -340,13 +343,13 @@ class TestNfPackage(TestCase):
def test_vnfd_parse_normal(self, mock_parse_vnfd):
VnfPackageModel(vnfPackageId="8", vnfdId="10").save()
mock_parse_vnfd.return_value = json.JSONEncoder().encode({"c": "d"})
- resp = self.client.post("/api/catalog/v1/parservnfd",
- {"csarId": "8", "inputs": []}, format='json')
+ req_data = {"csarId": "8", "inputs": []}
+ resp = self.client.post("/api/catalog/v1/parservnfd", req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual({"model": '{"c": "d"}'}, resp.data)
def test_vnfd_parse_when_csar_not_exist(self):
- resp = self.client.post("/api/catalog/v1/parservnfd",
- {"csarId": "1", "inputs": []}, format='json')
+ req_data = {"csarId": "1", "inputs": []}
+ resp = self.client.post("/api/catalog/v1/parservnfd", req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
self.assertEqual(resp.data, {"error": "VNF CSAR(1) does not exist."})
diff --git a/catalog/packages/tests/test_ns.py b/catalog/packages/tests/test_ns.py
index 21a1059f..d8894c1d 100644
--- a/catalog/packages/tests/test_ns.py
+++ b/catalog/packages/tests/test_ns.py
@@ -465,23 +465,33 @@ class TestNsPackage(TestCase):
resp = self.client.get("/api/catalog/v1/nspackages")
self.assertEqual(resp.status_code, status.HTTP_200_OK)
- self.assertEqual({"csars": [{"csarId":"13", "nsdId": "2",
- "nsdProvider": "3", "nsdVersion": "4"}]}, resp.data)
+ expect_data = {
+ "csars": [
+ {
+ "csarId": "13",
+ "nsdId": "2",
+ "nsdProvider": "3",
+ "nsdVersion": "4"
+ }
+ ]
+ }
+ self.assertEqual(expect_data, resp.data)
def test_ns_pkg_get_one(self):
- NSPackageModel(nsPackageId="14", nsdId="2", nsdDesginer="3",
- nsdVersion="4", nsPackageUri="14.csar").save()
-
+ NSPackageModel(nsPackageId="14", nsdId="2", nsdDesginer="3", nsdVersion="4", nsPackageUri="14.csar").save()
resp = self.client.get("/api/catalog/v1/nspackages/14")
self.assertEqual(resp.status_code, status.HTTP_200_OK)
- self.assertEqual({"csarId": "14",
+ expect_data = {
+ "csarId": "14",
"packageInfo": {
"nsdId": "2",
"nsdProvider": "3",
"nsdVersion": "4",
"csarName": "14.csar",
"downloadUrl": "http://127.0.0.1:8806/static/catalog/14/14.csar"
- }}, resp.data)
+ }
+ }
+ self.assertEqual(expect_data, resp.data)
###############################################################################################################
@@ -489,13 +499,13 @@ class TestNsPackage(TestCase):
def test_nsd_parse_normal(self, mock_parse_nsd):
NSPackageModel(nsPackageId="18", nsdId="12").save()
mock_parse_nsd.return_value = json.JSONEncoder().encode({"a": "b"})
- resp = self.client.post("/api/catalog/v1/parsernsd",
- {"csarId": "18", "inputs": []}, format='json')
+ req_data = {"csarId": "18", "inputs": []}
+ resp = self.client.post("/api/catalog/v1/parsernsd", req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_202_ACCEPTED)
self.assertEqual({"model": '{"a": "b"}'}, resp.data)
def test_nsd_parse_when_csar_not_exist(self):
- resp = self.client.post("/api/catalog/v1/parsernsd",
- {"csarId": "1", "inputs": []}, format='json')
+ req_data = {"csarId": "1", "inputs": []}
+ resp = self.client.post("/api/catalog/v1/parsernsd", req_data, format='json')
self.assertEqual(resp.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR)
self.assertEqual(resp.data, {"error": "NS CSAR(1) does not exist."})
diff --git a/catalog/pub/msapi/sdc.py b/catalog/pub/msapi/sdc.py
index 56fa2901..059adae7 100644
--- a/catalog/pub/msapi/sdc.py
+++ b/catalog/pub/msapi/sdc.py
@@ -30,14 +30,14 @@ def call_sdc(resource, method, content=''):
additional_headers = {
'X-ECOMP-InstanceID': 'VFC',
}
- return restcall.call_req(base_url=SDC_BASE_URL,
- user=SDC_USER,
- passwd=SDC_PASSWD,
- auth_type=restcall.rest_no_auth,
- resource=resource,
- method=method,
- content=content,
- additional_headers=additional_headers)
+ return restcall.call_req(base_url=SDC_BASE_URL,
+ user=SDC_USER,
+ passwd=SDC_PASSWD,
+ auth_type=restcall.rest_no_auth,
+ resource=resource,
+ method=method,
+ content=content,
+ additional_headers=additional_headers)
"""
@@ -92,13 +92,13 @@ def download_artifacts(download_url, local_path, file_name):
'X-ECOMP-InstanceID': 'VFC',
'accept': 'application/octet-stream'
}
- ret = restcall.call_req(base_url=SDC_BASE_URL,
- user=SDC_USER,
- passwd=SDC_PASSWD,
- auth_type=restcall.rest_no_auth,
- resource=download_url,
- method="GET",
- additional_headers=additional_headers)
+ ret = restcall.call_req(base_url=SDC_BASE_URL,
+ user=SDC_USER,
+ passwd=SDC_PASSWD,
+ auth_type=restcall.rest_no_auth,
+ resource=download_url,
+ method="GET",
+ additional_headers=additional_headers)
if ret[0] != 0:
logger.error("Status code is %s, detail is %s.", ret[2], ret[1])
raise CatalogException("Failed to download %s from sdc." % download_url)
diff --git a/catalog/pub/utils/restcall.py b/catalog/pub/utils/restcall.py
index 0618755b..6cdc14bc 100644
--- a/catalog/pub/utils/restcall.py
+++ b/catalog/pub/utils/restcall.py
@@ -91,8 +91,7 @@ def upload_by_msb(resource, method, file_data={}):
headers = {'Content-Type': 'application/octet-stream'}
full_url = "http://%s:%s/%s" % (MSB_SERVICE_IP, MSB_SERVICE_PORT, resource)
http = httplib2.Http()
- resp, resp_content = http.request(full_url,
- method=method.upper(), body=file_data, headers=headers)
+ resp, resp_content = http.request(full_url, method=method.upper(), body=file_data, headers=headers)
resp_status, resp_body = resp['status'], resp_content.decode('UTF-8')
if resp_status not in status_ok_list:
logger.error("Status code is %s, detail is %s.", resp_status, resp_body)
diff --git a/catalog/pub/utils/toscaparser/basemodel.py b/catalog/pub/utils/toscaparser/basemodel.py
index 83938a40..61be0d3c 100644
--- a/catalog/pub/utils/toscaparser/basemodel.py
+++ b/catalog/pub/utils/toscaparser/basemodel.py
@@ -197,8 +197,7 @@ class BaseInfoModel(object):
capabilities = json.dumps(nodeTemplate.entity_tpl.get('capabilities', None))
match = re.findall(r'\{"get_input":\s*"([\w|\-]+)"\}',capabilities)
for m in match:
- aa = [input_def for input_def in inputs
- if m == input_def.name][0]
+ aa = [input_def for input_def in inputs if m == input_def.name][0]
capabilities = re.sub(r'\{"get_input":\s*"([\w|\-]+)"\}', json.dumps(aa.default), capabilities,1)
if capabilities != 'null':
ret['capabilities'] = json.loads(capabilities)
@@ -207,8 +206,7 @@ class BaseInfoModel(object):
artifacts = json.dumps(nodeTemplate.entity_tpl.get('artifacts', None))
match = re.findall(r'\{"get_input":\s*"([\w|\-]+)"\}',artifacts)
for m in match:
- aa = [input_def for input_def in inputs
- if m == input_def.name][0]
+ aa = [input_def for input_def in inputs if m == input_def.name][0]
artifacts = re.sub(r'\{"get_input":\s*"([\w|\-]+)"\}', json.dumps(aa.default), artifacts,1)
if artifacts != 'null':
ret['artifacts'] = json.loads(artifacts)
diff --git a/catalog/pub/utils/toscaparser/dataentityext.py b/catalog/pub/utils/toscaparser/dataentityext.py
index 67e8757b..825e93bb 100644
--- a/catalog/pub/utils/toscaparser/dataentityext.py
+++ b/catalog/pub/utils/toscaparser/dataentityext.py
@@ -29,6 +29,5 @@ class DataEntityExt(object):
return float(value)
except Exception:
ExceptionCollector.appendException(ValueError(('"%s" is not an float.') % value))
-
return DataEntity.validate_datatype(type, value, entry_schema, custom_def)
return value
diff --git a/catalog/samples/views.py b/catalog/samples/views.py
index b113d06f..524280f3 100644
--- a/catalog/samples/views.py
+++ b/catalog/samples/views.py
@@ -42,8 +42,7 @@ class TablesList(APIView):
logger.debug("End delete model %s", name)
except:
logger.error(traceback.format_exc())
- return Response(data={"error": "failed"},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ return Response(data={"error": "failed"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data={}, status=status.HTTP_204_NO_CONTENT)
def get(self, request, modelName):
@@ -54,6 +53,5 @@ class TablesList(APIView):
count = len(model_obj.filter())
except:
logger.error(traceback.format_exc())
- return Response(data={"error": "failed"},
- status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ return Response(data={"error": "failed"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
return Response(data={"count": count}, status=status.HTTP_200_OK)
diff --git a/tox.ini b/tox.ini
index 0bae5c08..7119fde9 100644
--- a/tox.ini
+++ b/tox.ini
@@ -6,7 +6,7 @@ skipsdist = true
downloadcache = ~/cache/pip
[flake8]
-ignore = E501,E231,E128,W291,W293
+ignore = E501,E231,W291
exclude = ./venv-tox,./.tox
[testenv]