test_nova.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Bo Maryniuk <bo@suse.de>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import, print_function, unicode_literals
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase
  9. from tests.support.mock import MagicMock, patch
  10. from tests.unit.cloud.clouds import _preferred_ip
  11. # Import Salt libs
  12. from salt.cloud.clouds import nova
  13. class NovaTestCase(TestCase):
  14. '''
  15. Test case for openstack
  16. '''
  17. PRIVATE_IPS = ['0.0.0.0', '1.1.1.1', '2.2.2.2']
  18. @patch('salt.cloud.clouds.nova.show_instance',
  19. MagicMock(return_value={'state': 'ACTIVE',
  20. 'public_ips': [],
  21. 'addresses': [],
  22. 'private_ips': PRIVATE_IPS}))
  23. @patch('salt.cloud.clouds.nova.rackconnect', MagicMock(return_value=False))
  24. @patch('salt.cloud.clouds.nova.rackconnectv3', MagicMock(return_value={'mynet': ['1.1.1.1']}))
  25. @patch('salt.cloud.clouds.nova.cloudnetwork', MagicMock(return_value=False))
  26. @patch('salt.cloud.clouds.nova.managedcloud', MagicMock(return_value=False))
  27. @patch('salt.cloud.clouds.nova.preferred_ip', _preferred_ip(PRIVATE_IPS, ['0.0.0.0']))
  28. @patch('salt.cloud.clouds.nova.ssh_interface', MagicMock(return_value='public_ips'))
  29. def test_query_node_data_filter_preferred_ip_addresses(self):
  30. '''
  31. Test if query node data is filtering out unpreferred IP addresses.
  32. '''
  33. vm = {'name': None}
  34. data = MagicMock()
  35. data.public_ips = []
  36. assert nova._query_node_data(vm, data, MagicMock()).public_ips == ['0.0.0.0']