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