Skip to content

Commit

Permalink
Issue #69 Introducing vagrant-spec based acceptance tests and updatin…
Browse files Browse the repository at this point in the history
…g README
  • Loading branch information
hferentschik committed Mar 23, 2016
1 parent 99c47eb commit 81ed5c6
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ build/
# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
.ruby-version
.ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
6 changes: 5 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ source 'https://rubygems.org'
gemspec

group :development do
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
gem 'vagrant-spec', git: 'https://github.com/mitchellh/vagrant-spec.git'
gem 'gem-compare'
gem 'rake'
gem 'vagrant-vbguest'
gem 'vagrant-libvirt'
gem 'fog-libvirt', '0.0.3' # https://github.com/pradels/vagrant-libvirt/issues/568
end

group :plugins do
Expand Down
70 changes: 68 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
# vagrant-registration

<!-- MarkdownTOC -->

- [Installation](#installation)
- [Usage](#usage)
- [Plugin Configuration](#plugin-configuration)
- [Credentials Configuration](#credentials-configuration)
- [subscription-manager Configuration](#subscription-manager-configuration)
- [subscription-manager Default Options](#subscription-manager-default-options)
- [subscription-manager Options Reference](#subscription-manager-options-reference)
- [rhn-register Configuration](#rhn-register-configuration)
- [rhn-register Default Options](#rhn-register-default-options)
- [rhn-register Options Reference](#rhn-register-options-reference)
- [Development](#development)
- [Tests](#tests)
- [Shell script based tests](#shell-script-based-tests)
- [Vagrant Spec based tests](#vagrant-spec-based-tests)
- [Acknowledgements](#acknowledgements)

<!-- /MarkdownTOC -->

vagrant-registration plugin for Vagrant allows developers to easily register their guests for updates on systems with a subscription model (like Red Hat Enterprise Linux).

This plugin would run *register* action on `vagrant up` before any provisioning and *unregister* on `vagrant halt` or `vagrant destroy`. The actions then call the registration capabilities that have to be provided for given OS.


<a name="installation"></a>
## Installation

Install vagrant-registration as any other Vagrant plugin:
Expand All @@ -19,6 +39,7 @@ If you are on Fedora, you can install the packaged version of the plugin by runn
# dnf install vagrant-registration
```

<a name="usage"></a>
## Usage

The plugin is designed in an registration-manager-agnostic way which means that plugin itself does not depend on any OS nor way of registration. vagrant-registration only calls registration capabilities for given guest, passes the configuration options to them and handles interactive registration.
Expand All @@ -33,6 +54,7 @@ Vagrant.configure('2') do |config|
end
```

<a name="plugin-configuration"></a>
### Plugin Configuration

- **skip** skips the registration. If you wish to skip the registration process altogether, you can do so by setting a `skip` option to `true`:
Expand All @@ -53,6 +75,7 @@ end
config.registration.manager = 'subscription_manager'
```

<a name="credentials-configuration"></a>
### Credentials Configuration

Setting up the credentials can be done as follows:
Expand Down Expand Up @@ -96,6 +119,7 @@ If you do not provide credentials, you will be prompted for them in the "up proc
Please note the the interactive mode asks you for the preferred registration pair only
of the configured manager.

<a name="subscription-manager-configuration"></a>
### subscription-manager Configuration

vagrant-registration will use the `subscription_manager` manager by default or can be explicitly configured by setting the `manager` option to `subscription_manager`:
Expand All @@ -118,6 +142,7 @@ You can set any option easily by setting `config.registration.OPTION_NAME = 'OPT
in your Vagrantfile (please see the subscription-manager's documentation for option
description).

<a name="subscription-manager-default-options"></a>
#### subscription-manager Default Options

- **--force**: Subscription Manager will fail if you attempt to register an already registered machine (see the man page for explanation), therefore vagrant-registration appends the `--force` flag automatically when subscribing. If you would like to disable this feature, set `force` option to `false`:
Expand All @@ -135,6 +160,7 @@ description).

Note that the `auto_attach` option is set to false when using org/activationkey for registration or if pools are specified.

<a name="subscription-manager-options-reference"></a>
#### subscription-manager Options Reference

```ruby
Expand Down Expand Up @@ -197,6 +223,7 @@ Note that the `auto_attach` option is set to false when using org/activationkey
config.registration.pools
```

<a name="rhn-register-configuration"></a>
### rhn-register Configuration

vagrant-registration will use the `rhn_register` manager only if explicitly configured by setting the `manager` option to `rhn_register`:
Expand All @@ -217,6 +244,7 @@ vagrant-registration supports most of the options of rhnreg_ks's command. You ca

`rhn_register` manager reuses the naming of `subscription-manager`'s command options where possible.

<a name="rhn-register-default-options"></a>
#### rhn-register Default Options

- **--force**: `rhnreg_ks` command will fail if you attempt to register an already registered machine (see the man page for explanation), therefore vagrant-registration appends the `--force` flag automatically when subscribing. If you would like to disable this feature, set `force` option to `false`:
Expand All @@ -225,6 +253,7 @@ vagrant-registration supports most of the options of rhnreg_ks's command. You ca
config.registration.force = false
```

<a name="rhn-register-options-reference"></a>
#### rhn-register Options Reference

```ruby
Expand Down Expand Up @@ -291,7 +320,23 @@ vagrant-registration supports most of the options of rhnreg_ks's command. You ca
config.registration.skip
```

## Tests
<a name="development"></a>
## Development

To install a development environment, clone the repo and prepare dependencies by

```
gem install bundler -v 1.7.5
bundler install
```

The use of [RVM|https://rvm.io] is recommended. Verified to work with ruby 2.0.0p643.

<a name="tests"></a>
### Tests

<a name="shell-script-based-tests"></a>
#### Shell script based tests

Tests currently test the plugin with `subscription-manager` and `rhn_register` on RHEL 7.1 guest and Fedora host. You need an imported RHEL 7.1 Vagrant box named `rhel-7.1`.

Expand All @@ -316,6 +361,27 @@ environment variable on `1` before executing the test script:
export DEBUG=1
```

<a name="vagrant-spec-based-tests"></a>
#### Vagrant Spec based tests

The source contains also a set of [vagrant-spec](https://github.com/mitchellh/vagrant-spec) acceptance tests. They can be run via:

```
vagrant-spec test --components provider/virtualbox/cdk
vagrant-spec test --components provider/libvirt/cdk
```

In order to successfully run the tests, you need to set the following
environment variables:

* _VAGRANT_SPEC_BOX_VIRTUAL_BOX_ - URL to the VirtualBox box for testing
* _VAGRANT_SPEC_BOX_LIBVIRT_ - URL to the Libvirt box for testing
* _SUBSCRIPTION_USER_ - Valid Red Hat subscription user
* _SUBSCRIPTION_PASSWORD_ - Valid Red Hat subscription password

You need to at least specify one box file!

<a name="acknowledgements"></a>
## Acknowledgements

The project would like to make sure we thank [purpleidea](https://github.com/purpleidea/), [humaton](https://github.com/humaton/), [strzibny](https://github.com/strzibny), [scollier](https://github.com/scollier/), [puzzle](https://github.com/puzzle), [voxik](https://github.com/voxik), [lukaszachy](https://github.com/lukaszachy), [goern](https://github.com/goern), [iconoeugen](https://github.com/iconoeugen) and [pvalena](https://github.com/pvalena) (in no particular order) for their contributions of ideas, code and testing for this project.
16 changes: 16 additions & 0 deletions vagrant-spec.config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Vagrant::Spec::Acceptance.configure do |c|
errors = []
errors << 'You need to specify at least one box location via the environment variable VAGRANT_SPEC_BOX_VIRTUAL_BOX resp. VAGRANT_SPEC_BOX_LIBVIRT' unless ENV.has_key?('VAGRANT_SPEC_BOX_VIRTUAL_BOX') || ENV.has_key?('VAGRANT_SPEC_BOX_LIBVIRT')
errors << 'You need to specify a valid subscription username via the environment variable SUBSCRIPTION_USER' unless ENV.has_key?('SUBSCRIPTION_USER')
errors << 'You need to specify a valid subscription password via the environment variable SUBSCRIPTION_PASSWORD' unless ENV.has_key?('SUBSCRIPTION_PASSWORD')

unless errors.empty?
puts errors.join("\n")
abort
end

c.provider 'virtualbox', box: ENV['VAGRANT_SPEC_BOX_VIRTUAL_BOX'] if ENV.has_key?('VAGRANT_SPEC_BOX_VIRTUAL_BOX')
c.provider 'libvirt', box: ENV['VAGRANT_SPEC_BOX_LIBVIRT'] if ENV.has_key?('VAGRANT_SPEC_BOX_LIBVIRT')
c.component_paths << 'vagrant-spec'
c.skeleton_paths << 'vagrant-spec/skeleton'
end
63 changes: 63 additions & 0 deletions vagrant-spec/cdk_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
shared_examples "provider/cdk" do |provider, options|
if !options[:box]
raise ArgumentError,
"box_basic option must be specified for provider: #{provider}"
end

include_context "acceptance"

before do
assert_execute("vagrant", "box", "add", "box", options[:box])
end

after do
assert_execute("vagrant", "destroy", "--force")
end

if provider.eql? 'virtualbox'
it ": with vbguest plugin installed Virtual Box guest additons will be added" do
environment.skeleton("cdk-with-vbguest")
assert_execute("vagrant", "up", "--provider=#{provider}")

result = execute("vagrant", "ssh", "-c", "lsmod | grep -i vbox")
expect(result).to exit_with(0)
expect(result.stdout).to match(/vboxguest/)
end

it ": without vbguest plugin installed Virtual Box guest additons will NOT be added" do
environment.skeleton("cdk-without-vbguest")
assert_execute("vagrant", "up", "--provider=#{provider}")

result = execute("vagrant", "ssh", "-c", "lsmod | grep -i vbox")
expect(result).to exit_with(1)
expect(result.stdout).not_to match(/vboxguest/)
end
end

it ": registration succeeds with valid credentials" do
environment.skeleton("valid-credentials")
assert_execute("vagrant", "up", "--provider=#{provider}")

result = execute("vagrant", "ssh", "-c", "sudo subscription-manager version")
expect(result).to exit_with(0)
expect(result.stdout).to match(/Red Hat Subscription Management/)
end

it ": registration fails with invalid credentials" do
environment.skeleton("invalid-credentials")
result = execute("vagrant", "up", "--provider=#{provider}")

expect(result).to exit_with(1)
expect(result.stderr).to match(/Invalid username or password./)
end

it ": skipping registration results in unregistered VM" do
environment.skeleton("skipped-registration")
assert_execute("vagrant", "up", "--provider=#{provider}")

result = execute("vagrant", "ssh", "-c", "sudo subscription-manager version")
expect(result).to exit_with(0)
expect(result.stdout).to match(/This system is currently not registered/)
end

end
7 changes: 7 additions & 0 deletions vagrant-spec/skeleton/cdk-with-vbguest/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'vagrant-vbguest'

Vagrant.configure(2) do |config|
config.vm.box = 'box'
config.registration.username = ENV['SUBSCRIPTION_USER']
config.registration.password = ENV['SUBSCRIPTION_PASSWORD']
end
5 changes: 5 additions & 0 deletions vagrant-spec/skeleton/cdk-without-vbguest/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Vagrant.configure(2) do |config|
config.vm.box = "box"
config.registration.username = ENV['SUBSCRIPTION_USER']
config.registration.password = ENV['SUBSCRIPTION_PASSWORD']
end
7 changes: 7 additions & 0 deletions vagrant-spec/skeleton/invalid-credentials/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'vagrant-libvirt'

Vagrant.configure(2) do |config|
config.vm.box = 'box'
config.registration.username = 'foo'
config.registration.password = 'bar'
end
6 changes: 6 additions & 0 deletions vagrant-spec/skeleton/skipped-registration/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'vagrant-libvirt'

Vagrant.configure(2) do |config|
config.vm.box = 'box'
config.registration.skip = true
end
7 changes: 7 additions & 0 deletions vagrant-spec/skeleton/valid-credentials/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'vagrant-libvirt'

Vagrant.configure(2) do |config|
config.vm.box = 'box'
config.registration.username = ENV['SUBSCRIPTION_USER']
config.registration.password = ENV['SUBSCRIPTION_PASSWORD']
end

0 comments on commit 81ed5c6

Please sign in to comment.