From d6380cca427532d1af13c753ec0e9976276f9403 Mon Sep 17 00:00:00 2001 From: Roey Chen Date: Mon, 9 Nov 2015 03:11:13 -0800 Subject: [PATCH] Adding security-groups unittests This patch adds two new security-groups unittests: - test_create_port_with_multiple_security_groups - test_create_port_with_no_security_groups Closes-Bug: #1514397 Change-Id: Icebd6737f0e7997b0cbf01526b0c7b66376fbf44 --- .../unit/extensions/test_securitygroup.py | 46 ++++++++++++++----- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/neutron/tests/unit/extensions/test_securitygroup.py b/neutron/tests/unit/extensions/test_securitygroup.py index bf9be380d..6ff3ed0f3 100644 --- a/neutron/tests/unit/extensions/test_securitygroup.py +++ b/neutron/tests/unit/extensions/test_securitygroup.py @@ -1161,6 +1161,28 @@ class TestSecurityGroups(SecurityGroupDBTestCase): ('port_range_max', 'desc'), 2, 2, query_params='direction=egress') + def test_create_port_with_multiple_security_groups(self): + with self.network() as n: + with self.subnet(n): + with self.security_group() as sg1: + with self.security_group() as sg2: + res = self._create_port( + self.fmt, n['network']['id'], + security_groups=[sg1['security_group']['id'], + sg2['security_group']['id']]) + port = self.deserialize(self.fmt, res) + self.assertEqual(2, len( + port['port'][ext_sg.SECURITYGROUPS])) + self._delete('ports', port['port']['id']) + + def test_create_port_with_no_security_groups(self): + with self.network() as n: + with self.subnet(n): + res = self._create_port(self.fmt, n['network']['id'], + security_groups=[]) + port = self.deserialize(self.fmt, res) + self.assertEqual([], port['port'][ext_sg.SECURITYGROUPS]) + def test_update_port_with_security_group(self): with self.network() as n: with self.subnet(n): @@ -1195,17 +1217,19 @@ class TestSecurityGroups(SecurityGroupDBTestCase): def test_update_port_with_multiple_security_groups(self): with self.network() as n: - with self.subnet(n): - with self.security_group() as sg1: - with self.security_group() as sg2: - res = self._create_port( - self.fmt, n['network']['id'], - security_groups=[sg1['security_group']['id'], - sg2['security_group']['id']]) - port = self.deserialize(self.fmt, res) - self.assertEqual(len( - port['port'][ext_sg.SECURITYGROUPS]), 2) - self._delete('ports', port['port']['id']) + with self.subnet(n) as s: + with self.port(s) as port: + with self.security_group() as sg1: + with self.security_group() as sg2: + data = {'port': {ext_sg.SECURITYGROUPS: + [sg1['security_group']['id'], + sg2['security_group']['id']]}} + req = self.new_update_request( + 'ports', data, port['port']['id']) + port = self.deserialize( + self.fmt, req.get_response(self.api)) + self.assertEqual( + 2, len(port['port'][ext_sg.SECURITYGROUPS])) def test_update_port_remove_security_group_empty_list(self): with self.network() as n: -- 2.45.2