vagrant-libvirt 0.6.0 → 0.6.1

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
  SHA256:
3
- metadata.gz: 9e37a27120aef75fdd73d704321b96c7c881b07fa3cbdd655855300bf11163a3
4
- data.tar.gz: 4639827cc360b3f06304310f02dffea445f19d2f4b8675a6e0e05a9be3cea307
3
+ metadata.gz: d4e3e0061bb4ad5e0450c7707ce5e87d218b5c02420b9ba6d2f8c2f92760e247
4
+ data.tar.gz: ef229d196674e1e9771775eb917d3091b84853633356c1244a81be88f05d0a08
5
5
  SHA512:
6
- metadata.gz: cb13d39445a95f3514cc1be73bcf6e81ec7924959ec86e6cc712c50050ac8211f6b5beb26bbd42c137020e98143794d7b67aa7241e2461cdf2d1ca5ed2a15c30
7
- data.tar.gz: b341135cabad7d59963df62e9dd921470a43e4794fb203ff78b893bd058a38af877717f48b25a72135211e72d82082ec444227b97157e365903103240dfb1311
6
+ metadata.gz: 1067ed32c578df57810c451e95239c9e8d3e5dd8ef96719dd1cb835ff91e906357d391794ac9d0d300133c5b98bfe096b74f230d040f4a289275c28d459e933a
7
+ data.tar.gz: fcf09c0a02a054fbc10374361f69169c9a68434b4146473d7c3e150b813aa69e4172b9c5aad103124c2f3198f80f10a5ac0f59bd14d11458247851775dd5f2e9
@@ -1,5 +1,24 @@
1
1
  require 'log4r'
2
2
 
3
+ module VagrantPlugins
4
+ module ProviderLibvirt
5
+ module Action
6
+ # To wrap GracefulShutdown need to track the time taken
7
+ class StartShutdownTimer
8
+ def initialize(app, _env)
9
+ @app = app
10
+ end
11
+
12
+ def call(env)
13
+ env[:shutdown_start_time] = Time.now
14
+
15
+ @app.call(env)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
3
22
  module VagrantPlugins
4
23
  module ProviderLibvirt
5
24
  module Action
@@ -15,21 +34,22 @@ module VagrantPlugins
15
34
  def call(env)
16
35
  timeout = env[:machine].config.vm.graceful_halt_timeout
17
36
 
18
- start_time = Time.now
37
+ start_time = env[:shutdown_start_time]
19
38
 
20
- # call nested action first under the assumption it should try to
21
- # handle shutdown via client capabilities
22
- @app.call(env)
39
+ if start_time.nil?
40
+ # this really shouldn't happen
41
+ raise Errors::CallChainError, require_action: StartShutdownTimer.name, current_action: ShutdownDomain.name
42
+ end
23
43
 
24
44
  # return if successful, otherwise will ensure result is set to false
25
45
  env[:result] = env[:machine].state.id == @target_state
26
46
 
27
- return if env[:result]
47
+ return @app.call(env) if env[:result]
28
48
 
29
49
  current_time = Time.now
30
50
 
31
51
  # if we've already exceeded the timeout
32
- return if current_time - start_time >= timeout
52
+ return @app.call(env) if current_time - start_time >= timeout
33
53
 
34
54
  # otherwise construct a new timeout.
35
55
  timeout = timeout - (current_time - start_time)
@@ -42,6 +62,8 @@ module VagrantPlugins
42
62
  end
43
63
 
44
64
  env[:result] = env[:machine].state.id == @target_state
65
+
66
+ @app.call(env)
45
67
  end
46
68
  end
47
69
  end
@@ -143,19 +143,17 @@ module VagrantPlugins
143
143
  b2.use Call, IsRunning do |env2, b3|
144
144
  next unless env2[:result]
145
145
 
146
- b3.use Call, Message, "Attempting nice shutdowns..." do |_, b4|
147
- # ShutdownDomain will perform the domain shutdown on the out calls
148
- # so it runs after the remaining actions in the same action builder.
149
- b4.use ShutdownDomain, :shutoff, :running
150
- b4.use GracefulHalt, :shutoff, :running
146
+ b3.use StartShutdownTimer
147
+ b3.use Call, GracefulHalt, :shutoff, :running do |env3, b4|
148
+ if !env3[:result]
149
+ b4.use Call, ShutdownDomain, :shutoff, :running do |env4, b5|
150
+ if !env4[:result]
151
+ b5.use HaltDomain
152
+ end
153
+ end
154
+ end
151
155
  end
152
156
 
153
- # Only force halt if previous actions insufficient.
154
- b3.use Call, IsRunning do |env3, b4|
155
- next unless env3[:result]
156
-
157
- b4.use HaltDomain
158
- end
159
157
  end
160
158
  end
161
159
  end
@@ -360,6 +358,7 @@ module VagrantPlugins
360
358
  autoload :ForwardPorts, action_root.join('forward_ports')
361
359
  autoload :ClearForwardedPorts, action_root.join('forward_ports')
362
360
  autoload :HaltDomain, action_root.join('halt_domain')
361
+ autoload :StartShutdownTimer, action_root.join('shutdown_domain')
363
362
  autoload :ShutdownDomain, action_root.join('shutdown_domain')
