Merge lp:~cprov/adt-continuous-deployer/secgroup-leak into lp:adt-continuous-deployer

Proposed by Celso Providelo
Status: Merged
Approved by: Celso Providelo
Approved revision: 45
Merged at revision: 45
Proposed branch: lp:~cprov/adt-continuous-deployer/secgroup-leak
Merge into: lp:adt-continuous-deployer
Diff against target: 47 lines (+30/-1)
1 file modified
ci_automation/juju.py (+30/-1)
To merge this branch: bzr merge lp:~cprov/adt-continuous-deployer/secgroup-leak
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Para Siva (community) Approve
Review via email: mp+257849@code.launchpad.net

Commit message

Extending juju.destroy_environment() to ensure related security-groups are removed too.

Description of the change

Extending juju.destroy_environment() to ensure related security-groups are removed too.

See more information about the impacts on https://trello.com/c/N7l9ydBz/101-1-infra-neutron-quota-ports-bump-for-stg-ue-ci-engineering-on-ps4

To post a comment you must log in.
Revision history for this message
Para Siva (psivaa) wrote :

+1, LGTM.
I'm not sure though, if running 'destroy-environment' a couple of more times, with a delay will be a preferred approach. That used to work for me with bootstack.

review: Approve
Revision history for this message
Celso Providelo (cprov) wrote :

Psivaa,

Thanks for the review, I see your point about simply re-running `juju destroy-environment` a couple of times, but isn't more precise if we address the problems we know specifically, which is the secgroups left behind ?

Revision history for this message
Para Siva (psivaa) wrote :

cprov,

Re-running destroy-environment is a bigger hammer, I think.

iiuc, the reason why the secgroups were leaked was because of the race inside destroy-environment. i.e. The secgroups were attempted to be deleted before the services weren't fully destroyed. They were in-use and hence were left alone. Re-running destroy-environment would usually clean up the leftover secgroups, and any other resources that leaked in the first run.

I agree that deleting the secgroups is a good solution for the problem in hand and more specific. We would not, however, know if there is any other resource leaked by destroy-environment but we could find out that later and delete them. Not a biggie to block this MP.

Revision history for this message
Francis Ginther (fginther) wrote :

Discussed one comment with Celso on irc. 'juju destroy-environment' is synchronous with regard to the behavior of cleaning up secgroups. This is, if the command exists and there is still a secgroup defined, it's going to remain until it is manually cleaned up.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ci_automation/juju.py'
2--- ci_automation/juju.py 2015-04-02 19:29:27 +0000
3+++ ci_automation/juju.py 2015-04-30 04:57:44 +0000
4@@ -19,6 +19,7 @@
5 import os
6 import shutil
7 import subprocess
8+import time
9 import yaml
10
11 from . import utils
12@@ -47,7 +48,35 @@
13 args = ['juju', 'destroy-environment', '-y', '--force', name]
14 subprocess.check_call(args, env=env)
15
16- # XXX cprov 20150402: also destroy related bits secgroups,
17+ # Ensure all related security-groups left behind by `juju` are removed,
18+ # otherwise they will remain consuming resources (and quota).
19+ nova_output = subprocess.check_output(['nova', 'secgroup-list'])
20+ secgroups = [
21+ line.split('|')[2].strip()
22+ for line in nova_output.decode('utf-8').splitlines()
23+ if name in line
24+ ]
25+
26+ for secgroup in secgroups:
27+ secgroup = secgroup.strip()
28+ # Try harder because sometimes the instance retaining the secgroup
29+ # takes sometime to be purged.
30+ for i in range(3):
31+ try:
32+ subprocess.check_call(
33+ ['nova', 'secgroup-delete', secgroup],
34+ stdout=subprocess.DEVNULL,
35+ stderr=subprocess.DEVNULL
36+ )
37+ except subprocess.CalledProcessError:
38+ time.sleep(1)
39+ else:
40+ break
41+ else:
42+ print(
43+ 'The security-group "{}" could not be removed. '
44+ 'Please remove it manually.'.format(secgroup)
45+ )
46
47 shutil.rmtree(env_dir)
48

Subscribers

People subscribed via source and target branches

to all changes: