@@ -77,8 +77,8 @@ def __init__(self, dvs):
7777
7878class ApplDbValidator (object ):
7979 def __init__ (self , dvs ):
80- appl_db = swsscommon .DBConnector (swsscommon .APPL_DB , dvs .redis_sock , 0 )
81- self .neighTbl = swsscommon .Table (appl_db , "NEIGH_TABLE" )
80+ self . appl_db = swsscommon .DBConnector (swsscommon .APPL_DB , dvs .redis_sock , 0 )
81+ self .neighTbl = swsscommon .Table (self . appl_db , "NEIGH_TABLE" )
8282
8383 def __del__ (self ):
8484 # Make sure no neighbors on physical interfaces
@@ -155,13 +155,14 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
155155 'vrfmgrd' ,
156156 'portmgrd' ]
157157 self .syncd = ['syncd' ]
158- self .rtd = ['fpmsyncd' , 'zebra' ]
158+ self .rtd = ['fpmsyncd' , 'zebra' , 'staticd' ]
159159 self .teamd = ['teamsyncd' , 'teammgrd' ]
160160 # FIXME: We need to verify that NAT processes are running, once the
161161 # appropriate changes are merged into sonic-buildimage
162162 # self.natd = ['natsyncd', 'natmgrd']
163163 self .alld = self .basicd + self .swssd + self .syncd + self .rtd + self .teamd # + self.natd
164164 self .client = docker .from_env ()
165+ self .appldb = None
165166
166167 if subprocess .check_call (["/sbin/modprobe" , "team" ]) != 0 :
167168 raise NameError ("cannot install kernel team module" )
@@ -199,7 +200,7 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
199200 self .mount = "/var/run/redis-vs/{}" .format (ctn_sw_name )
200201
201202 self .net_cleanup ()
202- self .restart ()
203+ self .ctn_restart ()
203204 else :
204205 self .ctn_sw = self .client .containers .run ('debian:jessie' , privileged = True , detach = True ,
205206 command = "bash" , stdin_open = True )
@@ -224,8 +225,20 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
224225 network_mode = "container:%s" % self .ctn_sw .name ,
225226 volumes = { self .mount : { 'bind' : '/var/run/redis' , 'mode' : 'rw' } })
226227
227- self .appldb = None
228228 self .redis_sock = self .mount + '/' + "redis.sock"
229+ self .check_ctn_status_and_db_connect ()
230+
231+ def destroy (self ):
232+ if self .appldb :
233+ del self .appldb
234+ if self .cleanup :
235+ self .ctn .remove (force = True )
236+ self .ctn_sw .remove (force = True )
237+ os .system ("rm -rf {}" .format (self .mount ))
238+ for s in self .servers :
239+ s .destroy ()
240+
241+ def check_ctn_status_and_db_connect (self ):
229242 try :
230243 # temp fix: remove them once they are moved to vs start.sh
231244 self .ctn .exec_run ("sysctl -w net.ipv6.conf.default.disable_ipv6=0" )
@@ -239,15 +252,6 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
239252 self .destroy ()
240253 raise
241254
242- def destroy (self ):
243- if self .appldb :
244- del self .appldb
245- if self .cleanup :
246- self .ctn .remove (force = True )
247- self .ctn_sw .remove (force = True )
248- os .system ("rm -rf {}" .format (self .mount ))
249- for s in self .servers :
250- s .destroy ()
251255
252256 def check_ready (self , timeout = 30 ):
253257 '''check if all processes in the dvs is ready'''
@@ -314,15 +318,22 @@ def net_cleanup(self):
314318 print "remove extra link {}" .format (pname )
315319 return
316320
317- def restart (self ):
321+ def ctn_restart (self ):
318322 self .ctn .restart ()
319323
324+ def restart (self ):
325+ if self .appldb :
326+ del self .appldb
327+ self .ctn_restart ()
328+ self .check_ctn_status_and_db_connect ()
329+
320330 # start processes in SWSS
321331 def start_swss (self ):
322332 cmd = ""
323333 for pname in self .swssd :
324334 cmd += "supervisorctl start {}; " .format (pname )
325335 self .runcmd (['sh' , '-c' , cmd ])
336+ time .sleep (5 )
326337
327338 # stop processes in SWSS
328339 def stop_swss (self ):
@@ -839,3 +850,25 @@ def testlog(request, dvs):
839850 dvs .runcmd ("logger === start test %s ===" % request .node .name )
840851 yield testlog
841852 dvs .runcmd ("logger === finish test %s ===" % request .node .name )
853+
854+ ##################### DPB fixtures ###########################################
855+ @pytest .yield_fixture (scope = "module" )
856+ def create_dpb_config_file (dvs ):
857+ cmd = "sonic-cfggen -j /etc/sonic/init_cfg.json -j /tmp/ports.json --print-data > /tmp/dpb_config_db.json"
858+ dvs .runcmd (['sh' , '-c' , cmd ])
859+ cmd = "mv /etc/sonic/config_db.json /etc/sonic/config_db.json.bak"
860+ dvs .runcmd (cmd )
861+ cmd = "cp /tmp/dpb_config_db.json /etc/sonic/config_db.json"
862+ dvs .runcmd (cmd )
863+
864+ @pytest .yield_fixture (scope = "module" )
865+ def remove_dpb_config_file (dvs ):
866+ cmd = "mv /etc/sonic/config_db.json.bak /etc/sonic/config_db.json"
867+ dvs .runcmd (cmd )
868+
869+ @pytest .yield_fixture (scope = "module" )
870+ def dpb_setup_fixture (dvs ):
871+ create_dpb_config_file (dvs )
872+ dvs .restart ()
873+ yield
874+ remove_dpb_config_file (dvs )
0 commit comments