Skip to content

Commit 67f5509

Browse files
stephenfinIlia Petrov
authored andcommitted
tests: Add functional test for adding, removing SGs
The fix is in openstacksdk. Let's test it here though. Change-Id: I661e6d66c8196e8c9ca8b9cda3d08e756e3d5877 Signed-off-by: Stephen Finucane <stephenfin@redhat.com> Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/963945 Related-bug: #2089821 (cherry picked from commit e736394)
1 parent f9cc901 commit 67f5509

File tree

1 file changed

+87
-1
lines changed

1 file changed

+87
-1
lines changed

openstackclient/tests/functional/compute/v2/test_server.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ def test_server_add_remove_port(self):
12951295
)
12961296
if ip_address in cmd_output['addresses']['private']:
12971297
# Hang out for a bit and try again
1298-
print('retrying add port check')
1298+
print('retrying remove port check')
12991299
wait_time += 10
13001300
time.sleep(10)
13011301
else:
@@ -1367,6 +1367,92 @@ def test_server_add_fixed_ip(self):
13671367
addresses = cmd_output['addresses']['private']
13681368
self.assertIn(ip_address, addresses)
13691369

1370+
def test_server_add_remove_security_group(self):
1371+
name = uuid.uuid4().hex
1372+
cmd_output = self.openstack(
1373+
'server create '
1374+
+ '--network private '
1375+
+ '--flavor '
1376+
+ self.flavor_name
1377+
+ ' '
1378+
+ '--image '
1379+
+ self.image_name
1380+
+ ' '
1381+
+ '--wait '
1382+
+ name,
1383+
parse_output=True,
1384+
)
1385+
1386+
self.assertIsNotNone(cmd_output['id'])
1387+
self.assertEqual(name, cmd_output['name'])
1388+
self.addCleanup(self.openstack, 'server delete --wait ' + name)
1389+
1390+
# create security group
1391+
security_group_name = uuid.uuid4().hex
1392+
1393+
cmd_output = self.openstack(
1394+
'security group list',
1395+
parse_output=True,
1396+
)
1397+
self.assertNotIn(security_group_name, cmd_output)
1398+
1399+
cmd_output = self.openstack(
1400+
'security group create ' + security_group_name,
1401+
parse_output=True,
1402+
)
1403+
self.assertIsNotNone(cmd_output['id'])
1404+
self.addCleanup(
1405+
self.openstack, 'security group delete ' + security_group_name
1406+
)
1407+
1408+
# add security group to server, assert the name of the security group
1409+
# appears
1410+
self.openstack(
1411+
'server add security group ' + name + ' ' + security_group_name
1412+
)
1413+
1414+
wait_time = 0
1415+
while wait_time < 60:
1416+
cmd_output = self.openstack(
1417+
'server show ' + name,
1418+
parse_output=True,
1419+
)
1420+
if security_group_name not in [
1421+
x['name'] for x in cmd_output['security_groups']
1422+
]:
1423+
# Hang out for a bit and try again
1424+
print('retrying add security group check')
1425+
wait_time += 10
1426+
time.sleep(10)
1427+
else:
1428+
break
1429+
security_groups = [x['name'] for x in cmd_output['security_groups']]
1430+
self.assertIn(security_group_name, security_groups)
1431+
1432+
# remove security group, assert the name of the security group doesn't
1433+
# appear
1434+
self.openstack(
1435+
'server remove security group ' + name + ' ' + security_group_name
1436+
)
1437+
1438+
wait_time = 0
1439+
while wait_time < 60:
1440+
cmd_output = self.openstack(
1441+
'server show ' + name,
1442+
parse_output=True,
1443+
)
1444+
if security_group_name not in [
1445+
x['name'] for x in cmd_output['security_groups']
1446+
]:
1447+
# Hang out for a bit and try again
1448+
print('retrying remove security group check')
1449+
wait_time += 10
1450+
time.sleep(10)
1451+
else:
1452+
break
1453+
security_groups = [x['name'] for x in cmd_output['security_groups']]
1454+
self.assertNotIn(security_group_name, security_groups)
1455+
13701456
def test_server_add_remove_volume(self):
13711457
volume_wait_for = volume_common.BaseVolumeTests.wait_for_status
13721458

0 commit comments

Comments
 (0)