summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vio/vio/tests/test_apiv2_controller.py71
-rw-r--r--vio/vio/tests/test_fake_heat_view.py15
-rw-r--r--vio/vio/tests/test_fake_identity_view.py17
-rw-r--r--vio/vio/tests/test_fake_nova_view.py153
4 files changed, 251 insertions, 5 deletions
diff --git a/vio/vio/tests/test_apiv2_controller.py b/vio/vio/tests/test_apiv2_controller.py
new file mode 100644
index 0000000..d48b769
--- /dev/null
+++ b/vio/vio/tests/test_apiv2_controller.py
@@ -0,0 +1,71 @@
+# 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 keystoneauth1.identity import v2 as keystone_v2
+from keystoneauth1.identity import v3 as keystone_v3
+
+from vio.api_v2.api_router import controller_builder as cb
+from vio.api_v2.api_router import v0_controller
+from vio.pub.msapi import extsys
+
+
+class TestAPIv2Controller(unittest.TestCase):
+
+ @mock.patch.object(keystone_v2, "Password")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_get_vim_session_v2(self, mock_getvim, mock_kv2):
+ mock_getvim.return_value = {
+ "url": "http://aa/v2",
+ "userName": "admin",
+ "password": "admin",
+ "domain": "default"
+ }
+ mock_kv2.return_value = mock.Mock()
+ cb._get_vim_auth_session("vmware_vio", "tenant1")
+
+ @mock.patch.object(keystone_v3, "Password")
+ @mock.patch.object(extsys, "get_vim_by_id")
+ def test_get_vim_session_v3(self, mock_getvim, mock_kv3):
+ mock_getvim.return_value = {
+ "url": "http://aa/v3",
+ "userName": "admin",
+ "password": "admin",
+ "domain": "default"
+ }
+ mock_kv3.return_value = mock.Mock()
+ cb._get_vim_auth_session("vmware_vio", "tenant1")
+
+ def test_convert_default_val(self):
+ self.assertEqual(None, cb._convert_default_value("None"))
+ self.assertEqual(True, cb._convert_default_value("true"))
+ self.assertEqual(False, cb._convert_default_value("false"))
+
+ def test_property_exist(self):
+ res = {
+ "pp": "dd"
+ }
+ self.assertEqual(True, cb._property_exists(res, "pp", required=False))
+ self.assertEqual(False, cb._property_exists(res, "dd", required=False))
+ self.assertRaises(
+ Exception, cb._property_exists, res, "dd", required=True)
+
+ def test_insert_dynamic_controller(self):
+ controller = v0_controller.V0_Controller()
+ cb.insert_dynamic_controller(controller)
+ self.assertEqual(True, hasattr(controller, "hosts"))
+ self.assertEqual(True, hasattr(controller, "images"))
+ self.assertEqual(True, hasattr(controller, "ports"))
+ self.assertEqual(True, hasattr(controller, "networks"))
+ self.assertEqual(True, hasattr(controller, "subnets"))
diff --git a/vio/vio/tests/test_fake_heat_view.py b/vio/vio/tests/test_fake_heat_view.py
index 3cdb41a..5e87a61 100644
--- a/vio/vio/tests/test_fake_heat_view.py
+++ b/vio/vio/tests/test_fake_heat_view.py
@@ -67,18 +67,23 @@ class TestFakeHeatService(unittest.TestCase):
def setUp(self):
self.view = views.FakeHeatService()
- @mock.patch.object(fakeResponse, "getAllStacks")
- def test_get_heat_stacks(self, mock_getAllStacks):
+ def test_get_heat_stack(self):
req = mock.Mock()
req.META = {
"HTTP_X_AUTH_TOKEN": Token
}
- mock_getAllStacks.return_value = {
- "stack": "1234abcd"
- }
resp = self.view.get(req, "1234abcd", STACK_NAME, STACK_ID)
self.assertEqual(200, resp.status_code)
+ def test_list_stacks(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ resp = self.view.get(req, "1234abcd")
+ self.assertEqual(200, resp.status_code)
+ self.assertEqual(1, len(resp.data['stacks']))
+
@mock.patch.object(fakeResponse, "createStack")
def test_create_service_preview(self, mock_createStack):
req = mock.Mock()
diff --git a/vio/vio/tests/test_fake_identity_view.py b/vio/vio/tests/test_fake_identity_view.py
index e27a8c4..2dde2d6 100644
--- a/vio/vio/tests/test_fake_identity_view.py
+++ b/vio/vio/tests/test_fake_identity_view.py
@@ -40,6 +40,23 @@ class TestFakeProjects(unittest.TestCase):
resp = self.view.get(req, "1234abcd")
self.assertEqual(200, resp.status_code)
+ def test_list_projects(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ resp = self.view.get(req)
+ self.assertEqual(200, resp.status_code)
+ self.assertEqual(3, len(resp.data['projects']))
+
+ def test_list_projects_unauth(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": "invalid"
+ }
+ resp = self.view.get(req)
+ self.assertEqual(401, resp.status_code)
+
class TestFakeToken(unittest.TestCase):
diff --git a/vio/vio/tests/test_fake_nova_view.py b/vio/vio/tests/test_fake_nova_view.py
index c1c725d..f07aa47 100644
--- a/vio/vio/tests/test_fake_nova_view.py
+++ b/vio/vio/tests/test_fake_nova_view.py
@@ -10,6 +10,7 @@
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+import json
import mock
import unittest
@@ -29,6 +30,9 @@ class TestFakeNovaServer(unittest.TestCase):
def setUp(self):
self.view = views.FakeNovaServer()
+ def tearDown(self):
+ fakeResponse.serverMapps[Server]['status'] = "ACTIVE"
+
@mock.patch.object(fakeResponse, "show_serverDetail")
def test_get_server(self, mock_show_serverDetail):
req = mock.Mock()
@@ -51,6 +55,146 @@ class TestFakeNovaServer(unittest.TestCase):
resp = self.view.delete(req, "abcd", Server)
self.assertEqual(204, resp.status_code)
+ def test_list_servers(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ resp = self.view.get(req, "abcd")
+ self.assertEqual(200, resp.status_code)
+
+ def test_list_servers_unauth(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": "invalid"
+ }
+ resp = self.view.get(req, "abcd")
+ self.assertEqual(401, resp.status_code)
+
+ def test_operate_server_stop(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "os-stop": {}
+ })
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "POWERING_OFF", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_start(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "os-start": {}
+ })
+ fakeResponse.serverMapps[Server]['status'] = "SHUTDOWN"
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "POWERING_ON", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_resume(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "resume": {}
+ })
+ fakeResponse.serverMapps[Server]['status'] = "SUSPENDED"
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "ACTIVE", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_suspend(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "suspend": {}
+ })
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "SUSPENDED", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_unpause(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "unpause": {}
+ })
+ fakeResponse.serverMapps[Server]['status'] = "PAUSED"
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "ACTIVE", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_reboot(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "reboot": {}
+ })
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(202, resp.status_code)
+ self.assertEqual(
+ "REBOOTING", fakeResponse.serverMapps[Server]['status'])
+
+ def test_operate_server_unsupport(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "invalid": {}
+ })
+ resp = self.view.post(req, "abcd", Server)
+ self.assertEqual(405, resp.status_code)
+
+ def test_create_server(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ req.body = json.dumps({
+ "server": {
+ "name": "new_name"
+ }
+ })
+ resp = self.view.post(req, "abcd")
+ self.assertEqual(202, resp.status_code)
+ server_id = resp.data['server']['id']
+ self.assertEqual(
+ "BUILDING", fakeResponse.serverMapps[server_id]['status'])
+ self.assertEqual(
+ "new_name", fakeResponse.serverMapps[server_id]['name'])
+
+
+class TestFakeNovaHypervisorUptime(unittest.TestCase):
+
+ def setUp(self):
+ self.view = views.FakeNovaHypervisorsUptime()
+
+ def test_get_hypervisor_uptime(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ resp = self.view.get(req, "tenant1", "hypervisor1")
+ self.assertEqual(200, resp.status_code)
+
class TestFakeNovaHypervisors(unittest.TestCase):
@@ -123,6 +267,15 @@ class TestFakeFlavorDetail(unittest.TestCase):
resp = self.view.get(req, "abcd", "1234")
self.assertEqual(200, resp.status_code)
+ def test_get_flavors_detail(self):
+ req = mock.Mock()
+ req.META = {
+ "HTTP_X_AUTH_TOKEN": Token
+ }
+ resp = self.view.get(req, "abcd", "detail")
+ self.assertEqual(200, resp.status_code)
+ self.assertEqual(6, len(resp.data["flavors"]))
+
class TestFakeFlavorList(unittest.TestCase):