vagrant-openstack-provider 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.rubocop.yml +28 -0
- data/Appraisals +3 -3
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Rakefile +6 -2
- data/Vagrantfile +4 -15
- data/gemfiles/latest_stable.gemfile +2 -0
- data/gemfiles/oldest_current.gemfile +2 -0
- data/gemfiles/previous_release.gemfile +2 -0
- data/lib/vagrant-openstack-provider.rb +18 -13
- data/lib/vagrant-openstack-provider/action.rb +112 -46
- data/lib/vagrant-openstack-provider/action/connect_openstack.rb +9 -10
- data/lib/vagrant-openstack-provider/action/create_server.rb +86 -57
- data/lib/vagrant-openstack-provider/action/delete_server.rb +5 -6
- data/lib/vagrant-openstack-provider/action/{is_created.rb → message.rb} +4 -3
- data/lib/vagrant-openstack-provider/action/read_ssh_info.rb +7 -27
- data/lib/vagrant-openstack-provider/action/read_state.rb +7 -9
- data/lib/vagrant-openstack-provider/action/resume.rb +20 -0
- data/lib/vagrant-openstack-provider/action/start_server.rb +22 -0
- data/lib/vagrant-openstack-provider/action/stop_server.rb +22 -0
- data/lib/vagrant-openstack-provider/action/suspend.rb +20 -0
- data/lib/vagrant-openstack-provider/action/sync_folders.rb +27 -38
- data/lib/vagrant-openstack-provider/action/wait_stop.rb +29 -0
- data/lib/vagrant-openstack-provider/client/keystone.rb +76 -0
- data/lib/vagrant-openstack-provider/client/neutron.rb +32 -0
- data/lib/vagrant-openstack-provider/client/nova.rb +166 -0
- data/lib/vagrant-openstack-provider/client/openstack.rb +41 -0
- data/lib/vagrant-openstack-provider/client/utils.rb +38 -0
- data/lib/vagrant-openstack-provider/config.rb +38 -110
- data/lib/vagrant-openstack-provider/errors.rb +7 -3
- data/lib/vagrant-openstack-provider/plugin.rb +8 -8
- data/lib/vagrant-openstack-provider/provider.rb +6 -6
- data/lib/vagrant-openstack-provider/version.rb +1 -1
- data/locales/en.yml +83 -5
- data/numergyrc +22 -0
- data/spec/vagrant-openstack-provider/action/create_server_spec.rb +89 -0
- data/spec/vagrant-openstack-provider/client/keystone_spec.rb +140 -0
- data/spec/vagrant-openstack-provider/client/neutron_spec.rb +53 -0
- data/spec/vagrant-openstack-provider/client/nova_spec.rb +373 -0
- data/spec/vagrant-openstack-provider/client/utils_spec.rb +125 -0
- data/spec/vagrant-openstack-provider/config_spec.rb +117 -0
- data/spec/vagrant-openstack-provider/provider_spec.rb +13 -0
- data/spec/vagrant-openstack-provider/spec_helper.rb +23 -0
- data/vagrant-openstack-provider.gemspec +13 -14
- metadata +40 -30
- data/features/provision.feature +0 -35
- data/features/steps/sdk_steps.rb +0 -13
- data/features/steps/server_steps.rb +0 -25
- data/features/support/env.rb +0 -37
- data/features/support/fog_mock.rb +0 -19
- data/features/vagrant-openstack-provider.feature +0 -70
- data/lib/vagrant-openstack-provider/action/message_already_created.rb +0 -16
- data/lib/vagrant-openstack-provider/action/message_not_created.rb +0 -16
- data/lib/vagrant-openstack-provider/openstack_client.rb +0 -98
- data/spec/vagrant-openstack/config_spec.rb +0 -184
- data/stackrc +0 -31
data/features/provision.feature
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
@announce
|
2
|
-
@vagrant-openstack-provider
|
3
|
-
Feature: vagrant-openstack-provider fog tests
|
4
|
-
|
5
|
-
Background:
|
6
|
-
Given I have Openstack credentials available
|
7
|
-
And I have a "fog_mock.rb" file
|
8
|
-
|
9
|
-
Scenario: Create a single server (with provisioning)
|
10
|
-
Given a file named "Vagrantfile" with:
|
11
|
-
"""
|
12
|
-
Vagrant.configure("2") do |config|
|
13
|
-
Vagrant.require_plugin "vagrant-openstack-provider"
|
14
|
-
|
15
|
-
config.vm.box = "dummy"
|
16
|
-
config.ssh.private_key_path = "~/.ssh/id_rsa"
|
17
|
-
|
18
|
-
|
19
|
-
config.vm.provider :openstack do |rs|
|
20
|
-
rs.server_name = 'vagrant-provisioned-server'
|
21
|
-
rs.username = ENV['RAX_USERNAME']
|
22
|
-
rs.api_key = ENV['RAX_API_KEY']
|
23
|
-
rs.openstack_region = ENV['RAX_REGION'].downcase.to_sym
|
24
|
-
rs.flavor = /1 GB Performance/
|
25
|
-
rs.image = /Ubuntu/
|
26
|
-
rs.public_key_path = "~/.ssh/id_rsa.pub"
|
27
|
-
end
|
28
|
-
|
29
|
-
config.vm.provision :shell, :inline => "echo Hello, World"
|
30
|
-
end
|
31
|
-
"""
|
32
|
-
When I successfully run `bundle exec vagrant up --provider openstack`
|
33
|
-
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
|
34
|
-
# And I get the server from "Instance ID:"
|
35
|
-
Then the server "vagrant-provisioned-server" should be active
|
data/features/steps/sdk_steps.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
Given(/^I have Openstack credentials available$/) do
|
2
|
-
fail unless ENV['RAX_USERNAME'] && ENV['RAX_API_KEY']
|
3
|
-
end
|
4
|
-
|
5
|
-
Given(/^I have a "fog_mock.rb" file$/) do
|
6
|
-
script = File.open("features/support/fog_mock.rb").read
|
7
|
-
steps %Q{
|
8
|
-
Given a file named "fog_mock.rb" with:
|
9
|
-
"""
|
10
|
-
#{script}
|
11
|
-
"""
|
12
|
-
}
|
13
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
When(/^I get the server from "(.*?)"$/) do |label|
|
2
|
-
@server_id = all_output.match(/#{label}\s([\w-]*)/)[1]
|
3
|
-
puts "Server: #{@server_id}"
|
4
|
-
end
|
5
|
-
|
6
|
-
When(/^I load the server$/) do
|
7
|
-
@server_id = all_output.strip.lines.to_a.last
|
8
|
-
puts "Server: #{@server_id}"
|
9
|
-
end
|
10
|
-
|
11
|
-
Then(/^the server should be active$/) do
|
12
|
-
unless Fog.mock? # unfortunately we can't assert this with Fog.mock!, since mocked objects do not persist from the subprocess
|
13
|
-
assert_active @server_id
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
Then(/^the server "(.+)" should be active$/) do |server_name|
|
18
|
-
server = @compute.servers.all.find{|s| s.name == server_name}
|
19
|
-
assert_active server.id
|
20
|
-
end
|
21
|
-
|
22
|
-
def assert_active server_id
|
23
|
-
server = @compute.servers.get server_id
|
24
|
-
server.state.should == 'ACTIVE'
|
25
|
-
end
|
data/features/support/env.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
require 'aruba/cucumber'
|
3
|
-
|
4
|
-
Fog.mock! if ENV['RAX_MOCK'] == 'true'
|
5
|
-
|
6
|
-
Before do | scenario |
|
7
|
-
@aruba_timeout_seconds = 600
|
8
|
-
@scenario = File.basename(scenario.file)
|
9
|
-
ENV['CASSETTE'] = @scenario
|
10
|
-
|
11
|
-
proxy_options = {
|
12
|
-
:connection_options => {
|
13
|
-
:proxy => ENV['https_proxy'],
|
14
|
-
:ssl_verify_peer => false
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
connect_options = {
|
19
|
-
:provider => 'openstack',
|
20
|
-
:openstack_username => ENV['RAX_USERNAME'],
|
21
|
-
:openstack_api_key => ENV['RAX_API_KEY'],
|
22
|
-
:version => :v2, # Use Next Gen Cloud Servers
|
23
|
-
:openstack_region => ENV['RAX_REGION'].downcase.to_sym
|
24
|
-
}
|
25
|
-
connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
|
26
|
-
@compute = Fog::Compute.new(connect_options)
|
27
|
-
end
|
28
|
-
|
29
|
-
Around do | scenario, block |
|
30
|
-
Bundler.with_clean_env do
|
31
|
-
block.call
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
After('@creates_server') do
|
36
|
-
@compute.servers.delete @server_id
|
37
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'fog'
|
2
|
-
if ENV['RAX_MOCK'] == 'true'
|
3
|
-
Fog.mock!
|
4
|
-
Fog::Openstack::MockData.configure do |c|
|
5
|
-
c[:image_name_generator] = Proc.new { "Ubuntu" }
|
6
|
-
c[:ipv4_generator] = Proc.new { "10.11.12.2"}
|
7
|
-
end
|
8
|
-
connect_options = {
|
9
|
-
:provider => 'openstack',
|
10
|
-
:openstack_username => ENV['RAX_USERNAME'],
|
11
|
-
:openstack_api_key => ENV['RAX_API_KEY'],
|
12
|
-
:version => :v2, # Use Next Gen Cloud Servers
|
13
|
-
:openstack_region => :ord #Use Chicago Region
|
14
|
-
}
|
15
|
-
connect_options.merge!(proxy_options) unless ENV['https_proxy'].nil?
|
16
|
-
compute = Fog::Compute.new(connect_options)
|
17
|
-
# Force creation of Ubuntu image so it will show up in compute.images.list
|
18
|
-
compute.images.get(0)
|
19
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
@announce
|
2
|
-
@vagrant-openstack-provider
|
3
|
-
Feature: vagrant-openstack-provider fog tests
|
4
|
-
As a Fog developer
|
5
|
-
I want to smoke (or "fog") test vagrant-openstack-provider.
|
6
|
-
So I am confident my upstream changes did not create downstream problems.
|
7
|
-
|
8
|
-
Background:
|
9
|
-
Given I have Openstack credentials available
|
10
|
-
And I have a "fog_mock.rb" file
|
11
|
-
|
12
|
-
Scenario: Create a single server (region)
|
13
|
-
Given a file named "Vagrantfile" with:
|
14
|
-
"""
|
15
|
-
# Testing options
|
16
|
-
require File.expand_path '../fog_mock', __FILE__
|
17
|
-
|
18
|
-
Vagrant.configure("2") do |config|
|
19
|
-
# dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-openstack-provider'
|
20
|
-
Vagrant.require_plugin "vagrant-openstack-provider"
|
21
|
-
|
22
|
-
config.vm.box = "dummy"
|
23
|
-
config.ssh.username = "vagrant" if Fog.mock?
|
24
|
-
config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
|
25
|
-
|
26
|
-
config.vm.provider :openstack do |rs|
|
27
|
-
rs.server_name = 'vagrant-single-server'
|
28
|
-
rs.username = ENV['RAX_USERNAME']
|
29
|
-
rs.api_key = ENV['RAX_API_KEY']
|
30
|
-
rs.openstack_region = ENV['RAX_REGION'].downcase.to_sym
|
31
|
-
rs.flavor = /1 GB Performance/
|
32
|
-
rs.image = /Ubuntu/
|
33
|
-
rs.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
|
34
|
-
end
|
35
|
-
end
|
36
|
-
"""
|
37
|
-
When I successfully run `bundle exec vagrant up --provider openstack`
|
38
|
-
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
|
39
|
-
# And I get the server from "Instance ID:"
|
40
|
-
Then the server "vagrant-single-server" should be active
|
41
|
-
|
42
|
-
Scenario: Create a single server (openstack_compute_url)
|
43
|
-
Given a file named "Vagrantfile" with:
|
44
|
-
"""
|
45
|
-
# Testing options
|
46
|
-
require File.expand_path '../fog_mock', __FILE__
|
47
|
-
|
48
|
-
Vagrant.configure("2") do |config|
|
49
|
-
# dev/test method of loading plugin, normally would be 'vagrant plugin install vagrant-openstack-provider'
|
50
|
-
Vagrant.require_plugin "vagrant-openstack-provider"
|
51
|
-
|
52
|
-
config.vm.box = "dummy"
|
53
|
-
config.ssh.username = "vagrant" if Fog.mock?
|
54
|
-
config.ssh.private_key_path = "~/.ssh/id_rsa" unless Fog.mock?
|
55
|
-
|
56
|
-
config.vm.provider :openstack do |rs|
|
57
|
-
rs.server_name = 'vagrant-single-server'
|
58
|
-
rs.username = ENV['RAX_USERNAME']
|
59
|
-
rs.api_key = ENV['RAX_API_KEY']
|
60
|
-
rs.openstack_compute_url = "https://#{ENV['RAX_REGION'].downcase}.servers.api.openstackcloud.com/v2"
|
61
|
-
rs.flavor = /1 GB Performance/
|
62
|
-
rs.image = /Ubuntu/
|
63
|
-
rs.public_key_path = "~/.ssh/id_rsa.pub" unless Fog.mock?
|
64
|
-
end
|
65
|
-
end
|
66
|
-
"""
|
67
|
-
When I successfully run `bundle exec vagrant up --provider openstack`
|
68
|
-
# I want to capture the ID like I do in tests for other tools, but Vagrant doesn't print it!
|
69
|
-
# And I get the server from "Instance ID:"
|
70
|
-
Then the server "vagrant-single-server" should be active
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module Openstack
|
3
|
-
module Action
|
4
|
-
class MessageAlreadyCreated
|
5
|
-
def initialize(app, env)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
env[:ui].info(I18n.t("vagrant_openstack.already_created"))
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module VagrantPlugins
|
2
|
-
module Openstack
|
3
|
-
module Action
|
4
|
-
class MessageNotCreated
|
5
|
-
def initialize(app, env)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
env[:ui].info(I18n.t("vagrant_openstack.not_created"))
|
11
|
-
@app.call(env)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require "log4r"
|
2
|
-
require "restclient"
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
module VagrantPlugins
|
6
|
-
module Openstack
|
7
|
-
class OpenstackClient
|
8
|
-
|
9
|
-
def initialize()
|
10
|
-
@logger = Log4r::Logger.new("vagrant_openstack::openstack_client")
|
11
|
-
@token = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def authenticate(env)
|
15
|
-
@logger.debug("Authenticating on Keystone")
|
16
|
-
config = env[:machine].provider_config
|
17
|
-
authentication = RestClient.post(config.openstack_auth_url, {
|
18
|
-
:auth => {
|
19
|
-
:tenantName => config.tenant_name,
|
20
|
-
:passwordCredentials => {
|
21
|
-
:username => config.username,
|
22
|
-
:password => config.api_key
|
23
|
-
}
|
24
|
-
}
|
25
|
-
}.to_json,
|
26
|
-
:content_type => :json,
|
27
|
-
:accept => :json)
|
28
|
-
|
29
|
-
@token = JSON.parse(authentication)['access']['token']['id']
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_all_flavors(env)
|
33
|
-
config = env[:machine].provider_config
|
34
|
-
flavors_json = RestClient.get(config.openstack_compute_url + "/flavors",
|
35
|
-
{"X-Auth-Token" => @token, :accept => :json})
|
36
|
-
return JSON.parse(flavors_json)['flavors'].map { |fl| Item.new(fl['id'], fl['name']) }
|
37
|
-
end
|
38
|
-
|
39
|
-
def get_all_images(env)
|
40
|
-
config = env[:machine].provider_config
|
41
|
-
images_json = RestClient.get(config.openstack_compute_url + "/images",
|
42
|
-
{"X-Auth-Token" => @token, :accept => :json})
|
43
|
-
return JSON.parse(images_json)['images'].map { |im| Item.new(im['id'], im['name']) }
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_server(env, name, image_ref, flavor_ref, keypair)
|
47
|
-
config = env[:machine].provider_config
|
48
|
-
server = RestClient.post(config.openstack_compute_url + "/servers", {
|
49
|
-
:server => {
|
50
|
-
:name => name,
|
51
|
-
:imageRef => image_ref,
|
52
|
-
:flavorRef => flavor_ref,
|
53
|
-
:key_name => keypair
|
54
|
-
}
|
55
|
-
}.to_json,
|
56
|
-
"X-Auth-Token" => @token,
|
57
|
-
:accept => :json,
|
58
|
-
:content_type => :json)
|
59
|
-
return JSON.parse(server)['server']['id']
|
60
|
-
end
|
61
|
-
|
62
|
-
def delete_server(env, server_id)
|
63
|
-
config = env[:machine].provider_config
|
64
|
-
server = RestClient.delete(config.openstack_compute_url + "/servers/" + server_id,
|
65
|
-
"X-Auth-Token" => @token,
|
66
|
-
:accept => :json)
|
67
|
-
end
|
68
|
-
|
69
|
-
def get_server_details(env, server_id)
|
70
|
-
config = env[:machine].provider_config
|
71
|
-
server_details = RestClient.get(config.openstack_compute_url + "/servers/" + server_id,
|
72
|
-
"X-Auth-Token" => @token,
|
73
|
-
:accept => :json)
|
74
|
-
return JSON.parse(server_details)['server']
|
75
|
-
end
|
76
|
-
|
77
|
-
def add_floating_ip(env, server_id, floating_ip)
|
78
|
-
config = env[:machine].provider_config
|
79
|
-
server_details = RestClient.post(config.openstack_compute_url + "/servers/" + server_id + "/action", {
|
80
|
-
:addFloatingIp => {
|
81
|
-
:address => floating_ip
|
82
|
-
}
|
83
|
-
}.to_json,
|
84
|
-
"X-Auth-Token" => @token,
|
85
|
-
:accept => :json,
|
86
|
-
:content_type => :json)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class Item
|
91
|
-
attr_accessor :id, :name
|
92
|
-
def initialize(id, name)
|
93
|
-
@id = id
|
94
|
-
@name = name
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
@@ -1,184 +0,0 @@
|
|
1
|
-
if ENV['COVERAGE'] != 'false'
|
2
|
-
require 'simplecov'
|
3
|
-
require 'coveralls'
|
4
|
-
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
-
SimpleCov::Formatter::HTMLFormatter,
|
6
|
-
Coveralls::SimpleCov::Formatter
|
7
|
-
]
|
8
|
-
SimpleCov.start
|
9
|
-
end
|
10
|
-
|
11
|
-
require "vagrant-openstack-provider/config"
|
12
|
-
require 'fog'
|
13
|
-
|
14
|
-
describe VagrantPlugins::Openstack::Config do
|
15
|
-
describe "defaults" do
|
16
|
-
let(:vagrant_public_key) { Vagrant.source_root.join("keys/vagrant.pub") }
|
17
|
-
|
18
|
-
subject do
|
19
|
-
super().tap do |o|
|
20
|
-
o.finalize!
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
its(:api_key) { should be_nil }
|
25
|
-
its(:openstack_region) { should be_nil }
|
26
|
-
its(:openstack_compute_url) { should be_nil }
|
27
|
-
its(:openstack_auth_url) { should be_nil }
|
28
|
-
its(:flavor) { should eq(/m1.tiny/) }
|
29
|
-
its(:image) { should eq(/cirros/) }
|
30
|
-
its(:rackconnect) { should be_nil }
|
31
|
-
its(:network) { should be_nil }
|
32
|
-
its(:server_name) { should be_nil }
|
33
|
-
its(:username) { should be_nil }
|
34
|
-
its(:disk_config) { should be_nil }
|
35
|
-
its(:network) { should be_nil }
|
36
|
-
its(:rsync_includes) { should be_nil }
|
37
|
-
its(:keypair_name) { should be_nil }
|
38
|
-
its(:ssh_username) { should be_nil }
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "overriding defaults" do
|
42
|
-
[:api_key,
|
43
|
-
:openstack_region,
|
44
|
-
:openstack_compute_url,
|
45
|
-
:openstack_auth_url,
|
46
|
-
:flavor,
|
47
|
-
:image,
|
48
|
-
:rackconnect,
|
49
|
-
:server_name,
|
50
|
-
:network,
|
51
|
-
:disk_config,
|
52
|
-
:username,
|
53
|
-
:keypair_name,
|
54
|
-
:ssh_username].each do |attribute|
|
55
|
-
it "should not default #{attribute} if overridden" do
|
56
|
-
subject.send("#{attribute}=".to_sym, "foo")
|
57
|
-
subject.finalize!
|
58
|
-
subject.send(attribute).should == "foo"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
it "should not default rsync_includes if overridden" do
|
63
|
-
inc = "core"
|
64
|
-
subject.send(:rsync_include, inc)
|
65
|
-
subject.finalize!
|
66
|
-
subject.send(:rsync_includes).should include(inc)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "validation" do
|
71
|
-
let(:machine) { double("machine") }
|
72
|
-
let(:validation_errors) { subject.validate(machine)['Openstack Provider'] }
|
73
|
-
let(:error_message) { double("error message") }
|
74
|
-
|
75
|
-
before(:each) do
|
76
|
-
machine.stub_chain(:env, :root_path).and_return '/'
|
77
|
-
subject.username = 'foo'
|
78
|
-
subject.api_key = 'bar'
|
79
|
-
subject.keypair_name = 'keypair'
|
80
|
-
end
|
81
|
-
|
82
|
-
subject do
|
83
|
-
super().tap do |o|
|
84
|
-
o.finalize!
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context "with invalid key" do
|
89
|
-
it "should raise an error" do
|
90
|
-
subject.nonsense1 = true
|
91
|
-
subject.nonsense2 = false
|
92
|
-
I18n.should_receive(:t).with('vagrant.config.common.bad_field',
|
93
|
-
{ :fields => 'nonsense1, nonsense2' })
|
94
|
-
.and_return error_message
|
95
|
-
validation_errors.first.should == error_message
|
96
|
-
end
|
97
|
-
end
|
98
|
-
context "with good values" do
|
99
|
-
it "should validate" do
|
100
|
-
validation_errors.should be_empty
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
context "the keypair name" do
|
105
|
-
it "should error if not given" do
|
106
|
-
subject.keypair_name = nil
|
107
|
-
I18n.should_receive(:t).with('vagrant_openstack.config.keypair_name required').and_return error_message
|
108
|
-
validation_errors.first.should == error_message
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
context "the API key" do
|
113
|
-
it "should error if not given" do
|
114
|
-
subject.api_key = nil
|
115
|
-
I18n.should_receive(:t).with('vagrant_openstack.config.api_key required').and_return error_message
|
116
|
-
validation_errors.first.should == error_message
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
context "the username" do
|
121
|
-
it "should error if not given" do
|
122
|
-
subject.username = nil
|
123
|
-
I18n.should_receive(:t).with('vagrant_openstack.config.username required').and_return error_message
|
124
|
-
validation_errors.first.should == error_message
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
[:openstack_compute_url, :openstack_auth_url].each do |url|
|
129
|
-
context "the #{url}" do
|
130
|
-
it "should not validate if the URL is invalid" do
|
131
|
-
subject.send "#{url}=", 'baz'
|
132
|
-
I18n.should_receive(:t).with('vagrant_openstack.config.invalid_uri', {:key => url, :uri => 'baz'}).and_return error_message
|
133
|
-
validation_errors.first.should == error_message
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "openstack_auth_url" do
|
140
|
-
it "should return UNSET_VALUE if openstack_auth_url and openstack_region are UNSET" do
|
141
|
-
subject.openstack_auth_url.should == VagrantPlugins::Openstack::Config::UNSET_VALUE
|
142
|
-
end
|
143
|
-
it "should return UNSET_VALUE if openstack_auth_url is UNSET and openstack_region is :ord" do
|
144
|
-
subject.openstack_region = :ord
|
145
|
-
subject.openstack_auth_url.should == VagrantPlugins::Openstack::Config::UNSET_VALUE
|
146
|
-
end
|
147
|
-
it "should return custom endpoint if supplied and openstack_region is :lon" do
|
148
|
-
my_endpoint = 'http://custom-endpoint.com'
|
149
|
-
subject.openstack_region = :lon
|
150
|
-
subject.openstack_auth_url = my_endpoint
|
151
|
-
subject.openstack_auth_url.should == my_endpoint
|
152
|
-
end
|
153
|
-
it "should return custom endpoint if supplied and openstack_region is UNSET" do
|
154
|
-
my_endpoint = 'http://custom-endpoint.com'
|
155
|
-
subject.openstack_auth_url = my_endpoint
|
156
|
-
subject.openstack_auth_url.should == my_endpoint
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
|
161
|
-
describe "lon_region?" do
|
162
|
-
it "should return false if openstack_region is UNSET_VALUE" do
|
163
|
-
subject.openstack_region = VagrantPlugins::Openstack::Config::UNSET_VALUE
|
164
|
-
subject.send(:lon_region?).should be_false
|
165
|
-
end
|
166
|
-
it "should return false if openstack_region is nil" do
|
167
|
-
subject.openstack_region = nil
|
168
|
-
subject.send(:lon_region?).should be_false
|
169
|
-
end
|
170
|
-
it "should return false if openstack_region is :ord" do
|
171
|
-
subject.openstack_region = :ord
|
172
|
-
subject.send(:lon_region?).should be_false
|
173
|
-
end
|
174
|
-
it "should return true if openstack_region is 'lon'" do
|
175
|
-
subject.openstack_region = 'lon'
|
176
|
-
subject.send(:lon_region?).should be_true
|
177
|
-
end
|
178
|
-
it "should return true if openstack_Region is :lon" do
|
179
|
-
subject.openstack_region = :lon
|
180
|
-
subject.send(:lon_region?).should be_true
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
end
|