vagrant-openstack-cloud-provider 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b182a701fd3c8e02f164f19c6726ac2b541b4ca
4
- data.tar.gz: bb49494f4566256877a45da8ee63a86c9cfc9608
3
+ metadata.gz: 757087dec480ba560e7fcd2d238842934b5c5084
4
+ data.tar.gz: 5a2516fb166f82f322f54f5abbefc8b38adc39c5
5
5
  SHA512:
6
- metadata.gz: 6df57c41d76339adbbfbaca7e803005fe5b59b3ffaf9eb761cfa33b75d7f9990f4fd8d4938a8f6dafe3cc177577a3de29af3d23416cd22ad78590657b95888e5
7
- data.tar.gz: 5b88e61657a1134664e58359d24739b1305323f51824a2c2107fc78c1cae6641a62923db85e60e39859bb776a81067e309bf4ee10e0650dab56b9561049ae21f
6
+ metadata.gz: 65b8aa57e0fb0df88abef0b65f9949b0a9e4e8cf8de267946a3205e250d36b9841ce025e6ed56b292467aa2c35ac168eb67a4ce4a13fcec24e4345e13cfb9517
7
+ data.tar.gz: c3f159790ba459a74093074590bd7a31ae22c244f2dfc388aeba6d8f905fb8c4601926c17b4596882f597d8d488bd4cabcfe899ac05232d89897fe64930012d2
@@ -1,5 +1,6 @@
1
1
  require "fog"
2
2
  require "log4r"
3
+ require 'promise'
3
4
 
4
5
  module VagrantPlugins
5
6
  module OpenStack
@@ -14,20 +15,31 @@ module VagrantPlugins
14
15
  end
15
16
 
16
17
  def call(env)
17
- # Get the configs
18
- config = env[:machine].provider_config
19
- @logger.info("Connecting to OpenStack Compute...")
20
- env[:openstack_compute] = Fog::Compute.new({
21
- :provider => :openstack,
22
- :openstack_region => config.region,
23
- :openstack_username => config.username,
24
- :openstack_api_key => config.api_key,
25
- :openstack_auth_url => config.endpoint,
26
- :openstack_tenant => config.tenant
27
- })
18
+ config = env[:machine].provider_config
19
+
20
+ openstack_options = {
21
+ :provider => :openstack,
22
+ :openstack_region => config.region,
23
+ :openstack_username => config.username,
24
+ :openstack_api_key => config.api_key,
25
+ :openstack_auth_url => config.endpoint,
26
+ :openstack_tenant => config.tenant
27
+ }
28
+
29
+ env[:openstack_compute] = get_fog_promise('Compute', openstack_options)
30
+ env[:openstack_network] = get_fog_promise('Network', openstack_options)
28
31
 
29
32
  @app.call(env)
30
33
  end
34
+
35
+ private
36
+
37
+ def get_fog_promise(service_name, openstack_options)
38
+ promise {
39
+ @logger.info("Initializing OpenStack #{service_name}...")
40
+ Fog.const_get(service_name).new(openstack_options)
41
+ }
42
+ end
31
43
  end
32
44
  end
33
45
  end
@@ -23,19 +23,7 @@ module VagrantPlugins
23
23
 
24
24
  def call(env)
25
25
  # Get the configs
26
- config = env[:machine].provider_config
27
-
28
- if !config.networks.nil? and config.networks.any?
29
- @logger.info("Connecting to OpenStack Network...")
30
- env[:openstack_network] = Fog::Network.new({
31
- :provider => :openstack,
32
- :openstack_region => config.region,
33
- :openstack_username => config.username,
34
- :openstack_api_key => config.api_key,
35
- :openstack_auth_url => config.endpoint,
36
- :openstack_tenant => config.tenant
37
- })
38
- end
26
+ config = env[:machine].provider_config
39
27
 
40
28
  # Find the flavor
41
29
  env[:ui].info(I18n.t("vagrant_openstack.finding_flavor"))
@@ -115,15 +103,15 @@ module VagrantPlugins
115
103
 
116
104
  # Wait for the server to be ready
117
105
  begin
118
- (1..config.instance_build_timeout).each do |n|
106
+ (1..config.instance_build_timeout / config.instance_build_status_check_interval).each do |n|
119
107
  if config.report_progress
