Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge pull request #29 from maxlinc/integration
Browse files Browse the repository at this point in the history
Integration to merge multiple outstanding pull requests
  • Loading branch information
Kyle Rames committed Aug 21, 2013
2 parents 0c436ec + c0754dd commit b6a6c6b
Show file tree
Hide file tree
Showing 17 changed files with 438 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ spec/reports
test/tmp
test/version_tmp
tmp
Vagrantfile

.idea/
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ This provider exposes quite a few provider-specific configuration options:
* `image` - The server image to boot. This can be a string matching the
exact ID or name of the image, or this can be a regular expression to
partially match some image.
* `endpoint` - The endpoint to hit. By default this is DFW.
* `rackspace_region` - The region to hit. By default this is :dfw. Valid options are:
:dfw, :ord, :lon. User this OR rackspace_compute_url
* `rackspace_compute_url` - The compute_url to hit. This is good for custom endpoints.
Use this OR rackspace_region.
* `public_key_path` - The path to a public key to initialize with the remote
server. This should be the matching pair for the private key configured
with `config.ssh.private_key_path` on Vagrant.
Expand Down
122 changes: 122 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
Vagrant.require_plugin "vagrant-rackspace"
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.

# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "dummy"
config.vm.provider :rackspace do |rs|
rs.username = ENV['RAX_USERNAME']
rs.api_key = ENV['RAX_API_KEY']
end
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://domain.com/path/to/above.box"

# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
# config.vm.network :forwarded_port, guest: 80, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
# config.vm.network :private_network, ip: "192.168.33.10"

# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network :public_network

# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true

# Share an additional folder to the guest VM. The first argument is
# the path on the host to the actual folder. The second argument is
# the path on the guest to mount the folder. And the optional third
# argument is a set of non-required options.
# config.vm.synced_folder "../data", "/vagrant_data"

# Provider-specific configuration so you can fine-tune various
# backing providers for Vagrant. These expose provider-specific options.
# Example for VirtualBox:
#
# config.vm.provider :virtualbox do |vb|
# # Don't boot with headless mode
# vb.gui = true
#
# # Use VBoxManage to customize the VM. For example to change memory:
# vb.customize ["modifyvm", :id, "--memory", "1024"]
# end
#
# View the documentation for the provider you're using for more
# information on available options.

# Enable provisioning with Puppet stand alone. Puppet manifests
# are contained in a directory path relative to this Vagrantfile.
# You will need to create the manifests directory and a manifest in
# the file base.pp in the manifests_path directory.
#
# An example Puppet manifest to provision the message of the day:
#
# # group { "puppet":
# # ensure => "present",
# # }
# #
# # File { owner => 0, group => 0, mode => 0644 }
# #
# # file { '/etc/motd':
# # content => "Welcome to your Vagrant-built virtual machine!
# # Managed by Puppet.\n"
# # }
#
# config.vm.provision :puppet do |puppet|
# puppet.manifests_path = "manifests"
# puppet.manifest_file = "init.pp"
# end

# Enable provisioning with chef solo, specifying a cookbooks path, roles
# path, and data_bags path (all relative to this Vagrantfile), and adding
# some recipes and/or roles.
#
# config.vm.provision :chef_solo do |chef|
# chef.cookbooks_path = "../my-recipes/cookbooks"
# chef.roles_path = "../my-recipes/roles"
# chef.data_bags_path = "../my-recipes/data_bags"
# chef.add_recipe "mysql"
# chef.add_role "web"
#
# # You may also specify custom JSON attributes:
# chef.json = { :mysql_password => "foo" }
# end

