diff options
author | Yujun Zhang <zhang.yujunz@zte.com.cn> | 2016-11-23 07:59:31 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2016-11-23 07:59:31 +0000 |
commit | 8bc628a0e6821984780ad05688eb6649e1733c65 (patch) | |
tree | b6f440a75e78866f8f2546deb163a2440a93ec4c /tests/unit/utils/spawn_vm_test.py | |
parent | 07ee28b71118469f3946a009a126b7c21267173e (diff) | |
parent | 539405270b57a5ee7409a164a38b9fdb0b3624e7 (diff) |
Merge "Architecture evolution skeleton"
Diffstat (limited to 'tests/unit/utils/spawn_vm_test.py')
-rw-r--r-- | tests/unit/utils/spawn_vm_test.py | 56 |
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]) |