120
108
  env[:ui].clear_line
121
- env[:ui].report_progress(n, false)
109
+ env[:ui].report_progress(n * config.instance_build_status_check_interval, false)
122
110
  end
123
111
 
124
112
  server = env[:openstack_compute].servers.get(env[:machine].id)
125
113
  break if self.server_to_be_available?(server)
126
- sleep 1
114
+ sleep config.instance_build_status_check_interval
127
115
  end
128
116
  server = env[:openstack_compute].servers.get(env[:machine].id)
129
117
  raise unless self.server_to_be_available?(server)
@@ -142,27 +130,30 @@ module VagrantPlugins
142
130
  unless env[:interrupted]
143
131
  # Clear the line one more time so the progress is removed
144
132
  env[:ui].clear_line
145
- ssh_is_responding?(env)
133
+ ssh_is_responding?(env,
134
+ timeout=config.instance_ssh_timeout,
135
+ sleep_interval=config.instance_ssh_check_interval)
146
136
  env[:ui].info(I18n.t("vagrant_openstack.ready",
147
137
  :elapsed => (Time.now - launch_start_time).floor))
148
138
  end
149
139
 
150
140
  @app.call(env)
151
141
  end
142
+
152
143
  protected
153
144
 
154
- def ssh_is_responding?(env)
145
+ def ssh_is_responding?(env, timeout, sleep_interval)
155
146
  begin
156
147
  # Wait for SSH to become available
157
148
  env[:ui].info(I18n.t("vagrant_openstack.waiting_for_ssh"))
158
- (1..60).each do |n|
149
+ (1..timeout / sleep_interval).each do |n|
159
150
  begin
160
151
  # If we're interrupted then just back out
161
152
  break if env[:interrupted]
162
153
  break if env[:machine].communicate.ready?
163
154
  rescue Errno::ENETUNREACH
164
155
  end
165
- sleep 2
156
+ sleep sleep_interval
166
157
  end
167
158
  raise unless env[:machine].communicate.ready?
168
159
  rescue
@@ -1,4 +1,5 @@
1
1
  require "vagrant"
2
+ require "vagrant-openstack-cloud-provider/utils"
2
3
 
3
4
  module VagrantPlugins
4
5
  module OpenStack
@@ -70,14 +71,22 @@ module VagrantPlugins
70
71
  # @return [Hash]
71
72
  attr_accessor :scheduler_hints
72
73
 
73
- # @return [String]
74
- attr_accessor :instance_build_timeout
74
+ # @return [Integer]
75
+ casting_attr_accessor :instance_build_timeout, Integer, greater_than(0)
76
+
77
+ # @return [Integer]
78
+ casting_attr_accessor :instance_build_status_check_interval, Integer, greater_than(0)
79
+
80
+ # @return [Integer]
81
+ casting_attr_accessor :instance_ssh_timeout, Integer, greater_than(0)
82
+
83
+ # @return [Integer]
84
+ casting_attr_accessor :instance_ssh_check_interval, Integer, greater_than(0)
75
85
 
76
86
  # @return [Bool]
77
87
  attr_accessor :report_progress
78
88
  # alias_method :report_progress?, :report_progress
79
89
 
80
-
81
90
  def initialize
82
91
  @api_key = UNSET_VALUE
83
92
  @endpoint = UNSET_VALUE
@@ -95,6 +104,9 @@ module VagrantPlugins
95
104
  @tenant = UNSET_VALUE
96
105
  @scheduler_hints = UNSET_VALUE
97
106
  @instance_build_timeout = UNSET_VALUE
107
+ @instance_build_status_check_interval = UNSET_VALUE
108
+ @instance_ssh_timeout = UNSET_VALUE
109
+ @instance_ssh_check_interval = UNSET_VALUE
98
110
  @report_progress = UNSET_VALUE
99
111
  end
100
112
 
@@ -122,6 +134,10 @@ module VagrantPlugins
122
134
  @tenant = nil if @tenant == UNSET_VALUE
123
135
  @scheduler_hints = {} if @scheduler_hints == UNSET_VALUE
124
136
  @instance_build_timeout = 120 if @instance_build_timeout == UNSET_VALUE
