diff options
author | zhifeng.jiang <jiang.zhifeng@zte.com.cn> | 2016-07-12 17:06:58 +0800 |
---|---|---|
committer | zhifeng.jiang <jiang.zhifeng@zte.com.cn> | 2016-07-12 17:20:53 +0800 |
commit | d69313bf2b6cf2e4400451f1d9433749bfdbaf8c (patch) | |
tree | 69afdf048f2a9882718bb2f2e04f13115dafa470 /tests/spawn_vm_test.py | |
parent | 01c843df1684678072988283b3789e11a34b7499 (diff) |
Add some UT test cases and fix pep8 errors for spawn_vm
JIRA:QTIP-89
Change-Id: I2555a0a7a8ffaf6d19cfad88770cd8e378d154b2
Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'tests/spawn_vm_test.py')
-rw-r--r-- | tests/spawn_vm_test.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/spawn_vm_test.py b/tests/spawn_vm_test.py new file mode 100644 index 00000000..eb843ad9 --- /dev/null +++ b/tests/spawn_vm_test.py @@ -0,0 +1,71 @@ +import pytest +import mock +from mock import Mock, MagicMock +import os +from func.spawn_vm import SpawnVM + + +class KeystoneMock(MagicMock): + auth_token = Mock() + v2_0 = Mock() + + +class ImageMock(MagicMock): + name = 'QTIP_CentOS' + + +class ImagesMock(MagicMock): + def list(self): + return [ImageMock()] + + +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"}, + {'output_key': 'KeyPair_PublicKey', + "output_value": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpwIBAAKCAQEAqCiHcrLBXtxG0LhnKndU7VIVpYxORmv0d4tvujkWOkYuagiW\nU/MTRk0zhRvFQDVPEs0Jrj/BIecqm6fjjT6dZ/H7JLYGaqJitRkoupKgBsMSIqUz\nrR0ekOlfXZ6N+Ud8k6s+qjc7BO4b1ezz78jHisC5o0GCkUV0ECx64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f6HRJJsQKCAIAE2S5asTaWo+r4m/bYtmXm/eDZnfa7TI/T\nsOWELbTPNp5wjOgsgyhNaAhu7MtmesXn5cxLwohP94vhoMKMNptMD8iRPqJ471Iw\n4zW62NLGeW6AyIHes3CMPMIs+AtHoR33MkotSG5sY/jRk8+HoGoYo6/qK+l+CJ5z\neR579wR5sQKCAIAvPWq+bvcPTDKUU1Fe/Y/GyWoUA+uSqmCdORBkK38lALFGphxj\nfDz9dXskimqW+A9hOPOS8dm8YcVvi/TLXVE5Vsx9VkOg6z6AZBQpgNXGfOgpju4W\nbjER7bQaASatuWQyCxbA9oNlAUdSeOhGTxeFLkLj7hNMd6tLjfd8w7A/hA==\n-----END RSA PRIVATE KEY-----\n"}] + + +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('func.spawn_vm.Env_setup') + @mock.patch('func.spawn_vm.FetchImg') + @mock.patch('func.spawn_vm.create_zones') + @mock.patch('func.spawn_vm.client', autospec=True) + @mock.patch('func.spawn_vm.glanceclient', autospec=True) + @mock.patch('func.spawn_vm.keystoneclient.v2_0', autospec=True) + @mock.patch('func.spawn_vm.heatclient.client', autospec=True) + def test_create_zones_success(self, mock_heat, mock_keystone, mock_glance, + mock_nova_client, mock_zone, mock_fetch, + mock_setup, test_input, expected): + mock_glance.Client.return_value = Mock(images=ImagesMock()) + mock_nova_client.Client.return_value = Mock() + mock_heat.Client.return_value = Mock(stacks=HeatMock()) + k = mock.patch.dict(os.environ, {'INSTALLER_TYPE': 'fuel'}) + k.start() + SpawnVM(test_input) + k.stop() + mock_setup.ip_pw_list.append.assert_called_with(expected[0]) |