diff options
author | Ethan Lynn <ethanlynnl@vmware.com> | 2019-04-11 14:32:09 +0800 |
---|---|---|
committer | Ethan Lynn <ethanlynnl@vmware.com> | 2019-04-11 14:33:15 +0800 |
commit | 3cd73900d445b55cc7a82d3bb43b108db8134d8a (patch) | |
tree | 6f5af9e2711e8dc52012841f9d73fcd2e776df93 /vio | |
parent | 9e0f9994c0cab7839f09816b7187b2cbd58ad877 (diff) |
Add UT for heatbridge
Add unit test for heatbridge functions
Change-Id: I6acd74dc35b5f378296c9ac0bbbe31710506b7ad
Issue-ID: MULTICLOUD-507
Signed-off-by: Ethan Lynn <ethanlynnl@vmware.com>
Diffstat (limited to 'vio')
-rw-r--r-- | vio/vio/heatbridge.py | 3 | ||||
-rw-r--r-- | vio/vio/tests/test_heatbridge.py | 61 |
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) |