Skip to content

Commit e44d801

Browse files
committed
tests: Check for DHCP agents first in DHCP test
If there are no agents with type=dhcp, the neutron-dhcp-agent service is likely not enabled on the deployment. Change-Id: I1253f35e71cf996c559f2a2d8d1d8cde6b41a519 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 1678f87 commit e44d801

2 files changed

Lines changed: 32 additions & 22 deletions

File tree

openstackclient/tests/functional/network/v2/test_network.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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):

openstackclient/tests/functional/network/v2/test_network_agent.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,34 @@ def test_network_dhcp_agent_list(self):
8888
if not self.is_extension_enabled("dhcp_agent_scheduler"):
8989
self.skipTest("No dhcp_agent_scheduler extension present")
9090

91+
# Get DHCP Agent ID
92+
cmd_output = self.openstack(
93+
'network agent list --agent-type dhcp',
94+
parse_output=True,
95+
)
96+
if not cmd_output:
97+
self.skipTest("No agents with type=dhcp available")
98+
99+
agent_id = cmd_output[0]['ID']
100+
91101
name1 = uuid.uuid4().hex
92-
cmd_output1 = self.openstack(
102+
cmd_output = self.openstack(
93103
'network create --description aaaa %s' % name1,
94104
parse_output=True,
95105
)
96106

97107
self.addCleanup(self.openstack, 'network delete %s' % name1)
98108

99109
# Get network ID
100-
network_id = cmd_output1['id']
101-
102-
# Get DHCP Agent ID
103-
cmd_output2 = self.openstack(
104-
'network agent list --agent-type dhcp',
105-
parse_output=True,
106-
)
107-
agent_id = cmd_output2[0]['ID']
110+
network_id = cmd_output['id']
108111

109112
# Add Agent to Network
110113
self.openstack(
111114
'network agent add network --dhcp %s %s' % (agent_id, network_id)
112115
)
113116

114117
# Test network agent list --network
115-
cmd_output3 = self.openstack(
118+
cmd_output = self.openstack(
116119
'network agent list --network %s' % network_id,
117120
parse_output=True,
118121
)
@@ -125,7 +128,7 @@ def test_network_dhcp_agent_list(self):
125128
)
126129

127130
# Assert
128-
col_name = [x["ID"] for x in cmd_output3]
131+
col_name = [x["ID"] for x in cmd_output]
129132
self.assertIn(agent_id, col_name)
130133

131134
def test_network_agent_list_routers(self):

0 commit comments

Comments
 (0)