137
+ @instance_build_status_check_interval = 1 if @instance_build_status_check_interval == UNSET_VALUE
138
+ @instance_ssh_timeout = 60 if @instance_ssh_timeout == UNSET_VALUE
139
+ @instance_ssh_check_interval = 2 if @instance_ssh_check_interval == UNSET_VALUE
140
+
125
141
  @report_progress = true if @report_progress == UNSET_VALUE
126
142
  end
127
143
 
@@ -0,0 +1,24 @@
1
+ class InvalidValue < StandardError
2
+ end
3
+
4
+ def greater_than(base_value)
5
+ lambda { |val| val > base_value }
6
+ end
7
+
8
+
9
+ def casting_attr_accessor(accessor, type, *validators)
10
+
11
+ define_method(accessor) do
12
+ instance_variable_get("@#{accessor}")
13
+ end
14
+
15
+ define_method("#{accessor}=") do |val|
16
+ new_val = Kernel.send(type.to_s, val)
17
+ if validators and ! validators.all? {|v| v.call(new_val) }
18
+ raise InvalidValue, val
19
+ end
20
+
21
+ instance_variable_set("@#{accessor}", new_val)
22
+ end
23
+ end
24
+
@@ -1,5 +1,5 @@
1
1
  module VagrantPlugins
2
2
  module OpenStack
3
- VERSION = "1.1.8"
3
+ VERSION = "1.1.9"
4
4
  end
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -9,7 +9,6 @@ SimpleCov.start
9
9
  #
10
10
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
11
  RSpec.configure do |config|
12
- config.treat_symbols_as_metadata_keys_with_true_values = true
13
12
  config.run_all_when_everything_filtered = true
14
13
  config.filter_run :focus
15
14
 
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+ require 'vagrant-openstack-cloud-provider/errors'
3
+ require 'vagrant-openstack-cloud-provider/action/connect_openstack'
4
+ require "fog"
5
+
6
+ RSpec.describe VagrantPlugins::OpenStack::Action::ConnectOpenStack do
7
+ describe '#call?' do
8
+ let (:app) { double }
9
+ let (:machine) { double }
10
+ let (:config) { double(
11
+ :config,
12
+ :region => nil,
13
+ :username => 'username',
14
+ :api_key => 'password',
15
+ :endpoint => 'http://openstack.invalid/',
16
+ :tenant => nil,
17
+ )
18
+ }
19
+
20
+ subject {
21
+ described_class.new(app, nil)
22
+ }
23
+
24
+ it "should new members in env" do
25
+ expect(app).to receive(:call)
26
+ expect(machine).to receive(:provider_config).and_return(config)
27
+ env = { :machine => machine }
28
+
29
+ subject.call(env)
30
+
31
+ expect(env).to have_key(:openstack_compute)
32
+ expect(env).to have_key(:openstack_network)
33
+ end
34
+
35
+ {Fog::Compute => :openstack_compute,
36
+ Fog::Network => :openstack_network}.each do |klass, attribute|
37
+ it "should late-evaluate #{klass}" do
38
+ expect(app).to receive(:call)
39
+ expect(machine).to receive(:provider_config).and_return(config)
40
+ env = { :machine => machine }
41
+
42
+ expect(klass).to receive(:new).and_raise(MyError)
43
+
44
+ subject.call(env)
45
+
46
+ expect { env[attribute].any_call }.to raise_error(MyError)
47
+ end
48
+ end
49
+
50
+ end
51
+ end
52
+
53
+ class MyError < StandardError
54
+
55
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
  require 'vagrant-openstack-cloud-provider/errors'
3
3
  require 'vagrant-openstack-cloud-provider/action/create_server'
4
4
 
5
- describe VagrantPlugins::OpenStack::Action::CreateServer do
5
+ RSpec.describe VagrantPlugins::OpenStack::Action::CreateServer do
6
6
  describe '#server_to_be_available?' do
