Skip to content

Commit

Permalink
Merge pull request #173 from MissionCriticalCloud/refactor_read_info
Browse files Browse the repository at this point in the history
Refactor read info classes using a super class
  • Loading branch information
remibergsma authored May 16, 2017
2 parents ba0b056 + 8343f02 commit dfa42af
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 185 deletions.
2 changes: 1 addition & 1 deletion Docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV CHEFDK_VERSION 1.2.22
ENV CHEFDK_DEB_VERSION 8

# Currently the latest version of the plugin has been tested with Vagrant 1.8.1
ENV VAGRANT_VERSION 1.9.1
ENV VAGRANT_VERSION 1.9.3

# Update before all package installations
RUN apt-get update -y && \
Expand Down
91 changes: 39 additions & 52 deletions Docker/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,50 @@
# Vagrant Cloudstack Container

This container contains some tools commonly used with the vagrant-cloudstack plugin

## Features
* Run Vagrant with the plugin
* Run Test-Kitchen with the plugin
* Using Bundler, run Vagrant/Test-Kitchen with vagrant-cloudstack from source

## Usage
Retrieve the docker container:
```
docker pull missioncriticalcloud/vagrant-cloudstack
```
Change into the directory containing your project (Vagrantfile, .kitchen.yml), and execute:
```
docker run -ti --rm -v $(pwd):/work missioncriticalcloud/vagrant-cloudstack /bin/bash
```
This provides a bash shell (in the container) where you can execute e.g. Vagrant, Test-Kitchen, Bundler.

For use of Vagrantfile or .kitchen.yml files containing environment variables, environment variables need to be specified in the docker run, e.g.:
```
docker run \
-e USER=${USER} \
-e CLOUDSTACK_API_KEY=${CLOUDSTACK_API_KEY} \
-e CLOUDSTACK_SECRET_KEY=${CLOUDSTACK_SECRET_KEY} \
-ti --rm -v $(pwd):/work missioncriticalcloud/vagrant-cloudstack /bin/bash
```

