summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java15
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java21
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java45
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java22
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java25
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java55
-rw-r--r--zte/vmanager/driver/interfaces/serializers.py14
-rw-r--r--zte/vmanager/driver/interfaces/urls.py4
-rw-r--r--zte/vmanager/driver/interfaces/views.py93
-rw-r--r--zte/vmanager/tox.ini2
10 files changed, 217 insertions, 79 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java
index 535053bf..b3ba1760 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapter2DriverMgrService.java
@@ -82,12 +82,16 @@ public class VnfmAdapter2DriverMgrService implements IVnfmAdapter2DriverMgrServi
* @throws IOException
*/
public static String readVnfmAdapterInfoFromJson() throws IOException {
- String fileContent = "";
-
String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot()
+ System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR)
+ "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + VNFMADAPTER2DRIVERMGR;
+ return readJson(fileName);
+ }
+
+ public static String readJson(String fileName) throws IOException {
+ String fileContent = "";
+
try (InputStream ins = new FileInputStream(fileName)){
try(BufferedInputStream bins = new BufferedInputStream(ins)){
@@ -107,9 +111,6 @@ public class VnfmAdapter2DriverMgrService implements IVnfmAdapter2DriverMgrServi
private static class RegisterVnfm2DriverMgrThread implements Runnable {
- // Thread lock Object
- private final Object lockObject = new Object();
-
private IVnfmAdapter2DriverManager adapter2DriverMgr = new VnfmAdapter2DriverManager();
// url and mothedtype
@@ -153,9 +154,7 @@ public class VnfmAdapter2DriverMgrService implements IVnfmAdapter2DriverMgrServi
// if registration fails,wait one minute and try again
try {
- synchronized(lockObject) {
- lockObject.wait(Constant.REPEAT_REG_TIME);
- }
+ Thread.sleep(Constant.REPEAT_REG_TIME);
} catch(InterruptedException e) {
LOG.error(e.getMessage(), e);
// Restore interrupted state...
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java
index 28c018cb..8df2c796 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/api/internalsvc/impl/VnfmAdapterMgrService.java
@@ -81,14 +81,19 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService {
* @throws IOException
*/
public String readVnfmAdapterInfoFromJson() throws IOException {
- String fileContent = "";
-
String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot()
+ System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR)
+ "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + VNFMADAPTERINFO;
- try (InputStream ins = new FileInputStream(fileName)) {
- try (BufferedInputStream bins = new BufferedInputStream(ins)){
+
+ return readJson(fileName);
+ }
+
+ public static String readJson(String fileName) throws IOException {
+ String fileContent = "";
+
+ try (InputStream ins = new FileInputStream(fileName)){
+ try(BufferedInputStream bins = new BufferedInputStream(ins)){
byte[] contentByte = new byte[ins.available()];
int num = bins.read(contentByte);
@@ -104,10 +109,8 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService {
return fileContent;
}
- private static class RegisterVnfmAdapterThread implements Runnable {
- // Thread lock Object
- private final Object lockObject = new Object();
+ private static class RegisterVnfmAdapterThread implements Runnable {
private IDriver2MSBManager adapter2MSBMgr = new Driver2MSBManager();
@@ -152,9 +155,7 @@ public class VnfmAdapterMgrService implements IVnfmAdapterMgrService {
// if registration fails,wait one minute and try again
try {
- synchronized(lockObject) {
- lockObject.wait(Constant.REPEAT_REG_TIME);
- }
+ Thread.sleep(Constant.REPEAT_REG_TIME);
} catch(InterruptedException e) {
LOG.error(e.getMessage(), e);
// Restore interrupted state...
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
index 0dc6751b..3e93f2c2 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
@@ -16,10 +16,9 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.ResultRequestUtil;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
import mockit.Mock;
@@ -29,14 +28,15 @@ import net.sf.json.JSONObject;
public class ResultRequestUtilTest {
@Test
- public void callTestInternalError(){
- new MockUp<ConnectMgrVnfm>(){
+ public void callTestInternalError() {
+ new MockUp<ConnectMgrVnfm>() {
+
@Mock
public int connect(JSONObject vnfmObj) {
return 500;
}
};
- JSONObject vnfmObject = new JSONObject();;
+ JSONObject vnfmObject = new JSONObject();
String path = "http://localhost:8080";
String methodName = "get";
String paramsJson = "";
@@ -45,8 +45,9 @@ public class ResultRequestUtilTest {
}
@Test
- public void callTestConnectionErrot(){
- new MockUp<ConnectMgrVnfm>(){
+ public void callTestConnectionErrot() {
+ new MockUp<ConnectMgrVnfm>() {
+
@Mock
public int connect(JSONObject vnfmObj) {
return 200;
@@ -61,4 +62,34 @@ public class ResultRequestUtilTest {
assertTrue(resp.get("data").equals("get connection error"));
}
+ @Test
+ public void callTest() {
+ new MockUp<ConnectMgrVnfm>() {
+
+ @Mock
+ public int connect(JSONObject vnfmObj) {
+ return 200;
+ }
+
+ @Mock
+ public String getRoaRand() {
+ return "1234";
+ }
+
+ @Mock
+ public String getAccessSession() {
+ return "1234";
+ }
+
+ };
+
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url", "/test/123");
+ String path = "https://localhost:8080/%s";
+ String methodName = "get";
+ String paramsJson = "";
+ JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
+ assertTrue(resp.get("data").equals("get connection error"));
+ }
+
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
index 12910c8e..d61c3b1c 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapter2DriverMgrServiceTest.java
@@ -16,12 +16,15 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.ai.internalsvc.impl;
-import mockit.Mock;
-import mockit.MockUp;
+import java.io.File;
+import java.io.IOException;
+
import org.junit.Test;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.api.internalsvc.impl.VnfmAdapter2DriverMgrService;
-import java.io.IOException;
+import junit.framework.Assert;
+import mockit.Mock;
+import mockit.MockUp;
/**
* Created by QuanZhong on 2017/3/20.
@@ -48,4 +51,17 @@ public class VnfmAdapter2DriverMgrServiceTest {
mgr.register();
mgr.unregister();
}
+
+ @Test
+ public void testReadJson() {
+ File file = new File("./demo.json");
+ try {
+ file.createNewFile();
+ String content = VnfmAdapter2DriverMgrService.readJson("./demo.json");
+ Assert.assertEquals(content, "");
+ file.delete();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
index 84a7c914..56e1eea3 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/ai/internalsvc/impl/VnfmAdapterMgrServiceTest.java
@@ -16,14 +16,15 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.ai.internalsvc.impl;
-import mockit.Mock;
-import mockit.MockUp;
-import net.sf.json.JSONObject;
+import java.io.File;
+import java.io.IOException;
+
import org.junit.Test;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.api.internalsvc.impl.VnfmAdapterMgrService;
-import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr;
-import java.io.IOException;
+import junit.framework.Assert;
+import mockit.Mock;
+import mockit.MockUp;
/**
* Created by QuanZhong on 2017/3/20.
@@ -42,4 +43,18 @@ public class VnfmAdapterMgrServiceTest {
mgr.register();
}
+
+
+ @Test
+ public void testReadJson() {
+ File file = new File("./demo.json");
+ try {
+ file.createNewFile();
+ String content = VnfmAdapterMgrService.readJson("./demo.json");
+ Assert.assertEquals(content, "");
+ file.delete();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
index b82c26af..8012b5cb 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/rest/VnfRoaTest.java
@@ -26,6 +26,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmJsonUtil;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.ServiceException;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.process.VnfMgr;
@@ -577,4 +578,58 @@ public class VnfRoaTest {
}
+ @Test
+ public void testGetVnfmById() throws ServiceException {
+ new MockUp<VnfmUtil>() {
+
+ @Mock
+ public JSONObject getVnfmById(String vnfmId) {
+ JSONObject json = new JSONObject();
+ json.put("vnfm", "1234");
+ return json;
+ }
+ };
+ String result = vnfRoa.getVnfmById("1234", null);
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetJobFromVnfm() throws ServiceException {
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getJobFromVnfm(String jobId, String vnfmId) {
+ JSONObject json = new JSONObject();
+ json.put("retCode", "1");
+ return json;
+ }
+
+ @Mock
+ public String transferToLcm(JSONObject restJson) {
+ return "success";
+ }
+ };
+ String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", null, "responseId");
+ assertNotNull(result);
+ }
+
+ @Test
+ public void testGetJobFromVnfmFail() throws ServiceException {
+
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getJobFromVnfm(String jobId, String vnfmId) {
+ JSONObject json = new JSONObject();
+ json.put("retCode", "-1");
+ return json;
+ }
+
+ };
+ MockUp<HttpServletResponse> proxyResStub = new MockUp<HttpServletResponse>() {};
+ HttpServletResponse mockResInstance = proxyResStub.getMockInstance();
+ String result = vnfRoa.getJobFromVnfm("jobId", "vnfmId", mockResInstance, "responseId");
+ assertNotNull(result);
+ }
+
}
diff --git a/zte/vmanager/driver/interfaces/serializers.py b/zte/vmanager/driver/interfaces/serializers.py
index a19613ca..c9206579 100644
--- a/zte/vmanager/driver/interfaces/serializers.py
+++ b/zte/vmanager/driver/interfaces/serializers.py
@@ -97,6 +97,20 @@ class TerminateVnfRequestSerializer(serializers.Serializer):
required=False)
+class VnfInfoSerializer(serializers.Serializer):
+ vnfStatus = serializers.CharField(
+ help_text="vnfStatus",
+ required=True,
+ max_length=255,
+ allow_null=True)
+
+
+class QueryVnfResponseSerializer(serializers.Serializer):
+ vnfInfo = VnfInfoSerializer(
+ help_text="vnfInfo",
+ required=True)
+
+
class JobHistorySerializer(serializers.Serializer):
status = serializers.CharField(
help_text="Status of job",
diff --git a/zte/vmanager/driver/interfaces/urls.py b/zte/vmanager/driver/interfaces/urls.py
index 182b7478..e32e53ea 100644
--- a/zte/vmanager/driver/interfaces/urls.py
+++ b/zte/vmanager/driver/interfaces/urls.py
@@ -21,7 +21,7 @@ urlpatterns = [
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/terminate$',
views.TerminateVnf.as_view(), name='terminate_vnf'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)$',
- views.query_vnf, name='query_vnf'),
+ views.QueryVnf.as_view(), name='query_vnf'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/jobs/(?P<jobid>[0-9a-zA-Z\-\_]+)$',
views.JobView.as_view(), name='operation_status'),
url(r'^api/ztevnfmdriver/v1/resource/grant$', views.GrantVnf.as_view(), name='grantvnf'),
@@ -30,5 +30,5 @@ urlpatterns = [
views.Scale.as_view(), name='scale'),
url(r'^api/ztevnfmdriver/v1/(?P<vnfmid>[0-9a-zA-Z\-\_]+)/vnfs/(?P<vnfInstanceId>[0-9a-zA-Z\-\_]+)/heal$',
views.Heal.as_view(), name='heal'),
- url(r'^samples/$', views.samples, name='samples')
+ url(r'^samples/$', views.SampleList.as_view(), name='samples')
]
diff --git a/zte/vmanager/driver/interfaces/views.py b/zte/vmanager/driver/interfaces/views.py
index 1a1976ed..5a978c63 100644
--- a/zte/vmanager/driver/interfaces/views.py
+++ b/zte/vmanager/driver/interfaces/views.py
@@ -21,13 +21,12 @@ import traceback
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from rest_framework import status
-from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework.views import APIView
from driver.interfaces.serializers import HealReqSerializer, InstScaleHealRespSerializer, ScaleReqSerializer, \
NotifyReqSerializer, GrantRespSerializer, GrantReqSerializer, JobQueryRespSerializer, TerminateVnfRequestSerializer, \
- InstantiateVnfRequestSerializer
+ InstantiateVnfRequestSerializer, QueryVnfResponseSerializer
from driver.pub.config.config import VNF_FTP
from driver.pub.utils import restcall
from driver.pub.utils.restcall import req_by_msb
@@ -60,14 +59,6 @@ def ignorcase_get(args, key):
return ""
-def mapping_conv(keyword_map, rest_return):
- resp_data = {}
- for param in keyword_map:
- if keyword_map[param]:
- resp_data[keyword_map[param]] = ignorcase_get(rest_return, param)
- return resp_data
-
-
# Query vnfm_info from nslcm
def get_vnfminfo_from_nslcm(vnfmid):
ret = req_by_msb("api/nslcm/v1/vnfms/%s" % vnfmid, "GET")
@@ -143,11 +134,11 @@ class InstamtiateVnf(APIView):
data["VNFURL"] = data["VNFD"]
- for name, value in ignorcase_get(ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam"), "inputs").items():
+ additionalParam = ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam")
+ for name, value in ignorcase_get(additionalParam, "inputs").items():
inputs.append({"name": name, "value": value})
data["extension"]["inputs"] = json.dumps(inputs)
- additionalParam = ignorcase_get(instantiateVnfRequestSerializer.data, "additionalParam")
data["extension"]["extVirtualLinks"] = ignorcase_get(additionalParam, "extVirtualLinks")
data["extension"]["vnfinstancename"] = ignorcase_get(instantiateVnfRequestSerializer.data, "vnfInstanceName")
data["extension"]["vnfid"] = data["VNFD"]
@@ -177,6 +168,7 @@ class InstamtiateVnf(APIView):
if not instRespSerializer.is_valid():
raise Exception(instRespSerializer.errors)
+ logger.debug("[%s] instRespSerializer.data=%s", fun_name(), instRespSerializer.data)
return Response(data=instRespSerializer.data, status=status.HTTP_200_OK)
except Exception as e:
logger.error("Error occurred when instantiating VNF,error:%s", e.message)
@@ -232,34 +224,45 @@ class TerminateVnf(APIView):
return Response(data={'error': 'TerminateVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
-@api_view(http_method_names=['GET'])
-def query_vnf(request, *args, **kwargs):
- try:
- logger.debug("[%s] request.data=%s", fun_name(), request.data)
- vnfm_id = ignorcase_get(kwargs, "vnfmid")
- ret = get_vnfminfo_from_nslcm(vnfm_id)
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- vnfm_info = json.JSONDecoder().decode(ret[1])
- logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
- ret = restcall.call_req(
- base_url=ignorcase_get(vnfm_info, "url"),
- user=ignorcase_get(vnfm_info, "userName"),
- passwd=ignorcase_get(vnfm_info, "password"),
- auth_type=restcall.rest_no_auth,
- resource="v1/vnfs/%s" % (ignorcase_get(kwargs, "vnfInstanceID")),
- method='get',
- content=json.JSONEncoder().encode({}))
- if ret[0] != 0:
- return Response(data={'error': ret[1]}, status=ret[2])
- resp = json.JSONDecoder().decode(ret[1])
- vnf_status = ignorcase_get(resp, "vnfinstancestatus")
- resp_data = {"vnfInfo": {"vnfStatus": vnf_status}}
- logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
- except Exception as e:
- logger.error("Error occurred when querying VNF information.")
- raise e
- return Response(data=resp_data, status=ret[2])
+class QueryVnf(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: QueryVnfResponseSerializer(),
+ status.HTTP_500_INTERNAL_SERVER_ERROR: "Internal error"
+ }
+ )
+ def get(self, request, vnfmid, vnfInstanceId):
+ try:
+ logger.debug("[%s] request.data=%s", fun_name(), request.data)
+ ret = get_vnfminfo_from_nslcm(vnfmid)
+ if ret[0] != 0:
+ raise Exception(ret[1])
+
+ vnfm_info = json.JSONDecoder().decode(ret[1])
+ logger.debug("[%s] vnfm_info=%s", fun_name(), vnfm_info)
+ ret = restcall.call_req(
+ base_url=ignorcase_get(vnfm_info, "url"),
+ user=ignorcase_get(vnfm_info, "userName"),
+ passwd=ignorcase_get(vnfm_info, "password"),
+ auth_type=restcall.rest_no_auth,
+ resource="v1/vnfs/%s" % vnfInstanceId,
+ method='get',
+ content=json.JSONEncoder().encode({}))
+ if ret[0] != 0:
+ raise Exception(ret[1])
+
+ resp = json.JSONDecoder().decode(ret[1])
+ vnf_status = ignorcase_get(resp, "vnfinstancestatus")
+ resp_data = {"vnfInfo": {"vnfStatus": vnf_status}}
+ logger.debug("[%s]resp_data=%s", fun_name(), resp_data)
+ queryVnfResponseSerializer = QueryVnfResponseSerializer(data=resp_data)
+ if not queryVnfResponseSerializer.is_valid():
+ raise Exception(queryVnfResponseSerializer.errors)
+ return Response(data=queryVnfResponseSerializer.data, status=status.HTTP_200_OK)
+ except Exception as e:
+ logger.error("Error occurred when querying VNF information,error:%s", e.message)
+ logger.error(traceback.format_exc())
+ return Response(data={'error': 'QueryVnf expection'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
class JobView(APIView):
@@ -608,6 +611,10 @@ def get_vdus(nf_model, aspect_id):
return members
-@api_view(http_method_names=['GET'])
-def samples(request, *args, **kwargs):
- return Response(data={"status": "ok"})
+class SampleList(APIView):
+ @swagger_auto_schema(
+ responses={
+ status.HTTP_200_OK: 'Successfully'})
+ def get(self, request):
+ logger.debug("get")
+ return Response({"status": "active"})
diff --git a/zte/vmanager/tox.ini b/zte/vmanager/tox.ini
index 2d18a624..3bbe6c8a 100644
--- a/zte/vmanager/tox.ini
+++ b/zte/vmanager/tox.ini
@@ -19,4 +19,4 @@ commands =
{[testenv]commands}
[testenv:cov]
-commands = coverage html --omit="*test_*,*__init__.py,*site-packages*" -d htmlcov \ No newline at end of file
+commands = coverage html --omit="*test*,*__init__.py,*site-packages*" -d htmlcov \ No newline at end of file