Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mech connector #198

Merged
merged 11 commits into from
Jan 8, 2020
Merged

Add mech connector #198

merged 11 commits into from
Jan 8, 2020

Conversation

mkinney
Copy link
Contributor

@mkinney mkinney commented Jan 3, 2020

Working on #197

This does not work as expected yet. Need help on this.

Pyinfra only seems to run against one of the hosts because they all return "localhost" (or some other issue):

$ pyinfra -v @mech exec -- /sbin/ifconfig | grep 192
localhost: centos7	  192.168.2.218	                     bento/centos-7	 201912.05.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/centos7
localhost: centos8	  192.168.2.219	                     bento/centos-8	 201912.04.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/centos8
localhost: centos8b	  192.168.2.237	                     bento/centos-8	 201912.04.0	/Users/mikekinney/Documents/python/mech/mkinney_mech
localhost: debian8	  192.168.2.227	                     bento/debian-8	 201912.04.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/debian8
localhost: debian9	  192.168.2.228	                     bento/debian-9	 201912.05.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/debian9
localhost: fedora30	  192.168.2.229	                    bento/fedora-30	 201912.05.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/fedora30
localhost: fedora31	  192.168.2.226	                    bento/fedora-31	 201912.04.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/fedora31
localhost: ubuntu16	  192.168.2.230	                 bento/ubuntu-16.04	 201912.04.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/ubuntu16
localhost: ubuntu18	  192.168.2.236	                 bento/ubuntu-18.04	 201912.04.0	/Users/mikekinney/Documents/python/mech/multiple-mech/instances/ubuntu18
localhost: HostName 192.168.2.237
localhost: HostName 192.168.2.230
localhost: HostName 192.168.2.219
localhost: HostName 192.168.2.226
localhost: HostName 192.168.2.236
localhost: HostName 192.168.2.229
localhost: HostName 192.168.2.227
localhost: HostName 192.168.2.228
localhost: HostName 192.168.2.218
[@mech/mech] inet 192.168.2.218  netmask 255.255.255.0  broadcast 192.168.2.255
$

Any ideas?

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mech ls appears to list available boxes, rather than running instances, which would cause issues here.

Since mech only supports a single instance at once I think this connector should reflect that - in which case the connector should only need execute mech ssh-info to figure out the connection info.

A later extension could be to support multiple Mechfiles using a syntax roughly like:

pyinfra @mech/path/to/dir @mech/path/to/other/dir

@mkinney
Copy link
Contributor Author

mkinney commented Jan 3, 2020

The mech ls shows all instances. The column that has the address is what is running or not. The output shows blank if the instance is not running, "poweroff" if created but not running, or an ip address if running.

See https://github.com/mkinney/pyinfra/blob/add-mech-connector/tests/test_connector_mech.py#L30 for example output.

So, the output from the first comment should have run against all 9 hosts, but it only ran against one. Not sure why. I guess I'll take another look today.

Note that there is a bug in mech code that does not properly show the host when you run mech ssh-config someinstance. See mechboxes/mech#64

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see - so mech ssh-config <name> will work anywhere (not requiring Mechfile in the same dir). In that case it should work as expected - once the issue with Mech itself is fixed.

I've outlined one possible workaround below which should get this running without Mech being fixed/released.

pyinfra/api/connectors/mech.py Outdated Show resolved Hide resolved
@mkinney
Copy link
Contributor Author

mkinney commented Jan 5, 2020

Working for me now:

$ pyinfra @mech exec -- /sbin/ifconfig | grep 192
[@mech/ubuntu18] inet 192.168.2.232  netmask 255.255.255.0  broadcast 192.168.2.255
[@mech/centos8] inet 192.168.2.219  netmask 255.255.255.0  broadcast 192.168.2.255

Copy link
Member

@Fizzadar Fizzadar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkinney awesome! Will update & merge.

@Fizzadar
Copy link
Member

Fizzadar commented Jan 7, 2020

Ah there's a couple of linting things to fix in the tests - https://travis-ci.org/Fizzadar/pyinfra/jobs/633683328#L326.

@mkinney
Copy link
Contributor Author

mkinney commented Jan 7, 2020

Sorry about that. I'll run flake8 tests in the future.

I mostly ignored these warnings. Let me know if you want them handled differently.

@codecov-io
Copy link

Codecov Report

Merging #198 into master will increase coverage by 0.16%.
The diff coverage is 96.8%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #198      +/-   ##
==========================================
+ Coverage   88.09%   88.25%   +0.16%     
==========================================
  Files          86       87       +1     
  Lines        4677     4770      +93     
==========================================
+ Hits         4120     4210      +90     
- Misses        557      560       +3
Impacted Files Coverage Δ
pyinfra/api/connectors/__init__.py 100% <100%> (ø) ⬆️
pyinfra/api/connectors/mech.py 96.77% <96.77%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83f71d0...fc05a64. Read the comment docs.

@Fizzadar
Copy link
Member

Fizzadar commented Jan 8, 2020

@mkinney no worries - thank you for fixing! I only recently added flake8 to the tests to enforce style.

@Fizzadar Fizzadar merged commit 2b772b5 into pyinfra-dev:master Jan 8, 2020
@mkinney mkinney deleted the add-mech-connector branch January 12, 2020 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants