envato / ami-spec Goto Github PK
View Code? Open in Web Editor NEWAcceptance testing your AMIs
License: MIT License
Acceptance testing your AMIs
License: MIT License
Hi,
I'm not sure if this is a bug or i haven't configured something correctly, but it seems like my spec files are asserting against my local machine instead of the EC2 instance.
I'm trying to run the following command:
ami_spec
--role mesos
--ami
--subnet-id
--key-name
--key-file
--ssh-user ubuntu
--specs ./spec
--aws-region eu-west-1
It brings up an EC2 instances fine and attempts to run the specs.
However, it seems like it's running the specs against my local (OSX 10.12.3) machine as it is using brew to try and determine if a package is installed. To get around that i tried to run apt list, however i get a mac pop up saying i need to install a jdk if i want to use apt.
It's strange, because in the output it gives me the IP of the EC2 instance.
Excuse me if i am missing something obvious - anyone have any ideas?
spec/mesos/default_spec.rb:
require 'serverspec'
require 'spec_helper'
set :backend, :exec
describe package('mesos') do
it { should be_installed.with_version('1.2.0') }
end
describe command("apt list mesos") do
its(:stdout) { should contain('mesos/now 1.2.0') }
its(:stdout) { should contain('installed') }
end
Output:
ami_spec \
--role mesos \
--ami <amiid>\
--subnet-id <subnetid> \
--key-name <keyname> \
--key-file <keyfile> \
--ssh-user ubuntu \
--specs ./spec \
--aws-region eu-west-1
/usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-2.9.4/lib/net/ssh/transport/session.rb:67:in `initialize': Object#timeout is deprecated, use Timeout.timeout instead.
/usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-2.9.4/lib/net/ssh/transport/session.rb:84:in `initialize': Object#timeout is deprecated, use Timeout.timeout instead.
/usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-2.9.4/lib/net/ssh/transport/cipher_factory.rb:98: warning: constant OpenSSL::Cipher::Cipher is deprecated
/usr/local/lib/ruby/gems/2.4.0/gems/net-ssh-2.9.4/lib/net/ssh/transport/cipher_factory.rb:72: warning: constant OpenSSL::Cipher::Cipher is deprecated
boo!
Running tests for mesos
FFF
Failures:
1) Package "mesos" should be installed with version "1.2.0"
On host `10.185.38.238'
Failure/Error: it { should be_installed.with_version('1.2.0') }
expected Package "mesos" to be installed with version "1.2.0"
/bin/sh -c brew\ info\ mesos\ \|\ grep\ -E\ \"\^\$\(brew\ --prefix\)/Cellar/mesos/1.2.0\"
# ./spec/mesos/default_spec.rb:7:in `block (2 levels) in <top (required)>'
2) Command "apt list mesos" stdout should contain "mesos/now 1.2.0"
On host `10.185.38.238'
Failure/Error: its(:stdout) { should contain('mesos/now 1.2.0') }
expected "" to contain "mesos/now 1.2.0"
/bin/sh -c apt\ list\ mesos
# ./spec/mesos/default_spec.rb:11:in `block (2 levels) in <top (required)>'
Environment details:
ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin16]
OS: OSX 10.12.3
gem list
*** LOCAL GEMS ***
addressable (2.5.2)
ami_spec (0.3.0)
aws-sdk (2.10.54, 2.10.53)
aws-sdk-core (2.10.54, 2.10.53)
aws-sdk-resources (2.10.54, 2.10.53)
aws-sigv4 (1.0.2)
bigdecimal (default: 1.3.0)
bundler (1.15.4)
crack (0.4.3)
did_you_mean (1.1.0)
diff-lcs (1.3)
hashdiff (0.3.6)
hashie (3.5.6)
io-console (default: 0.4.6)
jmespath (1.3.1)
json (default: 2.0.4)
minitest (5.10.1)
multi_json (1.12.2)
net-scp (1.2.1)
net-ssh (2.9.4)
net-telnet (0.1.1)
openssl (default: 2.0.5)
power_assert (0.4.1)
psych (default: 2.2.2)
public_suffix (3.0.0)
rake (12.1.0, 12.0.0)
rdoc (default: 5.0.0)
rspec (3.6.0)
rspec-core (3.6.0)
rspec-expectations (3.6.0)
rspec-its (1.2.0)
rspec-mocks (3.6.0)
rspec-support (3.6.0)
safe_yaml (1.0.4)
serverspec (2.41.0)
sfl (2.3)
specinfra (2.72.0)
test-unit (3.2.3)
timecop (0.9.1)
trollop (2.1.2)
webmock (3.0.1)
xmlrpc (0.2.1)
https://github.com/envato/ami-spec/blob/master/lib/ami_spec/aws_instance.rb#L31
This connection does not use the region passed in from the command line.
I know technically this may not be an issue with ami-spec. Essentially, I can run ami-spec fine locally with the exact same command I am running via AWS codebuild with Ruby 2.7 (and tried 2.6). I thought it was an IAM permissions issue, but using the --debug flag proves that is not the case (the EC2 instance stays running with --debug).
I'm getting this stack trace:
/root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:92:in `rescue in initialize': Net::SSH::ConnectionTimeout (Net::SSH::ConnectionTimeout)
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:59:in `initialize'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `new'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `start'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec/wait_for_ssh.rb:11:in `wait'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:91:in `block in run'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:89:in `each'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:89:in `run'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:191:in `invoke'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/bin/ami_spec:5:in `<top (required)>'
from /root/.rbenv/versions/2.7.1/bin/ami_spec:23:in `load'
from /root/.rbenv/versions/2.7.1/bin/ami_spec:23:in `<main>'
/root/.rbenv/versions/2.7.1/lib/ruby/2.7.0/socket.rb:61:in `connect_internal': Connection timed out - user specified timeout (Errno::ETIMEDOUT)
from /root/.rbenv/versions/2.7.1/lib/ruby/2.7.0/socket.rb:137:in `connect'
from /root/.rbenv/versions/2.7.1/lib/ruby/2.7.0/socket.rb:642:in `block in tcp'
from /root/.rbenv/versions/2.7.1/lib/ruby/2.7.0/socket.rb:227:in `each'
from /root/.rbenv/versions/2.7.1/lib/ruby/2.7.0/socket.rb:227:in `foreach'
from /root/.rbenv/versions/2.7.1/lib/ruby/2.7.0/socket.rb:632:in `tcp'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh/transport/session.rb:73:in `initialize'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `new'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/net-ssh-5.2.0/lib/net/ssh.rb:246:in `start'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec/wait_for_ssh.rb:11:in `wait'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:91:in `block in run'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:89:in `each'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:89:in `run'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/lib/ami_spec.rb:191:in `invoke'
from /root/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/ami_spec-1.6.0/bin/ami_spec:5:in `<top (required)>'
from /root/.rbenv/versions/2.7.1/bin/ami_spec:23:in `load'
from /root/.rbenv/versions/2.7.1/bin/ami_spec:23:in `<main>'
I wanted to try with a newer version of net-ssh
gem but the spec is locked to version 5 and I see version 6 now available over at net-ssh.
It's definitely not security group related, and like I said, I can run the ami_spec
command all day local from my Mac with great success.
I'm wondering if you, or anyone may have any idea what's going on here?
Thanks,
Chris
As I understand your docu, the only way to test specs is to provide amazons key & key secret.
This means, amazons assume role feature is not supported yet?
BR, jerger
Just refactored my wrapper, and i spent way too long getting authentication errors because I was putting the keyfile in the wrong place.
If I had seen that it wasnt found at the path I specified I wouldve known right away.
I just wanted to reach out to see if anyone else is seeing similar behavior. I may be doing something wrong but I'm not sure. I keep randomly getting failures during EC2 instance creation with:
connection closed by remote host (Net::SSH::Disconnect)
It appears to only happen when an EC2 instance takes longer to initialize than usual (i.e. status checks don't pass for a long time). Should Net::SSH::Disconnect
be added to https://github.com/envato/ami-spec/blob/master/lib/ami_spec/wait_for_ssh.rb#L12?
Full stacktrace:
/var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/packet_stream.rb:110:in `block in next_packet': connection closed by remote host (Net::SSH::Disconnect)
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/packet_stream.rb:104:in `loop'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/packet_stream.rb:104:in `next_packet'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/session.rb:193:in `block in poll_message'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/session.rb:190:in `loop'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/session.rb:190:in `poll_message'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/transport/session.rb:175:in `next_message'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:101:in `block in next_message'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:100:in `loop'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:100:in `next_message'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/methods/publickey.rb:65:in `authenticate_with'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/methods/publickey.rb:20:in `block in authenticate'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:122:in `block in each_identity'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:119:in `each'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/key_manager.rb:119:in `each_identity'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/methods/publickey.rb:19:in `authenticate'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:85:in `block in authenticate'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:71:in `each'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh/authentication/session.rb:71:in `authenticate'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/net-ssh-5.1.0/lib/net/ssh.rb:246:in `start'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/ami_spec-1.2.0/lib/ami_spec/wait_for_ssh.rb:11:in `wait'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/ami_spec-1.2.0/lib/ami_spec.rb:57:in `block in run'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/ami_spec-1.2.0/lib/ami_spec.rb:55:in `each'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/ami_spec-1.2.0/lib/ami_spec.rb:55:in `run'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/ami_spec-1.2.0/lib/ami_spec.rb:134:in `invoke'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/gems/ami_spec-1.2.0/bin/ami_spec:5:in `<top (required)>'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/bin/ami_spec:23:in `load'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/bin/ami_spec:23:in `<main>'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/bin/ruby_executable_hooks:15:in `eval'
from /var/lib/jenkins/.rvm/gems/ruby-2.5.1@#REDACTED#/bin/ruby_executable_hooks:15:in `<main>'
Thanks!
This looks like a great tool. I think a few same spec files would help people (i.e. me) get started with it.
Do you have any simple tests you can reasonably share?
I would like to use rspec-wait
for testing things that take a while to complete in our ami. We have some long running boot processes that we need to ensure complete successfully and the serverspec tests are run too soon after the instance is booted and the ssh connection is successful.
I have tried adding a Gemfile in the root of the --specs
but that doesn't seem to work as well as our projects main Gemfile but neither seem to get the rspec-wait
gem loaded at serverspec run time.
Any ideas?
If you don't set :ssh_options
for ServerSpec, it throws an exception
`sudo?': undefined method `[]' for nil:NilClass (NoMethodError)
We set the :ssh_options
when calling AmiSpec::ServerSpec.run
, because the values of this are unknown until runtime.
SpecInfra wants to evaluate the conditional at load time, not at run time.
Stack trace:
./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/backend/ssh.rb:179:in `sudo?': undefined method `[]' for nil:NilClass (NoMethodError)
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/backend/ssh.rb:42:in `build_command'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/backend/ssh.rb:10:in `run_command'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/detect_os.rb:13:in `run_command'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/detect_os/freebsd.rb:3:in `detect'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/detect_os.rb:5:in `detect'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:24:in `block in detect_os'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:23:in `each'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:23:in `detect_os'
from ./vendor/bundle/ruby/1.9.1/gems/specinfra-2.45.0/lib/specinfra/helper/os.rb:9:in `os'
Recently I was getting Net::SSH::ConnectionTimeout error, and then I found out that this exception is not rescued here. So the script will end in first try irrespective of ssh_retries value. I was hoping it for to be rescued by Timeout::Error. Any idea why this exception is not included, as it is a common timeout error for Net::SSH? I can submit a PR if required. thanks
Running bundle install
in the fresh checkout results in:
Installing rake 12.3.1
Gem::InstallError: rake requires Ruby version >= 2.0.0.
...
An error occurred while installing rake (12.3.1), and Bundler cannot continue.
Make sure that `gem install rake -v '12.3.1'` succeeds before bundling.
.ruby-version
requires 1.9.3p551
, which is quite dated now. There's a commit about the downgrade from 2.2 (a3180c0) but without an explanation about why it's done.
Is there something preventing a bump to the latest ruby 2.5? After manual upgrade, tests pass.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.