Skip to content

Commit 0354421

Browse files
authored
Merge pull request saltstack#56379 from Ajnbro/fix-create-object
Fixes AzureRM create_object_model util
2 parents e313fb1 + a5511f2 commit 0354421

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

salt/utils/azurearm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def create_object_model(module_name, object_name, **kwargs):
255255
if "_attribute_map" in dir(Model):
256256
for attr, items in Model._attribute_map.items():
257257
param = kwargs.get(attr)
258-
if param:
258+
if param is not None:
259259
if items["type"][0].isupper() and isinstance(param, dict):
260260
object_kwargs[attr] = create_object_model(
261261
module_name, items["type"], **param

tests/unit/utils/test_azurearm.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

Comments
 (0)