openstack-vagrant 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +23 -0
- data/.travis.yml +11 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +23 -0
- data/README.md +169 -0
- data/Rakefile +21 -0
- data/dummy.box +0 -0
- data/example_box/README.md +13 -0
- data/example_box/metadata.json +3 -0
- data/lib/vagrant-openstack/action/connect_openstack.rb +34 -0
- data/lib/vagrant-openstack/action/create_server.rb +185 -0
- data/lib/vagrant-openstack/action/delete_server.rb +26 -0
- data/lib/vagrant-openstack/action/is_created.rb +16 -0
- data/lib/vagrant-openstack/action/message_already_created.rb +16 -0
- data/lib/vagrant-openstack/action/message_not_created.rb +16 -0
- data/lib/vagrant-openstack/action/read_ssh_info_from_api.rb +46 -0
- data/lib/vagrant-openstack/action/read_ssh_info_from_cache.rb +53 -0
- data/lib/vagrant-openstack/action/read_state.rb +38 -0
- data/lib/vagrant-openstack/action/sync_folders.rb +58 -0
- data/lib/vagrant-openstack/action.rb +129 -0
- data/lib/vagrant-openstack/config.rb +126 -0
- data/lib/vagrant-openstack/errors.rb +35 -0
- data/lib/vagrant-openstack/plugin.rb +37 -0
- data/lib/vagrant-openstack/provider.rb +50 -0
- data/lib/vagrant-openstack/version.rb +5 -0
- data/lib/vagrant-openstack.rb +53 -0
- data/locales/en.yml +81 -0
- data/openstack-vagrant.gemspec +24 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/vagrant-openstack/action/create_server_spec.rb +89 -0
- data/spec/vagrant-openstack/action/read_ssh_info_spec.rb +122 -0
- data/spec/vagrant-openstack/config_spec.rb +81 -0
- metadata +121 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative '../lib/vagrant-openstack/errors'
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
4
|
+
|
5
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
6
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
7
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
8
|
+
# loaded once.
|
9
|
+
#
|
10
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vagrant-openstack/errors'
|
3
|
+
require 'vagrant-openstack/action/create_server'
|
4
|
+
|
5
|
+
describe VagrantPlugins::OpenStack::Action::CreateServer do
|
6
|
+
describe '#server_to_be_available?' do
|
7
|
+
subject {
|
8
|
+
described_class.new(nil, nil)
|
9
|
+
}
|
10
|
+
|
11
|
+
let(:server) { double }
|
12
|
+
|
13
|
+
it "returns true when server is active" do
|
14
|
+
server.stub(:state).and_return('ACTIVE')
|
15
|
+
subject.server_to_be_available?(server).should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should raise when the server state is ERROR" do
|
19
|
+
server.stub(:state).and_return('ERROR')
|
20
|
+
expect { subject.server_to_be_available?(server) }.to raise_error(RuntimeError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#ssh_responding?' do
|
25
|
+
subject {
|
26
|
+
described_class.new(nil, nil)
|
27
|
+
}
|
28
|
+
|
29
|
+
let(:ui) { double }
|
30
|
+
let(:machine) { double }
|
31
|
+
let(:communicate) { double }
|
32
|
+
|
33
|
+
it "should continue if ssh is available" do
|
34
|
+
ui.stub(:info)
|
35
|
+
communicate.stub(:ready?).and_return(true)
|
36
|
+
machine.stub(:communicate).and_return(communicate)
|
37
|
+
env = { :ui => ui, :interrupted => false, :machine => machine }
|
38
|
+
subject.send('ssh_responding?', env)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should raise if ssh isn't available" do
|
42
|
+
ui.stub(:info)
|
43
|
+
communicate.stub(:ready?).and_return(false)
|
44
|
+
machine.stub(:communicate).and_return(communicate)
|
45
|
+
env = { :ui => ui, :interrupted => false, :machine => machine }
|
46
|
+
expect { subject.send('ssh_responding?', env) }.to raise_error(VagrantPlugins::OpenStack::Errors::SshUnavailable)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '#find_matching' do
|
51
|
+
subject {
|
52
|
+
described_class.new(nil, nil)
|
53
|
+
}
|
54
|
+
|
55
|
+
it "returns a match for a list of hashes" do
|
56
|
+
haystack = [{"status"=>"ACTIVE", "subnets"=>["d8908f8c-07f4-405b-bbab-e19c768f293f"], "name"=>"solidfire", "provider:physical_network"=>"physnet1", "admin_state_up"=>true, "tenant_id"=>"2c9fba23721f4126ab244020e641f5f5", "provider:network_type"=>"vlan", "router:external"=>false, "shared"=>true, "id"=>"192702e6-3444-4162-b244-3af8b50fbb45", "provider:segmentation_id"=>3999}, {"status"=>"ACTIVE", "subnets"=>["d4318e28-5acd-415f-b300-0502f33b0dea"], "name"=>"public", "provider:physical_network"=>"physnet0", "admin_state_up"=>true, "tenant_id"=>"2c9fba23721f4126ab244020e641f5f5", "provider:network_type"=>"vlan", "router:external"=>false, "shared"=>true, "id"=>"e44bf8cb-7326-4abc-b96d-5404d5ed7767", "provider:segmentation_id"=>2753}]
|
57
|
+
needle = {"status"=>"ACTIVE", "subnets"=>["d4318e28-5acd-415f-b300-0502f33b0dea"], "name"=>"public", "provider:physical_network"=>"physnet0", "admin_state_up"=>true, "tenant_id"=>"2c9fba23721f4126ab244020e641f5f5", "provider:network_type"=>"vlan", "router:external"=>false, "shared"=>true, "id"=>"e44bf8cb-7326-4abc-b96d-5404d5ed7767", "provider:segmentation_id"=>2753}
|
58
|
+
|
59
|
+
subject.send('find_matching', haystack, needle['name']).should == needle
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns a match for a list of objects with matching id" do
|
63
|
+
object1 = double()
|
64
|
+
object1.stub('id' => 'matching_value')
|
65
|
+
object1.stub('name' => 'not_this')
|
66
|
+
|
67
|
+
haystack = [object1]
|
68
|
+
subject.send('find_matching', haystack, 'matching_value').should == object1
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns a match for a list of objects with matching name" do
|
72
|
+
object1 = double()
|
73
|
+
object1.stub('id' => 'not_this')
|
74
|
+
object1.stub('name' => 'matching_value')
|
75
|
+
|
76
|
+
haystack = [object1]
|
77
|
+
subject.send('find_matching', haystack, 'matching_value').should == object1
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns a match for a list of objects with a matching regexp" do
|
81
|
+
object1 = double()
|
82
|
+
object1.stub('id' => 'not_this')
|
83
|
+
object1.stub('name' => '2020 des fin fin')
|
84
|
+
|
85
|
+
haystack = [object1]
|
86
|
+
subject.send('find_matching', haystack, /des fin/).should == object1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'vagrant-openstack/action/read_ssh_info_from_api'
|
3
|
+
|
4
|
+
describe VagrantPlugins::OpenStack::Action::ReadSSHInfoFromAPI do
|
5
|
+
describe '#call' do
|
6
|
+
it "passes proper parameters to read_ssh_info and puts them in machine_ssh_info" do
|
7
|
+
app = lambda { |only_one_parameter| }
|
8
|
+
env = {:openstack_compute => :my_compute, :machine => :my_machine}
|
9
|
+
|
10
|
+
subject = described_class.new(app, nil)
|
11
|
+
subject.should_receive(:read_ssh_info).with(:my_compute, :my_machine).and_return(:my_ssh_info)
|
12
|
+
|
13
|
+
subject.call(env)
|
14
|
+
env[:machine_ssh_info].should == :my_ssh_info
|
15
|
+
end
|
16
|
+
|
17
|
+
it "calls app.call with the right env" do
|
18
|
+
app = double()
|
19
|
+
env = {:openstack_compute => nil, :machine => nil}
|
20
|
+
app.should_receive(:call).with(env)
|
21
|
+
|
22
|
+
subject = described_class.new(app, nil)
|
23
|
+
subject.stub(:read_ssh_info)
|
24
|
+
subject.call(env)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#read_ssh_info' do
|
29
|
+
subject {
|
30
|
+
described_class.new(nil, nil)
|
31
|
+
}
|
32
|
+
|
33
|
+
let(:machine) { double }
|
34
|
+
let(:openstack) { double }
|
35
|
+
let(:servers) { double }
|
36
|
+
let(:provider_config) do
|
37
|
+
mock = double
|
38
|
+
mock.stub(:public_network_name => "public")
|
39
|
+
mock.stub(:ssh_username => "username")
|
40
|
+
mock
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return nil if machine is nil" do
|
44
|
+
machine.stub(:id).and_return(nil)
|
45
|
+
subject.read_ssh_info(nil, machine).should == nil
|
46
|
+
end
|
47
|
+
|
48
|
+
it "assigns machine_id to nil and returns nil if openstack returns nil" do
|
49
|
+
machine.stub(:id => "anything")
|
50
|
+
machine.stub(:id=)
|
51
|
+
|
52
|
+
servers.should_receive(:get).and_return(nil)
|
53
|
+
openstack.should_receive(:servers).and_return(servers)
|
54
|
+
|
55
|
+
subject.read_ssh_info(openstack, machine).should == nil
|
56
|
+
end
|
57
|
+
|
58
|
+
it "returns nil when something bad happens while fetching address" do
|
59
|
+
provider_config.stub(:ssh_username)
|
60
|
+
machine.stub(:id => "anything")
|
61
|
+
machine.stub(:provider_config => provider_config)
|
62
|
+
|
63
|
+
invalid_openstack_server_instance = double()
|
64
|
+
invalid_openstack_server_instance.should_receive(:addresses).and_raise(StandardError)
|
65
|
+
servers.should_receive(:get).and_return(invalid_openstack_server_instance)
|
66
|
+
openstack.should_receive(:servers).and_return(servers)
|
67
|
+
|
68
|
+
result = subject.read_ssh_info(openstack, machine)
|
69
|
+
|
70
|
+
result[:port].should == 22
|
71
|
+
result[:host].should == nil
|
72
|
+
end
|
73
|
+
|
74
|
+
it "returns a proper ssh_info hash" do
|
75
|
+
provider_config.stub(:ssh_username => "root")
|
76
|
+
machine.stub(:id => "anything")
|
77
|
+
machine.stub(:provider_config => provider_config)
|
78
|
+
|
79
|
+
valid_server_addresses = {
|
80
|
+
"public" => [
|
81
|
+
{ "addr" => 'server1.example.org' },
|
82
|
+
{ "addr" => 'server2.example.org' }
|
83
|
+
]
|
84
|
+
}
|
85
|
+
|
86
|
+
openstack_server_instance = double()
|
87
|
+
openstack_server_instance.should_receive(:addresses).and_return(valid_server_addresses)
|
88
|
+
|
89
|
+
servers.should_receive(:get).and_return(openstack_server_instance)
|
90
|
+
openstack.should_receive(:servers).and_return(servers)
|
91
|
+
|
92
|
+
result = subject.read_ssh_info(openstack, machine)
|
93
|
+
|
94
|
+
result[:port].should == 22
|
95
|
+
result[:host].should == "server2.example.org"
|
96
|
+
result[:username].should == "root"
|
97
|
+
end
|
98
|
+
|
99
|
+
it "uses the public network name from the config" do
|
100
|
+
provider_config.stub(:public_network_name => "my_custom_public_network_name")
|
101
|
+
machine.stub(:id => "anything")
|
102
|
+
machine.stub(:provider_config => provider_config)
|
103
|
+
|
104
|
+
valid_server_addresses = {
|
105
|
+
"my_custom_public_network_name" => [
|
106
|
+
{ "addr" => 'server1.example.org' },
|
107
|
+
{ "addr" => 'server2.example.org' }
|
108
|
+
]
|
109
|
+
}
|
110
|
+
|
111
|
+
openstack_server_instance = double()
|
112
|
+
openstack_server_instance.should_receive(:addresses).and_return(valid_server_addresses)
|
113
|
+
|
114
|
+
servers.should_receive(:get).and_return(openstack_server_instance)
|
115
|
+
openstack.should_receive(:servers).and_return(servers)
|
116
|
+
|
117
|
+
result = subject.read_ssh_info(openstack, machine)
|
118
|
+
|
119
|
+
result[:host].should == "server2.example.org"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require "vagrant-openstack/config"
|
3
|
+
|
4
|
+
describe VagrantPlugins::OpenStack::Config do
|
5
|
+
describe "defaults" do
|
6
|
+
let(:vagrant_public_key) { Vagrant.source_root.join("keys/vagrant.pub") }
|
7
|
+
|
8
|
+
subject do
|
9
|
+
super().tap do |o|
|
10
|
+
o.finalize!
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
its(:api_key) { should be_nil }
|
15
|
+
its(:endpoint) { should be_nil }
|
16
|
+
its(:region) { should be_nil }
|
17
|
+
its(:flavor) { should eq(/m1.tiny/) }
|
18
|
+
its(:image) { should eq(/cirros/) }
|
19
|
+
its(:server_name) { should be_nil }
|
20
|
+
its(:username) { should be_nil }
|
21
|
+
its(:keypair_name) { should be_nil }
|
22
|
+
its(:ssh_username) { should be_nil }
|
23
|
+
its(:user_data) { should eq("") }
|
24
|
+
its(:metadata) { should eq({}) }
|
25
|
+
its(:public_network_name) { should eq("public") }
|
26
|
+
its(:networks) { should eq(["public"]) }
|
27
|
+
its(:tenant) { should be_nil }
|
28
|
+
its(:scheduler_hints) { should eq({}) }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "overriding defaults" do
|
32
|
+
[:api_key,
|
33
|
+
:endpoint,
|
34
|
+
:region,
|
35
|
+
:flavor,
|
36
|
+
:image,
|
37
|
+
:server_name,
|
38
|
+
:username,
|
39
|
+
:keypair_name,
|
40
|
+
:ssh_username,
|
41
|
+
:metadata,
|
42
|
+
:public_network_name,
|
43
|
+
:networks,
|
44
|
+
:tenant,
|
45
|
+
:scheduler_hints].each do |attribute|
|
46
|
+
it "should not default #{attribute} if overridden" do
|
47
|
+
subject.send("#{attribute}=", "foo")
|
48
|
+
subject.finalize!
|
49
|
+
subject.send(attribute).should == "foo"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "validation" do
|
55
|
+
let(:machine) { double("machine") }
|
56
|
+
|
57
|
+
subject do
|
58
|
+
super().tap do |o|
|
59
|
+
o.finalize!
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context "with good values" do
|
64
|
+
it "should validate"
|
65
|
+
end
|
66
|
+
|
67
|
+
context "the API key" do
|
68
|
+
it "should error if not given"
|
69
|
+
end
|
70
|
+
|
71
|
+
context "the public key path" do
|
72
|
+
it "should have errors if the key doesn't exist"
|
73
|
+
it "should not have errors if the key exists with an absolute path"
|
74
|
+
it "should not have errors if the key exists with a relative path"
|
75
|
+
end
|
76
|
+
|
77
|
+
context "the username" do
|
78
|
+
it "should error if not given"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openstack-vagrant
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mitchell Hashimoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fog
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.22'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.22'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.13.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.13.0
|
55
|
+
description: Enables Vagrant to manage machines in OpenStack Cloud.
|
56
|
+
email:
|
57
|
+
- mitchell@hashicorp.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .travis.yml
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- dummy.box
|
69
|
+
- example_box/README.md
|
70
|
+
- example_box/metadata.json
|
71
|
+
- lib/vagrant-openstack.rb
|
72
|
+
- lib/vagrant-openstack/action.rb
|
73
|
+
- lib/vagrant-openstack/action/connect_openstack.rb
|
74
|
+
- lib/vagrant-openstack/action/create_server.rb
|
75
|
+
- lib/vagrant-openstack/action/delete_server.rb
|
76
|
+
- lib/vagrant-openstack/action/is_created.rb
|
77
|
+
- lib/vagrant-openstack/action/message_already_created.rb
|
78
|
+
- lib/vagrant-openstack/action/message_not_created.rb
|
79
|
+
- lib/vagrant-openstack/action/read_ssh_info_from_api.rb
|
80
|
+
- lib/vagrant-openstack/action/read_ssh_info_from_cache.rb
|
81
|
+
- lib/vagrant-openstack/action/read_state.rb
|
82
|
+
- lib/vagrant-openstack/action/sync_folders.rb
|
83
|
+
- lib/vagrant-openstack/config.rb
|
84
|
+
- lib/vagrant-openstack/errors.rb
|
85
|
+
- lib/vagrant-openstack/plugin.rb
|
86
|
+
- lib/vagrant-openstack/provider.rb
|
87
|
+
- lib/vagrant-openstack/version.rb
|
88
|
+
- locales/en.yml
|
89
|
+
- openstack-vagrant.gemspec
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/vagrant-openstack/action/create_server_spec.rb
|
92
|
+
- spec/vagrant-openstack/action/read_ssh_info_spec.rb
|
93
|
+
- spec/vagrant-openstack/config_spec.rb
|
94
|
+
homepage: http://www.vagrantup.com
|
95
|
+
licenses: []
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.4.5
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Enables Vagrant to manage machines in OpenStack Cloud.
|
117
|
+
test_files:
|
118
|
+
- spec/spec_helper.rb
|
119
|
+
- spec/vagrant-openstack/action/create_server_spec.rb
|
120
|
+
- spec/vagrant-openstack/action/read_ssh_info_spec.rb
|
121
|
+
- spec/vagrant-openstack/config_spec.rb
|