ami_spec 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c50eed3429c33081ff25fc9d4695b10c1f3696c839a53f2da7ebaca9457333f8
4
- data.tar.gz: 20a87adad2bfa8a80ae3f6c4794d08515612a4da46590a61656ac3c02608a1a0
3
+ metadata.gz: 4504c60fd0ce24f40be03e192159fcc9c8509cddbc2642cb0c8c50e351a7c7fa
4
+ data.tar.gz: 8fc38e659fb6436b8ad37467564445de49c92940991d3f8b820d1b2f6927355a
5
5
  SHA512:
6
- metadata.gz: d89d294411139f9645536b67aeab0e47eb744a9aad698c9e3807ac29b5bbf0589c6dbbfa4dc0250a938801878dae8ce673cb765d11c0b932d6e10d94f062ae80
7
- data.tar.gz: 1e0a0a653a5f792e7f126a891f0b6aa73a2aadcf2d3ecda8059cb5df0136337cf719e359cefd79d47227ee0dcd16c37f63adbced9a00b20441f6613b7dfd58e3
6
+ metadata.gz: 1a86bbfccdfbbe323eea7cea45bc9450d41626d3a40ed456a41b4228ef4eb1b211e23268a024dbecd81ebb768a06f00ac19e99f31387ce14e6b32635c99886cf
7
+ data.tar.gz: 65effb5f2d0a7053c645c79b9ffa0c42ca93c4ee4183cdfbc7ab909263affb431d54ba0ea7f0dcb339bc5f3b81466ed765393d644886910b499e6a8df501c673
data/.travis.yml CHANGED
@@ -3,3 +3,4 @@ rvm:
3
3
  - 1.9.3
4
4
  - 2.1.8
5
5
  - 2.2.4
6
+ script: bundle exec rake spec
data/README.md CHANGED
@@ -110,9 +110,23 @@ For bug fixes, documentation changes, and small features:
110
110
  4. Push to the branch (git push origin my-new-feature)
111
111
  5. Create a new Pull Request
112
112
 
113
+ ## Running tests
114
+
115
+ Use the following command to run non-integration tests:
116
+ ```
117
+ bundle exec rake spec
118
+ ```
119
+
120
+ If you're working on the `WaitForRC` feature you can run it's integration tests by first bringing up the containers, then executing the integration tests:
121
+ ```
122
+ docker-compose -f spec/containers/docker-compose.yml up -d
123
+ bundle exec rspec . --tag integration
124
+ docker-compose -f spec/containers/docker-compose.yml down
125
+ ```
126
+
113
127
  ## Maintainers
114
128
 
115
- Patrick Robinson (@nemski)
129
+ Patrick Robinson (@patrobinson)
116
130
 
117
131
  ## License
118
132
 
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
3
 
4
- RSpec::Core::RakeTask.new(:spec)
4
+ RSpec::Core::RakeTask.new(:spec) do |t|
5
+ t.rspec_opts = "--tag ~integration"
6
+ end
5
7
 
6
8
  task :default => :spec
@@ -1,3 +1,3 @@
1
1
  module AmiSpec
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -2,15 +2,39 @@ require 'net/ssh'
2
2
 
3
3
  module AmiSpec
4
4
  class WaitForRC
