diff --git a/octavia/db/repositories.py b/octavia/db/repositories.py index f6b0270aac..fe7deb9ba4 100644 --- a/octavia/db/repositories.py +++ b/octavia/db/repositories.py @@ -1244,23 +1244,22 @@ class AmphoraRepository(BaseRepository): :param amphora_id: The amphora id to list the load balancers from :returns: [octavia.common.data_model] """ - with session.begin(): - db_lb = ( - # Get LB records - session.query(models.LoadBalancer) - # Joined to amphora records - .filter(models.LoadBalancer.id == - models.Amphora.load_balancer_id) - # For just this amphora - .filter(models.Amphora.id == amphora_id) - # Where the amphora is not DELETED - .filter(models.Amphora.status != consts.DELETED) - # And the LB is also not DELETED - .filter(models.LoadBalancer.provisioning_status != - consts.DELETED)).first() - if db_lb: - return db_lb.to_data_model() - return None + db_lb = ( + # Get LB records + session.query(models.LoadBalancer) + # Joined to amphora records + .filter(models.LoadBalancer.id == + models.Amphora.load_balancer_id) + # For just this amphora + .filter(models.Amphora.id == amphora_id) + # Where the amphora is not DELETED + .filter(models.Amphora.status != consts.DELETED) + # And the LB is also not DELETED + .filter(models.LoadBalancer.provisioning_status != + consts.DELETED)).first() + if db_lb: + return db_lb.to_data_model() + return None def get_cert_expiring_amphora(self, session): """Retrieves an amphora whose cert is close to expiring.. diff --git a/octavia/tests/functional/db/test_repositories.py b/octavia/tests/functional/db/test_repositories.py index ed0fd3c343..7237399496 100644 --- a/octavia/tests/functional/db/test_repositories.py +++ b/octavia/tests/functional/db/test_repositories.py @@ -3721,21 +3721,12 @@ class AmphoraRepositoryTest(BaseRepositoryTest): self.assertIsInstance(new_amphora, data_models.Amphora) def test_get_lb_for_amphora(self): - # TODO(bzhao) this test will raise error as there are more than 64 - # tables in a Join statement in sqlite env. This is a new issue when - # we introduce resources tags and client certificates, both of them - # are 1:1 relationship. But we can image that if we have many - # associated loadbalancer subresources, such as listeners, pools, - # members and l7 resources. Even though, we don't have tags and - # client certificates features, we will still hit this issue in - # sqlite env. - self.skipTest("No idea how this should work yet") amphora = self.create_amphora(self.FAKE_UUID_1) self.amphora_repo.associate(self.session, self.lb.id, amphora.id) self.session.commit() lb = self.amphora_repo.get_lb_for_amphora(self.session, amphora.id) self.assertIsNotNone(lb) - self.assertEqual(self.lb, lb) + self.assertEqual(self.lb.id, lb.id) def test_get_all_deleted_expiring_amphora(self): exp_age = datetime.timedelta(seconds=self.FAKE_EXP_AGE) diff --git a/releasenotes/notes/fix-amphora-update-api-call-d90853d7f75304a4.yaml b/releasenotes/notes/fix-amphora-update-api-call-d90853d7f75304a4.yaml new file mode 100644 index 0000000000..ad9586a2a7 --- /dev/null +++ b/releasenotes/notes/fix-amphora-update-api-call-d90853d7f75304a4.yaml @@ -0,0 +1,6 @@ +--- +fixes: + - | + Fixed a bug that prevented the amphora from being updated by the Amphora + Configure API call, the API call was succesfull but the internal flow for + updating it failed.