github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/test/provisioner_ansible.bats (about) 1 #!/usr/bin/env bats 2 # 3 # This tests the ansible provisioner on Google Cloud Provider (i.e. 4 # googlecompute). The teardown function will delete any images with the text 5 # "packerbats" within the name. 6 7 load test_helper 8 fixtures provisioner-ansible 9 10 # Required parameters 11 : ${GC_ACCOUNT_FILE:?} 12 : ${GC_PROJECT_ID:?} 13 command -v gcloud >/dev/null 2>&1 || { 14 echo "'gcloud' must be installed" >&2 15 exit 1 16 } 17 18 USER_VARS="${USER_VARS} -var account_file=${GC_ACCOUNT_FILE}" 19 USER_VARS="${USER_VARS} -var project_id=${GC_PROJECT_ID}" 20 21 # This tests if GCE has an image that contains the given parameter. 22 gc_has_image() { 23 gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \ 24 | grep $1 | wc -l 25 } 26 27 setup(){ 28 rm -f $FIXTURE_ROOT/ansible-test-id 29 rm -f $FIXTURE_ROOT/ansible-server.key 30 ssh-keygen -N "" -f $FIXTURE_ROOT/ansible-test-id 31 ssh-keygen -N "" -f $FIXTURE_ROOT/ansible-server.key 32 } 33 34 teardown() { 35 gcloud compute --format='table[no-heading](name)' --project=${GC_PROJECT_ID} images list \ 36 | grep packerbats \ 37 | xargs -n1 gcloud compute --project=${GC_PROJECT_ID} images delete 38 39 rm -f $FIXTURE_ROOT/ansible-test-id 40 rm -f $FIXTURE_ROOT/ansible-test-id.pub 41 rm -f $FIXTURE_ROOT/ansible-server.key 42 rm -f $FIXTURE_ROOT/ansible-server.key.pub 43 rm -rf $FIXTURE_ROOT/fetched-dir 44 } 45 46 @test "ansible provisioner: build minimal.json" { 47 cd $FIXTURE_ROOT 48 run packer build ${USER_VARS} $FIXTURE_ROOT/minimal.json 49 [ "$status" -eq 0 ] 50 [ "$(gc_has_image "packerbats-minimal")" -eq 1 ] 51 diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null 52 } 53 54 @test "ansible provisioner: build all_options.json" { 55 cd $FIXTURE_ROOT 56 run packer build ${USER_VARS} $FIXTURE_ROOT/all_options.json 57 [ "$status" -eq 0 ] 58 [ "$(gc_has_image "packerbats-alloptions")" -eq 1 ] 59 diff -r dir fetched-dir/packer-test/tmp/remote-dir > /dev/null 60 } 61 62 @test "ansible provisioner: build scp.json" { 63 cd $FIXTURE_ROOT 64 run packer build ${USER_VARS} $FIXTURE_ROOT/scp.json 65 [ "$status" -eq 0 ] 66 [ "$(gc_has_image "packerbats-scp")" -eq 1 ] 67 diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null 68 } 69 70 @test "ansible provisioner: build sftp.json" { 71 cd $FIXTURE_ROOT 72 run packer build ${USER_VARS} $FIXTURE_ROOT/sftp.json 73 [ "$status" -eq 0 ] 74 [ "$(gc_has_image "packerbats-sftp")" -eq 1 ] 75 diff -r dir fetched-dir/default/tmp/remote-dir > /dev/null 76 } 77