test_cloud.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # -*- coding: utf-8 -*-
  2. '''
  3. :codeauthor: Eric Radman <ericshane@eradman.com>
  4. '''
  5. # Import Python libs
  6. from __future__ import absolute_import
  7. # Import Salt Testing libs
  8. from tests.support.unit import skipIf, TestCase
  9. from tests.support.mock import (
  10. MagicMock,
  11. patch,
  12. NO_MOCK,
  13. NO_MOCK_REASON,
  14. )
  15. # Import Salt libs
  16. import salt.cloud
  17. EXAMPLE_PROVIDERS = {
  18. 'nyc_vcenter': {'vmware': {'driver': 'vmware',
  19. 'password': '123456',
  20. 'profiles': {'nyc-vm': {'cluster': 'nycvirt',
  21. 'datastore': 'datastore1',
  22. 'devices': {'disk': {'Hard disk 1': {'controller': 'SCSI controller 1',
  23. 'size': 20}},
  24. 'network': {'Network Adapter 1': {'mac': '44:44:44:44:44:42',
  25. 'name': 'vlan50',
  26. 'switch_type': 'standard'}},
  27. 'scsi': {'SCSI controller 1': {'type': 'paravirtual'}}},
  28. 'extra_config': {'mem.hotadd': 'yes'},
  29. 'folder': 'coreinfra',
  30. 'image': 'rhel6_64Guest',
  31. 'memory': '8GB',
  32. 'num_cpus': 2,
  33. 'power_on': True,
  34. 'profile': 'nyc-vm',
  35. 'provider': 'nyc_vcenter:vmware',
  36. 'resourcepool': 'Resources'}},
  37. 'url': 'vca1.saltstack.com',
  38. 'user': 'root'}}
  39. }
  40. EXAMPLE_PROFILES = {
  41. 'nyc-vm': {'cluster': 'nycvirt',
  42. 'datastore': 'datastore1',
  43. 'devices': {'disk': {'Hard disk 1': {'controller': 'SCSI controller 1',
  44. 'size': 20}},
  45. 'network': {'Network Adapter 1': {'mac': '44:44:44:44:44:42',
  46. 'name': 'vlan50',
  47. 'switch_type': 'standard'}},
  48. 'scsi': {'SCSI controller 1': {'type': 'paravirtual'}}},
  49. 'extra_config': {'mem.hotadd': 'yes'},
  50. 'folder': 'coreinfra',
  51. 'image': 'rhel6_64Guest',
  52. 'memory': '8GB',
  53. 'num_cpus': 2,
  54. 'power_on': True,
  55. 'profile': 'nyc-vm',
  56. 'provider': 'nyc_vcenter:vmware',
  57. 'resourcepool': 'Resources'}
  58. }
  59. EXAMPLE_MAP = {
  60. 'nyc-vm': {'db1': {'cpus': 4,
  61. 'devices': {'disk': {'Hard disk 1': {'size': 40}},
  62. 'network': {'Network Adapter 1': {'mac': '22:4a:b2:92:b3:eb'}}},
  63. 'memory': '16GB',
  64. 'name': 'db1'}}
  65. }
  66. @skipIf(NO_MOCK, NO_MOCK_REASON)
  67. class MapConfTest(TestCase):
  68. '''
  69. Validate evaluation of salt-cloud map configuration
  70. '''
  71. def test_cloud_map_merge_conf(self):
  72. '''
  73. Ensure that nested values can be selectivly overridden in a map file
  74. '''
  75. with patch('salt.config.check_driver_dependencies', MagicMock(return_value=True)), \
  76. patch('salt.cloud.Map.read', MagicMock(return_value=EXAMPLE_MAP)):
  77. self.maxDiff = None
  78. opts = {'extension_modules': '/var/cache/salt/master/extmods',
  79. 'optimization_order': [0, 1, 2],
  80. 'providers': EXAMPLE_PROVIDERS, 'profiles': EXAMPLE_PROFILES}
  81. cloud_map = salt.cloud.Map(opts)
  82. merged_profile = {
  83. 'create': {'db1': {'cluster': 'nycvirt',
  84. 'cpus': 4,
  85. 'datastore': 'datastore1',
  86. 'devices': {'disk': {'Hard disk 1': {'controller': 'SCSI controller 1',
  87. 'size': 40}},
  88. 'network': {'Network Adapter 1': {'mac': '22:4a:b2:92:b3:eb',
  89. 'name': 'vlan50',
  90. 'switch_type': 'standard'}},
  91. 'scsi': {'SCSI controller 1': {'type': 'paravirtual'}}},
  92. 'driver': 'vmware',
  93. 'extra_config': {'mem.hotadd': 'yes'},
  94. 'folder': 'coreinfra',
  95. 'image': 'rhel6_64Guest',
  96. 'memory': '16GB',
  97. 'name': 'db1',
  98. 'num_cpus': 2,
  99. 'password': '123456',
  100. 'power_on': True,
  101. 'profile': 'nyc-vm',
  102. 'provider': 'nyc_vcenter:vmware',
  103. 'resourcepool': 'Resources',
  104. 'url': 'vca1.saltstack.com',
  105. 'user': 'root'}}
  106. }
  107. self.assertEqual(cloud_map.map_data(), merged_profile)