@@ -405,7 +405,9 @@ def test_auto_create_cert_with_long_device_name(self):
405405 vpn = self ._create_vpn (organization = org )
406406 d = self ._create_device (organization = org , name = device_name )
407407 c = self ._create_config (device = d )
408- client = VpnClient (vpn = vpn , config = c , auto_cert = True )
408+ client = VpnClient (
409+ vpn = vpn , config = c , auto_cert = True , template = self ._create_template ()
410+ )
409411 client .full_clean ()
410412 client .save ()
411413 # The last 9 characters gets truncated and replaced with unique id
@@ -818,10 +820,17 @@ def test_vpn_peers_changed(self):
818820class TestVxlan (BaseTestVpn , TestVxlanWireguardVpnMixin , TestCase ):
819821 def test_vxlan_config_creation (self ):
820822 tunnel , subnet = self ._create_vxlan_tunnel ()
823+ template = self ._create_template (
824+ name = 'vxlan-wireguard' ,
825+ type = 'vpn' ,
826+ vpn = tunnel ,
827+ organization = tunnel .organization ,
828+ auto_cert = True ,
829+ )
821830 with self .subTest ('vni 1' ):
822831 d1 = self ._create_device ()
823832 c1 = self ._create_config (device = d1 )
824- client = VpnClient (vpn = tunnel , config = c1 , auto_cert = True )
833+ client = VpnClient (vpn = tunnel , config = c1 , auto_cert = True , template = template )
825834 client .full_clean ()
826835 client .save ()
827836 client .refresh_from_db ()
@@ -830,7 +839,7 @@ def test_vxlan_config_creation(self):
830839 with self .subTest ('vni 2' ):
831840 d2 = self ._create_device (name = 'd2' , mac_address = '16:DB:7F:E8:50:01' )
832841 c2 = self ._create_config (device = d2 )
833- client = VpnClient (vpn = tunnel , config = c2 , auto_cert = True )
842+ client = VpnClient (vpn = tunnel , config = c2 , auto_cert = True , template = template )
834843 client .full_clean ()
835844 client .save ()
836845 client .refresh_from_db ()
@@ -853,23 +862,32 @@ def test_vxlan_config_creation(self):
853862 with self .subTest ('auto_cert=False' ):
854863 d3 = self ._create_device (name = 'd3' , mac_address = '16:DB:7F:E8:50:03' )
855864 c3 = self ._create_config (device = d3 )
856- client = VpnClient (vpn = tunnel , config = c3 , auto_cert = False )
865+ client = VpnClient (
866+ vpn = tunnel , config = c3 , auto_cert = False , template = template
867+ )
857868 client .full_clean ()
858869 client .save ()
859870 client .refresh_from_db ()
860871 self .assertEqual (client .vni , None )
861872
862873 def test_duplicate_vxlan_tunnels_same_vni (self ):
863874 tunnel , subnet = self ._create_vxlan_tunnel ()
875+ template = self ._create_template (
876+ name = 'vxlan-wireguard' ,
877+ type = 'vpn' ,
878+ vpn = tunnel ,
879+ organization = tunnel .organization ,
880+ auto_cert = True ,
881+ )
864882 d1 = self ._create_device ()
865883 c1 = self ._create_config (device = d1 )
866- client = VpnClient (vpn = tunnel , config = c1 , vni = 1 )
884+ client = VpnClient (vpn = tunnel , config = c1 , vni = 1 , template = template )
867885 client .full_clean ()
868886 client .save ()
869887 with self .subTest ('Test server configuration does not define VNI' ):
870888 d2 = self ._create_device (name = 'd2' , mac_address = '16:DB:7F:E8:50:01' )
871889 c2 = self ._create_config (device = d2 )
872- client = VpnClient (vpn = tunnel , config = c2 , vni = 1 )
890+ client = VpnClient (vpn = tunnel , config = c2 , vni = 1 , template = template )
873891 with self .assertRaises (ValidationError ) as context_manager :
874892 client .full_clean ()
875893 message_dict = context_manager .exception .message_dict
@@ -883,7 +901,7 @@ def test_duplicate_vxlan_tunnels_same_vni(self):
883901 tunnel .config ['vxlan' ] = [{'interface' : 'vxlan1' , 'vni' : 1 }]
884902 tunnel .full_clean ()
885903 tunnel .save ()
886- client = VpnClient (vpn = tunnel , config = c2 , vni = 1 )
904+ client = VpnClient (vpn = tunnel , config = c2 , vni = 1 , template = template )
887905 client .full_clean ()
888906 client .save ()
889907
@@ -1573,13 +1591,6 @@ def _reset_mocks():
15731591 organization = zt_vpn1 .organization ,
15741592 auto_cert = True ,
15751593 )
1576- zt_1_copy = self ._create_template (
1577- name = 'test-zt-template-1-copy' ,
1578- type = 'vpn' ,
1579- vpn = zt_vpn1 ,
1580- organization = zt_vpn1 .organization ,
1581- auto_cert = True ,
1582- )
15831594 zt2 = self ._create_template (
15841595 name = 'test-zt-template-2' ,
15851596 type = 'vpn' ,
@@ -1655,27 +1666,6 @@ def _reset_mocks():
16551666 self .assertEqual (mock_requests .post .call_count , 1 )
16561667 _reset_mocks ()
16571668
1658- with self .subTest (
1659- (
1660- 'Test zt no identity generation when same zt vpn server '
1661- 'vpn client template is already applied to the device'
1662- )
1663- ):
1664- device .config .templates .add (zt_1_copy )
1665- # No new zt vpn client object
1666- self .assertEqual (vpnclient_qs .count (), 1 )
1667- # Make sure only previously applied 'zt_vpn1' vpn client object is exist
1668- self .assertEqual (vpnclient_qs .first ().vpn , zt_vpn1 )
1669- self .assertEqual (IpAddress .objects .count (), 4 )
1670- # Make sure subprocess is not called for identity generation
1671- self .assertEqual (mock_subprocess .run .call_count , 0 )
1672- # No configuration changed
1673- self .assertEqual (mock_info .call_count , 0 )
1674- self .assertEqual (mock_warn .call_count , 0 )
1675- self .assertEqual (mock_error .call_count , 0 )
1676- self .assertEqual (mock_requests .post .call_count , 0 )
1677- _reset_mocks ()
1678-
16791669 with self .subTest (
16801670 (
16811671 'Test zt no identity generation when different '
0 commit comments