7
7
  subject {
8
8
  described_class.new(nil, nil)
@@ -11,12 +11,12 @@ describe VagrantPlugins::OpenStack::Action::CreateServer do
11
11
  let(:server) { double }
12
12
 
13
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
14
+ expect(server).to receive(:state).at_least(:once).and_return('ACTIVE')
15
+ expect(subject.server_to_be_available?(server)).to eq(true)
16
16
  end
17
17
 
18
18
  it "should raise when the server state is ERROR" do
19
- server.stub(:state).and_return('ERROR')
19
+ expect(server).to receive(:state).at_least(:once).and_return('ERROR')
20
20
  expect { subject.server_to_be_available?(server) }.to raise_error(RuntimeError)
21
21
  end
22
22
  end
@@ -31,19 +31,21 @@ describe VagrantPlugins::OpenStack::Action::CreateServer do
31
31
  let(:communicate) { double }
32
32
 
33
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)
34
+ expect(ui).to receive(:info).at_least(:once)
35
+ expect(communicate).to receive(:ready?).twice.and_return(true)
36
+ expect(machine).to receive(:communicate).at_least(:once).and_return(communicate)
37
+
37
38
  env = { :ui => ui, :interrupted => false, :machine => machine }
38
- subject.send('ssh_is_responding?', env)
39
+ subject.send('ssh_is_responding?', env, timeout=1, sleep_interval=0.001)
39
40
  end
40
41
 
41
42
  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)
43
+ expect(ui).to receive(:info).at_least(:once)
44
+ expect(communicate).to receive(:ready?).exactly(6).times.and_return(false)
45
+ expect(machine).to receive(:communicate).at_least(:once).and_return(communicate)
46
+
45
47
  env = { :ui => ui, :interrupted => false, :machine => machine }
46
- expect { subject.send('ssh_is_responding?', env) }.to raise_error(VagrantPlugins::OpenStack::Errors::SshUnavailable)
48
+ expect { subject.send('ssh_is_responding?', env, timeout=0.005, sleep_interval=0.001) }.to raise_error(VagrantPlugins::OpenStack::Errors::SshUnavailable)
47
49
  end
48
50
  end
49
51
 
@@ -56,34 +58,34 @@ describe VagrantPlugins::OpenStack::Action::CreateServer do
56
58
  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
59
  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
60
 
59
- subject.send('find_matching', haystack, needle['name']).should == needle
61
+ expect(subject.send('find_matching', haystack, needle['name'])).to eq(needle)
60
62
  end
61
63
 
62
64
  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')
65
+ object1 = double(:object1,
66
+ :id => 'matching_value',
67
+ :name => 'not_this')
66
68
 
67
69
  haystack = [object1]
68
- subject.send('find_matching', haystack, 'matching_value').should == object1
70
+ expect(subject.send('find_matching', haystack, 'matching_value')).to equal(object1)
69
71
  end
70
72
 
71
73
  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')
74
+ object1 = double(:object1,
75
+ :id => 'not_this',
76
+ :name => 'matching_value')
75
77
 
76
78
  haystack = [object1]
77
- subject.send('find_matching', haystack, 'matching_value').should == object1
79
+ expect(subject.send('find_matching', haystack, 'matching_value')).to equal(object1)
78
80
  end
79
81
 
80
82
  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')
83
+ object1 = double(:object1,
84
+ :id => 'not_this',
85
+ :name => '2020 des fin fin')
84
86
 
85
87
  haystack = [object1]
86
- subject.send('find_matching', haystack, /des fin/).should == object1
88
+ expect(subject.send('find_matching', haystack, /des fin/)).to equal(object1)
87
89
  end
88
90
  end
89
91
  end
@@ -1,26 +1,26 @@
1
1
  require 'spec_helper'
2
2
  require 'vagrant-openstack-cloud-provider/action/read_ssh_info_from_api'
3
3
 
4
- describe VagrantPlugins::OpenStack::Action::ReadSSHInfoFromAPI do
4
+ RSpec.describe VagrantPlugins::OpenStack::Action::ReadSSHInfoFromAPI do
5
5
  describe '#call' do
6
6
  it "passes proper parameters to read_ssh_info and puts them in machine_ssh_info" do
7
7
  app = lambda { |only_one_parameter| }
8
8
  env = {:openstack_compute => :my_compute, :machine => :my_machine}
9
9
 
10
10
  subject = described_class.new(app, nil)
11
- subject.should_receive(:read_ssh_info).with(:my_compute, :my_machine).and_return(:my_ssh_info)
11
+ expect(subject).to receive(:read_ssh_info).with(:my_compute, :my_machine).and_return(:my_ssh_info)
12
12
 
13
13
  subject.call(env)
