1313# limitations under the License.
1414#
1515
16+ from requests .exceptions import HTTPError
17+
1618
1719def setup_ntp_test (request , mgmt_root ):
1820 def teardown ():
@@ -23,6 +25,25 @@ def teardown():
2325 return n
2426
2527
28+ def delete_resource (mgmt_root , name , partition ):
29+ try :
30+ s = mgmt_root .tm .sys .ntp .restricts .restrict .load (
31+ name = name , partition = partition
32+ )
33+ except HTTPError as err :
34+ if err .response .status_code != 404 :
35+ raise
36+ return
37+ s .delete ()
38+
39+
40+ def setup_restrict_test (request , mgmt_root , name , partition , ** kwargs ):
41+ def teardown ():
42+ delete_resource (mgmt_root , name , partition )
43+ request .addfinalizer (teardown )
44+ return mgmt_root .tm .sys .ntp .restricts
45+
46+
2647class TestGlobal_Setting (object ):
2748 def test_RUL (self , request , mgmt_root ):
2849 # Load
@@ -40,3 +61,77 @@ def test_RUL(self, request, mgmt_root):
4061 # Refresh
4162 ntp2 .refresh ()
4263 assert ip in ntp2 .servers
64+
65+
66+ class TestNtpRestrictions (object ):
67+ def test_create_base (self , request , mgmt_root ):
68+ ntp = setup_restrict_test (request , mgmt_root ,
69+ name = "r1" , partition = "Common" )
70+
71+ ntp1 = ntp .restrict .create (name = 'r1' , partition = 'Common' )
72+
73+ assert ntp1 .name == 'r1'
74+ assert ntp1 .partition == 'Common'
75+ assert ntp1 .defaultEntry == "disabled"
76+ assert ntp1 .ignore == "disabled"
77+ assert ntp1 .kod == "disabled"
78+ assert ntp1 .limited == "disabled"
79+ assert ntp1 .lowPriorityTrap == "disabled"
80+ assert ntp1 .noModify == "disabled"
81+ assert ntp1 .noPeer == "disabled"
82+ assert ntp1 .noQuery == "disabled"
83+ assert ntp1 .noServePackets == "disabled"
84+ assert ntp1 .noTrap == "disabled"
85+ assert ntp1 .noTrust == "disabled"
86+ assert ntp1 .nonNtpPort == "disabled"
87+ assert ntp1 .ntpPort == "disabled"
88+ assert ntp1 .version == "disabled"
89+ assert ntp1 .kind == 'tm:sys:ntp:restrict:restrictstate'
90+ assert ntp1 .selfLink .startswith (
91+ 'https://localhost/mgmt/tm/sys/ntp/restrict/~Common~r1' )
92+
93+ def test_create_full (self , request , mgmt_root ):
94+ ntp = setup_restrict_test (request , mgmt_root ,
95+ name = "r2" , partition = "Common" )
96+
97+ params = dict (
98+ address = "192.168.1.0" ,
99+ defaultEntry = "enabled" ,
100+ ignore = "enabled" ,
101+ kod = "enabled" ,
102+ limited = "enabled" ,
103+ lowPriorityTrap = "enabled" ,
104+ mask = "255.255.255.0" ,
105+ noModify = "enabled" ,
106+ noPeer = "enabled" ,
107+ noQuery = "enabled" ,
108+ noServePackets = "enabled" ,
109+ noTrap = "disabled" ,
110+ noTrust = "enabled" ,
111+ nonNtpPort = "enabled" ,
112+ ntpPort = "enabled" ,
113+ version = "enabled"
114+ )
115+ ntp1 = ntp .restrict .create (name = 'r2' , partition = 'Common' , ** params )
116+
117+ assert ntp1 .name == 'r2'
118+ assert ntp1 .partition == 'Common'
119+ assert ntp1 .address == "192.168.1.0"
120+ assert ntp1 .defaultEntry == "enabled"
121+ assert ntp1 .ignore == "enabled"
122+ assert ntp1 .kod == "enabled"
123+ assert ntp1 .limited == "enabled"
124+ assert ntp1 .lowPriorityTrap == "enabled"
125+ assert ntp1 .mask == "255.255.255.0"
126+ assert ntp1 .noModify == "enabled"
127+ assert ntp1 .noPeer == "enabled"
128+ assert ntp1 .noQuery == "enabled"
129+ assert ntp1 .noServePackets == "enabled"
130+ assert ntp1 .noTrap == "disabled"
131+ assert ntp1 .noTrust == "enabled"
132+ assert ntp1 .nonNtpPort == "enabled"
133+ assert ntp1 .ntpPort == "enabled"
134+ assert ntp1 .version == "enabled"
135+ assert ntp1 .kind == 'tm:sys:ntp:restrict:restrictstate'
136+ assert ntp1 .selfLink .startswith (
137+ 'https://localhost/mgmt/tm/sys/ntp/restrict/~Common~r2' )
0 commit comments