summaryrefslogtreecommitdiffstats
path: root/tests/unit/utils/spawn_vm_test.py
diff options
context:
space:
mode:
authorYujun Zhang <zhang.yujunz@zte.com.cn>2016-11-17 13:52:03 +0800
committerYujun Zhang <zhang.yujunz@zte.com.cn>2016-11-21 10:36:52 +0800
commit539405270b57a5ee7409a164a38b9fdb0b3624e7 (patch)
treec8f9a6fd5d61b8060802ec06bba5f9c94fe66bcb /tests/unit/utils/spawn_vm_test.py
parentcaa171ac3796bbeacfdac0939713eedfad85e3c3 (diff)
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 <zhang.yujunz@zte.com.cn>
Diffstat (limited to 'tests/unit/utils/spawn_vm_test.py')
-rw-r--r--tests/unit/utils/spawn_vm_test.py56
1 files changed, 56 insertions, 0 deletions
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])