-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from trobrock/export
Adding export and import
- Loading branch information
Showing
8 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ configurations | |
current | ||
*.un~ | ||
.vagrant | ||
exports/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
# Usage: chefvm export CONFIG [--include-keys] | ||
# Summary: Export a configuration, ignoring key files (unless specified) | ||
# Help: This command will export a configuration to a file so it can be imported on another machine. | ||
|
||
set -e | ||
|
||
__chefvm_config $1 | ||
|
||
if [ -z "$config" ]; then | ||
echo "No name provided" | ||
exit 1 | ||
fi | ||
|
||
if [ ! -d $_CHEFVM_ROOT/$config_path ]; then | ||
echo "No configuration named $1 found." | ||
chefvm list | ||
exit 1 | ||
fi | ||
|
||
if [ "$2" = "--include-keys" ]; then | ||
include_keys=1 | ||
fi | ||
|
||
echo "Exporting: $config" | ||
|
||
pushd $_CHEFVM_ROOT/$config_path > /dev/null | ||
export_file="$_CHEFVM_ROOT/exports/${config}.tar.gz" | ||
rm -f $export_file | ||
|
||
if [ "$include_keys" = "1" ]; then | ||
tar czf $export_file ./ | ||
else | ||
tar czf $export_file --exclude '*.pem' ./ | ||
fi | ||
|
||
popd > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
# Usage: chefvm import FILE CONFIG_NAME | ||
# Summary: Import a configuration | ||
# Help: This command will import a file that was exported from chefvm to a new configuration. | ||
|
||
set -e | ||
|
||
file=$(readlink -f $1) | ||
if [ -z "$file" ] || [ ! -f "$file" ]; then | ||
echo "$file does not exist" | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$2" ]; then | ||
echo "No new config name specified" | ||
exit 1 | ||
fi | ||
|
||
__chefvm_config $2 | ||
|
||
echo "Importing '$1' as '$2'" | ||
|
||
mkdir -p $_CHEFVM_ROOT/$config_path | ||
pushd $_CHEFVM_ROOT/$config_path > /dev/null | ||
tar xzf $file | ||
popd > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
echo $_CHEFVM_ROOT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/usr/bin/env bats | ||
|
||
setup() { | ||
touch $(chefvm prefix)/configurations/example/knife.rb | ||
touch $(chefvm prefix)/configurations/example/myuser.pem | ||
touch $(chefvm prefix)/configurations/example/myvalidator.pem | ||
} | ||
|
||
@test "should have the exports directory" { | ||
chefvm_root=$(chefvm prefix) | ||
|
||
[ -d "$chefvm_root/exports" ] | ||
} | ||
|
||
@test "should create a tar file for the export" { | ||
chefvm_root=$(chefvm prefix) | ||
run chefvm export example | ||
|
||
[ "$status" -eq 0 ] | ||
[ "$output" = "Exporting: example" ] | ||
[ -f "$chefvm_root/exports/example.tar.gz" ] | ||
} | ||
|
||
@test "should ignore key files by default" { | ||
chefvm_root=$(chefvm prefix) | ||
run chefvm export example | ||
|
||
[ "$status" -eq 0 ] | ||
|
||
tempfile=$(mktemp -t chefvm-export-ignore-keys.XXXXXXXXXX) | ||
rm $tempfile | ||
mkdir -p $tempfile | ||
pushd $tempfile > /dev/null | ||
tar xzf $chefvm_root/exports/example.tar.gz | ||
|
||
[ -f "knife.rb" ] | ||
[ ! -f "myuser.pem" ] | ||
[ ! -f "myvalidator.pem" ] | ||
|
||
popd > /dev/null | ||
rm -rf $tempfile | ||
} | ||
|
||
@test "should be able to include key files" { | ||
chefvm_root=$(chefvm prefix) | ||
run chefvm export example --include-keys | ||
|
||
[ "$status" -eq 0 ] | ||
|
||
tempfile=$(mktemp -t chefvm-export-ignore-keys.XXXXXXXXXX) | ||
rm $tempfile | ||
mkdir -p $tempfile | ||
pushd $tempfile > /dev/null | ||
tar xzf $chefvm_root/exports/example.tar.gz | ||
|
||
[ -f "knife.rb" ] | ||
[ -f "myuser.pem" ] | ||
[ -f "myvalidator.pem" ] | ||
|
||
popd > /dev/null | ||
rm -rf $tempfile | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env bats | ||
|
||
setup() { | ||
touch $(chefvm prefix)/configurations/example/knife.rb | ||
touch $(chefvm prefix)/configurations/example/myuser.pem | ||
chefvm export example > /dev/null | ||
} | ||
|
||
teardown() { | ||
chefvm delete new_example > /dev/null | ||
} | ||
|
||
@test "should be able to import a configuration" { | ||
run chefvm import $(chefvm prefix)/exports/example.tar.gz new_example | ||
|
||
[ "$status" -eq 0 ] | ||
[ "$output" = "Importing '$(chefvm prefix)/exports/example.tar.gz' as 'new_example'" ] | ||
|
||
run chefvm list | ||
[ "${lines[0]}" = "*= example" ] | ||
[ "${lines[1]}" = " new_example" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bats | ||
|
||
@test "should print the chefvm root" { | ||
run chefvm prefix | ||
|
||
[ "$status" -eq 0 ] | ||
if [ ! -z $TRAVIS_BUILD_DIR ]; then | ||
[ "$output" = "$TRAVIS_BUILD_DIR" ] | ||
else | ||
[ "$output" = "/root/.chefvm" ] | ||
fi | ||
} |