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

Multi pr #71

Open
wants to merge 120 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
f1d55f5
Fix OSError if mech destroy #57
May 4, 2019
a67380c
This fixes #59: json.decoder.JSONDecodeError: Expecting property name…
Jun 8, 2019
204c779
show instance name when ssh-config command is run
mkinney Jan 3, 2020
1180354
add command line option to disable shared folder
mkinney Jan 5, 2020
ee1e270
add ability to override vcpus/mem
mkinney Jan 8, 2020
0f043f6
Merge remote-tracking branch 'dodo5522/fix-json-decode-error-by-broke…
mkinney Feb 1, 2020
b2d9b92
Merge remote-tracking branch 'origin/disable-shared-folder-option' in…
mkinney Feb 1, 2020
b173b0b
Merge remote-tracking branch 'origin/mem-and-vcpu' into multi-pr
mkinney Feb 1, 2020
2684174
Merge remote-tracking branch 'origin/show-instance-name-in-ssh-config…
mkinney Feb 1, 2020
d461bbf
add info on how to install from diff repo; update example
mkinney Feb 1, 2020
321fd37
add info in readme about new up options
mkinney Feb 1, 2020
578a811
flake8 fixes; add contributing file
mkinney Feb 1, 2020
7b20319
move all files under this dir .mech
mkinney Feb 1, 2020
13e265a
get list/destroy to work as expected
mkinney Feb 1, 2020
1681233
got mech up and ls working with multiple
mkinney Feb 2, 2020
3c4a20b
enable most commands to deal with single or multiple instances
mkinney Feb 2, 2020
fff0393
add docstrings; get scp working
mkinney Feb 2, 2020
377097d
test that snapshot add/list/delete work as expected
mkinney Feb 2, 2020
46333dc
validate mech box add/list/remove work as expected
mkinney Feb 2, 2020
e6faeb6
update help info
mkinney Feb 2, 2020
f89d149
add bats and simple int tests
mkinney Feb 3, 2020
1e263c3
add two instances test; added name to up/delete
mkinney Feb 3, 2020
82e800b
document the int tests
mkinney Feb 3, 2020
57d8021
update doc/TODOs
mkinney Feb 3, 2020
38842c6
add direnv
mkinney Feb 3, 2020
8109fff
migrate TODO notes into project board
mkinney Feb 3, 2020
a76f29e
change debug logging; pass named values; validate creating box from file
mkinney Feb 3, 2020
19b9176
improve int testing
mkinney Feb 3, 2020
1223951
add int testing for most functionality
mkinney Feb 3, 2020
e014e37
validate provisioning works as expected
mkinney Feb 4, 2020
166d406
validate shared_folders functionality
mkinney Feb 4, 2020
58c2b32
provision on start; add option to disable provisioining
mkinney Feb 4, 2020
cb6fa81
fix bugs that running the int tests would have caught
mkinney Feb 5, 2020
6185a44
refactor to a MechInstance class
mkinney Feb 5, 2020
a11eef9
no need to change dirs
mkinney Feb 5, 2020
7be0e95
add detailed list for instances
mkinney Feb 5, 2020
f0f5818
add/remove instances from Mechfile
mkinney Feb 5, 2020
70829d7
remove unused code; refactor path; improve comments
mkinney Feb 5, 2020
4f36fb8
remove unused methods
mkinney Feb 5, 2020
0d09ad6
initial unit tests
mkinney Feb 6, 2020
2ff2934
ignore these long lines
mkinney Feb 6, 2020
8388f4b
add some initial tests
mkinney Feb 7, 2020
4add67a
add code coverage; add more tests
mkinney Feb 7, 2020
d03fdc6
figured out how to *unit test* mech list
mkinney Feb 7, 2020
0b5e76d
disable deprecated warnings for now; mock out the utils.locate function
mkinney Feb 8, 2020
3673cfe
added unit tests for mech port
mkinney Feb 8, 2020
5dea760
add mech box list unit tests
mkinney Feb 8, 2020
ccfe195
pylint fixes
mkinney Feb 8, 2020
28e9a05
pylint the tests
mkinney Feb 8, 2020
2ca6d3a
pylint fixes
mkinney Feb 9, 2020
bf908a4
add mech snapshot list/save unittest
mkinney Feb 9, 2020
821cb33
remove puts_err calls; added mech snapshot delete unittest
mkinney Feb 9, 2020
01e4555
add some mech up and mech ssh-config unit tests
mkinney Feb 9, 2020
b9b83e1
add mech snapshot save unit tests
mkinney Feb 10, 2020
5e804b5
working on utils.build_mechfile_entry unittests
mkinney Feb 10, 2020
0d001b4
improved build_mechfile unit tests
mkinney Feb 10, 2020
0bac6bc
add mech box add/remove unittests
mkinney Feb 10, 2020
c8c6309
add unit test for mech init
mkinney Feb 10, 2020
ffb630c
add unittests for mech add/init
mkinney Feb 10, 2020
ab940df
add unittests for mech remove
mkinney Feb 10, 2020
32d56b4
add unittests for mech up
mkinney Feb 10, 2020
23b56fe
add another case for mech up
mkinney Feb 10, 2020
3525b07
add unittest for mech ps
mkinney Feb 10, 2020
1edbc9a
add more unittests pause/resume/stop; remove sleeps
mkinney Feb 10, 2020
a2f25c3
add more unittests mech ssh/suspend/ip
mkinney Feb 11, 2020
f55de9f
add mech provision unittests
mkinney Feb 11, 2020
7960703
migrate some test code into fixtures
mkinney Feb 11, 2020
f379177
pylint tests
mkinney Feb 11, 2020
74db045
pylint fixes
mkinney Feb 11, 2020
5a8e1b8
pylint fixes and additional unittests
mkinney Feb 11, 2020
ba49272
add unittest for update_vmx
mkinney Feb 11, 2020
dece82e
run pytest with multiple cpus
mkinney Feb 11, 2020
2a074d4
update info about seeing slowest pytest tests
mkinney Feb 11, 2020
50d896b
add more unittests to test_utils
mkinney Feb 11, 2020
d1ba7b9
unittest additions
mkinney Feb 12, 2020
abb5282
add ability to run int tests from pytest
mkinney Feb 12, 2020
7a61454
show how to run all tests from pytest
mkinney Feb 12, 2020
bf07d3f
more comments about running tests
mkinney Feb 12, 2020
ba9e262
after cleaning some .mech dirs, found unit test was using them and ha…
mkinney Feb 12, 2020
1fd9b68
add more unittests
mkinney Feb 12, 2020
945e76c
add test_tar unittest
mkinney Feb 12, 2020
6c2d077
add no-nat (eg bridged) networking
mkinney Feb 12, 2020
3c40866
args should use dash not underbar
mkinney Feb 12, 2020
8a24afb
add zsh completions
mkinney Feb 13, 2020
2f722b1
add bash completions
mkinney Feb 13, 2020
9de79b9
add ability to have multiple shared folders
mkinney Feb 14, 2020
0241c38
adding copyright
mkinney Feb 15, 2020
9935ed6
add initial workflow
mkinney Feb 15, 2020
5c2cfec
add docopt to deps
mkinney Feb 15, 2020
7b49d4b
add more deps
mkinney Feb 15, 2020
9f4f22c
move code into constructor; mock a few more things
mkinney Feb 15, 2020
34012db
do not test on python 2.7, it is dead, jim
mkinney Feb 15, 2020
ba15adc
mock get_provider
mkinney Feb 15, 2020
81d0790
drop test under python 3.5
mkinney Feb 15, 2020
5d1a3d7
give up on python 3.6
mkinney Feb 16, 2020
02f2250
fix issues that int tests found; init_from_file is intermittently fai…
mkinney Feb 16, 2020
b8cd3a8
refactor so each class in own file; all utils in utils.py
mkinney Feb 16, 2020
7799da5
refactor utils.provision
mkinney Feb 16, 2020
5f7160a
refactor variable names/comments
mkinney Feb 16, 2020
3ec0d52
add badge
mkinney Feb 16, 2020
7166419
fix badge
mkinney Feb 16, 2020
2b496cc
retrying badge
mkinney Feb 16, 2020
84c374d
add codecov.io
mkinney Feb 16, 2020
b4eeccc
add codecov badge in readme
mkinney Feb 16, 2020
d336310
add init from json int test
mkinney Feb 16, 2020
bc74773
add more utils unittests
mkinney Feb 16, 2020
f40c0ee
add more unittests for utils
mkinney Feb 16, 2020
8648061
remove options that are not implemented
mkinney Feb 16, 2020
00aba98
add upgradevm option; but there seems to be a bug in vmrun
mkinney Feb 16, 2020
533b81a
add a few more lines of unittest coverage
mkinney Feb 16, 2020
c4611da
add some unittests to vmrun
mkinney Feb 16, 2020
96d506b
set executable/provider in test
mkinney Feb 16, 2020
c41cdde
added unit test for vmrun.get_guest_ip_address
mkinney Feb 16, 2020
1f63830
only create vmrun object with user/pass when we need to
mkinney Feb 17, 2020
0e93177
added add-me option
mkinney Feb 17, 2020
ad91f68
add unit tests for vmrun class
mkinney Feb 17, 2020
5f12d24
add use-me/remove-vagrant options
mkinney Feb 17, 2020
afe6089
revamp the ssh output
mkinney Feb 18, 2020
7b4dfd7
fix issues that int tests caught; update readme with current help; li…
mkinney Feb 18, 2020
048386b
convert bats int tests to pure python
mkinney Feb 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export VIRTUAL_ENV=./venv
layout python-venv python3.7
43 changes: 43 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Python package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install docopt clint requests flake8 pytest pytest_mock mock pytest-cov pylint pytest-xdist
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- name: Generate coverage report
run: |
pytest --cov=mech --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
yml: ./codecov.yml
fail_ci_if_error: true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
.DS_Store
cov_html/
.coverage
*.pyc
.idea/
build/
dist/
mech.egg-info/
.mech/
Mechfile
.*swp
venv/
81 changes: 81 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Contributing to mech