14
- env[:machine_ssh_info].should == :my_ssh_info
14
+ expect(env[:machine_ssh_info]).to eq(:my_ssh_info)
15
15
  end
16
16
 
17
17
  it "calls app.call with the right env" do
18
18
  app = double()
19
19
  env = {:openstack_compute => nil, :machine => nil}
20
- app.should_receive(:call).with(env)
20
+ expect(app).to receive(:call).with(env)
21
21
 
22
22
  subject = described_class.new(app, nil)
23
- subject.stub(:read_ssh_info)
23
+ expect(subject).to receive(:read_ssh_info)
24
24
  subject.call(env)
25
25
  end
26
26
  end
@@ -33,48 +33,45 @@ describe VagrantPlugins::OpenStack::Action::ReadSSHInfoFromAPI do
33
33
  let(:machine) { double }
34
34
  let(:openstack) { double }
35
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
36
+ let(:invalid_openstack_server_instance) { double }
37
+ let(:openstack_server_instance) { double }
38
+ let(:provider_config) { double(:config,
39
+ :public_network_name => "public",
40
+ :ssh_username => "username")
41
+ }
42
42
 
43
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
44
+ expect(machine).to receive(:id).and_return(nil)
45
+ expect(subject.read_ssh_info(nil, machine)).to eq(nil)
46
46
  end
47
47
 
48
48
  it "assigns machine_id to nil and returns nil if openstack returns nil" do
49
- machine.stub(:id => "anything")
50
- machine.stub(:id=)
49
+ expect(machine).to receive(:id).at_least(:once).and_return("anything")
50
+ expect(machine).to receive(:id=).at_least(:once)
51
51
 
52
- servers.should_receive(:get).and_return(nil)
53
- openstack.should_receive(:servers).and_return(servers)
52
+ expect(servers).to receive(:get).and_return(nil)
53
+ expect(openstack).to receive(:servers).and_return(servers)
54
54
 
55
- subject.read_ssh_info(openstack, machine).should == nil
55
+ expect(subject.read_ssh_info(openstack, machine)).to eq(nil)
56
56
  end
57
57
 
58
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)
59
+ expect(machine).to receive(:id).at_least(:once).and_return("anything")
60
+ expect(machine).to receive(:provider_config).and_return(provider_config)
62
61
 
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)
62
+ expect(invalid_openstack_server_instance).to receive(:addresses).and_raise(StandardError)
63
+ expect(servers).to receive(:get).and_return(invalid_openstack_server_instance)
64
+ expect(openstack).to receive(:servers).and_return(servers)
67
65
 
68
66
  result = subject.read_ssh_info(openstack, machine)
69
67
 
70
- result[:port].should == 22
71
- result[:host].should == nil
68
+ expect(result).to eq({:port => 22, :username => 'username', :host => nil})
72
69
  end
73
70
 
74
71
  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)
72
+ expect(provider_config).to receive(:ssh_username).and_return("root")
73
+ expect(machine).to receive(:id).at_least(:once).and_return("anything")
74
+ expect(machine).to receive(:provider_config).and_return(provider_config)
78
75
 
79
76
  valid_server_addresses = {
80
77
  "public" => [
@@ -83,23 +80,21 @@ describe VagrantPlugins::OpenStack::Action::ReadSSHInfoFromAPI do
83
80
  ]
84
81
  }
85
82
 
86
- openstack_server_instance = double()
87
- openstack_server_instance.should_receive(:addresses).and_return(valid_server_addresses)
83
+ expect(openstack_server_instance).to receive(:addresses).and_return(valid_server_addresses)
88
84
 
89
- servers.should_receive(:get).and_return(openstack_server_instance)
90
- openstack.should_receive(:servers).and_return(servers)
85
+ expect(servers).to receive(:get).and_return(openstack_server_instance)
86
+ expect(openstack).to receive(:servers).and_return(servers)
91
87
 
92
88
  result = subject.read_ssh_info(openstack, machine)
93
89
 
94
- result[:port].should == 22
95
- result[:host].should == "server2.example.org"
96
- result[:username].should == "root"
90
+ expect(result).to eq({:port => 22, :username => "root", :host => "server2.example.org"})
97
91
  end
98
92
 
99
93
  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)