364
363
  autoload :HandleBoxImage, action_root.join('handle_box_image')
365
364
  autoload :HandleStoragePool, action_root.join('handle_storage_pool')
@@ -9,6 +9,10 @@ module VagrantPlugins
9
9
  error_namespace('vagrant_libvirt.errors')
10
10
  end
11
11
 
12
+ class CallChainError < VagrantLibvirtError
13
+ error_key(:call_chain_error)
14
+ end
15
+
12
16
  # package not supported
13
17
  class PackageNotSupported < VagrantLibvirtError
14
18
  error_key(:package_not_supported)
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
data/locales/en.yml CHANGED
@@ -62,6 +62,7 @@ en:
62
62
  Forwarding UDP ports is not supported. Ignoring.
63
63
 
64
64
  errors:
65
+ call_chain_error: Invalid action chain, must ensure that '%{require_action}' is called prior to calling '%{current_action}'
65
66
  package_not_supported: No support for package with Libvirt. Create box manually.
66
67
  fog_error: |-
67
68
  There was an error talking to Libvirt. The error message is shown
@@ -3,6 +3,20 @@ require 'support/sharedcontext'
3
3
  require 'support/libvirt_context'
4
4
  require 'vagrant-libvirt/action/shutdown_domain'
5
5
 
6
+ describe VagrantPlugins::ProviderLibvirt::Action::StartShutdownTimer do
7
+ subject { described_class.new(app, env) }
8
+
9
+ include_context 'unit'
10
+
11
+ describe '#call' do
12
+ it 'should set shutdown_start_time' do
13
+ expect(env[:shutdown_start_time]).to eq(nil)
14
+ expect(subject.call(env)).to eq(nil)
15
+ expect(env[:shutdown_start_time]).to_not eq(nil)
16
+ end
17
+ end
18
+ end
19
+
6
20
  describe VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain do
7
21
  subject { described_class.new(app, env, target_state, current_state) }
8
22
 
@@ -26,6 +40,8 @@ describe VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain do
26
40
  allow(connection).to receive(:servers).and_return(servers)
27
41
  allow(servers).to receive(:get).and_return(domain)
28
42
  allow(ui).to receive(:info).with('Attempting direct shutdown of domain...')
43
+ allow(env).to receive(:[]).and_call_original
44
+ allow(env).to receive(:[]).with(:shutdown_start_time).and_return(Time.now)
29
45
  end
30
46
 
31
47
  context "when state is shutoff" do
@@ -97,7 +113,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain do
97
113
  context "when timeout exceeded" do
98
114
  before do
99
115
  expect(machine).to receive_message_chain('config.vm.graceful_halt_timeout').and_return(1)
100
- expect(app).to receive(:call) { sleep 1.5 }
116
+ expect(Time).to receive(:now).and_return(env[:shutdown_start_time] + 2)
101
117
  expect(driver).to receive(:state).and_return(:running).exactly(1).times
102
118
  expect(domain).to_not receive(:wait_for)
103
119
  expect(domain).to_not receive(:shutdown)
@@ -112,7 +128,7 @@ describe VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain do
112
128
  context "when timeout not exceeded" do
113
129
  before do
114
130
  expect(machine).to receive_message_chain('config.vm.graceful_halt_timeout').and_return(2)
115
- expect(app).to receive(:call) { sleep 1 }
131
+ expect(Time).to receive(:now).and_return(env[:shutdown_start_time] + 1.5)
116
132
  expect(driver).to receive(:state).and_return(:running).exactly(3).times
117
133
  expect(domain).to receive(:wait_for) do |time|
118
134
  expect(time).to be < 1
@@ -127,5 +143,18 @@ describe VagrantPlugins::ProviderLibvirt::Action::ShutdownDomain do
127
143
  end
128
144
  end
129
145
  end
146
+
147
+ context "when required action not run" do
148
+ before do
149
+ expect(env).to receive(:[]).with(:shutdown_start_time).and_call_original
150
+ end
151
+
152
+ it "should raise an exception" do
153
+ expect { subject.call(env) }.to raise_error(
154
+ VagrantPlugins::ProviderLibvirt::Errors::CallChainError,
155
+ /Invalid action chain, must ensure that '.*ShutdownTimer' is called prior to calling '.*ShutdownDomain'/
156
+ )
157
+ end
158
+ end
130
159
  end
131
160
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-libvirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Stanek
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2021-10-08 00:00:00.000000000 Z
14
+ date: 2021-10-11 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rspec-core
@@ -324,9 +324,9 @@ test_files:
324
324
  - spec/unit/action/start_domain_spec.rb
325
325
  - spec/unit/action/destroy_domain_spec.rb
326
326
  - spec/unit/action/halt_domain_spec.rb
327
- - spec/unit/action/shutdown_domain_spec.rb
328
327
  - spec/unit/action/create_domain_spec.rb
329
328
  - spec/unit/action/package_domain_spec.rb
329
+ - spec/unit/action/shutdown_domain_spec.rb
330
330
  - spec/unit/templates/tpm/version_1.2.xml
331
331
  - spec/unit/templates/tpm/version_2.0.xml
332
332
  - spec/unit/templates/domain_custom_cpu_model.xml