aboutsummaryrefslogtreecommitdiffstats
path: root/tests/spawn_vm_test.py
blob: 7890abd110d4ae292b628237adaa85602268f08b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 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+qjc7BO4b1ezz78jHisC5o0GCkUV0ECx64Re1fO+oKs1c\nfL9aaexahJUYN3J48pazQz+imc2x/G9nuqHX3cqEszmxnT4jwv//In1GjHy2AyXw\n1oA5F6wZoQCSrXc2BditU+1tlVhEkPFt5JgiHUpY8T8mYbroT7JH6xjcGSKUN+HG\nN8PXNUTD1VAQfwHpkfsGMfDyzjytCXsoTEOqnwIDAQABAoIBAAEL/4vfQQTuKiKy\ngzHofEbd8/SL4xDdKzBzVca7BEBon3FZjFYJdV1CrcduXNQBgPSFAkJrczBa2BEQ\nAoKmmSREhWO9Hl0blbG67l36+7QPEtXUYXX6cG5Ghal3izq6DzR8JG+62Es3kETM\nrNgZT+S1PnKdvcpZvFc9b6ZnF2InuTbrmNVBZKrhdWOJ5tCwRGKKUl6BHoJH3yu0\n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icMock):
    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.AvailabilityZone')
    @mock.patch('func.spawn_vm.client', 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_nova_client, mock_zone,
                                  mock_setup, test_input, expected):
        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])