@@ -51,27 +51,28 @@ def setUpTestData(cls):
51
51
device_type = devicetype ,
52
52
device_role = devicerole ,
53
53
)
54
- virtual_chassis = VirtualChassis .objects .create (name = "Virtual Chassis 1" )
55
- virtual_chassis_member = Device .objects .create (
56
- name = "VC Device" ,
57
- site = site ,
58
- device_type = devicetype ,
59
- device_role = devicerole ,
60
- virtual_chassis = virtual_chassis ,
61
- vc_position = 1 ,
62
- )
63
- cluster_member = Device .objects .create (
64
- name = "Cluster Device" ,
65
- site = site ,
66
- device_type = devicetype ,
67
- device_role = devicerole ,
68
- )
69
- clustertype = ClusterType .objects .create (name = "Cluster Type 1" )
70
- cluster = Cluster .objects .create (
71
- name = "Cluster 1" ,
72
- type = clustertype ,
73
- )
54
+ # virtual_chassis = VirtualChassis.objects.create(name="Virtual Chassis 1")
55
+ # virtual_chassis_member = Device.objects.create(
56
+ # name="VC Device",
57
+ # site=site,
58
+ # device_type=devicetype,
59
+ # device_role=devicerole,
60
+ # virtual_chassis=virtual_chassis,
61
+ # vc_position=1,
62
+ # )
63
+ # cluster_member = Device.objects.create(
64
+ # name="Cluster Device",
65
+ # site=site,
66
+ # device_type=devicetype,
67
+ # device_role=devicerole,
68
+ # )
69
+ # clustertype = ClusterType.objects.create(name="Cluster Type 1")
70
+ # cluster = Cluster.objects.create(
71
+ # name="Cluster 1",
72
+ # type=clustertype,
73
+ # )
74
74
virtual_machine = VirtualMachine .objects .create (name = "VirtualMachine 1" )
75
+ virtual_machine .save ()
75
76
prefix = Prefix .objects .create (prefix = "10.0.0.0/8" )
76
77
77
78
@@ -256,12 +257,12 @@ def setUpTestData(cls):
256
257
VMInterface (name = "Interface 2" , virtual_machine = virtual_machine ),
257
258
)
258
259
)
259
- prefixes = Prefix .objects .bulk_create (
260
- (
261
- Prefix (prefix = IPNetwork ("10.0.0.0/24" )),
262
- Prefix (prefix = IPNetwork ("192.168.1.0/24" )),
263
- )
264
- )
260
+ # prefixes = Prefix.objects.bulk_create(
261
+ # (
262
+ # Prefix(prefix=IPNetwork("10.0.0.0/24")),
263
+ # Prefix(prefix=IPNetwork("192.168.1.0/24")),
264
+ # )
265
+ # )
265
266
266
267
def test_acl_interface_assignment_success (self ):
267
268
"""
@@ -272,18 +273,36 @@ def test_acl_interface_assignment_success(self):
272
273
comments = "STANDARD_ACL" ,
273
274
type = "standard" ,
274
275
default_action = "permit" ,
275
- assigned_object_id = 1 ,
276
- assigned_object_type = ContentType .objects .get_for_model (Device ),
276
+ assigned_object = Device .objects .first (),
277
277
)
278
278
device_acl .save ()
279
279
acl_device_interface = ACLInterfaceAssignment (
280
280
access_list = device_acl ,
281
281
direction = "ingress" ,
282
- assigned_object_id = 1 ,
283
- assigned_object_type = ContentType .objects .get_for_model (Interface ),
282
+ assigned_object = Interface .objects .first (),
284
283
)
285
284
acl_device_interface .full_clean ()
286
285
286
+ def test_aclinterface_assignment_fail (self ):
287
+ """
288
+ Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the vminterface and direction.
289
+ """
290
+ device_acl = AccessList (
291
+ name = "STANDARD_ACL" ,
292
+ comments = "STANDARD_ACL" ,
293
+ type = "standard" ,
294
+ default_action = "permit" ,
295
+ assigned_object = Device .objects .first (),
296
+ )
297
+ device_acl .save ()
298
+ acl_vm_interface = ACLInterfaceAssignment (
299
+ access_list = device_acl ,
300
+ direction = "ingress" ,
301
+ assigned_object = VMInterface .objects .first (),
302
+ )
303
+ with self .assertRaises (ValidationError ):
304
+ acl_vm_interface .full_clean ()
305
+
287
306
def test_acl_vminterface_assignment_success (self ):
288
307
"""
289
308
Test that ACLInterfaceAssignment passes validation if the ACL is assigned to the host and not already assigned to the vminterface and direction.
0 commit comments