vagrant-notify 0.2.0 → 0.2.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
  SHA1:
3
- metadata.gz: a1074a71950090d90ae0b29f1a84c15ceb70ba2e
4
- data.tar.gz: 9da0d636fd6ebe6f8023ed14d2338574a90c5868
3
+ metadata.gz: 0d66b2dcc7b07f99723c453e8a8708720d3e3139
4
+ data.tar.gz: d58378442c0b7f1a2850589d146cd620133aa1c4
5
5
  SHA512:
6
- metadata.gz: 4aa952173645b5a6e165b180fbd4111c8e06dac056673813d3a658b09a4c19fb284e675233a414d605a92fe63b32aae2d7daec2c57e2ab5596e86b7ee8643723
7
- data.tar.gz: 7858e8b543ff5236af42f2c32c894bf3980814979fb94d5eb8c6d41329e9fe4410809a19961173fb5f6f37167a66f546bd8f82aea33af5b967ef56372d2d390c
6
+ metadata.gz: 90758ab9aec949ec3ccbe9b14a188da3b1f9555576e59ce7acc4730143578b8024cfca89ad9feb7d80a438b280b63de45b25e8b891c501af2477d6d72f1a69cf
7
+ data.tar.gz: 6659609a5349738fd444e5f4fa4c0a65370f8b39bd786527c8f1aa9d4511551b58cf203716614df7c6a2ba0671a559624e01e2043057c5e2f1db8313864b374b
data/Gemfile.lock CHANGED
@@ -14,7 +14,7 @@ GIT
14
14
  PATH
15
15
  remote: .
16
16
  specs:
17
- vagrant-notify (0.2.0)
17
+ vagrant-notify (0.2.1)
18
18
 
19
19
  GEM
20
20
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -27,8 +27,12 @@ command.
27
27
  If by any chance your IP changes, you can run `vagrant provision` in order to
28
28
  update the guest script with the new IP.
29
29
 
30
- As of now, the plugin is not supported on multi vm environments, it used to be
31
- for the Vagrant < 1.1 version and I'm planning to fix that as soon as I have a chance.
30
+ ## Known issues
31
+
32
+ * Does not work properly on multi vm environments, it used to work on a Vagrant
33
+ < 1.1 version and I'm planning to fix that as soon as I have a chance.
34
+
35
+ * vagrant's `suspend` does not stop the notification server
32
36
 
33
37
 
34
38
  ## Contributing
@@ -4,13 +4,14 @@ module Vagrant
4
4
  name 'vagrant notify'
5
5
  description 'Forwards notify-send from guest to host machine'
6
6
 
7
+ # TODO: This should be generic, we don't want to hard code every single
8
+ # possible provider action class that Vagrant might have
7
9
  action_hook 'start-server-after-boot' do |hook|
8
10
  require_relative './action'
9
- # TODO: This should be generic
10
11
  hook.after VagrantPlugins::ProviderVirtualBox::Action::Boot, Vagrant::Notify::Action.action_start_server
11
12
 
12
13
  if defined?(Vagrant::LXC)
13
- # TODO: Require just the boot file once its "require dependencies" are sorted out
14
+ # TODO: Require just the boot action file once its "require dependencies" are sorted out
14
15
  require 'vagrant-lxc/action'
15
16
  hook.after Vagrant::LXC::Action::Boot, Vagrant::Notify::Action.action_start_server
16
17
  end
@@ -20,10 +21,23 @@ module Vagrant
20
21
  hook.after Vagrant::Action::Builtin::Provision, Vagrant::Notify::Action.action_start_server
21
22
  end
22
23
 
23
- action_hook 'stop-server-after-halting' do |hook|
24
+ action_hook 'stop-server-after-halting', :machine_action_halt do |hook|
24
25
  require_relative './action'
25
26
  hook.after Vagrant::Action::Builtin::GracefulHalt, Vagrant::Notify::Action.action_stop_server
26
27
  end
