From 7b2c6a7ce618764a15aa303b299a24b1c7715364 Mon Sep 17 00:00:00 2001 From: "Sean M. Collins" Date: Fri, 4 Dec 2015 12:06:23 -0500 Subject: [PATCH] Create unit tests to test v4 and v6 security group rules The branch for if classifier_type is model.Ipv4Classifier was not covered by a unit test, so a typo slipped through. My bad. Change-Id: Id1ec95d6131226ee8a0055e35f98c24b846499a4 --- neutron_classifier/db/api.py | 2 +- neutron_classifier/tests/test_db_api.py | 38 ++++++++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/neutron_classifier/db/api.py b/neutron_classifier/db/api.py index bf2d4e3..2afd866 100644 --- a/neutron_classifier/db/api.py +++ b/neutron_classifier/db/api.py @@ -112,7 +112,7 @@ def convert_classifier_group_to_security_group(context, classifier_group_id): classifier.ethertype) continue if classifier_type is models.Ipv4Classifier: - sg_dict['protocol'] = classifier.protcol + sg_dict['protocol'] = classifier.protocol continue if classifier_type is models.Ipv6Classifier: sg_dict['protocol'] = classifier.next_header diff --git a/neutron_classifier/tests/test_db_api.py b/neutron_classifier/tests/test_db_api.py index 3f7bd92..80aa22f 100644 --- a/neutron_classifier/tests/test_db_api.py +++ b/neutron_classifier/tests/test_db_api.py @@ -20,15 +20,18 @@ from oslo_utils import uuidutils from oslotest import base -FAKE_SG_RULE = {'direction': 'INGRESS', 'protocol': 'tcp', 'ethertype': 'IPv6', - 'tenant_id': 'fake_tenant', 'port_range_min': 80, - 'port_range_max': 80, 'remote_ip_prefix': 'fddf:cb3b:bc4::/48', - } +FAKE_SG_RULE_V6 = {'direction': 'INGRESS', 'protocol': 'tcp', 'ethertype': + 'IPv6', 'tenant_id': 'fake_tenant', 'port_range_min': 80, + 'port_range_max': 80, 'remote_ip_prefix': + 'fddf:cb3b:bc4::/48', } -FAKE_SG = {'name': 'fake security group', - 'tenant_id': uuidutils.generate_uuid(), - 'description': 'this is fake', - 'security_group_rules': [FAKE_SG_RULE]} +FAKE_SG_RULE_V4 = {'direction': 'INGRESS', 'protocol': 'tcp', 'ethertype': + 'IPv4', 'tenant_id': 'fake_tenant', 'port_range_min': 80, + 'port_range_max': 80, 'remote_ip_prefix': '10.0.0.0/8', } + +FAKE_SG_V6 = {'name': 'fake security group', 'tenant_id': + uuidutils.generate_uuid(), 'description': 'this is fake', + 'security_group_rules': [FAKE_SG_RULE_V6]} class ClassifierTestContext(object): @@ -64,11 +67,12 @@ class DbApiTestCase(base.BaseTestCase): api.create_classifier_chain(cg, [ipc]) self.assertGreater(len(cg.classifier_chain), 0) - def test_convert_security_group_rule_to_classifier(self): + def _test_convert_security_group_rule_to_classifier(self, + security_group_rule): # TODO(sc68cal) make this not call session.commit directly cg = self._create_classifier_group('security-group') api.convert_security_group_rule_to_classifier(self.context, - FAKE_SG_RULE, cg) + security_group_rule, cg) # Save to the database self.context.session.add(cg) self.context.session.commit() @@ -77,6 +81,12 @@ class DbApiTestCase(base.BaseTestCase): cg = api.get_classifier_group(self.context, cg.id) self.assertGreater(len(cg.classifier_chain), 0) + def test_convert_security_group_rule_v4_to_classifier(self): + self._test_convert_security_group_rule_to_classifier(FAKE_SG_RULE_V4) + + def test_convert_security_group_rule_v6_to_classifier(self): + self._test_convert_security_group_rule_to_classifier(FAKE_SG_RULE_V6) + def test_convert_firewall_rule_to_classifier(self): firewall_rule = {'protocol': 'foo', 'ip_version': 6, @@ -95,16 +105,16 @@ class DbApiTestCase(base.BaseTestCase): def test_convert_security_group_to_classifier_chain(self): result = api.convert_security_group_to_classifier(self.context, - FAKE_SG) + FAKE_SG_V6) self.assertIsNotNone(result) def test_convert_classifier_chain_to_security_group(self): classifier_id = api.convert_security_group_to_classifier( - self.context, FAKE_SG).id + self.context, FAKE_SG_V6).id result = api.convert_classifier_group_to_security_group(self.context, classifier_id) - result['tenant_id'] = FAKE_SG_RULE['tenant_id'] - self.assertEqual(FAKE_SG_RULE, result) + result['tenant_id'] = FAKE_SG_RULE_V6['tenant_id'] + self.assertEqual(FAKE_SG_RULE_V6, result) def test_convert_classifier_chain_to_firewall_policy(self): pass