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

Remove VCR from InSpec #1029

Merged
merged 3 commits into from
Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions .ci/acceptance-tests/inspec-integration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ set +x
echo "${TERRAFORM_KEY}" > /tmp/google-account.json
set -x

gcloud auth activate-service-account [email protected] --key-file=$GOOGLE_CLOUD_KEYFILE_JSON

pushd magic-modules-new-prs

# Compile inspec because we are running off of new-prs
Expand Down Expand Up @@ -60,8 +58,6 @@ do
rm -r inspec-cassettes

if inspec exec verify-mm --attrs=attributes/attributes.yaml -t gcp:// --no-distinct-exit; then
# Upload cassettes to storage bucket for unit test use
gsutil cp inspec-cassettes/* gs://magic-modules-inspec-bucket/inspec-cassettes
exit 0
fi
done
Expand Down
26 changes: 0 additions & 26 deletions .ci/ci.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -261,31 +261,6 @@ jobs:
get_params:
skip_clone: true

- name: inspec-test
plan:
- get: magic-modules
version: every
trigger: true
params:
submodules: [build/inspec]
passed: [mm-generate]
- task: test
file: magic-modules/.ci/unit-tests/inspec.yml
params:
TERRAFORM_KEY: ((terraform-key))
timeout: 30m
on_failure:
do:
- get: magic-modules-new-prs
passed: [mm-generate]
- put: magic-modules-new-prs
params:
status: failure
context: inspec-tests
path: magic-modules-new-prs
get_params:
skip_clone: true

- name: create-prs
plan:
- get: magic-modules
Expand All @@ -297,7 +272,6 @@ jobs:
- mm-generate
- terraform-test
- ansible-test
- inspec-test
- get: mm-initial-pr
attempts: 2
resource: magic-modules-new-prs
Expand Down
1 change: 0 additions & 1 deletion .ci/containers/inspec/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ gem 'github_changelog_generator'
gem 'passgen'
gem 'pry-coolline'
gem 'rake'
gem 'vcr'
gem 'webmock'
59 changes: 1 addition & 58 deletions .ci/unit-tests/inspec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,61 +3,4 @@
set -e
set -x

# Service account credentials for GCP to pull VCR cassettes
export GOOGLE_CLOUD_KEYFILE_JSON="/tmp/google-account.json"

# CI sets the contents of our json account secret in our environment; dump it
# to disk for use in tests.
set +x
echo "${TERRAFORM_KEY}" > /tmp/google-account.json
set -x

export CLOUD_SDK_REPO="cloud-sdk-stretch"
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
apt-get update && apt-get install google-cloud-sdk -y

gcloud auth activate-service-account [email protected] --key-file=$GOOGLE_CLOUD_KEYFILE_JSON

pushd "magic-modules/build/inspec/test/integration"

# Generate a rsa private key to use in mocks
# Due to using gauth library InSpec + train expect to load a service account file from an env variable
# This service account file must contain a real RSA key, but this key is never used in unit tests.
rsatmp=$(mktemp /tmp/rsatmp.XXXXXX)
yes y | ssh-keygen -f "${rsatmp}" -t rsa -N ''


echo '{
"type": "service_account",
"project_id": "fake",
"private_key_id": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"private_key": "<%= @fake_private_key %>",
"client_email": "[email protected]",
"client_id": "123451234512345123451",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/fake%40fake.iam.gserviceaccount.com"
}' > inspec.json.erb

# Formatting a rsa key file for use is surprisingly difficult
echo -n "@fake_private_key = '$(echo -n "$(cat ${rsatmp})")'.gsub(\"\n\", '\n')" > var.rb
rm ${rsatmp}
erb -r './var' inspec.json.erb > inspec.json

export GOOGLE_APPLICATION_CREDENTIALS=${PWD}/inspec.json

bundle install
# TODO change this to use a github repo
gsutil cp -r gs://magic-modules-inspec-bucket/inspec-cassettes .

function cleanup {
rm -rf inspec-cassettes
rm inspec.json
rm inspec.json.erb
rm var.rb
}
trap cleanup EXIT

inspec exec verify-mm --attrs=attributes/attributes.yaml -t gcp:// --no-distinct-exit
echo "TODO(slevenick): re add VCR testing"
1 change: 0 additions & 1 deletion provider/inspec/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ group :development do
gem 'passgen'
gem 'pry-coolline'
gem 'rake'
gem 'vcr'
gem 'webmock'
end
6 changes: 1 addition & 5 deletions templates/inspec/integration_test_template.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<%= lines(autogen_notice :ruby) -%>

require_relative '../vcr_config'

title 'Test GCP <%= name -%> resource.'

<%= compile("templates/inspec/examples/attributes/#{name}.erb") -%>
Expand All @@ -10,7 +8,5 @@ control '<%= name -%>-1.0' do
impact 1.0
title '<%= name -%> resource test'

VCR.use_cassette('<%= name -%>') do
<%= indent(compile("templates/inspec/examples/#{name}.erb"), 4) %>
end
<%= indent(compile("templates/inspec/examples/#{name}.erb"), 2) %>
end
34 changes: 0 additions & 34 deletions templates/inspec/tests/integration/verify-mm/vcr_config.rb

This file was deleted.