From 428fee9748499ff6606016af41b85bf946f06b44 Mon Sep 17 00:00:00 2001 From: Trevor Vardeman Date: Wed, 24 Feb 2016 17:25:25 -0600 Subject: [PATCH] Use unique SNI identifier when building data model The to_data_model method previously labeled an SNI container without a unique identifier, using the "listener_id". Now it will use the "tls_container_id" to ensure it is truly unique. Change-Id: I174f8f650fc51668fd7b70e845d4706916f06295 --- octavia/db/base_models.py | 5 ++++- octavia/tests/functional/db/test_models.py | 7 +++++-- octavia/tests/functional/db/test_repositories.py | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/octavia/db/base_models.py b/octavia/db/base_models.py index f15bd00ed6..1362bae051 100644 --- a/octavia/db/base_models.py +++ b/octavia/db/base_models.py @@ -34,12 +34,15 @@ class OctaviaBase(models.ModelBase): return obj.__class__.__name__ + obj.id elif obj.__class__.__name__ in ['SessionPersistence', 'HealthMonitor']: return obj.__class__.__name__ + obj.pool_id - elif obj.__class__.__name__ in ['ListenerStatistics', 'SNI']: + elif obj.__class__.__name__ in ['ListenerStatistics']: return obj.__class__.__name__ + obj.listener_id elif obj.__class__.__name__ in ['VRRPGroup', 'Vip']: return obj.__class__.__name__ + obj.load_balancer_id elif obj.__class__.__name__ in ['AmphoraHealth']: return obj.__class__.__name__ + obj.amphora_id + elif obj.__class__.__name__ in ['SNI']: + return (obj.__class__.__name__ + + obj.listener_id + obj.tls_container_id) else: raise NotImplementedError diff --git a/octavia/tests/functional/db/test_models.py b/octavia/tests/functional/db/test_models.py index 0da8a55c39..8149989d72 100644 --- a/octavia/tests/functional/db/test_models.py +++ b/octavia/tests/functional/db/test_models.py @@ -779,10 +779,10 @@ class L7RuleModelTest(base.OctaviaDBTestBase, ModelTestMixin): self.assertIsInstance(new_l7rule.l7policy, models.L7Policy) -class DataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin): +class TestDataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin): def setUp(self): - super(DataModelConversionTest, self).setUp() + super(TestDataModelConversionTest, self).setUp() self.lb = self.create_load_balancer(self.session) self.pool = self.create_pool(self.session, load_balancer_id=self.lb.id) self.hm = self.create_health_monitor(self.session, self.pool.id) @@ -821,6 +821,9 @@ class DataModelConversionTest(base.OctaviaDBTestBase, ModelTestMixin): return obj.__class__.__name__ + obj.load_balancer_id elif obj.__class__.__name__ in ['AmphoraHealth']: return obj.__class__.__name__ + obj.amphora_id + elif obj.__class__.__name__ in ['SNI']: + return (obj.__class__.__name__ + + obj.listener_id + obj.tls_container_id) else: raise NotImplementedError diff --git a/octavia/tests/functional/db/test_repositories.py b/octavia/tests/functional/db/test_repositories.py index 60c97ab543..ae89b9ebd5 100644 --- a/octavia/tests/functional/db/test_repositories.py +++ b/octavia/tests/functional/db/test_repositories.py @@ -645,6 +645,20 @@ class ListenerRepositoryTest(BaseRepositoryTest): self.assertRaises(exceptions.NotFound, self.create_listener, self.FAKE_UUID_1, 80, default_pool_id=pool.id) + def test_create_2_sni_containers(self): + listener = self.create_listener(self.FAKE_UUID_1, 80) + container1 = {'listener_id': listener.id, + 'tls_container_id': self.FAKE_UUID_1} + container2 = {'listener_id': listener.id, + 'tls_container_id': self.FAKE_UUID_2} + container1_dm = models.SNI(**container1) + container2_dm = models.SNI(**container2) + self.sni_repo.create(self.session, **container1) + self.sni_repo.create(self.session, **container2) + new_listener = self.listener_repo.get(self.session, id=listener.id) + self.assertIn(container1_dm, new_listener.sni_containers) + self.assertIn(container2_dm, new_listener.sni_containers) + def test_update(self): name_change = "new_listener_name" listener = self.create_listener(self.FAKE_UUID_1, 80)