Anyone can open a pull request to help expand/enhance the functionality are essential to mech's growth.

This guide should help get you started contributing to mech.


## Dev Setup

```sh
# Clone the repo
git clone [email protected]:mkinney/mech.git

# Change into that cloned directory
cd mech

# If virtualenv is not installed:
sudo apt-get install virtualenv

# Create a virtualenv
virtualenv -p python3 venv

# Activate the python virtual environment
source venv/bin/activate

# consider installing/using direnv (there is a .envrc in this repo)
# may need to run "direnv allow"

# install mech from this code
python setup.py install

# if doing development
pip install docopt clint requests flake8 pytest pytest_mock mock pytest-cov pylint pytest-xdist pytest-timeout

# also optional
pip install autopep8
# use like this: autopep8 --in-place --aggressive --aggressive somefile.py

# Configure git to use pre-commit hook
flake8 --install-hook git

# for running unit tests:
pytest

# for code coverage
pytest --cov mech

# to see what lines are not covered
pytest --cov-report term-missing --cov mech

# or to get a nice html output
pytest --cov-report html:cov_html --cov=mech
# then open cov_html/index.html
# or if you want all coverage html report
pytest --cov-report html:cov_html --cov=mech -m"int or not int"

# if you want to do a quick-ish (takes 1.5 minutes) smoke test
# this runs thru most basic functionality of mech
./smoke_test

# to see the slowest unit tests
pytest --durations=0

# if you have a unittest that is taking too long, but cannot find out which one
# add "timeout = 10" (for 10 seconds)

# for testing/validation, we have also some integration tests
# NOTE: Can take 5+ minutes.
# cd tests/int (see "all" file)
# You can run the int tests by themselves directly if you change
# into the tests/int directory.
# Or, you can run them from the main project directory like this:
pytest -m"int"

# To run all tests (with verbose output and show local variables):
pytest -m"int or not int" -vv -l
# or just run "./full_test"

# Or, just one run int test like this (with verbose and show local variables):
pytest -m"int" -k"provision" -v -l
```
134 changes: 108 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# mech