28
+
29
+ # TODO: This should be generic, we don't want to hard code every single
30
+ # possible provider action class that Vagrant might have
31
+ action_hook 'stop-server-before-destruction', :machine_action_destroy do |hook|
32
+ require_relative './action'
33
+ hook.before VagrantPlugins::ProviderVirtualBox::Action::Destroy, Vagrant::Notify::Action.action_stop_server
34
+
35
+ if defined?(Vagrant::LXC)
36
+ # TODO: Require just the destroy action file once its "require dependencies" are sorted out
37
+ require 'vagrant-lxc/action'
38
+ hook.before Vagrant::LXC::Action::Destroy, Vagrant::Notify::Action.action_stop_server
39
+ end
40
+ end
27
41
  end
28
42
  end
29
43
  end
@@ -68,12 +68,9 @@ module Vagrant
68
68
  end
69
69
 
70
70
  def communicator
71
- @communicator ||=
72
- begin
73
- env = Vagrant::Environment.new
74
- machine = env.machine(@machine_name, @provider)
75
- machine.communicate
76
- end
71
+ env = Vagrant::Environment.new
72
+ machine = env.machine(@machine_name, @provider)
73
+ machine.communicate
77
74
  end
78
75
  end
79
76
  end
@@ -1,5 +1,5 @@
1
1
  module Vagrant
2
2
  module Notify
3
- VERSION = "0.2.0"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-notify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabio Rehm
@@ -27,13 +27,6 @@ files:
27
27
  - LICENSE.txt
28
28
  - README.md
29
29
  - Rakefile
30
- - burn/middleware/install_command.rb
31
- - burn/middleware/start_server.rb
32
- - burn/middleware/stop_server.rb
33
- - burn/old_stack.rb
34
- - burn/spec/middleware/install_command_spec.rb
35
- - burn/spec/middleware/start_server_spec.rb
36
- - burn/spec/middleware/stop_server_spec.rb
37
30
  - files/notify-send.erb
38
31
  - lib/vagrant-notify.rb
39
32
  - lib/vagrant-notify/action.rb