# Enable provisioning with chef server, specifying the chef server URL,
# and the path to the validation key (relative to this Vagrantfile).
#
# The Opscode Platform uses HTTPS. Substitute your organization for
# ORGNAME in the URL and validation key.
#
# If you have your own Chef Server, use the appropriate URL, which may be
# HTTP instead of HTTPS depending on your configuration. Also change the
# validation key to validation.pem.
#
# config.vm.provision :chef_client do |chef|
# chef.chef_server_url = "https://api.opscode.com/organizations/ORGNAME"
# chef.validation_key_path = "ORGNAME-validator.pem"
# end
#
# If you're using the Opscode platform, your validator client is
# ORGNAME-validator, replacing ORGNAME with your organization name.
#
# If you have your own Chef Server, the default validation client name is
# chef-validator, unless you changed the configuration.
#
# chef.validation_client_name = "ORGNAME-validator"
end
36 changes: 36 additions & 0 deletions features/provision.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@announce
@vagrant-rackspace
Feature: vagrant-rackspace fog tests

Background:
Given I have Rackspace credentials available
And I have a "fog_mock.rb" file

Scenario: Create a single server (with provisioning)
Given a file named "Vagrantfile" with:
"""
Vagrant.configure("2") do |config|
Vagrant.require_plugin "vagrant-rackspace"
config.vm.box = "dummy"
config.ssh.private_key_path = "~/.ssh/id_rsa"
config.ssh.max_tries = 1
config.ssh.timeout = 10
config.vm.provider :rackspace do |rs|
rs.server_name = 'vagrant-provisioned-server'
rs.username = ENV['RAX_USERNAME']
rs.api_key = ENV['RAX_API_KEY']
rs.rackspace_region = ENV['RAX_REGION'].downcase.to_sym
rs.flavor = /512MB/
rs.image = /Ubuntu/
rs.public_key_path = "~/.ssh/id_rsa.pub"
end
config.vm.provision :shell, :inline => "echo Hello, World"
end
"""
When I successfully run `bundle exec vagrant up --provider rackspace`
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
# And I get the server from "Instance ID:"
Then the server "vagrant-provisioned-server" should be active
13 changes: 13 additions & 0 deletions features/steps/sdk_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Given(/^I have Rackspace credentials available$/) do
fail unless ENV['RAX_USERNAME'] && ENV['RAX_API_KEY']
end

