Implement Model.add_machine() #56

Merged
merged 5 commits into from Feb 24, 2017

Conversation

Projects
None yet
4 participants
Member

tvansteenburgh commented Feb 21, 2017

Also fixes a bug that was causing the 'to' parameter to
Model.deploy() to not be handled correctly.

Add docs and examples for adding machines and containers
and deploying charms to them.

Fixes #51.

Implement Model.add_machine()
Also Fixes a bug that was causing the 'to' parameter to
Model.deploy() to not be handled correctly.

Add docs and examples for adding machines and containers
and deploying charms to them.

Fixes #51.
Member

johnsca commented Feb 21, 2017

Should we also change BundleHandler to use this?

- placement = [
- client.Placement(**p) for p in to
- ]
+ placement = parse_placement(to)
@petevg

petevg Feb 21, 2017

Collaborator

This makes a lot of sense. Thank you.

You can technically get rid of the call to parse_placement in application.py (though the "backwards compatibility" line in placement.py means that the multiple calls won't break anything).

@tvansteenburgh

tvansteenburgh Feb 22, 2017

Member

You mean the one in Application.add_unit()? AFAICT that's still needed, what am I missing?

examples/add_machine.py
+from juju.model import Model
+
+MB = 1024 * 1024
+GB = MB * 1024
@petevg

petevg Feb 21, 2017

Collaborator

If you take a look in constraints.py, these conversions are already built, and they use megabytes, rather than bytes, as a unit, per the Go code on the core side. I'm fairly certain that these numbers will give you machines with much more memory than expected (unless I'm missing a line where you downsize stuff before passing it to the API.)

@tvansteenburgh

tvansteenburgh Feb 22, 2017

Member

Thanks, fixed.

return [
- client.Placement(scope=MACHINE_SCOPE, directive=machine),
- client.Placement(scope=container, directive=container_num)
+ client.Placement(scope=MACHINE_SCOPE, directive=directive),
]
@petevg

petevg Feb 21, 2017

Collaborator

Thx for the fix.

Overall, I am +1 on this, but I think that you want to use Megabytes as your units for RAM, rather than bytes. (Feel free to ignore and merge anyway if I'm wrong.)

Unit tests 🙏?

Member

tvansteenburgh commented Feb 22, 2017

@johnsca Re: BundleHandler, I thought about it, but they are different enough that we'd need to factor some stuff out into a 3rd (private) method anyway. Since these are the only two callers, I don't think it's worth it. Maybe later if we end up with more code using the AddMachines api.

Member

tvansteenburgh commented Feb 22, 2017

@sparkiegeek Yep, coming. I knew you'd be watching. ;) Thanks for keeping me honest.

tvansteenburgh added some commits Feb 23, 2017

Add functional tests for Model.add_machine()
Clean up other tests, ensuring that connections are closed
and a new event loop is used for each test.

Update py.test args in tox.ini to properly on nocapture so
logging output can be seen when needed.
Make Machine.destroy() block
Block the current coro until the machine is actually removed
from the remote model. This follows the same pattern as other
operations, e.g. Model.deploy().

Also clean up tests, making each functional test run on its
own clean model.
Enable parallel testing
Should help speed up tests, especially as more functional tests
are added in the future. Each can be run in parallel on a separate
model.

Also removed unused import from client/connection.py

@tvansteenburgh tvansteenburgh merged commit afb309d into master Feb 24, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment