inprovise-fork 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 +15 -0
- data/.gitignore +4 -0
- data/.travis.yml +28 -0
- data/Gemfile +9 -0
- data/README.md +120 -0
- data/Rakefile.rb +9 -0
- data/inprovise-fork.gemspec +18 -0
- data/lib/inprovise/fork/fork.rb +72 -0
- data/lib/inprovise/fork/version.rb +10 -0
- data/lib/inprovise/fork.rb +10 -0
- data/test/fixtures/inprovise.rb +1 -0
- data/test/fork_test.rb +141 -0
- data/test/test_helper.rb +238 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZmQyNThhZmIwOTkzOGJiYzU2NDk1ZjRmZTEyODAzYzk4NTI3Y2E1Ng==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGU1MzRiNWM4MGE3NzhmZTMwMjJiMTM1NGJkZjI4YzU3NDMxMDg5Yg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZDc4MDJjYTAwNGY4ZGU5N2MwMzU2MjhjMDNmYWNiNDgzMmE5YTc4N2NiN2I1
|
10
|
+
N2NiOWE2YjFiMGMyZTBjYjQzN2FjYWI5YzExZTJjZDg3N2U2YTcwMTNlNTg0
|
11
|
+
MjY0MmMwYzI2ZjA1ZDc2OWQ0MTg1MWEzZDdiZjE4YTJlNDAzY2U=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZWFjMTdmNWE1YmNhZjQ5ZjU4ODRkZmI2MWIyZTYzMTg1MTdmMzg5ZjI5NTBm
|
14
|
+
MWIzZGNiNzg3YmQwMDgwNzIwNjAyNGFjMTU0MWI2ZGY4MTc5YjdkYzVjMWMx
|
15
|
+
MWRiMzdlOTVmY2JjMWJlYTAxYTJiMTZhOTk2ZDA1MDVhNzlhMzM=
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
before_install:
|
2
|
+
- gem install bundler
|
3
|
+
bundler_args: "--verbose"
|
4
|
+
script: rake test
|
5
|
+
rvm:
|
6
|
+
- 2.0.0
|
7
|
+
- 2.1
|
8
|
+
- 2.2
|
9
|
+
- 2.3.1
|
10
|
+
- ruby-head
|
11
|
+
gemfile:
|
12
|
+
- Gemfile
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
env: CODECLIMATE_REPO_TOKEN=3733be865016cababd969f8888810daf54fa824d10b126a2fec6123e8a21e2f5
|
17
|
+
bundle exec rake
|
18
|
+
addons:
|
19
|
+
code_climate:
|
20
|
+
repo_token: 3733be865016cababd969f8888810daf54fa824d10b126a2fec6123e8a21e2f5
|
21
|
+
deploy:
|
22
|
+
provider: rubygems
|
23
|
+
api_key:
|
24
|
+
secure: g5mnJR1siaBstvvifQVgJZRUcwLYLx5DeLimXMoRBJV2llBiZevSt6Heo4MgvWeNjvh6fRsp5NOhfXKDbLaxS6FLt+5buIMfYBFqJnFjzFoGf4PZj8Zd0XA3SGW82SGfFaHJepykGN7Jx9sOXwEBsbdEbssfiYqvm/uhpew7cAv5le9V3SVLqLsQnN5NwFkbgdHgrD2z1IkOhudkt2b9VZygg8Hj8WimLXq39+bc6eDz1xOV/q9N87r0lnZZqWI2HEL7MAA0pNkX3F8ca27BIe+VSQ9rNCYCmDrzHFpU3R+XjvjlVuv6i5lpQhRZBZCeOSI4/v69PQSosAovC5fIthW2h4XeS2XYHnYszeZKKwbfab8rjt9Mw6fWH3Y3FSMcvKAMNwuTpTYAVDvqLalfpzirryqT/a7Lwi2Hg2LqdoYuhoFrMP8q3vjB+LhxX+4tmTJI/2lt4LaR2HsKRSTZrgGWIr7re57onsSlZIcAXHdmIyXCuh5O9zHn2Bbv4XpAoyVUi7hDmR64oNncn3zTFGOyu6na2BnImoI/mQLm/BxnsQjeaYlV20MPA+Y5kXRhkIyaZzktjsQ+91JRp0JXzxl+cn1ozT1kVsGG8pFNJ0iXKRzy3/Xfcs0OAx6S0nCc7kVyUM2gV6BYvpADoQPm+Uquv7gC0zfjTWW08BBfERA=
|
25
|
+
gemspec: inprovise-fork.gemspec
|
26
|
+
on:
|
27
|
+
tags: true
|
28
|
+
repo: mcorino/Inprovise-Fork
|
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
|
2
|
+
Inprovise Fork
|
3
|
+
==============
|
4
|
+
|
5
|
+
This project implements an extension for the Inprovise provisioning tool providing a `fork` method to the execution contexts
|
6
|
+
of Inprovise scripts allowing scripts to fork off provisioning commands (`apply`, `revert`, `validate` or `trigger`) for
|
7
|
+
other nodes.
|
8
|
+
|
9
|
+
[](https://travis-ci.org/mcorino/Inprovise-Fork)
|
10
|
+
[](https://codeclimate.com/github/mcorino/Inprovise-Fork)
|
11
|
+
[](https://codeclimate.com/github/mcorino/Inprovise-Fork/coverage)
|
12
|
+
[](https://badge.fury.io/rb/inprovise-fork)
|
13
|
+
|
14
|
+
Installation
|
15
|
+
------------
|
16
|
+
|
17
|
+
$ gem install inprovise-fork
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
Add the following to (for example) your Inprovise project's `rigrc` file.
|
23
|
+
|
24
|
+
````ruby
|
25
|
+
require 'inprovise/fork'
|
26
|
+
````
|
27
|
+
|
28
|
+
Syntax
|
29
|
+
------
|
30
|
+
|
31
|
+
````ruby
|
32
|
+
fork(mode = :sync).apply('script', 'name'[, 'name'[, ...]][, config={}])
|
33
|
+
fork(mode = :sync).revert('script', 'name'[, 'name'[, ...]][, config={}])
|
34
|
+
fork(mode = :sync).validate('script', 'name'[, 'name'[, ...]][, config={}])
|
35
|
+
fork(mode = :sync).trigger('action', 'name'[, 'name'[, ...]][, config={}])
|
36
|
+
````
|
37
|
+
|
38
|
+
or
|
39
|
+
|
40
|
+
````ruby
|
41
|
+
fork(mode = :sync) do
|
42
|
+
apply('script', 'name'[, 'name'[, ...]][, config={}])
|
43
|
+
end
|
44
|
+
fork(mode = :sync) do
|
45
|
+
revert('script', 'name'[, 'name'[, ...]][, config={}])
|
46
|
+
end
|
47
|
+
fork(mode = :sync) do
|
48
|
+
validate('script', 'name'[, 'name'[, ...]][, config={}])
|
49
|
+
end
|
50
|
+
fork(mode = :sync) do
|
51
|
+
trigger('action', 'name'[, 'name'[, ...]][, config={}])
|
52
|
+
end
|
53
|
+
````
|
54
|
+
|
55
|
+
The `mode` argument can be `:sync` (default) or `:async`. With the first the provisioning methods will not return
|
56
|
+
until the provisioning process they kicked off has finished. With the latter the provisioning methods kick off the
|
57
|
+
provisioning process in parallel and return immediately.
|
58
|
+
|
59
|
+
The provisioning methods return a reference to the forking execution context allowing provisioning methods to be
|
60
|
+
chained like:
|
61
|
+
|
62
|
+
````ruby
|
63
|
+
fork.apply('script', 'node1').trigger('action', 'node1')
|
64
|
+
|
65
|
+
````
|
66
|
+
|
67
|
+
Example
|
68
|
+
-------
|
69
|
+
|
70
|
+
By combining the [Inprovise-VBox](https://github.com/mcorino/Inprovise-VBox) plugin and the [Inprovise-Fork](https://github.com/mcorino/Inprovise-Fork) plugin
|
71
|
+
provisioning scripts could add a virtual machine on a host server, register an Inprovise node and provision that new node with a single
|
72
|
+
`rig` command using a scheme like this:
|
73
|
+
|
74
|
+
````ruby
|
75
|
+
# assumes rigrc has been defined with
|
76
|
+
# require 'inprovise/vbox' and
|
77
|
+
# require 'inprovise/fork'
|
78
|
+
|
79
|
+
include 'rubysetup.rb' # includes a scheme defining scripts to control ruby provisioning dependencies
|
80
|
+
|
81
|
+
script 'vmSetup' do
|
82
|
+
|
83
|
+
validate do
|
84
|
+
# check node setup
|
85
|
+
trigger 'gem:exists', 'rails'
|
86
|
+
end
|
87
|
+
|
88
|
+
apply do
|
89
|
+
trigger 'gem:install', 'rails'
|
90
|
+
end
|
91
|
+
|
92
|
+
revert do
|
93
|
+
trigger 'gem:uninstall', 'rails'
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
vbox 'myVM' do
|
100
|
+
configuration ({
|
101
|
+
:name => 'MyVM',
|
102
|
+
:image => '/remote/image/path/MyVM.qcow2',
|
103
|
+
:memory => 1024,
|
104
|
+
:cpus => 2
|
105
|
+
})
|
106
|
+
|
107
|
+
apply do
|
108
|
+
fork(:async).apply('vmSetup', 'MyVM')
|
109
|
+
end
|
110
|
+
|
111
|
+
revert do
|
112
|
+
# in real life you may not want to do this to be able to reinstate
|
113
|
+
# the VM faster with all setup already in place
|
114
|
+
fork(:sync).revert('vmSetup', 'MyVM')
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
````
|
data/Rakefile.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib/inprovise/fork/version')
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Martin Corino"]
|
5
|
+
gem.email = ["mcorino@remedy.nl"]
|
6
|
+
gem.description = %q{Fork extension for Inprovise scripts}
|
7
|
+
gem.summary = %q{Simple, easy and intuitive virtual machine provisioning}
|
8
|
+
gem.homepage = ""
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "inprovise-fork"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = Inprovise::Fork::VERSION
|
16
|
+
gem.add_dependency('inprovise')
|
17
|
+
gem.post_install_message = ''
|
18
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Fork support for Inprovise scripts
|
2
|
+
#
|
3
|
+
# Author:: Martin Corino
|
4
|
+
# License:: Distributes under the same license as Ruby
|
5
|
+
|
6
|
+
module Inprovise::Fork
|
7
|
+
|
8
|
+
module ContextDSLExt
|
9
|
+
def fork(mode=:sync, &action)
|
10
|
+
fork = Inprovise::Fork::DSL.new(@context, mode)
|
11
|
+
fork.instance_eval(&action) if block_given?
|
12
|
+
fork
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Inprovise::ExecutionContext::DSL.send(:include, ContextDSLExt)
|
17
|
+
|
18
|
+
class DSL
|
19
|
+
|
20
|
+
def initialize(context, mode)
|
21
|
+
@context = context
|
22
|
+
@async = mode == :async
|
23
|
+
end
|
24
|
+
|
25
|
+
def verify_targets(*names)
|
26
|
+
if names.any? { |name| @context.node.name == name || Inprovise::Infrastructure.find(name).includes?(@context.node.name) }
|
27
|
+
raise ArgumentError, "Not allowed to fork for same node as running context : #{@context.node.name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
private :verify_targets
|
31
|
+
|
32
|
+
def run_command(cmd, script_or_action, *args)
|
33
|
+
config = Hash === args.last ? args.pop : {}
|
34
|
+
verify_targets(*args)
|
35
|
+
if @async
|
36
|
+
Inprovise::Controller.run_provisioning_command(cmd, script_or_action, config, *args)
|
37
|
+
else
|
38
|
+
ctrl = Inprovise::Controller.new
|
39
|
+
ctrl.run_provisioning_command(cmd, script_or_action, config, *args)
|
40
|
+
ctrl.wait
|
41
|
+
end
|
42
|
+
self
|
43
|
+
end
|
44
|
+
private :run_command
|
45
|
+
|
46
|
+
def config
|
47
|
+
@context.config
|
48
|
+
end
|
49
|
+
|
50
|
+
def method_missing(meth, *args)
|
51
|
+
@context.config.send(meth, *args)
|
52
|
+
end
|
53
|
+
|
54
|
+
def apply(script, *args)
|
55
|
+
run_command(:apply, script, *args)
|
56
|
+
end
|
57
|
+
|
58
|
+
def revert(script, *args)
|
59
|
+
run_command(:revert, script, *args)
|
60
|
+
end
|
61
|
+
|
62
|
+
def validate(script, *args)
|
63
|
+
run_command(:validate, script, *args)
|
64
|
+
end
|
65
|
+
|
66
|
+
def trigger(action, *args)
|
67
|
+
run_command(:trigger, action, *args)
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# default test scheme
|
data/test/fork_test.rb
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# Script tests for Inprovise::Fork
|
2
|
+
#
|
3
|
+
# Author:: Martin Corino
|
4
|
+
# License:: Distributes under the same license as Ruby
|
5
|
+
|
6
|
+
require_relative 'test_helper'
|
7
|
+
|
8
|
+
describe Inprovise::Fork do
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@node = Inprovise::Infrastructure::Node.new('myNode', {channel: 'test', helper: 'test'})
|
12
|
+
@node2 = Inprovise::Infrastructure::Node.new('myNode2', {channel: 'test', helper: 'test'})
|
13
|
+
@script = Inprovise::DSL.script('myScript') {}
|
14
|
+
end
|
15
|
+
|
16
|
+
after :each do
|
17
|
+
reset_script_index!
|
18
|
+
reset_infrastructure!
|
19
|
+
end
|
20
|
+
|
21
|
+
describe Inprovise::Fork::DSL do
|
22
|
+
|
23
|
+
describe 'fork' do
|
24
|
+
|
25
|
+
before :each do
|
26
|
+
@fork_dsl = Inprovise::Fork::DSL.new(nil, :sync)
|
27
|
+
@runner = Inprovise::ScriptRunner.new(@node, 'myScript')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'supports forking apply' do
|
31
|
+
@fork_dsl.expects(:run_command).with(:apply, 'anotherScript', 'myNode2')
|
32
|
+
@script.apply { fork.apply('anotherScript', 'myNode2') }
|
33
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
34
|
+
@runner.execute(:apply)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'supports forking revert' do
|
39
|
+
@fork_dsl.expects(:run_command).with(:revert, 'anotherScript', 'myNode2')
|
40
|
+
@script.revert { fork.revert('anotherScript', 'myNode2') }
|
41
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
42
|
+
@runner.execute(:revert)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'supports forking validate' do
|
47
|
+
@fork_dsl.expects(:run_command).with(:validate, 'anotherScript', 'myNode2')
|
48
|
+
@script.validate { fork.validate('anotherScript', 'myNode2'); true }
|
49
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
50
|
+
@runner.execute(:validate)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'supports forking trigger' do
|
55
|
+
@fork_dsl.expects(:run_command).with(:trigger, 'anotherScript:action[arg]', 'myNode2')
|
56
|
+
@script.apply { fork.trigger('anotherScript:action[arg]', 'myNode2') }
|
57
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
58
|
+
@runner.execute(:apply)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'executes a forked script' do
|
63
|
+
@script2 = Inprovise::DSL.script('anotherScript') { apply { config[:myMockup].do_something('test') } }
|
64
|
+
@script.apply { fork.apply('anotherScript', 'myNode2', {:myMockup => config[:myMockup]}) }
|
65
|
+
@mockObj = mock
|
66
|
+
@mockObj.expects(:do_something).with('test')
|
67
|
+
@runner.execute(:apply, {:myMockup => @mockObj})
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'fork block' do
|
73
|
+
|
74
|
+
before :each do
|
75
|
+
@fork_dsl = Inprovise::Fork::DSL.new(nil, :sync)
|
76
|
+
@runner = Inprovise::ScriptRunner.new(@node, 'myScript')
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'supports forking apply' do
|
80
|
+
@fork_dsl.expects(:run_command).with(:apply, 'anotherScript', 'myNode2')
|
81
|
+
@script.apply { fork { apply('anotherScript', 'myNode2') } }
|
82
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
83
|
+
@runner.execute(:apply)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'supports forking revert' do
|
88
|
+
@fork_dsl.expects(:run_command).with(:revert, 'anotherScript', 'myNode2')
|
89
|
+
@script.revert { fork { revert('anotherScript', 'myNode2') } }
|
90
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
91
|
+
@runner.execute(:revert)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'supports forking validate' do
|
96
|
+
@fork_dsl.expects(:run_command).with(:validate, 'anotherScript', 'myNode2')
|
97
|
+
@script.validate { fork { validate('anotherScript', 'myNode2') }; true }
|
98
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
99
|
+
@runner.execute(:validate)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'supports forking trigger' do
|
104
|
+
@fork_dsl.expects(:run_command).with(:trigger, 'anotherScript:action[arg]', 'myNode2')
|
105
|
+
@script.apply { fork { trigger('anotherScript:action[arg]', 'myNode2') } }
|
106
|
+
Inprovise::Fork::DSL.stub(:new, @fork_dsl) do
|
107
|
+
@runner.execute(:apply)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'executes a forked script' do
|
112
|
+
@script2 = Inprovise::DSL.script('anotherScript') { apply { config[:myMockup].do_something('test') } }
|
113
|
+
@script.apply { fork { apply('anotherScript', 'myNode2', {:myMockup => config[:myMockup]}) } }
|
114
|
+
@mockObj = mock
|
115
|
+
@mockObj.expects(:do_something).with('test')
|
116
|
+
@runner.execute(:apply, {:myMockup => @mockObj})
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'checks target' do
|
122
|
+
|
123
|
+
before :each do
|
124
|
+
@fork_dsl = Inprovise::Fork::DSL.new(nil, :sync)
|
125
|
+
@runner = Inprovise::ScriptRunner.new(@node, 'myScript')
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'does not allow fork for active node' do
|
129
|
+
@script2 = Inprovise::DSL.script('anotherScript') { apply { config[:myMockup].do_something('test') } }
|
130
|
+
@script.apply { fork.apply('anotherScript', 'myNode', {:myMockup => config[:myMockup]}) }
|
131
|
+
@mockObj = mock
|
132
|
+
assert_raises ArgumentError do
|
133
|
+
@runner.execute(:apply, {:myMockup => @mockObj})
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
# Test helper for Inprovise::Fork
|
2
|
+
#
|
3
|
+
# Author:: Martin Corino
|
4
|
+
# License:: Distributes under the same license as Ruby
|
5
|
+
require "codeclimate-test-reporter"
|
6
|
+
CodeClimate::TestReporter.start
|
7
|
+
|
8
|
+
gem 'minitest'
|
9
|
+
require 'minitest/autorun'
|
10
|
+
require 'mocha/setup'
|
11
|
+
gem 'inprovise'
|
12
|
+
require_relative '../lib/inprovise/fork'
|
13
|
+
|
14
|
+
# force root file
|
15
|
+
ENV['INPROVISE_INFRA'] = File.join(File.dirname(__FILE__), 'fixtures', Inprovise::INFRA_FILE)
|
16
|
+
|
17
|
+
def reset_script_index!
|
18
|
+
Inprovise::ScriptIndex.default.clear!
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset_infrastructure!
|
22
|
+
Inprovise::Infrastructure.reset
|
23
|
+
end
|
24
|
+
|
25
|
+
# patch Infrastructure#load and #save to do nothing
|
26
|
+
module Inprovise::Infrastructure
|
27
|
+
class << self
|
28
|
+
def load
|
29
|
+
# noop
|
30
|
+
end
|
31
|
+
def save
|
32
|
+
# noop
|
33
|
+
end
|
34
|
+
|
35
|
+
# add reset
|
36
|
+
def reset
|
37
|
+
targets.synchronize do
|
38
|
+
targets.clear
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# create mock test channel
|
45
|
+
|
46
|
+
Inprovise::CmdChannel.define('test') do
|
47
|
+
|
48
|
+
def initialize(node, user=nil)
|
49
|
+
@node = node
|
50
|
+
@user = user || node.user
|
51
|
+
end
|
52
|
+
|
53
|
+
# command execution
|
54
|
+
|
55
|
+
def run(command, forcelog=false)
|
56
|
+
@node.log.execute("RUN: #{command}") if Inprovise.verbosity > 0
|
57
|
+
"RUN: #{command}"
|
58
|
+
end
|
59
|
+
|
60
|
+
# file management
|
61
|
+
|
62
|
+
def upload(from, to)
|
63
|
+
@node.log.execute("UPLOAD: #{from} => #{to}") if Inprovise.verbosity > 0
|
64
|
+
end
|
65
|
+
|
66
|
+
def download(from, to)
|
67
|
+
@node.log.execute("DOWNLOAD: #{from} => #{to}") if Inprovise.verbosity > 0
|
68
|
+
end
|
69
|
+
|
70
|
+
def mkdir(path)
|
71
|
+
@node.log.execute("MKDIR: #{path}") if Inprovise.verbosity > 0
|
72
|
+
end
|
73
|
+
|
74
|
+
def exists?(path)
|
75
|
+
@node.log.execute("EXISTS?: #{path}") if Inprovise.verbosity > 0
|
76
|
+
true
|
77
|
+
end
|
78
|
+
|
79
|
+
def file?(path)
|
80
|
+
@node.log.execute("FILE?: #{path}") if Inprovise.verbosity > 0
|
81
|
+
true
|
82
|
+
end
|
83
|
+
|
84
|
+
def directory?(path)
|
85
|
+
@node.log.execute("DIRECTORY?: #{path}") if Inprovise.verbosity > 0
|
86
|
+
true
|
87
|
+
end
|
88
|
+
|
89
|
+
def content(path)
|
90
|
+
@node.log.execute("READ: #{path}") if Inprovise.verbosity > 0
|
91
|
+
"READ: #{path}"
|
92
|
+
end
|
93
|
+
|
94
|
+
def delete(path)
|
95
|
+
@node.log.execute("DELETE: #{path}") if Inprovise.verbosity > 0
|
96
|
+
end
|
97
|
+
|
98
|
+
def permissions(path)
|
99
|
+
@node.log.execute("PERMISSIONS: #{path}") if Inprovise.verbosity > 0
|
100
|
+
0
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_permissions(path, perm)
|
104
|
+
@node.log.execute("SETPERMISSIONS: #{path} #{perm}") if Inprovise.verbosity > 0
|
105
|
+
end
|
106
|
+
|
107
|
+
def owner(path)
|
108
|
+
@node.log.execute("OWNER: #{path}") if Inprovise.verbosity > 0
|
109
|
+
{:user => @user, :group => 'users'}
|
110
|
+
end
|
111
|
+
|
112
|
+
def set_owner(path, user, group=nil)
|
113
|
+
@node.log.execute("SET_OWNER: #{path} #{user} #{group}") if Inprovise.verbosity > 0
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
# create mock test helper
|
119
|
+
|
120
|
+
Inprovise::CmdHelper.define('test') do
|
121
|
+
|
122
|
+
def initialize(channel, sudo=false)
|
123
|
+
super(channel)
|
124
|
+
end
|
125
|
+
|
126
|
+
# platform properties
|
127
|
+
|
128
|
+
def admin_user
|
129
|
+
'root'
|
130
|
+
end
|
131
|
+
|
132
|
+
def env_reference(varname)
|
133
|
+
"\$#{varname}"
|
134
|
+
end
|
135
|
+
|
136
|
+
# generic command execution
|
137
|
+
|
138
|
+
def sudo
|
139
|
+
return self
|
140
|
+
end
|
141
|
+
|
142
|
+
# basic commands
|
143
|
+
|
144
|
+
def echo(arg)
|
145
|
+
run("echo #{arg}")
|
146
|
+
end
|
147
|
+
|
148
|
+
def cat(path)
|
149
|
+
begin
|
150
|
+
@channel.content(path)
|
151
|
+
rescue
|
152
|
+
run("cat #{path}")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def hash_for(path)
|
157
|
+
Digest::SHA1.hexdigest(run("sha1sum #{path}"))
|
158
|
+
end
|
159
|
+
|
160
|
+
def mkdir(path)
|
161
|
+
run("mkdir -p #{path}")
|
162
|
+
end
|
163
|
+
|
164
|
+
def exists?(path)
|
165
|
+
begin
|
166
|
+
@channel.exists?(path)
|
167
|
+
rescue
|
168
|
+
run(%{if [ -f #{path} ]; then echo "true"; else echo "false"; fi}).strip == 'true'
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def file?(path)
|
173
|
+
begin
|
174
|
+
@channel.file?(path)
|
175
|
+
rescue
|
176
|
+
(run("stat --format=%f #{path}").chomp.hex & 0x8000) == 0x8000
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def directory?(path)
|
181
|
+
begin
|
182
|
+
@channel.file?(path)
|
183
|
+
rescue
|
184
|
+
(run("stat --format=%f #{path}").chomp.hex & 0x4000) == 0x4000
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def copy(from, to)
|
189
|
+
run("cp #{from} #{to}")
|
190
|
+
end
|
191
|
+
|
192
|
+
def delete(path)
|
193
|
+
begin
|
194
|
+
@channel.delete(path)
|
195
|
+
rescue
|
196
|
+
run("rm #{path}")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def permissions(path)
|
201
|
+
begin
|
202
|
+
@channel.permissions(path)
|
203
|
+
rescue
|
204
|
+
run("stat --format=%a #{path}").strip.to_i(8)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def set_permissions(path, perm)
|
209
|
+
begin
|
210
|
+
@channel.set_permissions(path, perm)
|
211
|
+
rescue
|
212
|
+
run("chmod -R #{sprintf("%o",perm)} #{path}")
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
def owner(path)
|
217
|
+
begin
|
218
|
+
@channel.owner(path)
|
219
|
+
rescue
|
220
|
+
user, group = run("stat --format=%U:%G #{path}").chomp.split(":")
|
221
|
+
{:user => user, :group => group}
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def set_owner(path, user, group=nil)
|
226
|
+
begin
|
227
|
+
@channel.set_owner(path, user, group)
|
228
|
+
rescue
|
229
|
+
run(%{chown -R #{user}#{group ? ":#{group}" : ''} #{path}})
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
def binary_exists?(bin)
|
234
|
+
run("which #{bin}") =~ /\/#{bin}/
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inprovise-fork
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Martin Corino
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: inprovise
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Fork extension for Inprovise scripts
|
28
|
+
email:
|
29
|
+
- mcorino@remedy.nl
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- .gitignore
|
35
|
+
- .travis.yml
|
36
|
+
- Gemfile
|
37
|
+
- README.md
|
38
|
+
- Rakefile.rb
|
39
|
+
- inprovise-fork.gemspec
|
40
|
+
- lib/inprovise/fork.rb
|
41
|
+
- lib/inprovise/fork/fork.rb
|
42
|
+
- lib/inprovise/fork/version.rb
|
43
|
+
- test/fixtures/inprovise.rb
|
44
|
+
- test/fork_test.rb
|
45
|
+
- test/test_helper.rb
|
46
|
+
homepage: ''
|
47
|
+
licenses: []
|
48
|
+
metadata: {}
|
49
|
+
post_install_message: ''
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 2.4.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Simple, easy and intuitive virtual machine provisioning
|
69
|
+
test_files:
|
70
|
+
- test/fixtures/inprovise.rb
|
71
|
+
- test/fork_test.rb
|
72
|
+
- test/test_helper.rb
|