summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2019-04-11 11:59:08 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-11 11:59:08 +0000
commit05cffa755e43fa8e7c4b1baa4eb0071050436699 (patch)
tree9083a2e2270dd44f01a03080be09273dd442f51d
parentcee4d618b395e4e6d85f7f28a778c2f0d93155db (diff)
parent3cd73900d445b55cc7a82d3bb43b108db8134d8a (diff)
Merge "Add UT for heatbridge"
-rw-r--r--vio/vio/heatbridge.py3
-rw-r--r--vio/vio/tests/test_heatbridge.py61
2 files changed, 63 insertions, 1 deletions
diff --git a/vio/vio/heatbridge.py b/vio/vio/heatbridge.py
index 325d20c..94912c1 100644
--- a/vio/vio/heatbridge.py
+++ b/vio/vio/heatbridge.py
@@ -41,9 +41,10 @@ def heat_bridge(vim_info, stack_id):
if instance is None:
logger.info("can not find server %s" % res.physical_resource_id)
continue
+ slink = ""
for link in instance.links:
if link['rel'] == "self":
- slink = link['rel']
+ slink = link['href']
break
ret['servers'].append({
"name": instance.name,
diff --git a/vio/vio/tests/test_heatbridge.py b/vio/vio/tests/test_heatbridge.py
new file mode 100644
index 0000000..53df009
--- /dev/null
+++ b/vio/vio/tests/test_heatbridge.py
@@ -0,0 +1,61 @@
+# Copyright (c) 2019 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 import heatbridge
+from vio.pub.vim.vimapi.heat import OperateStack
+from vio.pub.vim.vimapi.nova import OperateServers
+
+
+class TestHeatBridge(unittest.TestCase):
+
+ @mock.patch.object(OperateServers, "OperateServers")
+ @mock.patch.object(OperateStack, "OperateStack")
+ def test_heat_bridge(self, mock_stack, mock_server):
+ stack_op = mock.Mock()
+ stack_op.get_stack_resources.return_value = [mock.Mock(
+ resource_type="OS::Nova::Server",
+ status="CREATE_COMPLETE",
+ physical_resource_id="server-id",
+ )]
+ mock_stack.return_value = stack_op
+ server_op = mock.Mock()
+ server = mock.Mock(
+ name="server",
+ id="server-id",
+ status="ACTIVE",
+ links=[{
+ "rel": "self",
+ "href": "/servers/server-id"
+ }]
+ )
+ server_op.get_server.return_value = server
+ mock_server.return_value = server_op
+ vim_info = {
+ "vimId": "vim-id",
+ "name": "vmware_nova",
+ "userName": "user",
+ "password": "pass",
+ "url": "http://1.2.3.4:5000"
+ }
+ ret = heatbridge.heat_bridge(vim_info, "stack-id")
+ expect_ret = {
+ "servers": [{
+ "name": server.name,
+ "id": server.id,
+ "status": server.status,
+ "link": "/servers/server-id"
+ }]
+ }
+ self.assertEqual(ret, expect_ret)