@@ -1,45 +0,0 @@
1
- module Vagrant
2
- module Notify
3
- module Middleware
4
- class InstallCommand
5
- def initialize(app, env)
6
- @app = app
7
- @command_template_file = Vagrant::Notify.files_path + '/notify-send.erb'
8
- end
9
-
10
- def call(env)
11
- env[:ui].info('Compiling and installing notify-send script on guest machine')
12
- path = compile_command(env)
13
- install_command_on_guest(env, path)
14
- @app.call(env)
15
- end
16
-
17
- def host_ip(env)
18
- ip = nil
19
- env[:vm].channel.execute('echo -n $SSH_CLIENT | cut -d" " -f1') do |buffer, data|
20
- ip = data.chomp if buffer == :stdout
21
- end
22
- ip
23
- end
24
-
25
- private
26
-
27
- def compile_command(env)
28
- uuid = env[:vm].uuid.to_s
29
- local_data = env[:vm].env.local_data
30
- host_port = local_data['vagrant-notify'][uuid]['port']
31
- template_binding = OpenStruct.new(:host_ip => host_ip(env), :host_port => host_port)
32
- command = ERB.new(File.read(@command_template_file)).result(template_binding.instance_eval { binding })
33
- File.open(env[:vm].env.tmp_path + 'vagrant-notify-send', 'w') { |f| f.write(command) }
34
- end
35
-
36
- def install_command_on_guest(env, command_path)
37
- # DISCUSS: Should we back up the original command if present?
38
- source = env[:vm].env.tmp_path + 'vagrant-notify-send'
39
- env[:vm].channel.upload(source.to_s, '/tmp/notify-send')
40
- env[:vm].channel.sudo('mv /tmp/notify-send /usr/bin/notify-send && chmod +x /usr/bin/notify-send')
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,78 +0,0 @@
1
- module Vagrant
2
- module Notify
3
- module Middleware
4
- class StartServer
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- @env = env
11
- if pid = server_is_running?
12
- env[:ui].info "Notification server is already running (#{pid})"
13
- else
14
- port, pid = run_server
15
- env[:ui].info "Notification server is listening on #{port} (#{pid})"
16
- end
17
-
18
- @app.call(env)
19
- end
20
-
21
- private
22
-
23
- def run_server
24
- port = next_available_port
25
- uuid = @env[:vm].uuid.to_s
26
- pid = Server.run(@env, port)
27
-
28
- local_data = @env[:vm].env.local_data
29
- config = local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
30
- config.merge!(uuid => {'pid' => pid, 'port' => port })
31
- local_data.commit
32
-
33
- [port, pid]
34
- end
35
-
36
- def next_available_port
37
- range = @env[:vm].config.vm.auto_port_range.to_a
38
- range -= @env[:vm].config.vm.forwarded_ports.collect { |opts| opts[:hostport].to_i }
39
- range -= used_ports
40
-
41
- if range.empty?
42
- raise 'Unable to find a port to bind the notification server to'
43
- end
44
-
45
- # Set the port up to be the last one since vagrant's port collision handler
46
- # will use the first as in:
47
- # https://github.com/mitchellh/vagrant/blob/1-0-stable/lib/vagrant/action/vm/check_port_collisions.rb#L51
48
- port = range.pop
49
- end
50
-
51
- def used_ports
52
- local_data = @env[:vm].env.local_data
53
- local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
54
- local_data['vagrant-notify'].values.map do |settings|
55
- settings['port'].to_i if settings['port']
56
- end.compact
57
- end
58
-
59
- # REFACTOR: This is duplicated on Middleware::StopServer
60
- def server_is_running?
61
- uuid = @env[:vm].uuid.to_s
62
- begin
63
- pid = @env[:vm].env.local_data.
64
- fetch('vagrant-notify', {}).
65
- fetch(uuid, {}).
66
- fetch('pid', nil)
67
- return false unless pid
68
-
69
- Process.getpgid(pid)
70
- pid
71
- rescue Errno::ESRCH
72
- false
73
- end
74
- end
75
- end
76
- end
77
- end
78
- end
@@ -1,54 +0,0 @@
1
- module Vagrant
2
- module Notify
3
- module Middleware
4
- class StopServer
5
- def initialize(app, env)
6
- @app = app
7
- end
8
-
9
- def call(env)
10
- # TODO: Need to handle multi VMs setup
11
-
12
- if pid = server_is_running?(env)
13
- env[:ui].info('Stopping notification server...')
14
- stop_server(pid)
15
- cleanup_local_data(env)
16
- end
17
-
18
- @app.call(env)
19
- end
20
-
21
- private
22
-
23
- def stop_server(pid)
24
- Process.kill('KILL', pid.to_i) rescue nil
25
- end
26
-
27
- def cleanup_local_data(env)
28
- uuid = env[:vm].uuid.to_s
29
- local_data = env[:vm].env.local_data
30
- local_data['vagrant-notify'] ||= Vagrant::Util::HashWithIndifferentAccess.new
31
- local_data['vagrant-notify'].delete(uuid)
32
- local_data.commit
33
- end
34
-
35
- # REFACTOR: This is duplicated on Middleware::StartServer
36
- def server_is_running?(env)
37
- uuid = env[:vm].uuid.to_s
38
- begin
39
- pid = env[:vm].env.local_data.
40
- fetch('vagrant-notify', {}).
41
- fetch(uuid, {}).
42
- fetch('pid', nil)
43
- return false unless pid
44
-
45
- Process.getpgid(pid.to_i)
46
- pid
47
- rescue Errno::ESRCH
48
- false
49
- end
50
- end
51
- end
52
- end
53
- end
54
- end
data/burn/old_stack.rb DELETED
@@ -1,11 +0,0 @@
1
- Vagrant.actions[:start].tap do |start|
2
- start.insert_after Vagrant::Action::VM::Boot, Vagrant::Notify::Middleware::StartServer
3
- start.insert_after Vagrant::Notify::Middleware::StartServer, Vagrant::Notify::Middleware::InstallCommand
4
- end
5
- Vagrant.actions[:resume].tap do |start|
6
- start.use Vagrant::Notify::Middleware::StartServer
7
- start.use Vagrant::Notify::Middleware::InstallCommand
8
- end
9
- Vagrant.actions[:halt].use Vagrant::Notify::Middleware::StopServer
10
- Vagrant.actions[:suspend].use Vagrant::Notify::Middleware::StopServer
11
- Vagrant.actions[:provision].use Vagrant::Notify::Middleware::InstallCommand
@@ -1,68 +0,0 @@
1
- describe Vagrant::Notify::Middleware::InstallCommand do
2
- let(:start_stack) { Vagrant.actions[:start].send(:stack) }
3
- let(:provision_stack) { Vagrant.actions[:provision].send(:stack) }
4
- let(:resume_stack) { Vagrant.actions[:resume].send(:stack) }
5
- let(:host_ip) { 'host-ip' }
6
- let(:host_port) { 789 }
7
- let(:template) { ERB.new('<%= host_ip %> <%= host_port %>') }
8
- let(:compiled_command_path) { @env[:vm].env.tmp_path + 'vagrant-notify-send' }
9
- let(:target_tmp_path) { '/tmp/notify-send' }
10
- let(:target_path) { '/usr/bin/notify-send' }
11
- let(:channel) { mock(:channel, :sudo => true, :upload => true, :execute => true) }
12
- let(:get_ip_command) { 'echo -n $SSH_CLIENT | cut -d" " -f1' }
13
- let(:uuid) { @env[:vm].uuid.to_s }
14
- let(:local_data) { Hash.new }
15
-
16
- subject { described_class.new(@app, @env) }
17
-
18
- before do
19
- @app, @env = action_env(vagrant_env.vms.values.first.env)
20
- @env[:vm].stub(:channel => channel)
21
- @env[:vm].env.stub(:local_data => local_data)
22
- local_data['vagrant-notify'] = { uuid => {'port' => host_port } }
23
- ERB.stub(:new => template)
24
- end
25
-
26
- it 'gets called after boot middleware when starting machine' do
27
- boot_index = start_stack.index([Vagrant::Action::VM::Boot, [], nil])
28
- middleware_index = start_stack.index([described_class, [], nil])
29
-
30
- boot_index.should < middleware_index
31
- end
32
-
33
- it 'gets called when resuming machine' do
34
- resume_stack.should include([described_class, [], nil])
35
- end
36
-
37
- it 'gets called when provisioning machine' do
38
- provision_stack.should include([described_class, [], nil])
39
- end
40
-
41
- it "is able to identify host's ip" do
42
- channel.should_receive(:execute).with(get_ip_command).and_yield(:stdout, host_ip + "\n")
43
- subject.host_ip(@env).should == host_ip
44
- end
45
-
46
- it 'compiles command script passing host ip and server port' do
47
- subject.stub(:host_ip => host_ip)
48
- subject.call(@env)
49
- File.read(compiled_command_path).should == "#{host_ip} #{host_port}"
50
- end
51
-
52
- it 'uploads compiled command script over to guest machine' do
53
- channel.should_receive(:upload).with(compiled_command_path.to_s, target_tmp_path)
54
- subject.stub(:host_ip => host_ip)
55
- subject.call(@env)
56
- end
57
-
58
- it 'installs command for all users' do
59
- channel.should_receive(:sudo).with("mv #{target_tmp_path} #{target_path} && chmod +x #{target_path}")
60
- subject.stub(:host_ip => host_ip)
61
- subject.call(@env)
62
- end
63
-
64
- it 'notifies user about script installation' do
65
- @env[:ui].should_receive(:info).with('Compiling and installing notify-send script on guest machine')
66
- subject.call(@env)
67
- end
68
- end
@@ -1,85 +0,0 @@
1
- describe Vagrant::Notify::Middleware::StartServer do
2
- let(:start_stack) { Vagrant.actions[:start].send(:stack) }
3
- let(:resume_stack) { Vagrant.actions[:resume].send(:stack) }
4
- let(:server_pid) { 1234 }
5
- let(:available_port) { 8080 }
6
- let(:uuid) { @env[:vm].uuid.to_s }
7
- let(:local_data) { Hash.new }
8
-
9
- subject { described_class.new(@app, @env) }
10
-
11
- before do
12
- @app, @env = action_env(vagrant_env.vms.values.first.env)
13
- @env[:vm].env.stub(:local_data => local_data)
14
- local_data.stub(:commit)
15
- Vagrant::Notify::Server.stub(:run => server_pid)
16
- end
17
-
18
- it 'gets called when starting machine' do
19
- start_stack.should include([described_class, [], nil])
20
- end
21
-
22
- it 'gets called when resuming machine' do
23
- resume_stack.should include([described_class, [], nil])
24
- end
25
-
26
- context 'server is down' do
27
- before do
28
- Process.stub(:getpgid).and_raise(Errno::ESRCH)
29
- subject.stub(:next_available_port => available_port)
30
- end
31
-
32
- it 'fires up notification server when called' do
33
- Vagrant::Notify::Server.should_receive(:run).with(@env, available_port)
34
- subject.call(@env)
35
- end
36
-
37
- it 'notifies user about server start' do
38
- @env[:ui].should_receive(:info).with("Notification server is listening on #{available_port} (#{server_pid})")
39
- subject.call(@env)
40
- end
41
-
42
- it "persists server PID on local data" do
43
- local_data.should_receive(:commit)
44
- subject.call(@env)
45
- local_data['vagrant-notify'][uuid]['pid'].should == server_pid
46
- end
47
-
48
- it "persists server port on local data" do
49
- local_data.should_receive(:commit)
50
- subject.call(@env)
51
- local_data['vagrant-notify'][uuid]['port'].should == available_port
52
- end
53
-
54
- context "and a PID is present on Vagrant's local data" do
55
- let(:new_pid) { server_pid + 1 }
56
-
57
- before do
58
- Vagrant::Notify::Server.stub(:run => new_pid)
59
- local_data['vagrant-notify'] = { uuid => { 'pid' => server_pid } }
60
- end
61
-
62
- it 'updates server PID' do
63
- subject.call(@env)
64
- local_data['vagrant-notify'][uuid]['pid'].should == new_pid
65
- end
66
- end
67
- end
68
-
69
- context 'server is up' do
70
- before do
71
- Process.stub(:getpgid => true)
72
- local_data['vagrant-notify'] = { uuid => { 'pid' => server_pid } }
73
- end
74
-
75
- it 'does not start a new server instance' do
76
- Vagrant::Notify::Server.should_not_receive(:run)
77
- subject.call(@env)
78
- end
79
-
80
- it 'notifies user that server is already running' do
81
- @env[:ui].should_receive(:info).with("Notification server is already running (#{server_pid})")
82
- subject.call(@env)
83
- end
84
- end
85
- end
@@ -1,55 +0,0 @@
1
- describe Vagrant::Notify::Middleware::StopServer do
2
- let(:halt_stack) { Vagrant.actions[:halt].send(:stack) }
3
- let(:suspend_stack) { Vagrant.actions[:halt].send(:stack) }
4
- let(:server_pid) { '1234' }
5
- let(:uuid) { @env[:vm].uuid.to_s }
6
- let(:local_data) { { 'vagrant-notify' => { uuid => { 'pid' => server_pid } } } }
7
-
8
- subject { described_class.new(@app, @env) }
9
-
10
- before do
11
- @app, @env = action_env(vagrant_env.vms.values.first.env)
12
- @env[:vm].env.stub(:local_data => local_data)
13
- local_data.stub(:commit)
14
- end
15
-
16
- it 'gets called when halting machine' do
17
- halt_stack.should include([described_class, [], nil])
18
- end
19
-
20
- it 'gets called when suspending machine' do
21
- suspend_stack.should include([described_class, [], nil])
22
- end
23
-
24
- context 'server is down' do
25
- before { Process.stub(:getpgid).and_raise(Errno::ESRCH) }
26
-
27
- it 'does not notify user about server stop' do
28
- @env[:ui].should_not_receive(:info)
29
- subject.call(@env)
30
- end
31
- end
32
-
33
- context 'server is up' do
34
- before do
35
- Process.stub(:getpgid => true)
36
- local_data['vagrant-notify'] = { uuid => { 'pid' => server_pid } }
37
- end
38
-
39
- it 'notifies user that server is stopping' do
40
- @env[:ui].should_receive(:info).with('Stopping notification server...')
41
- subject.call(@env)
42
- end
43
-
44
- it 'kills notification server' do
45
- Process.should_receive(:kill).with('KILL', server_pid.to_i)
46
- subject.call(@env)
47
- end
48
-
49
- it "removes server PID on local data" do
50
- local_data.should_receive(:commit)
51
- subject.call(@env)
52
- local_data['vagrant-notify']['pid'].should be_nil
53
- end
54
- end
55
- end