salt/tests/unit/cloud/clouds/test_openstack.py
2017-04-25 16:41:39 -06:00

45 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Bo Maryniuk <bo@suse.de>`
'''
# Import Python libs
from __future__ import absolute_import
# Import Salt Testing Libs
from tests.support.unit import TestCase
from tests.support.mock import MagicMock, patch
from tests.unit.cloud.clouds import _preferred_ip
# Import Salt libs
from salt.cloud.clouds import openstack
class OpenstackTestCase(TestCase):
'''
Test case for openstack
'''
PRIVATE_IPS = ['0.0.0.0', '1.1.1.1', '2.2.2.2']
@patch('salt.cloud.clouds.openstack.show_instance',
MagicMock(return_value={'state': True,
'public_ips': [],
'private_ips': PRIVATE_IPS}))
@patch('salt.cloud.clouds.openstack.rackconnect', MagicMock(return_value=False))
@patch('salt.cloud.clouds.openstack.managedcloud', MagicMock(return_value=False))
@patch('salt.cloud.clouds.openstack.preferred_ip', _preferred_ip(PRIVATE_IPS, ['0.0.0.0']))
@patch('salt.cloud.clouds.openstack.ssh_interface', MagicMock(return_value=False))
def test_query_node_data_filter_preferred_ip_addresses(self):
'''
Test if query node data is filtering out unpreferred IP addresses.
'''
openstack.NodeState = MagicMock() # pylint: disable=blacklisted-unmocked-patching
openstack.NodeState.RUNNING = True
vm = {'name': None}
data = MagicMock()
data.public_ips = []
with patch('salt.utils.cloud.is_public_ip', MagicMock(return_value=True)):
assert openstack._query_node_data(vm, data, False, MagicMock()).public_ips == ['0.0.0.0']