I made this because I don't like VirtualBox and I wanted to use vagrant
with VMWare Fusion but was too cheap to buy the Vagrant plugin.
![Python package](https://github.com/mkinney/mech/workflows/Python%20package/badge.svg?branch=multi-pr)
[![codecov](https://codecov.io/gh/mkinney/mech/branch/multi-pr/graph/badge.svg)](https://codecov.io/gh/mkinney/mech)

One of the authors made this because they don't like VirtualBox and wanted to use vagrant
with VMmare Fusion but was too cheap to buy the Vagrant plugin.

https://blog.kchung.co/mech-vagrant-with-vmware-integration-for-free/

Expand All @@ -16,44 +19,64 @@ Options:
--debug Show debug messages.

Common commands:
(list|ls) lists all available boxes
init initializes a new Mech environment by creating a Mechfile
destroy stops and deletes all traces of the Mech machine
(up|start) starts and provisions the Mech environment
(down|stop|halt) stops the Mech machine
suspend suspends the machine
pause pauses the Mech machine
ssh connects to machine via SSH
ssh-config outputs OpenSSH valid configuration to connect to the machine
scp copies files to and from the machine via SCP
ip outputs ip of the Mech machine
box manages boxes: installation, removal, etc.
global-status outputs status Mech environments for this user
status outputs status of the Mech machine
ps list running processes in Guest OS
provision provisions the Mech machine
reload restarts Mech machine, loads new Mechfile configuration
resume resume a paused/suspended Mech machine
snapshot manages snapshots: saving, restoring, etc.
port displays information about guest port mappings
push deploys code in this environment to a configured destination
box manages boxes: add, list remove, etc.
destroy stops and deletes all traces of the instances
(down|stop|halt) stops the instances
global-status outputs status of all virutal machines on this host
init initializes a new Mech environment by creating a Mechfile
ip outputs ip of an instance
(list|ls) lists all available boxes
pause pauses the instances
port displays information about guest port mappings
provision provisions the Mech machine
ps list running processes for an instance
reload restarts Mech machine, loads new Mechfile configuration
resume resume a paused/suspended Mech machine
scp copies files to/from the machine via SCP
snapshot manages snapshots: save, list, remove, etc.
ssh connects to an instance via SSH
ssh-config outputs OpenSSH valid configuration to connect to the instances
status outputs status of the instances
suspend suspends the instances
(up|start) starts instances (aka virtual machines)
upgrade upgrade the instances

For help on any individual command run `mech <command> -h`

Example:

mech up --help

% mech up --help
Starts and provisions the mech environment.

Usage: mech up [options] [<instance>]

Options:
--disable-provisioning Do not provision
--disable-shared-folders Do not share folders with VM
--gui Start GUI
--memsize 1024 Specify the size of memory for VM
--no-cache Do not save the downloaded box
--no-nat Do not use NAT network (i.e., bridged)
--numvcpus 1 Specify the number of vcpus for VM
-h, --help Print this help
-r, --remove-vagrant Remove vagrant user

Example using mech:


Initializing and using a machine from HashiCorp's Vagrant Cloud:

mech init bento/ubuntu-14.04
mech init bento/ubuntu-18.04
mech up
mech ssh
```

`mech init` can be used to pull a box file which will be installed and
generate a Mechfile in the current directory. You can also pull boxes
from Vagrant Cloud with `mech init freebsd/FreeBSD-11.1-RELEASE`.
Barring that, `mech up <name>` can also be used to specify a vmx file
to start.
See the `mech up -h` page for more information.

# Install

Expand All @@ -63,6 +86,11 @@ or for the latest:

`pip install -U git+https://github.com/mechboxes/mech.git`

There are some open PRs that have yet to be merged. Until they are, you may consider
installing from:

`pip install -U git+https://github.com/mkinney/mech.git@multi-pr#egg=mech`

# Shared Folders

If the box you init was created properly, you will be able to access
Expand All @@ -85,3 +113,57 @@ or
```bash
vmhgfs-fuse .host:/mech /mnt/hgfs
```

# Changing vcpus and/or memory size

If you do not specify how many vcpus or memory, then the values
in the .box file will be used. To override, use appropriate settings:

`mech up --numvcpus 2 --memsize 1024`


# Want zsh completion for commands/options (aka "tab completion")?
1. add these lines to ~/.zshrc

```bash
# folder of all of your autocomplete functions
fpath=($HOME/.zsh-completions $fpath)
# enable autocomplete function
autoload -U compinit
compinit
```

2. Copy script to something in fpath (Note: Run `echo $fpath` to show value.)

```bash
cp _mech ~/.zsh-completions/
```

3. Reload zsh

```bash
exec zsh
```

4. Try it out by typing `mech <tab>`. It should show the options available.

# Want bash completion for commands/options (aka "tab completion")?
1. add these lines to ~/.bash_profile

```bash
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
```

2. Copy script to path above

```bash
cp mech_completion.sh /usr/local/etc/bash_completion/
```

3. Reload .bash_profile

```bash
source ~/.bash_profile
```

4. Try it out by typing `mech <tab>`. It should show the options available.
Loading