1717import os
1818import sys
1919import pytest
20+ import shutil
2021import unittest
2122
2223from logging import DEBUG , INFO
2324from netsim_wrapper import main
24- from netsim_wrapper . nwrap import NWrap
25+ from netsim_wrapper import utils
2526
2627from _pytest .monkeypatch import MonkeyPatch
2728
@@ -188,25 +189,88 @@ def test_nwrap_create_device_json_with_file(self):
188189 assert msg in messages
189190 self ._caplog .clear ()
190191
192+ class TestNwrapTemplateData :
193+ @classmethod
194+ def network (cls ):
195+ return {
196+ "nso-packages-path" : "./nso-run/packages" ,
197+ "download-neds" : True ,
198+ "neds" : [
199+ "https://earth.tail-f.com:8443/ncs-pkgs/cisco-ios/5.7.1/ncs-5.7.1-cisco-ios-6.79.signed.bin"
200+ ],
201+ "compile-neds" : True ,
202+ "start-devices" : True ,
203+ "add-to-nso" : True ,
204+ "add-authgroup-to-nso" : True ,
205+ "authgroup" : {
206+ "type" : "system"
207+ },
208+ "device-mode" : {
209+ "prefix-based" : {
210+ "cisco-ios-6.56" : {
211+ "count" : 2 ,
212+ "prefix" : "network-ios"
213+ }
214+ }
215+ },
216+ "load-day0-config" : True ,
217+ "config-path" : "./day0/" ,
218+ "config-files" : [
219+ "interface_loopback10.cfg" ,
220+ "interface_loopback100.cfg" ,
221+ ]
222+ }
223+
224+ @classmethod
225+ def device (cls ):
226+ return {
227+ "nso-packages-path" : "./nso-run/packages" ,
228+ "download-neds" : True ,
229+ "neds" : [
230+ "https://earth.tail-f.com:8443/ncs-pkgs/cisco-ios/5.7.1/ncs-5.7.1-cisco-ios-6.79.signed.bin"
231+ ],
232+ "compile-neds" : True ,
233+ "start-devices" : True ,
234+ "add-to-nso" : True ,
235+ "add-authgroup-to-nso" : True ,
236+ "authgroup" : {
237+ "type" : "custom" ,
238+ "path" : "./custom_authgroup.xml"
239+ },
240+ "device-mode" : {
241+ "name-based" : {
242+ "cisco-ios-6.56" : [
243+ "device-ios0" ,
244+ "device-ios1"
245+ ]
246+ }
247+ },
248+ "load-day0-config" : True ,
249+ "config-path" : "./day0/" ,
250+ "config-files" : [
251+ "interface_loopback10.cfg" ,
252+ "interface_loopback100.cfg" ,
253+ ]
254+ }
191255
192256# @pytest.mark.run
193- class TestNwrapTemplateLoadNetwork (unittest .TestCase ):
257+ class TestNwrapTemplateLoad (unittest .TestCase ):
258+ yaml = utils .Yaml ()
259+ json = utils .Json ()
194260
195261 def setUp (self ):
196262 self .monkeypatch = MonkeyPatch ()
197263 self .args = ['nwrap' ]
198- files = ['template.json' , 'template.yaml' , 'basic_template.json' , 'basic_template.yaml' ]
199264
200265 def tearDown (self ) -> None :
201266 gc .collect ()
202- files = ['template.json' , 'template.yaml' , 'basic_template.json' , 'basic_template.yaml' ]
203- [os .unlink (each ) for each in files if os .path .exists (each )]
204267 self .monkeypatch .undo ()
205268 return super ().tearDown ()
206269
207270 @property
208271 def applyPatch (self ):
209272 self .monkeypatch .setattr (sys , 'argv' , self .args )
273+ self .monkeypatch .setattr (utils .Download , 'get' , lambda s , u , p , l : None )
210274
211275 @pytest .fixture (autouse = True )
212276 def inject_fixtures (self , capfd ):
@@ -216,3 +280,20 @@ def inject_fixtures(self, capfd):
216280 def inject_fixtures_log (self , caplog ):
217281 self ._caplog = caplog
218282
283+ def test_nwrap_create_network_json (self ):
284+ self .json .dump (TestNwrapTemplateData .network (), 'network.json' )
285+ command = 'template load network.json' .split ()
286+ self .args .extend (command )
287+ self .applyPatch
288+ # try:
289+ # main.nwrap()
290+ # except SystemExit as e:
291+ # assert type(e) == SystemExit
292+ # finally:
293+ # out, err = self._capfd.readouterr()
294+ # assert out.strip() == ''
295+ # # TODO: need to add some validations
296+ # messages = [ x.message for x in self._caplog.get_records('call') if x.levelno == INFO ]
297+ # msg = 'update the base YAML template file: template.yaml'
298+ # assert msg in messages
299+ # self._caplog.clear()
0 commit comments