test_azurearm.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- coding: utf-8 -*-
  2. # import Python Libs
  3. from __future__ import absolute_import, print_function, unicode_literals
  4. import logging
  5. # Import Salt Libs
  6. import salt.utils.azurearm as azurearm
  7. # Import Salt Testing Libs
  8. from tests.support.unit import TestCase, skipIf
  9. # Azure libs
  10. # pylint: disable=import-error
  11. HAS_LIBS = False
  12. try:
  13. import azure.mgmt.compute.models # pylint: disable=unused-import
  14. import azure.mgmt.network.models # pylint: disable=unused-import
  15. HAS_LIBS = True
  16. except ImportError:
  17. pass
  18. # pylint: enable=import-error
  19. log = logging.getLogger(__name__)
  20. MOCK_CREDENTIALS = {
  21. "client_id": "CLIENT_ID",
  22. "secret": "SECRET",
  23. "subscription_id": "SUBSCRIPTION_ID",
  24. "tenant": "TENANT",
  25. }
  26. @skipIf(HAS_LIBS is False, "The azure.mgmt.network module must be installed.")
  27. class AzureRmUtilsTestCase(TestCase):
  28. def test_create_object_model_vnet(self):
  29. module_name = "network"
  30. object_name = "VirtualNetwork"
  31. vnet = {
  32. "address_space": {"address_prefixes": ["10.0.0.0/8"]},
  33. "enable_ddos_protection": False,
  34. "enable_vm_protection": True,
  35. "tags": {"contact_name": "Elmer Fudd Gantry"},
  36. }
  37. model = azurearm.create_object_model(module_name, object_name, **vnet)
  38. self.assertEqual(vnet, model.as_dict())
  39. def test_create_object_model_nic_ref(self):
  40. module_name = "compute"
  41. object_name = "NetworkInterfaceReference"
  42. ref = {
  43. "id": "/subscriptions/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/resourceGroups/rg/providers/Microsoft.Network/networkInterfaces/nic",
  44. "primary": False,
  45. }
  46. model = azurearm.create_object_model(module_name, object_name, **ref)
  47. self.assertEqual(ref, model.as_dict())