5
- def self.wait(ip_address, user, key)
6
- Net::SSH.start(ip_address, user, keys: [key], paranoid: false) do |ssh|
7
- # Wait for SystemV to start
8
- # This only works for Ubuntu with upstart.
9
- # Detecting OS and Release will need something like this
10
- # https://github.com/mizzy/specinfra/blob/master/lib/specinfra/helper/detect_os/debian.rb
11
- ssh.exec 'while /usr/sbin/service rc status | grep -q "^rc start/running, process"; do sleep 1; done'
5
+ def self.wait(ip_address, user, key, port=22)
6
+ Net::SSH.start(ip_address, user, keys: [key], paranoid: false, port: port) do |ssh|
7
+ distrib_stdout = ""
8
+ # Determine the OS family
9
+ ssh.exec!("source /etc/*release && echo -n $DISTRIB_ID && echo -n $ID") do |channel, stream, data|
10
+ distrib_stdout << data if stream == :stdout
11
+ end
12
+ if distrib_stdout == "Ubuntu"
13
+ codename_stdout = ""
14
+ ssh.exec!("source /etc/*release && echo -n $DISTRIB_CODENAME") do |channel, stream, data|
15
+ codename_stdout << data if stream == :stdout
16
+ end
17
+ if codename_stdout == "trusty"
18
+ ssh.exec 'while /usr/sbin/service rc status | grep -q "^rc start/running, process"; do sleep 1; done'
19
+ elsif codename_stdout == "xenial"
20
+ ssh.exec 'while /usr/sbin/service rc status >/dev/null; do sleep 1; done'
21
+ else
22
+ puts "WARNING: Only Ubuntu trusty and xenial supported and we detected '#{codename_stdout}'. --wait-for-rc has no effect."
23
+ end
24
+ elsif distrib_stdout == "amzn"
25
+ version_stdout = ""
26
+ ssh.exec!("source /etc/*release && echo -n $VERSION_ID") do |channel, stream, data|
27
+ version_stdout << data if stream == :stdout
28
+ end
29
+ if version_stdout =~ %r{201[0-9]{1}\.[0-9]+}
30
+ ssh.exec 'while initctl status rc |grep -q "^rc start/running"; do sleep 1; done'
31
+ else
32
+ puts "WARNING: Only Amazon Linux 1 is supported and we detected '#{version_stdout}'. --wait-for-rc has no effect."
33
+ end
34
+ else
35
+ puts "WARNING: Only Ubuntu and Amazon linux are supported and we detected '#{distrib_stdout}'. --wait-for-rc has no effect."
36
+ end
12
37
  end
13
38
  end
14
39
  end
15
40
  end