For actual development of the plugin, a lot more variables are required. To this end you can use the [bash script `vac.sh`](https://raw.githubusercontent.com/MissionCriticalCloud/vagrant-cloudstack/master/Docker/vac.sh) or [PowerShell script `vac.ps1`](https://raw.githubusercontent.com/MissionCriticalCloud/vagrant-cloudstack/master/Docker/vac.ps1) in the git repo.

_Note on usage of SSH keyfile_: As the container is mounted on a specific folder (`$(pwd)`), the keyfile must be specified (by `SSH_KEY`) relative to, __and within__, the specified folder!

## Version / Tag notes
### Vagrant
Development of the plugin, means running Vagrant from source, in combination with the specific bundler version (conflict) between ChefDK and Vagrant and ruby version (conflict) between ChefDK and Vagrant, leads to the following version combination:

## dev
The versions have been specifically tuned to provide a working set for development of the plugin. To this end also developer tools (e.g. make, g++) are installed to enable bundler to pull in and compile required gems.
So this one is _required_ for developing and testing the plugin from (latest, master) source.
* [Vagrant](http://www.vagrantup.com) 1.8.1
* [Vagrant](http://www.vagrantup.com) 1.9.3
* [Vagrant-cloudstack](https://github.com/missioncriticalcloud/vagrant-cloudstack) plugin _current_
* [Vagrant-winrm](https://github.com/criteo/vagrant-winrm) 0.7.0 (latest)
* [Chef-DK](https://downloads.chef.io/chef-dk/) 0.10.0
* [Chef-DK](https://downloads.chef.io/chef-dk/) 1.2.22
* [Kitchen-Vagrant](https://github.com/test-kitchen/kitchen-vagrant) 0.20.0

As the container is build automatically on triggers, latest versions are latest at time of (re)build_
_As the container is build automatically on triggers, latest versions are latest at time of (re)build_


## latest_dependencies
Expand All @@ -26,7 +60,7 @@ _As the container is build automatically on triggers, latest versions are latest


## chefdk_0_17
This will install chef-client 12.13.37 which is needed for some compatibilty reasons.
This will install chef-client 12.13.37 which is needed for some compatibility reasons.
* [Vagrant](http://www.vagrantup.com) 1.8.1
* [Vagrant-cloudstack](https://github.com/missioncriticalcloud/vagrant-cloudstack) plugin _current_
* [Vagrant-winrm](https://github.com/criteo/vagrant-winrm) 0.7.0 (latest)
Expand All @@ -41,54 +75,7 @@ Links to the respective Dockerfiles:
* [latest_dependencies](https://raw.githubusercontent.com/MissionCriticalCloud/vagrant-cloudstack/master/Docker/Dockerfile.latest_dependencies)
* [chefdk_0_17](https://raw.githubusercontent.com/MissionCriticalCloud/vagrant-cloudstack/master/Docker/Dockerfile.chefdk_0_17)

## Features
* Run Vagrant with the plugin
* Run Test-Kitchen with the plugin
* Using Bundler, run Vagrant/Test-Kitchen with vagrant-cloudstack from source

## Usage
Retrieve the docker container:
```
docker pull missioncriticalcloud/vagrant-cloudstack
```
Change into the directory containing your project (Vagrantfile, .kitchen.yml), and execute:
```
docker run -ti --rm -v $(pwd):/work missioncriticalcloud/vagrant-cloudstack /bin/bash
```
This provides a bash shell (in the container) where you can execute e.g. Vagrant, Test-Kitchen, Bundler.

For use of Vagrantfile or .kitchen.yml files containing environment variables, environment variables need to be specified in the docker run, e.g.:
```
docker run \
-e USER=${USER} \
-e CLOUDSTACK_API_KEY=${CLOUDSTACK_API_KEY} \
-e CLOUDSTACK_SECRET_KEY=${CLOUDSTACK_SECRET_KEY} \
-ti --rm -v $(pwd):/work missioncriticalcloud/vagrant-cloudstack /bin/bash
```

For actual development of the plugin, a lot more variables are required. To this end you can use the [bash script `vac.sh`](https://raw.githubusercontent.com/MissionCriticalCloud/vagrant-cloudstack/master/Docker/vac.sh) or [PowerShell script `vac.ps1`](https://raw.githubusercontent.com/MissionCriticalCloud/vagrant-cloudstack/master/Docker/vac.ps1) in the git repo.

_Note on usage of SSH keyfile_: As the container is mounted on a specific folder (`$(pwd)`), the keyfile must be specified (by `SSH_KEY`) relative to, __and within__, the specified folder!

## Version notes
### Vagrant
Development of the plugin, means running Vagrant from source, in combination with the specific bundler version (conflict) between ChefDK and Vagrant and ruby version (conflict) between ChefDK and Vagrant, leads to the following version combination:

"dev" container:
* Vagrant 1.9.1
* ChefDK 1.2.22
### latest_dependencies
Based on (somewhat subjective :) experience, the latest version of ChefDK is mostly compatible, is used as latest version.

"latest_dependencies" container:
* Vagrant 1.8.1
* ChefDK 0.19
### ChefDK
For convenience of some reported incompatibilities, a separate container is defined:
"chefdk_0_17" container:
* Vagrant 1.8.1
* ChefDK 0.17

## Additional notes on versions of used packages
### Kitchen-Vagrant plugin
Due to new functionality in this plugin (0.21.0), using existing features, the plugin creates a Vagrantfile which has problems executing. This possibly revealed bugs in Vagrant, which might be fixed in newer Vagrant versions.
Untill a new Vagrant is in use, this plugin will be pinned to the latest working combination.
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ group :development do
# We depend on Vagrant for development, but we don't add it as a
# gem dependency because we expect to be installed within the
# Vagrant environment itself using `vagrant plugin`.
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.9.1'
gem 'vagrant', git: 'git://github.com/mitchellh/vagrant.git', tag: 'v1.9.3'
gem 'coveralls', require: false
gem 'simplecov', require: false
gem 'rspec-core'
Expand Down
57 changes: 31 additions & 26 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
GIT
remote: git://github.com/mitchellh/vagrant.git
revision: d8c2b2e5ababcdecc65b62b91e5dec21a4bc2d96
tag: v1.9.1
revision: 267bec38b8f5210c80cf67ebf144f77a81b3a867
tag: v1.9.3
specs:
vagrant (1.9.1)
vagrant (1.9.3)
childprocess (~> 0.5.0)
erubis (~> 2.7.0)
hashicorp-checkpoint (~> 0.1.1)
Expand All @@ -18,8 +18,9 @@ GIT
rest-client (>= 1.6.0, < 3.0)
ruby_dep (<= 1.3.1)
wdm (~> 0.1.0)
winrm (~> 1.6)
winrm-fs (~> 0.3.0)
winrm (~> 2.1)
winrm-elevated (~> 1.1)
winrm-fs (~> 1.0)

PATH
remote: .
Expand All @@ -35,15 +36,15 @@ GEM
builder (3.2.3)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
coveralls (0.8.19)
coveralls (0.8.21)
json (>= 1.8, < 3)
simplecov (~> 0.12.0)
simplecov (~> 0.14.1)
term-ansicolor (~> 1.3)
thor (~> 0.19.1)
thor (~> 0.19.4)
tins (~> 1.6)
diff-lcs (1.3)
docile (1.1.5)
domain_name (0.5.20170223)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
erubis (2.7.0)
excon (0.55.0)
Expand Down Expand Up @@ -90,7 +91,7 @@ GEM
fog-atmos (0.1.0)
fog-core
fog-xml
fog-aws (1.2.1)
fog-aws (1.3.0)
fog-core (~> 1.38)
fog-json (~> 1.0)
fog-xml (~> 0.1)
Expand All @@ -104,7 +105,7 @@ GEM
fog-json (~> 1.0)
fog-xml (~> 0.1)
ipaddress (~> 0.8)
fog-core (1.43.0)
fog-core (1.44.1)
builder
excon (~> 0.49)
formatador (~> 0.2)
Expand Down Expand Up @@ -143,7 +144,7 @@ GEM
fog-profitbricks (3.0.0)
fog-core (~> 1.42)
fog-json (~> 1.0)
fog-rackspace (0.1.4)
fog-rackspace (0.1.5)
fog-core (>= 1.35)
fog-json (>= 1.0)
fog-xml (>= 0.1)
Expand Down Expand Up @@ -177,15 +178,15 @@ GEM
fog-voxel (0.1.0)
fog-core
fog-xml
fog-vsphere (1.8.0)
fog-vsphere (1.9.1)
fog-core
rbvmomi (~> 1.9)
fog-xenserver (0.3.0)
fog-core
fog-xml
fog-xml (0.1.2)
fog-xml (0.1.3)
fog-core
nokogiri (~> 1.5, >= 1.5.11)
nokogiri (>= 1.5.11, < 2.0.0)
formatador (0.2.5)
gssapi (1.2.0)
ffi (>= 1.0.1)
Expand All @@ -205,7 +206,7 @@ GEM
ruby_dep (~> 1.2)
little-plugger (1.1.4)
log4r (1.1.10)
logging (2.2.0)
logging (2.2.2)
little-plugger (~> 1.1)
multi_json (~> 1.10)
mime-types (3.1)
Expand All @@ -228,12 +229,12 @@ GEM
ffi (>= 0.5.0)
rb-kqueue (0.2.4)
ffi (>= 0.5.0)
rbvmomi (1.10.0)
rbvmomi (1.11.2)
builder (~> 3.0)
json (>= 1.8)
nokogiri (~> 1.5)
trollop (~> 2.1)
rest-client (2.0.1)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
Expand All @@ -250,35 +251,39 @@ GEM
rspec-support (~> 3.5.0)
rspec-support (3.5.0)
ruby_dep (1.3.1)
rubyntlm (0.6.1)
rubyntlm (0.6.2)
rubyzip (1.2.1)
simplecov (0.12.0)
simplecov (0.14.1)
docile (~> 1.1.0)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
term-ansicolor (1.4.0)
term-ansicolor (1.6.0)
tins (~> 1.0)
thor (0.19.4)
tins (1.13.2)
trollop (2.1.2)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
unf_ext (0.0.7.4)
wdm (0.1.1)
winrm (1.8.1)
winrm (2.2.2)
builder (>= 2.1.2)
erubis (~> 2.7)
gssapi (~> 1.2)
gyoku (~> 1.0)
httpclient (~> 2.2, >= 2.2.0.2)
logging (>= 1.6.1, < 3.0)
nori (~> 2.0)
rubyntlm (~> 0.6.0)
winrm-fs (0.3.2)
rubyntlm (~> 0.6.0, >= 0.6.1)
winrm-elevated (1.1.0)
winrm (~> 2.0)
winrm-fs (~> 1.0)
winrm-fs (1.0.1)
erubis (~> 2.7)
logging (>= 1.6.1, < 3.0)
rubyzip (~> 1.1)
winrm (~> 1.5)
winrm (~> 2.0)
xml-simple (1.1.5)

PLATFORMS
Expand Down
16 changes: 14 additions & 2 deletions functional-tests/vmlifecycle/vmlifecycle_spec.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end
insert_tee_log = ' 2>&1 | tee -a vagrant.log ' if which('tee')

describe 'VM Life Cycle' do
it 'starts Linux and Windows VM' do
expect(`vagrant up`).to include(
expect(`vagrant up #{insert_tee_log}`).to include(
'linux-box: Machine is booted and ready for use!',
'windows-box: Machine is booted and ready for use!'
)
expect($?.exitstatus).to eq(0)
end
it 'destroys Linux and Windows VM' do
expect(`vagrant destroy --force`).to include('Done removing resources')
expect(`vagrant destroy --force #{insert_tee_log}`).to include('Done removing resources')
expect($?.exitstatus).to eq(0)
end
end
41 changes: 8 additions & 33 deletions lib/vagrant-cloudstack/action/read_rdp_info.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
require_relative 'read_transport_info.rb'
require 'log4r'

module VagrantPlugins
module Cloudstack
module Action
# This action reads the WinRM info for the machine and puts it into the
# `:machine_winrm_info` key in the environment.
class ReadRdpInfo
class ReadRdpInfo < ReadTransportInfo
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant_cloudstack::action::read_rdp_info")

@public_port_fieldname = 'pf_public_rdp_port'
end

def call(env)
Expand All @@ -33,42 +36,14 @@ def read_rdp_info(cloudstack, machine)
domain = machine.provider_config.domain_id
domain_config = machine.provider_config.get_domain_config(domain)

pf_ip_address_id = domain_config.pf_ip_address_id
pf_ip_address = domain_config.pf_ip_address
pf_public_rdp_port = domain_config.pf_public_rdp_port

if pf_public_rdp_port.nil?
pf_public_rdp_port_file = machine.data_dir.join('pf_public_rdp_port')
if pf_public_rdp_port_file.file?
File.read(pf_public_rdp_port_file).each_line do |line|
pf_public_rdp_port = line.strip
end
domain_config.pf_public_rdp_port = pf_public_rdp_port
end
end

if not pf_ip_address and pf_ip_address_id and pf_public_rdp_port
begin
response = cloudstack.list_public_ip_addresses({:id => pf_ip_address_id})
rescue Fog::Compute::Cloudstack::Error => e
raise Errors::FogError, :message => e.message
end

if response["listpublicipaddressesresponse"]["count"] == 0
@logger.info("IP address #{pf_ip_address_id} not exists.")
env[:ui].info(I18n.t("IP address #{pf_ip_address_id} not exists."))
pf_ip_address = nil
else
pf_ip_address = response["listpublicipaddressesresponse"]["publicipaddress"][0]["ipaddress"]
end
end
pf_ip_address, pf_public_port = retrieve_public_ip_port(cloudstack, domain_config, machine)

rdp_info = {
transport_info = {
:host => pf_ip_address || server.nics[0]['ipaddress'],
:port => pf_public_rdp_port
:port => pf_public_port
}

rdp_info
transport_info
end
end
end
Expand Down
Loading

0 comments on commit dfa42af

Please sign in to comment.