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

Serverspec tests added #34

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
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
76 changes: 49 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
== HOW TO USE ==
## HOW TO USE

Clone repo
- Clone repo
- `bundle install`
- `BASE_BUILD=centos-7 bundle exec rake build`

bundle install

BASE_BUILD=centos-7 bundle exec rake build

== NOTE ON BOX NAMES ==
## NOTE ON BOX NAMES

Dash count indicates level in hierarchy and thus build order -

For instance -

```
rhel-7 <- base
rhel-7-puppet4 <- next layer
rhel-7-puppet4-ruby <- final layer
```

FOR RHEL7 - to build the ruby layer, you'll need to add the rhel subscription manager username and password to the script centos/7/ruby.sh
FOR RHEL7 - to build the ruby layer, you'll need to add the rhel subscription manager username and password to the script `centos/7/ruby.sh`

```
centos-6 <-- base build
centos-6-puppet <-- builds on this
centos-6-puppet-jenkins <-- builds on centos-6-puppet
```

== NOTE ON WINDOWS BUILDS ==
## NOTE ON WINDOWS BUILDS

You will need an updates file locally (to be fixed later) for windows to mount. For now, this needs to be downloaded from Slalom's S3 service to a blobs/ directory within the baseboxes directory.
You will need an updates file locally (to be fixed later) for windows to mount. For now, this needs to be downloaded from Slalom's S3 service to a `blobs/` directory within the baseboxes directory.

Download the Windows updates ISO by running:

Expand All @@ -34,25 +36,27 @@ bundle exec rake winblob

That command creates the blobs directory and downloads the updates ISO to that directory.

== Proxies ==
Call packer with -var and then http_proxy and https_proxy (and their capitalized counterparts if you like) to build boxes with proxies.
## Proxies
Call packer with `-var` and then `http_proxy` and `https_proxy` (and their capitalized counterparts if you like) to build boxes with proxies.

== Environment variables ==
## Environment variables

```
HTTP_PROXY
HTTPS_PROXY
NO_PROXY
BOX_BUILD - set to the name of a build to build only that box during rake spec
BOX_OVERRIDE - set to true to have rake spec avoid building each box
BOX_FORCE - rebuild packer box even if artifacts are present
```

== Extra environment variables ==
## Extra environment variables

If you set the variable `P_USE_VAR_FILE` packer will be passed the option to use a var-file. This var file can be populated with environment variables that are prefixed with `P_` by using the script `scripts/common/packer_variables.sh`

This can then be used by vagrant or other builder processes to pass lots of variables into the packer build to set things such as the mirror location, iso checksum, etc.

== WINDOWS BOXES ==
## WINDOWS BOXES

In order to patch Windows offline the WSUS Offline Updater should be used to create an .ISO file of the available updates. A separate .ISO file should be made for each Operating System version by selecting "Create ISO image per selected product and language" option.

