Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
lifecycle: clean after deleting container #1587
Conversation
kalikiana
self-assigned this
Oct 6, 2017
| project_options = get_project_options(**kwargs) | ||
| container_config = env.get_container_config() | ||
| - if container_config.use_container: | ||
| - step = step or 'pull' | ||
| + if container_config.use_container and step == 'pull' and not parts: |
elopio
Oct 7, 2017
Member
I don't get this @kalikiana. I might be doing something wrong while testing it, but it seems to me that this still just deletes the container.
The execute method in lxd checks if we are cleaning, and if so, it just deletes the container.
In this pr I see nothing to modify that behaviour.
kalikiana
Oct 8, 2017
Collaborator
Sorry about that. It looks like the second commit was lost... I re-did the missing piece. So: clean should be called with the container to delete it, in all other cases "normal" lifecycle clean is used so that it works even if the container is broken or already deleted.
kyrofa
Oct 10, 2017
Member
I'd like to rectify the poor separation of concerns, here. We're going to great lengths to ensure we only ever call lifecycle.containerbuild('clean') if step == 'pull' and not parts, with no apparent reason. We then proceed to pass the step as well as the parts (that we just ensured was empty) to the very generic-sounding lifecycle.containerbuild() method. That method then calls the very generic-sounding lxd.Project().execute() method. Finally, that method checks to see if we're cleaning the pull step with no parts, in which case it blows the container away.
I'd like to see lxd.Project().execute() be written more generically. If it was asked to clean with no parts, fine, blow the container away. If it was asked to clean with parts, do nothing. If something else, call super(). Then we don't have to let the conditions where the container needs to be removed leak to this line, where we're checking those conditions again. We can simply call lifecycle.containerbuild('clean') just like we call lifecycle.clean() and expect it to do the right thing.
kalikiana
added some commits
Oct 8, 2017
|
Note: All but the snap test have passed |
kyrofa
requested changes
Oct 10, 2017
Good progress here, thank you! However, there's a concerns leakage that looks like a bug waiting to happen. I suggest we fix that.
| project_options = get_project_options(**kwargs) | ||
| container_config = env.get_container_config() | ||
| - if container_config.use_container: | ||
| - step = step or 'pull' | ||
| + if container_config.use_container and step == 'pull' and not parts: |
elopio
Oct 7, 2017
Member
I don't get this @kalikiana. I might be doing something wrong while testing it, but it seems to me that this still just deletes the container.
The execute method in lxd checks if we are cleaning, and if so, it just deletes the container.
In this pr I see nothing to modify that behaviour.
kalikiana
Oct 8, 2017
Collaborator
Sorry about that. It looks like the second commit was lost... I re-did the missing piece. So: clean should be called with the container to delete it, in all other cases "normal" lifecycle clean is used so that it works even if the container is broken or already deleted.
kyrofa
Oct 10, 2017
Member
I'd like to rectify the poor separation of concerns, here. We're going to great lengths to ensure we only ever call lifecycle.containerbuild('clean') if step == 'pull' and not parts, with no apparent reason. We then proceed to pass the step as well as the parts (that we just ensured was empty) to the very generic-sounding lifecycle.containerbuild() method. That method then calls the very generic-sounding lxd.Project().execute() method. Finally, that method checks to see if we're cleaning the pull step with no parts, in which case it blows the container away.
I'd like to see lxd.Project().execute() be written more generically. If it was asked to clean with no parts, fine, blow the container away. If it was asked to clean with parts, do nothing. If something else, call super(). Then we don't have to let the conditions where the container needs to be removed leak to this line, where we're checking those conditions again. We can simply call lifecycle.containerbuild('clean') just like we call lifecycle.clean() and expect it to do the right thing.
|
@kyrofa Somehow I can reply... something's off with GitHub since today I think. In any case, I changed it as per your suggestion and the logic is only in lxd.py now. |
| + if step == 'clean': | ||
| + # we don't execute clean here but rely on CLI to do it | ||
| + # clean with no parts deletes the container | ||
| + if self._get_container_status() and args == ['--step', 'pull']: |
kyrofa
Oct 11, 2017
•
Member
I think re-purposing this function to clean is both confusing (clean is not a lifecycle step, and then one sees --step pull and gets more confused) and is causing the diff of this PR to be larger than it needs to be (changing the step from None to 'pull' everywhere, which seems unnecessary). How difficult would it be to simply add a clean function here that accepts a step (the step being cleaned) and args?
kyrofa
Oct 11, 2017
Member
Eh, I changed my mind on defaulting step to pull at a higher level, otherwise you'll need to treat None and 'pull' as equivalent here. However, I would still like to see a clean function here instead of execute.
kalikiana
Oct 12, 2017
Collaborator
I reverted the default change now. It's not essential to the PR, it just seemed like a simplification.
And I replaced the subclass' execute logic with a delete method - now lifecycle remains in charge and reading lxd.py doesn't require any knowledge of what lifecycle does with it.
| - if not step: | ||
| - step = 'pull' | ||
| - | ||
| +def clean(project_options, parts, step): |
| @@ -653,7 +653,7 @@ def test_clean_removes_global_state(self): | ||
| plugin: nil | ||
| """) | ||
| lifecycle.execute('pull', self.project_options) | ||
| - lifecycle.clean(self.project_options, parts=None) | ||
| + lifecycle.clean(self.project_options, parts=None, step='pull') |
kalikiana
added some commits
Oct 12, 2017
|
Tests are green again! |
kyrofa
reviewed
Oct 13, 2017
This seems fine to me, now. We'll need to refactor it if the container ever needs to actually do something when individual parts or steps are cleaned, but this solves the problem for now.
elopio
approved these changes
Oct 13, 2017
If I understand correctly, this calls the clean commands outside of the container. I can see no issue right now, but I think this has the potential to break. I think that if the build is done in the container, the clean should execute in there too. But for now, I think this is a good improvement. Maybe we care about this when it becomes an issue, not now.
|
the business logic seems to have spread a bit too much into the cli components, hasn't it? |
|
Yes indeed. |
sergiusens
reviewed
Oct 16, 2017
Sorry to say, but it would be good to prevent leaking too much into this.
It is acceptable if you want to surface UI (click.echo, echo.warn or prompts) but not for usage of moving common logic.
I would personally rather have it repeated.
kalikiana
added some commits
Oct 20, 2017
|
@sergiusens I moved all logic back into the container, in the |
elopio
approved these changes
Oct 24, 2017
To me, this looks more readable than before. Reapproving.
kyrofa
dismissed
their
stale review
Oct 24, 2017
Significant change occurred.
|
I updated the branch against master (no change in code, but it now lives in |
sergiusens
added this to the 2.35 milestone
Oct 26, 2017
kalikiana
dismissed
sergiusens’s
stale review
Oct 26, 2017
Moved the logic back into the container, out of lifecycle. Needs re-checking.
| @@ -175,11 +177,12 @@ def clean(parts, step, **kwargs): | ||
| """ | ||
| project_options = get_project_options(**kwargs) | ||
| container_config = env.get_container_config() | ||
| + step = step or 'pull' |
kyrofa
Oct 30, 2017
•
Member
You can fix LP: #1727445 right here by not doing this and handling both cases within Project.clean().
kalikiana commentedOct 4, 2017
•
Edited 1 time
-
kalikiana
Oct 10, 2017
./runtests.sh static?./runtests.sh unit?See the forum discussion.