16
-
@@ -0,0 +1,9 @@
1
+ FROM amazonlinux:1
2
+
3
+ RUN yum install -y upstart openssh-server && yum clean all
4
+ ADD rc.conf /etc/init/rc.conf
5
+
6
+ COPY ami-spec.pub /root/.ssh/authorized_keys
7
+ COPY sshd_config /etc/ssh/sshd_config
8
+
9
+ CMD ["/bin/bash", "-c", "exec /sbin/init"]
@@ -0,0 +1,8 @@
1
+ FROM ubuntu-upstart:trusty
2
+
3
+ ENV DEBIAN_FRONTEND noninteractive
4
+ RUN apt-get update && apt-get install -y openssh-server && apt-get clean
5
+
6
+ COPY ami-spec.pub /root/.ssh/authorized_keys
7
+
8
+ EXPOSE 22
@@ -0,0 +1,22 @@
1
+ FROM ubuntu:xenial
2
+
3
+ RUN cd /lib/systemd/system/sysinit.target.wants/; ls | grep -v systemd-tmpfiles-setup | xargs rm -f $1 \
4
+ rm -f /lib/systemd/system/multi-user.target.wants/*;\
5
+ rm -f /etc/systemd/system/*.wants/*;\
6
+ rm -f /lib/systemd/system/local-fs.target.wants/*; \
7
+ rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
8
+ rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
9
+ rm -f /lib/systemd/system/basic.target.wants/*;\
10
+ rm -f /lib/systemd/system/anaconda.target.wants/*; \
11
+ rm -f /lib/systemd/system/plymouth*; \
12
+ rm -f /lib/systemd/system/systemd-update-utmp*;
13
+
14
+ RUN apt-get update && apt-get install -y openssh-server dbus && apt-get clean
15
+
16
+ RUN systemctl set-default multi-user.target
17
+
18
+ COPY ami-spec.pub /root/.ssh/authorized_keys
19
+
20
+ EXPOSE 22
21
+
22
+ CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]
@@ -0,0 +1,5 @@
1
+ ## Integration test containers
2
+
3
+ This directory is used to create containers that can be used to test the `WaitForRC` class. Because they require upstart/systemd to exist we have to install and start the init environment. We also setup SSH so that we can simple call the `wait` function and have it SSH to our container to execute.
4
+
5
+ Refer to the [README](../../README.md#running-tests) for how to execute them.
@@ -0,0 +1,27 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIIEowIBAAKCAQEAwWn2++lylp8RcHzy7H9QpYli3nxLDh769DDbnb9cw2UDd9OH
3
+ 6JZKaT3xe3IbMr39SmkGlOygkBmeH43VxAkiVJv3awDPRU0UvDyUvCsbaYj1/cOS
4
+ 8Vxr7ENExoiKkengcg6k3mFj65ooJ1pf8RoXuj+0+YU0fgejuR/M4x6V8GKFCJhU
5
+ wFmRs3mcoCx0EiJtTx40IW87uOQUruDX5HcgTUInRhyRxltNrXJaap1weMGpIA/o
6
+ Bo8foOx1Os9o3YKQlkPF4iqk2AVJ4FZGbMay0cIq3075Jeig6bdlIhRpYA+w+SAI
7
+ y/yT/K3U1ciQqKtPgahGEyihrh7Ks2F2FSLhdwIDAQABAoIBABWt/QNLrY54kgnb
8
+ 15buxmlntu9dW0Rf8J1ChLtv4cP9JKBf05IcloapbNH7flT3utaGYzh6NZ0xYeoD
9
+ ifyJUZHOUbNqydDozPQ0ji9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h89FhH
25
+ gjvJV5NjaNhFqBWTnNfjSr4o09WFDoQyVwEUrWNJXXZmsjOHqMDT/kwVoAsld1tO
26
+ N+JW6/4M+EMYvF39yWzdQn/U3A1gZIfzAC6S3HUCi9BgKLBMKEN3
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDBafb76XKWnxFwfPLsf1CliWLefEsOHvr0MNudv1zDZQN304folkppPfF7chsyvf1KaQaU7KCQGZ4fjdXECSJUm/drAM9FTRS8PJS8KxtpiPX9w5LxXGvsQ0TGiIqR6eByDqTeYWPrmignWl/xGhe6P7T5hTR+B6O5H8zjHpXwYoUImFTAWZGzeZygLHQSIm1PHjQhbzu45BSu4NfkdyBNQidGHJHGW02tclpqnXB4wakgD+gGjx+g7HU6z2jdgpCWQ8XiKqTYBUngVkZsxrLRwirfTvkl6KDpt2UiFGlgD7D5IAjL/JP8rdTVyJCoq0+BqEYTKKGuHsqzYXYVIuF3
@@ -0,0 +1,28 @@
1
+ version: '3'
2
+ services:
3
+ xenial:
4
+ build:
5
+ context: .
6
+ dockerfile: Dockerfile.xenial
7
+ ports:
8
+ - "1122:22"
9
+ # --security-opt seccomp=unconfined --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro
10
+ security_opt:
11
+ - seccomp:unconfined
12
+ tmpfs:
13
+ - /run
14
+ - /run/lock
15
+ volumes:
16
+ - /sys/fs/cgroup:/sys/fs/cgroup:ro
17
+ trusty:
18
+ build:
19
+ context: .
20
+ dockerfile: Dockerfile.trusty
21
+ ports:
22
+ - "1123:22"
23
+ amazon_linux:
24
+ build:
25
+ context: .
26
+ dockerfile: Dockerfile.amazon_linux
27
+ ports:
28
+ - "1124:22"
@@ -0,0 +1,17 @@
1
+ # rc - System V runlevel compatibility
2
+ #
3
+ # This task runs the old sysv-rc runlevel scripts. It
4
+ # is usually started by the telinit compatibility wrapper.
5
+ #
6
+ # Do not edit this file directly. If you want to change the behaviour,
7
+ # please create a file rc.override and put your changes there.
8
+
9
+ start on runlevel [0123456]
10
+
11
+ stop on runlevel [!$RUNLEVEL]
12
+
13
+ task
14
+
15
+ export RUNLEVEL
16
+ console output
17
+ exec /etc/rc.d/rc $RUNLEVEL
@@ -0,0 +1,17 @@
1
+ HostKey /etc/ssh/ssh_host_rsa_key
2
+ HostKey /etc/ssh/ssh_host_ecdsa_key
3
+ HostKey /etc/ssh/ssh_host_ed25519_key
4
+ SyslogFacility AUTHPRIV
5
+ AuthorizedKeysFile .ssh/authorized_keys
6
+ PasswordAuthentication no
7
+ ChallengeResponseAuthentication no
8
+ UsePAM yes
9
+ X11Forwarding yes
10
+ PrintLastLog yes
11
+ UsePrivilegeSeparation sandbox
12
+ AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
13
+ AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
14
+ AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
15
+ AcceptEnv XMODIFIERS
16
+ Subsystem sftp /usr/libexec/openssh/sftp-server
17
+ PermitRootLogin yes
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe AmiSpec::WaitForRC, integration: true do
4
+ let(:private_key_file) { File.expand_path(File.join('..', 'containers', 'ami-spec'), __FILE__) }
5
+ context 'xenial server' do
6
+ let(:ssh_port) { 1122 }
7
+ it 'executes without printing any errors' do
8
+ expect { described_class.wait("localhost", "root", private_key_file, ssh_port) }.to_not output.to_stdout
9
+ end
10
+ end
11
+
12
+ context 'trusty server' do
13
+ let(:ssh_port) { 1123 }
14
+ it 'executes without printing any errors' do
15
+ expect { described_class.wait("localhost", "root", private_key_file, ssh_port) }.to_not output.to_stdout
16
+ end
17
+ end
18
+
19
+ context 'amazon linux server' do
20
+ let(:ssh_port) { 1124 }
21
+ it 'executes without printing any errors' do
22
+ expect { described_class.wait("localhost", "root", private_key_file, ssh_port) }.to_not output.to_stdout
23
+ end
24
+ end
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ami_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Robinson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-06-28 00:00:00.000000000 Z
12
+ date: 2018-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -135,7 +135,17 @@ files:
135
135
  - lib/ami_spec/wait_for_ssh.rb
136
136
  - spec/ami_spec_spec.rb
137
137
  - spec/aws_instance_spec.rb
138
+ - spec/containers/Dockerfile.amazon_linux
139
+ - spec/containers/Dockerfile.trusty
140
+ - spec/containers/Dockerfile.xenial
141
+ - spec/containers/README.md
142
+ - spec/containers/ami-spec
143
+ - spec/containers/ami-spec.pub
144
+ - spec/containers/docker-compose.yml
145
+ - spec/containers/rc.conf
146
+ - spec/containers/sshd_config
138
147
  - spec/spec_helper.rb
148
+ - spec/wait_for_rc_spec.rb
139
149
  - spec/wait_for_ssh_spec.rb
140
150
  homepage: https://github.com/envato/ami-spec
141
151
  licenses: []
@@ -163,5 +173,15 @@ summary: Acceptance testing your AMIs
163
173
  test_files:
164
174
  - spec/ami_spec_spec.rb
165
175
  - spec/aws_instance_spec.rb
176
+ - spec/containers/Dockerfile.amazon_linux
177
+ - spec/containers/Dockerfile.trusty
178
+ - spec/containers/Dockerfile.xenial
179
+ - spec/containers/README.md
180
+ - spec/containers/ami-spec
181
+ - spec/containers/ami-spec.pub
182
+ - spec/containers/docker-compose.yml
183
+ - spec/containers/rc.conf
184
+ - spec/containers/sshd_config
166
185
  - spec/spec_helper.rb
186
+ - spec/wait_for_rc_spec.rb
167
187
  - spec/wait_for_ssh_spec.rb