Expand All @@ -62,36 +66,54 @@ For more information on how to use the Offline Updater look [here](http://www.ws

Once the updates have been downloaded and the .ISO file created it is mounted as a separate DVD drive in VirtualBox. The updates are then applied from the local collection.

== RHEL BOXES ==

You can choose RHN or Satellite. By default the builder will choose RHN. You can override this setting with
## RHEL BOXES

UPDATE_SOURCE

which can be set to either "rhn" or "satellite."
You can choose RHN or Satellite. By default the builder will choose RHN. You can override this setting with `UPDATE_SOURCE` which can be set to either "rhn" or "satellite."

If you have set "rhn" the following two variables are used:

```
RHN_UNAME
RHN_PW
```

Set these to your Red Hat network credentials prior to building the rhel-7-rhn build.
Set these to your Red Hat network credentials prior to building the `rhel-7-rhn` build.

If you have set "satellite" you will need:

```
SATELLITE_SERVER
SATELLITE_KEY
```

SERVER should be the FQDN of your satellite server, and KEY should be your activation key
`SERVER` should be the FQDN of your satellite server, and `KEY` should be your activation key

== Ruby versions ==
## Ruby versions

When building the centos-7-puppet4-ruby build, use the RUBY_VERSION environment variable. Warning, not everything works the earlier you go! YMMV. 2.3.0 and above known working.
When building the `centos-7-puppet4-ruby` build, use the `RUBY_VERSION` environment variable. **Warning, not everything works the earlier you go!** YMMV. 2.3.0 and above known working.

NOTE: The version must be in x.y.z semver format.

== Puppet versions ==
## Puppet versions

When building the centos-7-puppet4 build, use the PUPPET_VERSION environment variable. This refers to the agent version - https://docs.puppet.com/puppet/latest/reference/about_agent.html
When building the centos-7-puppet4 build, use the `PUPPET_VERSION` environment variable. This refers to the agent version - https://docs.puppet.com/puppet/latest/reference/about_agent.html

NOTE: The version must be in x.y.z semver format.

## Acceptance Testing

To initiate an acceptance test, run, e.g.:

```
BUILDER=vmware rake spec:acceptance:centos-7-puppet4
```

This assumes the virtual machine has been built and packaged for vagrant. It will:


- force add the box to vagrant,
- drop a scratch `Vagrantfile` in the repository configured to use the box under test,
- bring up an instance of that box,
- configure serverspec to log in to the box and run whichever tests are appropriate

Tests are to be organized in layers, under the `spec/acceptance` folder.
68 changes: 66 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,74 @@ require './lib/util'
require './lib/util/packer'

task :before do
@http_proxy = ENV['http_proxy'] if ENV['http_proxy']
@http_proxy = ENV['http_proxy'] if ENV['http_proxy']
@https_proxy = ENV['https_proxy'] if ENV['https_proxy']
@override = ENV['spec_override']
@override = ENV['spec_override']
end

RSpec::Core::RakeTask.new(:spec)
Dir.glob('./lib/tasks/**/*.rake').each { |r| import r }

def list_templates(dir = '.')
Dir.glob(File.join(dir, '*.json')).map do |path|
path.gsub(%r(^#{dir}/|\.json$), '')
end
end

def ary_to_regexp(ary)
Regexp.new('(' + ary.join('|') + ')')
end

def tokenize_build(name)
raise ArgumentError unless name.is_a?(String)
nix_bases = %w(centos-6 centos-7 rhel-7 esxi-6u2 solaris-10)
win_bases = %w(windows-2012r2 windows-7)

base = name.match(ary_to_regexp(nix_bases)) ||
name.match(ary_to_regexp(win_bases))
abort unless base[1]

layers = name.gsub(base[1], '').split('-').reject(&:empty?)

{ base: base[1], layers: layers }
end

namespace :vagrant do
desc 'package a build in to a box'
task :add, [:build] do |_t, args|
build = args.build
provider = ENV['BUILDER'] || 'virtualbox'

sh "vagrant box add -f builds/#{build}.#{provider}.box --name #{build}"
end

desc 'bring up a vagrant instance'
task :up, [:box] do |_t, args|
sh "vagrant init -f --minimal #{args.box}"
sh 'vagrant destroy -f'
sh 'vagrant up'
end

desc 'force destroy vagrant default'
task :down do |_t|
sh 'vagrant destroy -f'
end
end

namespace :spec do
namespace :acceptance do
list_templates.each do |template|
RSpec::Core::RakeTask.new(template.to_sym) do |t|
Rake::Task['vagrant:add'].invoke(template)
Rake::Task['vagrant:up'].invoke(template)

ENV['TARGET_HOST'] = 'default'

base, layers = tokenize_build(template).values_at(:base, :layers)
tests = layers.empty? ? [base] : [base, layers].flatten

t.pattern = "spec/acceptance/{#{tests.join(',')}}/*_spec.rb"
end
end
end
end
1 change: 0 additions & 1 deletion serverspec/centos-6-puppet-rbenv/.rspec

This file was deleted.

7 changes: 0 additions & 7 deletions serverspec/centos-6-puppet-rbenv/Gemfile

This file was deleted.

27 changes: 0 additions & 27 deletions serverspec/centos-6-puppet-rbenv/Rakefile

This file was deleted.

4 changes: 0 additions & 4 deletions serverspec/centos-6-puppet-rbenv/serverspec.sh

This file was deleted.

5 changes: 0 additions & 5 deletions serverspec/centos-6-puppet-rbenv/spec/localhost/base_spec.rb

This file was deleted.

4 changes: 0 additions & 4 deletions serverspec/centos-6-puppet-rbenv/spec/spec_helper.rb

This file was deleted.

1 change: 0 additions & 1 deletion serverspec/centos-6-puppet/.rspec

This file was deleted.

7 changes: 0 additions & 7 deletions serverspec/centos-6-puppet/Gemfile

This file was deleted.

27 changes: 0 additions & 27 deletions serverspec/centos-6-puppet/Rakefile

This file was deleted.

4 changes: 0 additions & 4 deletions serverspec/centos-6-puppet/serverspec.sh

This file was deleted.

5 changes: 0 additions & 5 deletions serverspec/centos-6-puppet/spec/localhost/base_spec.rb

This file was deleted.

4 changes: 0 additions & 4 deletions serverspec/centos-6-puppet/spec/spec_helper.rb

This file was deleted.

1 change: 0 additions & 1 deletion serverspec/centos-6-puppet4/.rspec

This file was deleted.

7 changes: 0 additions & 7 deletions serverspec/centos-6-puppet4/Gemfile

This file was deleted.

27 changes: 0 additions & 27 deletions serverspec/centos-6-puppet4/Rakefile

This file was deleted.

4 changes: 0 additions & 4 deletions serverspec/centos-6-puppet4/serverspec.sh

This file was deleted.

5 changes: 0 additions & 5 deletions serverspec/centos-6-puppet4/spec/localhost/base_spec.rb

This file was deleted.

4 changes: 0 additions & 4 deletions serverspec/centos-6-puppet4/spec/spec_helper.rb

This file was deleted.

1 change: 0 additions & 1 deletion serverspec/centos-6/.rspec

This file was deleted.

7 changes: 0 additions & 7 deletions serverspec/centos-6/Gemfile

This file was deleted.

Loading