Skip to content

Commit 1b00074

Browse files
committed
Bugfix: Clean up trusts for all deleted clusters
Cluster conductor creates trusts for all drivers, but does not clean them up. The Heat driver has previously performed this action. This change moves the lifecycle of trust and certificate creation to the Conductor, so drivers do not need to clean up resources they didn't create. Change-Id: I2b3e99589d2d3069191d0727406601f0647a9722
1 parent 0c82bb5 commit 1b00074

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

magnum/common/keystone.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,16 @@ def create_trustee(self, username, password):
263263
domain_id=domain_id)
264264
return user
265265

266-
def delete_trustee(self, trustee_id):
266+
def delete_trustee(self, trustee_user_id):
267+
if trustee_user_id is None:
268+
return
267269
try:
268-
self.domain_admin_client.users.delete(trustee_id)
270+
self.domain_admin_client.users.delete(trustee_user_id)
269271
except kc_exception.NotFound:
270272
pass
271273
except Exception:
272274
LOG.exception('Failed to delete trustee')
273-
raise exception.TrusteeDeleteFailed(trustee_id=trustee_id)
275+
raise exception.TrusteeDeleteFailed(trustee_id=trustee_user_id)
274276

275277
def get_validate_region_name(self, region_name):
276278
if region_name is None:

magnum/conductor/handlers/common/trust_manager.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ def create_trustee_and_trust(osc, cluster):
4444

4545

4646
def delete_trustee_and_trust(osc, context, cluster):
47+
kst = osc.keystone()
4748
try:
48-
kst = osc.keystone()
49-
50-
# The cluster which is upgraded from Liberty doesn't have trust_id
5149
if cluster.trust_id:
5250
kst.delete_trust(context, cluster)
51+
cluster.trust_id = None
5352
except Exception:
5453
# Exceptions are already logged by keystone().delete_trust
5554
pass
5655
try:
57-
# The cluster which is upgraded from Liberty doesn't have
58-
# trustee_user_id
5956
if cluster.trustee_user_id:
60-
osc.keystone().delete_trustee(cluster.trustee_user_id)
57+
kst.delete_trustee(cluster.trustee_user_id)
58+
cluster.trustee_user_id = None
59+
cluster.trustee_username = None
60+
cluster.trustee_password = None
6161
except Exception:
6262
# Exceptions are already logged by keystone().delete_trustee
6363
pass

magnum/service/periodic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@
2121

2222
from pycadf import cadftaxonomy as taxonomy
2323

24+
from magnum.common import clients
2425
from magnum.common import context
2526
from magnum.common import exception
2627
from magnum.common import profiler
2728
from magnum.common import rpc
29+
from magnum.conductor.handlers.common import cert_manager
30+
from magnum.conductor.handlers.common import trust_manager
2831
from magnum.conductor import monitors
2932
from magnum.conductor import utils as conductor_utils
3033
import magnum.conf
@@ -95,6 +98,14 @@ def update_status(self):
9598
taxonomy.OUTCOME_FAILURE, self.cluster)
9699
# if we're done with it, delete it
97100
if self.cluster.status == objects.fields.ClusterStatus.DELETE_COMPLETE:
101+
# Clean up trusts and certificates, if they still exist.
102+
os_client = clients.OpenStackClients(self.ctx)
103+
LOG.debug("Calling delete_trustee_and_trusts from periodic "
104+
"DELETE_COMPLETE")
105+
trust_manager.delete_trustee_and_trust(os_client, self.ctx,
106+
self.cluster)
107+
cert_manager.delete_certificates_from_cluster(self.cluster,
108+
context=self.ctx)
98109
# delete all the nodegroups that belong to this cluster
99110
for ng in objects.NodeGroup.list(self.ctx, self.cluster.uuid):
100111
ng.destroy()

magnum/tests/unit/conductor/handlers/common/test_trust_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_delete_trustee_and_trust(self):
8989
context, mock_cluster
9090
)
9191
mock_keystone.delete_trustee.assert_called_once_with(
92-
mock_cluster.trustee_user_id,
92+
'trustee_user_id',
9393
)
9494

9595
def test_delete_trustee_and_trust_without_trust_id(self):
@@ -105,7 +105,7 @@ def test_delete_trustee_and_trust_without_trust_id(self):
105105

106106
self.assertEqual(0, mock_keystone.delete_trust.call_count)
107107
mock_keystone.delete_trustee.assert_called_once_with(
108-
mock_cluster.trustee_user_id,
108+
'trustee_user_id',
109109
)
110110

111111
def test_delete_trustee_and_trust_without_trustee_user_id(self):

0 commit comments

Comments
 (0)