94
+ expect(provider_config).to receive(:public_network_name).and_return("my_custom_public_network_name")
95
+ expect(machine).to receive(:id).at_least(:once).and_return("anything")
96
+
97
+ expect(machine).to receive(:provider_config).and_return(provider_config)
103
98
 
104
99
  valid_server_addresses = {
105
100
  "my_custom_public_network_name" => [
@@ -108,15 +103,14 @@ describe VagrantPlugins::OpenStack::Action::ReadSSHInfoFromAPI do
108
103
  ]
109
104
  }
110
105
 
111
- openstack_server_instance = double()
112
- openstack_server_instance.should_receive(:addresses).and_return(valid_server_addresses)
106
+ expect(openstack_server_instance).to receive(:addresses).and_return(valid_server_addresses)
113
107
 
114
- servers.should_receive(:get).and_return(openstack_server_instance)
115
- openstack.should_receive(:servers).and_return(servers)
108
+ expect(servers).to receive(:get).and_return(openstack_server_instance)
109
+ expect(openstack).to receive(:servers).and_return(servers)
116
110
 
117
111
  result = subject.read_ssh_info(openstack, machine)
118
112
 
119
- result[:host].should == "server2.example.org"
113
+ expect(result).to eq({:port => 22, :username => "username", :host => "server2.example.org"})
120
114
  end
121
115
  end
122
- end
116
+ end
@@ -1,7 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require "vagrant-openstack-cloud-provider/config"
3
+ require "vagrant-openstack-cloud-provider/utils"
3
4
 
4
- describe VagrantPlugins::OpenStack::Config do
5
+ RSpec.describe VagrantPlugins::OpenStack::Config do
5
6
  describe "defaults" do
6
7
  let(:vagrant_public_key) { Vagrant.source_root.join("keys/vagrant.pub") }
7
8
 
@@ -11,26 +12,29 @@ describe VagrantPlugins::OpenStack::Config do
11
12
  end
12
13
  end
13
14
 
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
- its(:instance_build_timeout) { should eq(120) }
30
- its(:report_progress) { should be_true }
15
+ it { is_expected.to have_attributes(api_key: nil) }
16
+ it { is_expected.to have_attributes(endpoint: nil) }
17
+ it { is_expected.to have_attributes(region: nil) }
18
+ it { is_expected.to have_attributes(flavor: /m1.tiny/) }
19
+ it { is_expected.to have_attributes(image: /cirros/) }
20
+ it { is_expected.to have_attributes(server_name: nil) }
21
+ it { is_expected.to have_attributes(username: nil) }
22
+ it { is_expected.to have_attributes(keypair_name: nil) }
23
+ it { is_expected.to have_attributes(ssh_username: nil) }
24
+ it { is_expected.to have_attributes(user_data: "") }
25
+ it { is_expected.to have_attributes(metadata: {}) }
26
+ it { is_expected.to have_attributes(public_network_name: "public") }
27
+ it { is_expected.to have_attributes(networks: ["public"]) }
28
+ it { is_expected.to have_attributes(tenant: nil) }
29
+ it { is_expected.to have_attributes(scheduler_hints: {}) }
30
+ it { is_expected.to have_attributes(instance_build_timeout: 120) }
31
+ it { is_expected.to have_attributes(instance_build_status_check_interval: 1) }
32
+ it { is_expected.to have_attributes(instance_ssh_timeout: 60) }
33
+ it { is_expected.to have_attributes(instance_ssh_check_interval: 2) }
34
+ it { is_expected.to have_attributes(report_progress: true) }
31
35
  end
32
36
 
33
- describe "overriding defaults" do
37
+ describe "overriding defaults - strings" do
34
38
  [:api_key,
35
39
  :endpoint,
36
40
  :region,
@@ -45,12 +49,24 @@ describe VagrantPlugins::OpenStack::Config do
45
49
  :networks,
46
50
  :tenant,
47
51
  :scheduler_hints,
48
- :instance_build_timeout,
49
52
  :report_progress].each do |attribute|
50
53
  it "should not default #{attribute} if overridden" do
51
54
  subject.send("#{attribute}=", "foo")
52
55
  subject.finalize!
