mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 08:42:33 -04:00
test: remove directory
The test directory contains artifacts from the project's past which are never used nowadays. All those remains are therefore removed with this commit, and we can replace that directory's contents with more up-to-date contents.
This commit is contained in:
parent
930b6c3e2b
commit
a8f8902cd3
31 changed files with 0 additions and 893 deletions
|
|
@ -1,74 +0,0 @@
|
|||
# Packer Black-Box Tests
|
||||
|
||||
This folder contains tests that test Packer using a black-box approach:
|
||||
`packer` is executed directly (with whatever is on the PATH) and certain
|
||||
results are expected.
|
||||
|
||||
Tests are run using [Bats](https://github.com/sstephenson/bats), and therefore
|
||||
Bash is required to run any tests.
|
||||
|
||||
**Warning:** Many of these tests run using cloud infrastructure, and therefore have
|
||||
a real-world cost associated with running the tests. Be aware of that prior
|
||||
to running the tests. Additionally, many tests will leave left-over artifacts
|
||||
(AMIs) that you'll have to manually clean up.
|
||||
|
||||
## Running Tests
|
||||
|
||||
### Required Software
|
||||
|
||||
Before running the tests, you'll need the following installed. If you're
|
||||
running on macOS, most of these are available with `brew`:
|
||||
|
||||
* [Bats](https://github.com/sstephenson/bats)
|
||||
|
||||
* [AWS cli](http://aws.amazon.com/cli/) for AWS tests as well as most
|
||||
of the components.
|
||||
|
||||
* [gcutil](https://developers.google.com/compute/docs/gcutil/#install) for
|
||||
Google Compute Engine tests.
|
||||
|
||||
* [h1-cli](https://github.com/hyperonecom/h1-client-go) for HyperOne tests.
|
||||
|
||||
### Configuring Tests
|
||||
|
||||
**For tests that require AWS credentials:**
|
||||
|
||||
Set the following self-explanatory environmental variables:
|
||||
|
||||
* `AWS_ACCESS_KEY_ID`
|
||||
* `AWS_SECRET_ACCESS_KEY`
|
||||
|
||||
**For tests that test Google Compute Engine:**
|
||||
|
||||
Set the following environmental variables:
|
||||
|
||||
* `GC_BUCKET_NAME`
|
||||
* `GC_ACCOUNT_FILE`
|
||||
* `GC_PROJECT_ID`
|
||||
|
||||
**For tests that test HyperOne:**
|
||||
|
||||
Set the following environmental variables:
|
||||
|
||||
* `HYPERONE_TOKEN`
|
||||
* `HYPERONE_PROJECT`
|
||||
|
||||
You have to be authenticated within the `h1` tool (use `h1 login`).
|
||||
|
||||
### Running
|
||||
|
||||
These tests are meant to be run _one file at a time_. There are some
|
||||
test files (such as the amazon-chroot builder test) that simply won't
|
||||
run except in special environments, so running all test files will probably
|
||||
never work.
|
||||
|
||||
If you're working on Packer and want to test that your change didn't
|
||||
adversely affect something, try running only the test that is related to
|
||||
your change.
|
||||
|
||||
```
|
||||
$ bats builder_amazon_ebs.bats
|
||||
```
|
||||
|
||||
Note: Working directory doesn't matter. You can call the bats test file
|
||||
from any directory.
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the googlecompute builder. The teardown function will
|
||||
# delete any images with the text "packerbats" within the name.
|
||||
|
||||
load test_helper
|
||||
fixtures builder-googlecompute
|
||||
|
||||
# Required parameters
|
||||
: ${GC_ACCOUNT_FILE:?}
|
||||
: ${GC_PROJECT_ID:?}
|
||||
command -v gcloud >/dev/null 2>&1 || {
|
||||
echo "'gcloud' must be installed" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}"
|
||||
USER_VARS="${USER_VARS} -var project_id=${GC_PROJECT_ID}"
|
||||
|
||||
# This tests if GCE has an image that contains the given parameter.
|
||||
gc_has_image() {
|
||||
gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \
|
||||
| grep $1 | wc -l
|
||||
}
|
||||
|
||||
teardown() {
|
||||
gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \
|
||||
| grep packerbats \
|
||||
| xargs -n1 gcloud compute --project=${GC_PROJECT_ID} images delete
|
||||
}
|
||||
|
||||
@test "googlecompute: build minimal.json" {
|
||||
run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(gc_has_image "packerbats-minimal")" -eq 1 ]
|
||||
}
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the hyperone builder. The teardown function will
|
||||
# delete any images with the text "packerbats" within the name.
|
||||
|
||||
load test_helper
|
||||
fixtures builder-hyperone
|
||||
|
||||
# Required parameters
|
||||
: ${HYPERONE_TOKEN:?}
|
||||
: ${HYPERONE_PROJECT:?}
|
||||
command -v h1 >/dev/null 2>&1 || {
|
||||
echo "'h1' must be installed" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
USER_VARS="${USER_VARS} -var token=${HYPERONE_TOKEN}"
|
||||
USER_VARS="${USER_VARS} -var project=${HYPERONE_PROJECT}"
|
||||
|
||||
hyperone_has_image() {
|
||||
h1 image list --project-select=${HYPERONE_PROJECT} --query "[?tag.${2}=='${3}']" --output=tsv | grep $1 -c
|
||||
}
|
||||
|
||||
teardown() {
|
||||
h1 image list --project-select=${HYPERONE_PROJECT} --output=tsv \
|
||||
| grep packerbats \
|
||||
| awk '{print $1}' \
|
||||
| xargs -n1 h1 image delete --project-select=${HYPERONE_PROJECT} --yes --image
|
||||
}
|
||||
|
||||
@test "hyperone: build minimal.json" {
|
||||
run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(hyperone_has_image "packerbats-minimal" "key" "value")" -eq 1 ]
|
||||
}
|
||||
|
||||
@test "hyperone: build new-syntax.pkr.hcl" {
|
||||
run packer build ${USER_VARS} $FIXTURE_ROOT/new-syntax.pkr.hcl
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(hyperone_has_image "packerbats-hcl" "key" "value")" -eq 1 ]
|
||||
}
|
||||
|
||||
|
||||
@test "hyperone: build chroot.json" {
|
||||
run packer build ${USER_VARS} $FIXTURE_ROOT/chroot.json
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(hyperone_has_image "packerbats-chroot" "key2" "value2")" -eq 1 ]
|
||||
}
|
||||
|
|
@ -1,106 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the lxc builder by creating minimal containers and checking that
|
||||
# custom lxc container configuration files are successfully applied. The
|
||||
# teardown function will delete any images in the output-lxc-* folders along
|
||||
# with the auto-generated lxc container configuration files and hook scripts.
|
||||
|
||||
#load test_helper
|
||||
#fixtures builder-lxc
|
||||
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/builder-lxc"
|
||||
|
||||
have_command() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# Required parameters
|
||||
have_command lxc-create || {
|
||||
echo "'lxc-create' must be installed via the lxc (or lxc1 for ubuntu >=16.04) package" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
DESTROY_HOOK_SCRIPT=$FIXTURE_ROOT/destroy-hook.sh
|
||||
DESTROY_HOOK_LOG=$FIXTURE_ROOT/destroy-hook.log
|
||||
printf > "$DESTROY_HOOK_SCRIPT" '
|
||||
echo "$LXC_NAME" > "%s"
|
||||
' "$DESTROY_HOOK_LOG"
|
||||
chmod +x "$DESTROY_HOOK_SCRIPT"
|
||||
|
||||
INIT_CONFIG=$FIXTURE_ROOT/lxc.custom.conf
|
||||
printf > "$INIT_CONFIG" '
|
||||
lxc.hook.destroy = %s
|
||||
' "$DESTROY_HOOK_SCRIPT"
|
||||
|
||||
teardown() {
|
||||
for f in "$INIT_CONFIG" "$DESTROY_HOOK_SCRIPT" "$DESTROY_HOOK_LOG"; do
|
||||
[ -e "$f" ] && rm -f "$f"
|
||||
done
|
||||
|
||||
rm -rf output-lxc-*
|
||||
}
|
||||
|
||||
assert_build() {
|
||||
local template_name="$1"
|
||||
shift
|
||||
|
||||
local build_status=0
|
||||
|
||||
run packer build -var template_name="$template_name" "$@"
|
||||
|
||||
[ "$status" -eq 0 ] || {
|
||||
echo "${template_name} build exited badly: $status" >&2
|
||||
echo "$output" >&2
|
||||
build_status="$status"
|
||||
}
|
||||
|
||||
for expected in "output-lxc-${template_name}"/{rootfs.tar.gz,lxc-config}; do
|
||||
[ -f "$expected" ] || {
|
||||
echo "missing expected artifact '${expected}'" >&2
|
||||
build_status=1
|
||||
}
|
||||
done
|
||||
|
||||
return $build_status
|
||||
}
|
||||
|
||||
assert_container_name() {
|
||||
local container_name="$1"
|
||||
|
||||
[ -f "$DESTROY_HOOK_LOG" ] || {
|
||||
echo "missing expected lxc.hook.destroy logfile '$DESTROY_HOOK_LOG'"
|
||||
return 1
|
||||
}
|
||||
|
||||
read -r lxc_name < "$DESTROY_HOOK_LOG"
|
||||
|
||||
[ "$lxc_name" = "$container_name" ]
|
||||
}
|
||||
|
||||
@test "lxc: build centos minimal.json" {
|
||||
have_command yum || skip "'yum' must be installed to build centos containers"
|
||||
local container_name=packer-lxc-centos
|
||||
assert_build centos -var init_config="$INIT_CONFIG" \
|
||||
-var container_name="$container_name" \
|
||||
$FIXTURE_ROOT/minimal.json
|
||||
assert_container_name "$container_name"
|
||||
}
|
||||
|
||||
@test "lxc: build trusty minimal.json" {
|
||||
have_command debootstrap || skip "'debootstrap' must be installed to build ubuntu containers"
|
||||
local container_name=packer-lxc-ubuntu
|
||||
assert_build ubuntu -var init_config="$INIT_CONFIG" \
|
||||
-var container_name="$container_name" \
|
||||
-var template_parameters="SUITE=trusty" \
|
||||
$FIXTURE_ROOT/minimal.json
|
||||
assert_container_name "$container_name"
|
||||
}
|
||||
|
||||
@test "lxc: build debian minimal.json" {
|
||||
have_command debootstrap || skip "'debootstrap' must be installed to build debian containers"
|
||||
local container_name=packer-lxc-debian
|
||||
assert_build debian -var init_config="$INIT_CONFIG" \
|
||||
-var container_name="$container_name" \
|
||||
-var template_parameters="SUITE=jessie" \
|
||||
$FIXTURE_ROOT/minimal.json
|
||||
assert_container_name "$container_name"
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the basic CLI functionality of Packer. It makes no network
|
||||
# requests and should be very fast.
|
||||
|
||||
load test_helper
|
||||
|
||||
@test "cli: packer should show help" {
|
||||
run packer
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" == *"usage: packer"* ]]
|
||||
}
|
||||
|
||||
@test "cli: packer version" {
|
||||
run packer version
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Packer v"* ]]
|
||||
|
||||
run packer -v
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ ([0-9]+\.[0-9]+) ]]
|
||||
|
||||
run packer --version
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ ([0-9]+\.[0-9]+) ]]
|
||||
}
|
||||
|
||||
@test "cli: packer version show help" {
|
||||
run packer version -h
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Packer v"* ]]
|
||||
|
||||
run packer version --help
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Packer v"* ]]
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the ssh communicator using AWS builder. The teardown function will automatically
|
||||
# delete any AMIs with a tag of `packer-test` being equal to "true" so
|
||||
# be sure any test cases set this.
|
||||
|
||||
load test_helper
|
||||
verify_aws_cli
|
||||
fixtures communicator-ssh
|
||||
|
||||
setup() {
|
||||
cd $FIXTURE_ROOT
|
||||
}
|
||||
|
||||
teardown() {
|
||||
aws_ami_cleanup
|
||||
}
|
||||
|
||||
@test "shell provisioner: local port tunneling" {
|
||||
run packer build $FIXTURE_ROOT/local-tunnel.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Connection to localhost port 10022 [tcp/*] succeeded"* ]]
|
||||
}
|
||||
|
||||
@test "shell provisioner: remote port tunneling" {
|
||||
run packer build $FIXTURE_ROOT/remote-tunnel.json
|
||||
[ "$status" -eq 0 ]
|
||||
MY_LOCAL_IP=$(curl -s https://ifconfig.co/)
|
||||
[[ "$output" == *"$MY_LOCAL_IP"* ]]
|
||||
}
|
||||
15
test/fixtures/amazon-ebs/ami_region_copy.json
vendored
15
test/fixtures/amazon-ebs/ami_region_copy.json
vendored
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true",
|
||||
"packer-id": "ami_region_copy"
|
||||
},
|
||||
"ami_regions": ["us-west-1", "us-west-2"]
|
||||
}]
|
||||
}
|
||||
13
test/fixtures/amazon-ebs/minimal.json
vendored
13
test/fixtures/amazon-ebs/minimal.json
vendored
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}]
|
||||
}
|
||||
16
test/fixtures/builder-googlecompute/minimal.json
vendored
16
test/fixtures/builder-googlecompute/minimal.json
vendored
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"variables": {
|
||||
"account_file": null,
|
||||
"project_id": null
|
||||
},
|
||||
|
||||
"builders": [{
|
||||
"type": "googlecompute",
|
||||
"account_file": "{{user `account_file`}}",
|
||||
"project_id": "{{user `project_id`}}",
|
||||
|
||||
"image_name": "packerbats-minimal-{{timestamp}}",
|
||||
"source_image": "debian-7-wheezy-v20141108",
|
||||
"zone": "us-central1-a"
|
||||
}]
|
||||
}
|
||||
30
test/fixtures/builder-hyperone/chroot.json
vendored
30
test/fixtures/builder-hyperone/chroot.json
vendored
|
|
@ -1,30 +0,0 @@
|
|||
{
|
||||
"variables": {
|
||||
"token": null,
|
||||
"project": null
|
||||
},
|
||||
"builders": [{
|
||||
"token": "{{ user `token` }}",
|
||||
"project": "{{ user `project` }}",
|
||||
"type": "hyperone",
|
||||
"source_image": "ubuntu",
|
||||
"disk_size": 10,
|
||||
"vm_type": "a1.nano",
|
||||
"chroot_disk": true,
|
||||
"chroot_command_wrapper": "sudo {{.Command}}",
|
||||
"pre_mount_commands": [
|
||||
"parted {{.Device}} mklabel msdos mkpart primary 1M 100% set 1 boot on print",
|
||||
"mkfs.ext4 {{.Device}}1"
|
||||
],
|
||||
"post_mount_commands": [
|
||||
"apt-get update",
|
||||
"apt-get install debootstrap",
|
||||
"debootstrap --arch amd64 bionic {{.MountPath}}"
|
||||
],
|
||||
"image_name": "packerbats-chroot-{{timestamp}}",
|
||||
"image_tags": {
|
||||
"key2":"value2"
|
||||
}
|
||||
}],
|
||||
"provisioners": []
|
||||
}
|
||||
18
test/fixtures/builder-hyperone/minimal.json
vendored
18
test/fixtures/builder-hyperone/minimal.json
vendored
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"variables": {
|
||||
"token": null,
|
||||
"project": null
|
||||
},
|
||||
"builders": [{
|
||||
"token": "{{ user `token` }}",
|
||||
"project": "{{ user `project` }}",
|
||||
"type": "hyperone",
|
||||
"source_image": "ubuntu",
|
||||
"disk_size": 10,
|
||||
"vm_type": "a1.nano",
|
||||
"image_name": "packerbats-minimal-{{timestamp}}",
|
||||
"image_tags": {
|
||||
"key":"value"
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
variable "token" {
|
||||
type = string
|
||||
}
|
||||
|
||||
variable "project" {
|
||||
type = string
|
||||
}
|
||||
|
||||
source "hyperone" "new-syntax" {
|
||||
token = var.token
|
||||
project = var.project
|
||||
source_image = "debian"
|
||||
disk_size = 10
|
||||
vm_type = "a1.nano"
|
||||
image_name = "packerbats-hcl-{{timestamp}}"
|
||||
image_tags = {
|
||||
key="value"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
sources = [
|
||||
"source.hyperone.new-syntax"
|
||||
]
|
||||
|
||||
provisioner "shell" {
|
||||
inline = ["sleep 5"]
|
||||
}
|
||||
}
|
||||
28
test/fixtures/builder-linode/minimal.json
vendored
28
test/fixtures/builder-linode/minimal.json
vendored
|
|
@ -1,28 +0,0 @@
|
|||
{
|
||||
"variables": {
|
||||
"linode_token": "{{env `LINODE_TOKEN`}}"
|
||||
},
|
||||
"builders": [
|
||||
{
|
||||
"type": "linode",
|
||||
"linode_token": "{{user `linode_token`}}",
|
||||
|
||||
"region": "us-central",
|
||||
"swap_size": 256,
|
||||
"image": "linode/debian9",
|
||||
"instance_type": "g6-nanode-1",
|
||||
"instance_label": "packerbats-minimal-{{timestamp}}",
|
||||
|
||||
"image_label": "packerbats-minimal-image-{{timestamp}}",
|
||||
"image_description": "packerbats",
|
||||
|
||||
"ssh_username": "root"
|
||||
}
|
||||
],
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell",
|
||||
"inline": ["echo Hello > /root/message.txt"]
|
||||
}
|
||||
]
|
||||
}
|
||||
31
test/fixtures/builder-lxc/minimal.json
vendored
31
test/fixtures/builder-lxc/minimal.json
vendored
|
|
@ -1,31 +0,0 @@
|
|||
{
|
||||
"variables": {
|
||||
"template_name": "debian",
|
||||
"template_parameters": "SUITE=jessie",
|
||||
"container_name": "packer-lxc",
|
||||
"set_var": "hello"
|
||||
},
|
||||
"provisioners": [
|
||||
{
|
||||
"type": "shell",
|
||||
"inline": [
|
||||
"if [ \"$SET_VAR\" != \"{{user `set_var`}}\" ]; then",
|
||||
" echo \"Got unexpected value '$SET_VAR' for SET_VAR\" 1>&2",
|
||||
" exit 1",
|
||||
"fi"
|
||||
]
|
||||
}
|
||||
],
|
||||
"builders": [
|
||||
{
|
||||
"type": "lxc",
|
||||
"name": "lxc-{{user `template_name`}}",
|
||||
"template_name": "{{user `template_name`}}",
|
||||
"container_name": "{{user `container_name`}}",
|
||||
"create_options": [ "-f", "{{user `init_config`}}" ],
|
||||
"attach_options": [ "--clear-env", "--set-var", "SET_VAR={{user `set_var`}}" ],
|
||||
"config_file": "/usr/share/lxc/config/{{user `template_name`}}.common.conf",
|
||||
"template_environment_vars": [ "{{user `template_parameters`}}" ]
|
||||
}
|
||||
]
|
||||
}
|
||||
21
test/fixtures/communicator-ssh/local-tunnel.json
vendored
21
test/fixtures/communicator-ssh/local-tunnel.json
vendored
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"ssh_local_tunnels": ["10022:localhost:22"],
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "shell-local",
|
||||
"inline": [
|
||||
"echo | nc -G 5 -w 5 -v localhost 10022 2>&1"
|
||||
]
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "t2.micro",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"ssh_remote_tunnels": ["8443:ifconfig.co:443"],
|
||||
"source_ami": "ami-0111e8c43a763eb71",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
"provisioners": [{
|
||||
"inline": [
|
||||
"curl -kvs --connect-to ifconfig.co:443:localhost:8443 https://ifconfig.co/"
|
||||
],
|
||||
"type": "shell"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
1
test/fixtures/provisioner-file/dir/file.txt
vendored
1
test/fixtures/provisioner-file/dir/file.txt
vendored
|
|
@ -1 +0,0 @@
|
|||
337 miles
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "file",
|
||||
"source": "dir",
|
||||
"destination": "/tmp"
|
||||
}, {
|
||||
"type": "shell",
|
||||
"inline": ["cat /tmp/dir/file.txt"]
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "t2.micro",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ec2-user",
|
||||
"ssh_file_transfer_method": "sftp",
|
||||
"source_ami": "ami-8da458e6",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "file",
|
||||
"source": "dir",
|
||||
"destination": "/tmp"
|
||||
}, {
|
||||
"type": "shell",
|
||||
"inline": ["cat /tmp/dir/file.txt"]
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "file",
|
||||
"source": "dir/",
|
||||
"destination": "/tmp"
|
||||
}, {
|
||||
"type": "shell",
|
||||
"inline": ["cat /tmp/file.txt"]
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "t2.micro",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ec2-user",
|
||||
"ssh_file_transfer_method": "sftp",
|
||||
"source_ami": "ami-8da458e6",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "file",
|
||||
"source": "dir/",
|
||||
"destination": "/tmp"
|
||||
}, {
|
||||
"type": "shell",
|
||||
"inline": ["cat /tmp/file.txt"]
|
||||
}]
|
||||
}
|
||||
22
test/fixtures/provisioner-file/file.json
vendored
22
test/fixtures/provisioner-file/file.json
vendored
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "file",
|
||||
"source": "file.txt",
|
||||
"destination": "/tmp/file.txt"
|
||||
}, {
|
||||
"type": "shell",
|
||||
"inline": ["cat /tmp/file.txt"]
|
||||
}]
|
||||
}
|
||||
1
test/fixtures/provisioner-file/file.txt
vendored
1
test/fixtures/provisioner-file/file.txt
vendored
|
|
@ -1 +0,0 @@
|
|||
24901 miles
|
||||
23
test/fixtures/provisioner-file/file_sftp.json
vendored
23
test/fixtures/provisioner-file/file_sftp.json
vendored
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "t2.micro",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ec2-user",
|
||||
"ssh_file_transfer_method": "sftp",
|
||||
"source_ami": "ami-8da458e6",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "file",
|
||||
"source": "file.txt",
|
||||
"destination": "/tmp/file.txt"
|
||||
}, {
|
||||
"type": "shell",
|
||||
"inline": ["cat /tmp/file.txt"]
|
||||
}]
|
||||
}
|
||||
21
test/fixtures/provisioner-shell/inline.json
vendored
21
test/fixtures/provisioner-shell/inline.json
vendored
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "shell",
|
||||
"inline": [
|
||||
"bash -c 'echo HELLO I AM `whoami`'",
|
||||
"echo AND ANOTHER"
|
||||
]
|
||||
}]
|
||||
}
|
||||
18
test/fixtures/provisioner-shell/script.json
vendored
18
test/fixtures/provisioner-shell/script.json
vendored
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "shell",
|
||||
"script": "script.sh"
|
||||
}]
|
||||
}
|
||||
3
test/fixtures/provisioner-shell/script.sh
vendored
3
test/fixtures/provisioner-shell/script.sh
vendored
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo HELLO I AM DOG
|
||||
20
test/fixtures/provisioner-shell/scripts.json
vendored
20
test/fixtures/provisioner-shell/scripts.json
vendored
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"builders": [{
|
||||
"type": "amazon-ebs",
|
||||
"ami_name": "packer-test {{timestamp}}",
|
||||
"instance_type": "m1.small",
|
||||
"region": "us-east-1",
|
||||
"ssh_username": "ubuntu",
|
||||
"source_ami": "ami-0568456c",
|
||||
"tags": {
|
||||
"packer-test": "true"
|
||||
}
|
||||
}],
|
||||
|
||||
"provisioners": [{
|
||||
"type": "shell",
|
||||
"scripts": [
|
||||
"script.sh"
|
||||
]
|
||||
}]
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the amazon-ebs builder. The teardown function will automatically
|
||||
# delete any AMIs with a tag of `packer-test` being equal to "true" so
|
||||
# be sure any test cases set this.
|
||||
|
||||
load test_helper
|
||||
verify_aws_cli
|
||||
fixtures provisioner-file
|
||||
|
||||
setup() {
|
||||
cd $FIXTURE_ROOT
|
||||
}
|
||||
|
||||
teardown() {
|
||||
aws_ami_cleanup
|
||||
}
|
||||
|
||||
@test "file provisioner: single file" {
|
||||
run packer build $FIXTURE_ROOT/file.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"24901 miles"* ]]
|
||||
}
|
||||
|
||||
@test "file provisioner: directory (no trailing slash)" {
|
||||
run packer build $FIXTURE_ROOT/dir_no_trailing.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"337 miles"* ]]
|
||||
}
|
||||
|
||||
@test "file provisioner: directory (with trailing slash)" {
|
||||
run packer build $FIXTURE_ROOT/dir_with_trailing.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"337 miles"* ]]
|
||||
}
|
||||
|
||||
@test "file provisioner: single file through sftp" {
|
||||
run packer build $FIXTURE_ROOT/file_sftp.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"24901 miles"* ]]
|
||||
}
|
||||
|
||||
@test "file provisioner: directory through sftp (no trailing slash)" {
|
||||
run packer build $FIXTURE_ROOT/dir_no_trailing_sftp.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"337 miles"* ]]
|
||||
}
|
||||
|
||||
@test "file provisioner: directory through sftp (with trailing slash)" {
|
||||
run packer build $FIXTURE_ROOT/dir_with_trailing_sftp.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"337 miles"* ]]
|
||||
}
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
#!/usr/bin/env bats
|
||||
#
|
||||
# This tests the amazon-ebs builder. The teardown function will automatically
|
||||
# delete any AMIs with a tag of `packer-test` being equal to "true" so
|
||||
# be sure any test cases set this.
|
||||
|
||||
load test_helper
|
||||
verify_aws_cli
|
||||
fixtures provisioner-shell
|
||||
|
||||
setup() {
|
||||
cd $FIXTURE_ROOT
|
||||
}
|
||||
|
||||
teardown() {
|
||||
aws_ami_cleanup
|
||||
}
|
||||
|
||||
@test "shell provisioner: inline scripts" {
|
||||
run packer build $FIXTURE_ROOT/inline.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"HELLO I AM ubuntu"* ]]
|
||||
[[ "$output" == *"AND ANOTHER"* ]]
|
||||
}
|
||||
|
||||
@test "shell provisioner: script" {
|
||||
run packer build $FIXTURE_ROOT/script.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"HELLO I AM DOG"* ]]
|
||||
}
|
||||
|
||||
@test "shell provisioner: scripts" {
|
||||
run packer build $FIXTURE_ROOT/scripts.json
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"HELLO I AM DOG"* ]]
|
||||
}
|
||||
|
|
@ -1,52 +0,0 @@
|
|||
# Let's verify that the tools we need are installed
|
||||
verify_aws_cli() {
|
||||
declare -a required=(aws)
|
||||
for cmd in "${required[@]}"; do
|
||||
command -v $cmd >/dev/null 2>&1 || {
|
||||
echo "'$cmd' must be installed" >&2
|
||||
exit 1
|
||||
}
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Bats modification
|
||||
#--------------------------------------------------------------------
|
||||
# This allows us to override a function in Bash
|
||||
save_function() {
|
||||
local ORIG_FUNC=$(declare -f $1)
|
||||
local NEWNAME_FUNC="$2${ORIG_FUNC#$1}"
|
||||
eval "$NEWNAME_FUNC"
|
||||
}
|
||||
|
||||
# Override the run function so that we always output the output
|
||||
save_function run old_run
|
||||
run() {
|
||||
old_run $@
|
||||
|
||||
# Output the command we ran
|
||||
echo "Executing: " $@
|
||||
|
||||
# "$output" gets rid of newlines. This will bring them back.
|
||||
for line in "${lines[@]}"; do
|
||||
echo $line
|
||||
done
|
||||
}
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Helper functions
|
||||
#--------------------------------------------------------------------
|
||||
# This sets the directory for fixtures by specifying the name of
|
||||
# the folder with fixtures.
|
||||
fixtures() {
|
||||
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
|
||||
}
|
||||
|
||||
# This deletes any AMIs with a tag "packer-test" of "true"
|
||||
aws_ami_cleanup() {
|
||||
local region=${1:-us-east-1}
|
||||
aws ec2 describe-images --region ${region} --owners self --output text \
|
||||
--filters 'Name=tag:packer-test,Values=true' \
|
||||
--query 'Images[*].ImageId' \
|
||||
| xargs -n1 aws ec2 deregister-image --region ${region} --image-id
|
||||
}
|
||||
Loading…
Reference in a new issue