Given(/^I have a "fog_mock.rb" file$/) do
script = File.open("features/support/fog_mock.rb").read
steps %Q{
Given a file named "fog_mock.rb" with:
"""
#{script}
"""
}
end
25 changes: 25 additions & 0 deletions features/steps/server_steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
When(/^I get the server from "(.*?)"$/) do |label|
@server_id = all_output.match(/#{label}\s([\w-]*)/)[1]
puts "Server: #{@server_id}"
end

When(/^I load the server$/) do
@server_id = all_output.strip.lines.to_a.last
puts "Server: #{@server_id}"
end

Then(/^the server should be active$/) do
unless Fog.mock? # unfortunately we can't assert this with Fog.mock!, since mocked objects do not persist from the subprocess
assert_active @server_id
end
end

Then(/^the server "(.+)" should be active$/) do |server_name|
server = @compute.servers.all.find{|s| s.name == server_name}
assert_active server.id
end

def assert_active server_id
server = @compute.servers.get server_id
server.state.should == 'ACTIVE'
end
37 changes: 37 additions & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'fog'
require 'aruba/cucumber'

Fog.mock! if ENV['RAX_MOCK'] == 'true'

Before do | scenario |
@aruba_timeout_seconds = 600
@scenario = File.basename(scenario.file)
ENV['CASSETTE'] = @scenario

proxy_options = {
:connection_options => {
:proxy => ENV['https_proxy'],
:ssl_verify_peer => false
}
}

connect_options = {
:provider => 'rackspace',
:rackspace_username => ENV['RAX_USERNAME'],
:rackspace_api_key => ENV['RAX_API_KEY'],
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_region => ENV['RAX_REGION'].downcase.to_sym
}
connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
@compute = Fog::Compute.new(connect_options)
end

Around do | scenario, block |
Bundler.with_clean_env do
block.call
end
end

After('@creates_server') do
@compute.servers.delete @server_id
end
19 changes: 19 additions & 0 deletions features/support/fog_mock.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require 'fog'
if ENV['RAX_MOCK'] == 'true'
Fog.mock!
Fog::Rackspace::MockData.configure do |c|
c[:image_name_generator] = Proc.new { "Ubuntu" }
c[:ipv4_generator] = Proc.new { "10.11.12.2"}
end
connect_options = {
:provider => 'rackspace',
:rackspace_username => ENV['RAX_USERNAME'],
:rackspace_api_key => ENV['RAX_API_KEY'],
:version => :v2, # Use Next Gen Cloud Servers
:rackspace_region => :ord #Use Chicago Region
}
connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
compute = Fog::Compute.new(connect_options)
# Force creation of Ubuntu image so it will show up in compute.images.list
compute.images.get(0)
end
74 changes: 74 additions & 0 deletions features/vagrant-rackspace.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
@announce
@vagrant-rackspace
Feature: vagrant-rackspace fog tests
As a Fog developer
I want to smoke (or "fog") test vagrant-rackspace.
So I am confident my upstream changes did not create downstream problems.

Background:
Given I have Rackspace credentials available
And I have a "fog_mock.rb" file

Scenario: Create a single server (region)
Given a file named "Vagrantfile" with:
"""
# Testing options
require File.expand_path '../fog_mock', __FILE__
Vagrant.configure("2") do |config|
# dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-rackspace'
Vagrant.require_plugin "vagrant-rackspace"
config.vm.box = "dummy"
config.ssh.username = "vagrant" if Fog.mock?
config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
config.ssh.max_tries = 1
config.ssh.timeout = 10
config.vm.provider :rackspace do |rs|
rs.server_name = 'vagrant-single-server'
rs.username = ENV['RAX_USERNAME']
rs.api_key = ENV['RAX_API_KEY']
rs.rackspace_region = ENV['RAX_REGION'].downcase.to_sym
rs.flavor = /512MB/
rs.image = /Ubuntu/
rs.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
end
end
"""
When I successfully run `bundle exec vagrant up --provider rackspace`
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
# And I get the server from "Instance ID:"
Then the server "vagrant-single-server" should be active

Scenario: Create a single server (compute_url)
Given a file named "Vagrantfile" with:
"""
# Testing options
require File.expand_path '../fog_mock', __FILE__
Vagrant.configure("2") do |config|
# dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-rackspace'
Vagrant.require_plugin "vagrant-rackspace"
config.vm.box = "dummy"
config.ssh.username = "vagrant" if Fog.mock?
config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
config.ssh.max_tries = 1
config.ssh.timeout = 10
config.vm.provider :rackspace do |rs|
rs.server_name = 'vagrant-single-server'
rs.username = ENV['RAX_USERNAME']
rs.api_key = ENV['RAX_API_KEY']
rs.compute_url = "https://#{ENV['RAX_REGION'].downcase}.servers.api.rackspacecloud.com/v2"
rs.flavor = /512MB/
rs.image = /Ubuntu/
rs.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
end
end
"""
When I successfully run `bundle exec vagrant up --provider rackspace`
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
# And I get the server from "Instance ID:"
Then the server "vagrant-single-server" should be active
16 changes: 16 additions & 0 deletions lib/vagrant-rackspace/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ def self.action_destroy
end
end

# This action is called when `vagrant provision` is called.
def self.action_provision
Vagrant::Action::Builder.new.tap do |b|
b.use ConfigValidate
b.use Call, IsCreated do |env, b2|
if !env[:result]
b2.use MessageNotCreated
next
end

b2.use Provision
b2.use SyncFolders
end
end
end

# This action is called to read the SSH info of the machine. The
# resulting state is expected to be put into the `:machine_ssh_info`
# key.
Expand Down
Loading

0 comments on commit b6a6c6b

Please sign in to comment.