From 539405270b57a5ee7409a164a38b9fdb0b3624e7 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Thu, 17 Nov 2016 13:52:03 +0800 Subject: Architecture evolution skeleton - benchmarks will be driven by qtip.runner - qtip.runner is used by both qtip.cli and qtip.api - unit test for each module will be placed under tests/unit - functional tests will be moved to tests/functional - data as testing sample will be moved to tests/data NOTE: this patch moves files only, it may fails many tests. To be followed up in next step. JIRA: QTIP-148 Change-Id: I27e8169a74783970a1f7818456eb76a7311fb60c Signed-off-by: Yujun Zhang --- tests/unit/utils/spawn_vm_test.py | 56 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 tests/unit/utils/spawn_vm_test.py (limited to 'tests/unit/utils/spawn_vm_test.py') diff --git a/tests/unit/utils/spawn_vm_test.py b/tests/unit/utils/spawn_vm_test.py new file mode 100644 index 00000000..ba237378 --- /dev/null +++ b/tests/unit/utils/spawn_vm_test.py @@ -0,0 +1,56 @@ +import pytest +import mock +from mock import Mock, MagicMock +import os +from qtip.utils.spawn_vm import SpawnVM + + +class KeystoneMock(MagicMock): + auth_token = Mock() + v2_0 = Mock() + + +class StackMock(MagicMock): + status = 'COMPLETE' + outputs = [{'output_key': 'availability_instance_1', + 'output_value': 'output_value_1'}, + {'output_key': 'instance_ip_1', + "output_value": "172.10.0.154"}, + {"output_key": "instance_PIP_1", + "output_value": "10.10.17.5"}] + + +class HeatMock(MagicMock): + def list(self): + return [] + + def get(self, stackname): + return StackMock() + + def create(self, stack_name, template): + pass + + +class TestClass: + @pytest.mark.parametrize("test_input, expected", [ + ({'availability_zone': ['compute1', 'compute1'], + 'OS_image': ['QTIP_CentOS', 'QTIP_CentOS'], + 'public_network': ['admin-floating_net', 'admin-floating_net'], + 'flavor': ['m1.large', 'm1.large'], + 'role': ['1-server', '2-host']}, + [('172.10.0.154', '')]), + ]) + @mock.patch('qtip.utils.spawn_vm.Env_setup') + @mock.patch('qtip.utils.spawn_vm.AvailabilityZone') + @mock.patch('qtip.utils.spawn_vm.keystoneclient.v2_0', autospec=True) + @mock.patch('qtip.utils.spawn_vm.heatclient.client', autospec=True) + def test_create_zones_success(self, mock_heat, mock_keystone, + mock_zone, mock_setup, test_input, expected): + open('./config/QtipKey.pub', 'a').close() + mock_heat.Client.return_value = Mock(stacks=HeatMock()) + k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel'}) + k.start() + SpawnVM(test_input) + k.stop() + os.remove('./config/QtipKey.pub') + mock_setup.ip_pw_list.append.assert_called_with(expected[0]) -- cgit 1.2.3-korg