53
- subject.send(attribute).should == "foo"
56
+ expect(subject.send(attribute)).to eq("foo")
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "overriding defaults - integers" do
62
+ [:instance_build_timeout,
63
+ :instance_build_status_check_interval,
64
+ :instance_ssh_timeout,
65
+ :instance_ssh_check_interval].each do |attribute|
66
+ it "should not default #{attribute} if overridden" do
67
+ subject.send("#{attribute}=", 12345)
68
+ subject.finalize!
69
+ expect(subject.send(attribute)).to eq(12345)
54
70
  end
55
71
  end
56
72
  end
@@ -81,5 +97,33 @@ describe VagrantPlugins::OpenStack::Config do
81
97
  context "the username" do
82
98
  it "should error if not given"
83
99
  end
100
+
101
+ context "the numeric values" do
102
+ [:instance_build_timeout,
103
+ :instance_build_status_check_interval,
104
+ :instance_ssh_timeout,
105
+ :instance_ssh_check_interval].each do |attribute|
106
+ it "should cast #{attribute} to an int" do
107
+ subject.send("#{attribute}=", "100")
108
+ subject.finalize!
109
+ expect(subject.send(attribute)).to eq(100)
110
+ end
111
+ it "should raise when given a wrong value" do
112
+ expect { subject.send("#{attribute}=", "huhu") }.to raise_error(ArgumentError)
113
+ end
114
+ end
115
+ end
116
+
117
+ context "non-null positive integers" do
118
+ [:instance_build_timeout,
119
+ :instance_build_status_check_interval,
120
+ :instance_ssh_timeout,
121
+ :instance_ssh_check_interval].each do |attribute|
122
+ it "should cast #{attribute} to an int" do
123
+ expect { subject.send("#{attribute}=", "0") }.to raise_error(InvalidValue)
124
+ expect { subject.send("#{attribute}=", -1) }.to raise_error(InvalidValue)
125
+ end
126
+ end
127
+ end
84
128
  end
85
129
  end
@@ -14,9 +14,10 @@ Gem::Specification.new do |gem|
14
14
  gem.homepage = "http://www.vagrantup.com"
15
15
 
16
16
  gem.add_runtime_dependency "fog", "~> 1.22"
17
+ gem.add_runtime_dependency "promise", "~> 0.3.1"
17
18
 
18
19
  gem.add_development_dependency "rake", '< 11.0'
19
- gem.add_development_dependency "rspec", "~> 2.13.0"
20
+ gem.add_development_dependency "rspec", "~> 3.5.0"
20
21
 
21
22
  gem.files = `git ls-files`.split($/)
22
23
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-openstack-cloud-provider
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Mitchell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.22'
27
+ - !ruby/object:Gem::Dependency
28
+ name: promise
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 2.13.0
61
+ version: 3.5.0
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 2.13.0
68
+ version: 3.5.0
55
69
  description: Vagrant provider for OpenStack clouds.
56
70
  email:
57
71
  - mat128@gmail.com
@@ -85,10 +99,12 @@ files:
85
99
  - lib/vagrant-openstack-cloud-provider/errors.rb
86
100
  - lib/vagrant-openstack-cloud-provider/plugin.rb
87
101
  - lib/vagrant-openstack-cloud-provider/provider.rb
102
+ - lib/vagrant-openstack-cloud-provider/utils.rb
88
103
  - lib/vagrant-openstack-cloud-provider/version.rb
89
104
  - lib/vagrant-openstack.rb
90
105
  - locales/en.yml
91
106
  - spec/spec_helper.rb
107
+ - spec/vagrant-openstack-cloud-provider/action/connect_openstack_spec.rb
92
108
  - spec/vagrant-openstack-cloud-provider/action/create_server_spec.rb
93
109
  - spec/vagrant-openstack-cloud-provider/action/read_ssh_info_spec.rb
94
110
  - spec/vagrant-openstack-cloud-provider/config_spec.rb
@@ -119,6 +135,7 @@ specification_version: 4
119
135
  summary: Enables Vagrant to manage machines in OpenStack Cloud.
120
136
  test_files:
121
137
  - spec/spec_helper.rb
138
+ - spec/vagrant-openstack-cloud-provider/action/connect_openstack_spec.rb
122
139
  - spec/vagrant-openstack-cloud-provider/action/create_server_spec.rb
123
140
  - spec/vagrant-openstack-cloud-provider/action/read_ssh_info_spec.rb
124
141
  - spec/vagrant-openstack-cloud-provider/config_spec.rb