@@ -323,34 +323,41 @@ def test_network_list(self):
323323 def test_network_dhcp_agent (self ):
324324 if not self .haz_network :
325325 self .skipTest ("No Network service present" )
326+
327+ if not self .is_extension_enabled ("agent" ):
328+ self .skipTest ("No dhcp_agent_scheduler extension present" )
329+
326330 if not self .is_extension_enabled ("dhcp_agent_scheduler" ):
327331 self .skipTest ("No dhcp_agent_scheduler extension present" )
328332
333+ # Get DHCP Agent ID
334+ cmd_output = self .openstack (
335+ 'network agent list --agent-type dhcp' ,
336+ parse_output = True ,
337+ )
338+ if not cmd_output :
339+ self .skipTest ("No agents with type=dhcp available" )
340+
341+ agent_id = cmd_output [0 ]['ID' ]
342+
329343 name1 = uuid .uuid4 ().hex
330- cmd_output1 = self .openstack (
344+ cmd_output = self .openstack (
331345 'network create --description aaaa %s' % name1 ,
332346 parse_output = True ,
333347 )
334348
335349 self .addCleanup (self .openstack , 'network delete %s' % name1 )
336350
337351 # Get network ID
338- network_id = cmd_output1 ['id' ]
339-
340- # Get DHCP Agent ID
341- cmd_output2 = self .openstack (
342- 'network agent list --agent-type dhcp' ,
343- parse_output = True ,
344- )
345- agent_id = cmd_output2 [0 ]['ID' ]
352+ network_id = cmd_output ['id' ]
346353
347354 # Add Agent to Network
348355 self .openstack (
349356 'network agent add network --dhcp %s %s' % (agent_id , network_id )
350357 )
351358
352359 # Test network list --agent
353- cmd_output3 = self .openstack (
360+ cmd_output = self .openstack (
354361 'network list --agent %s' % agent_id ,
355362 parse_output = True ,
356363 )
@@ -363,7 +370,7 @@ def test_network_dhcp_agent(self):
363370 )
364371
365372 # Assert
366- col_name = [x ["ID" ] for x in cmd_output3 ]
373+ col_name = [x ["ID" ] for x in cmd_output ]
367374 self .assertIn (network_id , col_name )
368375
369376 def test_network_set (self ):
0 commit comments