salt/tests/unit/utils/test_azurearm.py
Pedro Algarvio d990363f8a Stop using @skipIf
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
2022-12-06 06:03:10 +00:00

55 lines
1.6 KiB
Python

import logging
import pytest
import salt.utils.azurearm as azurearm
from tests.support.unit import TestCase
# Azure libs
# pylint: disable=import-error
HAS_LIBS = False
try:
import azure.mgmt.compute.models # pylint: disable=unused-import
import azure.mgmt.network.models # pylint: disable=unused-import
HAS_LIBS = True
except ImportError:
pass
# pylint: enable=import-error
log = logging.getLogger(__name__)
MOCK_CREDENTIALS = {
"client_id": "CLIENT_ID",
"secret": "SECRET",
"subscription_id": "SUBSCRIPTION_ID",
"tenant": "TENANT",
}
@pytest.mark.skipif(
HAS_LIBS is False, reason="The azure.mgmt.network module must be installed."
)
class AzureRmUtilsTestCase(TestCase):
def test_create_object_model_vnet(self):
module_name = "network"
object_name = "VirtualNetwork"
vnet = {
"address_space": {"address_prefixes": ["10.0.0.0/8"]},
"enable_ddos_protection": False,
"enable_vm_protection": True,
"tags": {"contact_name": "Elmer Fudd Gantry"},
}
model = azurearm.create_object_model(module_name, object_name, **vnet)
self.assertEqual(vnet, model.as_dict())
def test_create_object_model_nic_ref(self):
module_name = "compute"
object_name = "NetworkInterfaceReference"
ref = {
"id": "/subscriptions/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/resourceGroups/rg/providers/Microsoft.Network/networkInterfaces/nic",
"primary": False,
}
model = azurearm.create_object_model(module_name, object_name, **ref)
self.assertEqual(ref, model.as_dict())