summaryrefslogtreecommitdiffstats
path: root/vio
diff options
context:
space:
mode:
Diffstat (limited to 'vio')
-rw-r--r--vio/vio/samples/tests.py2
-rw-r--r--vio/vio/samples/views.py9
-rw-r--r--vio/vio/swagger/views/hypervisor/views.py11
-rw-r--r--vio/vio/swagger/views/image/views.py14
-rw-r--r--vio/vio/swagger/views/network/views.py16
-rw-r--r--vio/vio/tests/test_image_view.py93
6 files changed, 143 insertions, 2 deletions
diff --git a/vio/vio/samples/tests.py b/vio/vio/samples/tests.py
index 0dd2731..910ded6 100644
--- a/vio/vio/samples/tests.py
+++ b/vio/vio/samples/tests.py
@@ -28,4 +28,4 @@ class SampleViewTest(unittest.TestCase):
self.assertEqual(status.HTTP_200_OK,
response.status_code, response.content)
resp_data = json.loads(response.content)
- self.assertEqual({"status": "active"}, resp_data)
+ self.assertEqual("active", resp_data["status"])
diff --git a/vio/vio/samples/views.py b/vio/vio/samples/views.py
index 36670d1..4775e78 100644
--- a/vio/vio/samples/views.py
+++ b/vio/vio/samples/views.py
@@ -10,12 +10,14 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+import os
import logging
from rest_framework.views import APIView
from rest_framework.response import Response
logger = logging.getLogger(__name__)
+log_file = "/var/log/onap/multicloud/vio/vio.log"
class SampleList(APIView):
@@ -25,4 +27,9 @@ class SampleList(APIView):
def get(self, request, format=None):
logger.debug("get")
- return Response({"status": "active"})
+ output = ""
+ if os.path.exists(log_file):
+ with open("/var/log/onap/multicloud/vio/vio.log", "r") as f:
+ lines = f.readlines()
+ output = lines[-1]
+ return Response({"status": "active", "logs": output})
diff --git a/vio/vio/swagger/views/hypervisor/views.py b/vio/vio/swagger/views/hypervisor/views.py
index a027d7c..0f7e1f9 100644
--- a/vio/vio/swagger/views/hypervisor/views.py
+++ b/vio/vio/swagger/views/hypervisor/views.py
@@ -27,6 +27,17 @@ from vio.swagger import nova_utils
class HostView(APIView):
def get(self, request, vimid, tenantid, hostname):
+ if vimid == "vmware_fake":
+ return Response(data={
+ 'vimid': vimid,
+ 'vimName': vimid,
+ 'tenantId': tenantid,
+ 'memory_mb': 196516,
+ 'name': "domain-c202.22bfc05c-da55-4ba6-ba93-08d9a067138e",
+ 'disk_gb': 6143,
+ 'cpu': 48
+ }, status=status.HTTP_200_OK)
+
try:
vim_info = extsys.get_vim_by_id(vimid)
except VimDriverVioException as e:
diff --git a/vio/vio/swagger/views/image/views.py b/vio/vio/swagger/views/image/views.py
index 62770c7..a876529 100644
--- a/vio/vio/swagger/views/image/views.py
+++ b/vio/vio/swagger/views/image/views.py
@@ -28,6 +28,20 @@ from vio.pub.exceptions import VimDriverVioException
class GetDeleteImageView(APIView):
def get(self, request, vimid, tenantid, imageid):
+ if vimid == "vmware_fake":
+ return Response(data={
+ "vimid": vimid,
+ "vimName": vimid,
+ "tenantId": tenantid,
+ "status": "active",
+ "name": "ubuntu-16.04-server-cloudimg-amd64",
+ "visibility": "public",
+ "id": "170641db-78cd-49a3-8bab-4cfa3d6ef131",
+ "size": 10737418240,
+ "imageType": "vmdk",
+ "containerFormat": "bare"
+ }, status=status.HTTP_200_OK)
+
try:
vim_info = extsys.get_vim_by_id(vimid)
vim_info['tenant'] = tenantid
diff --git a/vio/vio/swagger/views/network/views.py b/vio/vio/swagger/views/network/views.py
index 229e9a3..27d0f3a 100644
--- a/vio/vio/swagger/views/network/views.py
+++ b/vio/vio/swagger/views/network/views.py
@@ -77,6 +77,22 @@ class CreateNetworkView(APIView):
class DeleteNetworkView(APIView):
def get(self, request, vimid, tenantid, networkid):
+ if vimid == "vmware_fake":
+ return Response(data={
+ "vimid": vimid,
+ "vimName": vimid,
+ "tenantId": tenantid,
+ "status": "ACTIVE",
+ "segmentationId": None,
+ "name": "oam_onap_AQYG",
+ "physicalNetwork": None,
+ "shared": False,
+ "routerExternal": False,
+ "networkType": None,
+ "vlanTransparent": False,
+ "id": "0085970f-a214-4da2-a449-75acfb813fec"
+ }, status=status.HTTP_200_OK)
+
logger.info("Enter %s, method is %s, vim_id is %s",
syscomm.fun_name(), request.method, vimid)
net = OperateNetwork.OperateNetwork()
diff --git a/vio/vio/tests/test_image_view.py b/vio/vio/tests/test_image_view.py
new file mode 100644
index 0000000..112ee5a
--- /dev/null
+++ b/vio/vio/tests/test_image_view.py
@@ -0,0 +1,93 @@
+# Copyright (c) 2018 VMware, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+
+import mock
+import unittest
+
+from vio.pub.msapi import extsys
+from vio.swagger.views.image import views
+from vio.pub.vim.vimapi.glance import OperateImage
+
+
+class TestGetDeleteImageView(unittest.TestCase):
+
+ def setUp(self):
+ self.view = views.GetDeleteImageView()
+
+ @mock.patch.object(OperateImage.OperateImage, "get_vim_image")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_get(self, mock_getvim, mock_getimg):
+ mock_getvim.return_value = {
+ "tenant": "tenant-id"
+ }
+ img = mock.Mock()
+ img.to_dict.return_value = {
+ "id": "image-id"
+ }
+ mock_getimg.return_value = img
+ resp = self.view.get(mock.Mock(), "vmware_nova", "tenant1", "image1")
+ self.assertEqual(200, resp.status_code)
+ self.assertEqual("image-id", resp.data.get('id'))
+
+ @mock.patch.object(OperateImage.OperateImage, "delete_vim_image")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_delete(self, mock_getvim, mock_delimg):
+ mock_getvim.return_value = {
+ "tenant": "tenant-id"
+ }
+ resp = self.view.delete(
+ mock.Mock(), "vmware_nova", "tenant1", "image1")
+ self.assertEqual(204, resp.status_code)
+ mock_delimg.assert_called_once()
+
+
+class TestCreateListImagesView(unittest.TestCase):
+
+ def setUp(self):
+ self.view = views.CreateListImagesView()
+
+ @mock.patch.object(OperateImage.OperateImage, "get_vim_images")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_get(self, mock_getvim, mock_getimgs):
+ mock_getvim.return_value = {
+ "tenant": "tenant-id"
+ }
+ img = mock.Mock()
+ img.to_dict.return_value = {
+ "id": "image-id"
+ }
+ mock_getimgs.return_value = [img]
+ resp = self.view.get(
+ mock.Mock(query_params=[]), "vmware_nova", "tenant1")
+ self.assertEqual(200, resp.status_code)
+
+ @mock.patch.object(OperateImage.OperateImage, "get_vim_image")
+ @mock.patch.object(OperateImage.OperateImage, "get_vim_images")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_post(self, mock_getvim, mock_getimgs, mock_getimg):
+ mock_getvim.return_value = {
+ "tenant": "tenant-id"
+ }
+ img = mock.Mock()
+ img.id = "image-id"
+ img.name = "image-a"
+ img.to_dict.return_value = {
+ "id": "image-id",
+ "name": "image-a"
+ }
+ mock_getimgs.return_value = [img]
+ req = mock.Mock()
+ req.body = """{
+ "name": "image-a"
+ }"""
+ resp = self.view.post(req, "vmware_nova", "tenant1")
+ self.assertEqual(200, resp.status_code)