rivet 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/bin/rivet +6 -1
- data/lib/rivet/client.rb +10 -3
- data/lib/rivet/utils.rb +7 -16
- data/lib/rivet/version.rb +1 -1
- data/spec/rivet_bootstrap_spec.rb +9 -17
- data/spec/rivet_util_spec.rb +16 -30
- metadata +1 -1
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
Rivet CHANGELOG
|
2
2
|
===
|
3
3
|
|
4
|
+
1.1.0 - Released 11/12/13
|
5
|
+
---
|
6
|
+
* Rivet no allows you to specify a directory with the -d [--definitions-directory] option
|
7
|
+
* Rivet no longer creates the autoscale directory if it does not exist
|
8
|
+
|
4
9
|
1.0.8 - Released 11/12/13
|
5
10
|
---
|
6
11
|
* Fixes the unit tests which were incorrect.
|
data/bin/rivet
CHANGED
@@ -12,7 +12,8 @@ INFO = Logger::INFO
|
|
12
12
|
# Default option values
|
13
13
|
options = {
|
14
14
|
:log_level => INFO,
|
15
|
-
:profile => 'default'
|
15
|
+
:profile => 'default',
|
16
|
+
:definitions_directory => './autoscale'
|
16
17
|
}
|
17
18
|
|
18
19
|
OptionParser.new do |o|
|
@@ -33,6 +34,10 @@ OptionParser.new do |o|
|
|
33
34
|
options[:sync] = s
|
34
35
|
end
|
35
36
|
|
37
|
+
o.on('-d', '--definitions-directory [PATH]', "The autoscale definitions directory to use (default is ./autoscale)") do |d|
|
38
|
+
options[:definitions_directory] = d
|
39
|
+
end
|
40
|
+
|
36
41
|
o.on('-h') { puts o; exit }
|
37
42
|
o.parse!
|
38
43
|
end
|
data/lib/rivet/client.rb
CHANGED
@@ -6,11 +6,18 @@ module Rivet
|
|
6
6
|
def run(options)
|
7
7
|
AwsUtils.set_aws_credentials(options[:profile])
|
8
8
|
Rivet::Log.level(options[:log_level])
|
9
|
-
Rivet::Utils.ensure_minimum_setup
|
10
9
|
|
11
|
-
|
10
|
+
unless Dir.exists?(options[:definitions_directory])
|
11
|
+
Rivet::Utils.die("The autoscale definitions directory doesn't exist")
|
12
|
+
end
|
13
|
+
|
14
|
+
group_def = Rivet::Utils.get_definition(
|
15
|
+
options[:group],
|
16
|
+
options[:definitions_directory])
|
12
17
|
|
13
|
-
|
18
|
+
unless group_def
|
19
|
+
Rivet::Utils.die "The #{options[:group]} definition doesn't exist"
|
20
|
+
end
|
14
21
|
|
15
22
|
Rivet::Log.info("Checking #{options[:group]} autoscaling definition")
|
16
23
|
autoscale_def = Rivet::Autoscale.new(options[:group],group_def)
|
data/lib/rivet/utils.rb
CHANGED
@@ -1,26 +1,17 @@
|
|
1
1
|
module Rivet
|
2
2
|
module Utils
|
3
|
-
AUTOSCALE_DIR = "autoscale"
|
4
3
|
|
5
4
|
def self.die(level = 'fatal',message)
|
6
5
|
Rivet::Log.write(level,message)
|
7
6
|
exit
|
8
7
|
end
|
9
8
|
|
10
|
-
def self.ensure_minimum_setup
|
11
|
-
if Dir.exists?(AUTOSCALE_DIR)
|
12
|
-
true
|
13
|
-
else
|
14
|
-
Rivet::Log.info("Creating #{AUTOSCALE_DIR}")
|
15
|
-
Dir.mkdir(AUTOSCALE_DIR)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
9
|
# This returns the merged definition given a group
|
20
10
|
|
21
|
-
def self.get_definition(group)
|
22
|
-
defaults = consume_defaults
|
23
|
-
group_def = load_definition(group)
|
11
|
+
def self.get_definition(group,directory)
|
12
|
+
defaults = consume_defaults(directory)
|
13
|
+
group_def = load_definition(group,directory)
|
14
|
+
|
24
15
|
if defaults && group_def
|
25
16
|
group_def = defaults.deep_merge(group_def)
|
26
17
|
end
|
@@ -29,7 +20,7 @@ module Rivet
|
|
29
20
|
|
30
21
|
# Gobbles up the defaults file from YML, returns the hash or false if empty
|
31
22
|
|
32
|
-
def self.consume_defaults(autoscale_dir
|
23
|
+
def self.consume_defaults(autoscale_dir)
|
33
24
|
defaults_file = File.join(autoscale_dir,"defaults.yml")
|
34
25
|
if File.exists?(defaults_file)
|
35
26
|
parsed = begin
|
@@ -47,8 +38,8 @@ module Rivet
|
|
47
38
|
# This loads the given definition from it's YML file, returns the hash or
|
48
39
|
# false if empty
|
49
40
|
|
50
|
-
def self.load_definition(name)
|
51
|
-
definition_dir = File.join(
|
41
|
+
def self.load_definition(name,directory)
|
42
|
+
definition_dir = File.join(directory,name)
|
52
43
|
conf_file = File.join(definition_dir,"conf.yml")
|
53
44
|
if Dir.exists?(definition_dir) && File.exists?(conf_file)
|
54
45
|
Rivet::Log.debug("Loading definition for #{name} from #{conf_file}")
|
data/lib/rivet/version.rb
CHANGED
@@ -8,33 +8,33 @@ describe 'rivet bootstrap' do
|
|
8
8
|
|
9
9
|
tempdir_context 'with all necessary files in place' do
|
10
10
|
before do
|
11
|
-
|
11
|
+
FileUtils.mkdir_p(bootstrap_def['config_dir'])
|
12
12
|
|
13
13
|
validator_file = File.join(
|
14
14
|
bootstrap_def['config_dir'],
|
15
15
|
"#{bootstrap_def['environment']}-validator.pem")
|
16
16
|
|
17
|
+
FileUtils.touch(validator_file)
|
18
|
+
|
17
19
|
template_dir = File.join(
|
18
20
|
bootstrap_def['config_dir'],
|
19
21
|
Rivet::Bootstrap::TEMPLATE_SUB_DIR)
|
20
22
|
|
21
|
-
template_file = File.join(template_dir,bootstrap_def['template'])
|
22
|
-
|
23
|
-
FileUtils.mkdir_p(bootstrap_def['config_dir'])
|
24
23
|
FileUtils.mkdir_p(template_dir)
|
24
|
+
|
25
|
+
template_file = File.join(template_dir,bootstrap_def['template'])
|
25
26
|
File.open(template_file,'w') { |f| f.write(SpecHelpers::BOOTSTRAP_TEMPLATE) }
|
26
|
-
FileUtils.touch(validator_file)
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "#user_data" do
|
30
30
|
it 'returns a string that contains the chef organization' do
|
31
31
|
org = bootstrap_def['organization']
|
32
|
-
bootstrap.user_data.should =~ /chef_server_url\s
|
32
|
+
bootstrap.user_data.should =~ /chef_server_url\s+.*#{org}.*/
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'returns a string that contains the environment' do
|
36
36
|
env = bootstrap_def['env']
|
37
|
-
bootstrap.user_data.should =~ /environment\s
|
37
|
+
bootstrap.user_data.should =~ /environment\s+.*#{env}.*/
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'returns a string that contains the run_list as json' do
|
@@ -45,9 +45,9 @@ describe 'rivet bootstrap' do
|
|
45
45
|
it 'returns a string that contains each gem to install' do
|
46
46
|
bootstrap_def['gems'].each do |g|
|
47
47
|
if g.size > 1
|
48
|
-
gem_regexp = /gem\s
|
48
|
+
gem_regexp = /gem\s+install\s+#{g[0]}.+#{g[1]}/
|
49
49
|
else
|
50
|
-
gem_regexp = /gem\s
|
50
|
+
gem_regexp = /gem\s+install\s+#{g[0]}/
|
51
51
|
end
|
52
52
|
bootstrap.user_data.should =~ gem_regexp
|
53
53
|
end
|
@@ -59,11 +59,3 @@ describe 'rivet bootstrap' do
|
|
59
59
|
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
data/spec/rivet_util_spec.rb
CHANGED
@@ -2,9 +2,10 @@ require_relative './rivet_spec_setup'
|
|
2
2
|
|
3
3
|
include SpecHelpers
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
AUTOSCALE_DIR = "."
|
6
|
+
DEFINITION_NAME = "unit_test"
|
7
|
+
DEFINITION_DIR = File.join(AUTOSCALE_DIR,DEFINITION_NAME)
|
8
|
+
LAUNCH_CONFIG_PARAMS = ['ssh_key','instance_size','security_groups','ami','bootstrap']
|
8
9
|
|
9
10
|
defaults_hash = {
|
10
11
|
'min_size' => 0,
|
@@ -29,85 +30,70 @@ unit_test_definition_hash = {
|
|
29
30
|
}
|
30
31
|
|
31
32
|
describe "rivet utils" do
|
32
|
-
tempdir_context "without an autoscaling directory" do
|
33
|
-
describe "ensure_minimum_setup" do
|
34
|
-
it "creates the autoscale directory if it doesn't exist" do
|
35
|
-
Rivet::Utils.ensure_minimum_setup
|
36
|
-
Dir.exists?(Rivet::Utils::AUTOSCALE_DIR).should be_true
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
33
|
tempdir_context "with an autoscaling directory" do
|
42
34
|
before do
|
43
|
-
FileUtils.mkdir_p(
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "ensure_minimum_setup" do
|
47
|
-
it "should return true" do
|
48
|
-
Rivet::Utils.ensure_minimum_setup.should be_true
|
49
|
-
end
|
35
|
+
FileUtils.mkdir_p(AUTOSCALE_DIR)
|
50
36
|
end
|
51
37
|
|
52
38
|
describe "consume_defaults" do
|
53
39
|
it "should return false" do
|
54
|
-
Rivet::Utils.consume_defaults.should be_false
|
40
|
+
Rivet::Utils.consume_defaults(AUTOSCALE_DIR).should be_false
|
55
41
|
end
|
56
42
|
end
|
57
43
|
|
58
44
|
describe "load_definition" do
|
59
45
|
it "should return false" do
|
60
|
-
Rivet::Utils.load_definition("unit_test").should be_false
|
46
|
+
Rivet::Utils.load_definition("unit_test",AUTOSCALE_DIR).should be_false
|
61
47
|
end
|
62
48
|
end
|
63
49
|
|
64
50
|
describe "get_definition" do
|
65
51
|
it "should return false" do
|
66
|
-
Rivet::Utils.get_definition("unit_test")
|
52
|
+
Rivet::Utils.get_definition("unit_test",AUTOSCALE_DIR)
|
67
53
|
end
|
68
54
|
end
|
69
55
|
|
70
56
|
context "and with a group directory" do
|
71
57
|
before do
|
72
|
-
FileUtils.mkdir_p
|
58
|
+
FileUtils.mkdir_p DEFINITION_DIR
|
73
59
|
end
|
74
60
|
|
75
61
|
describe "load_definition" do
|
76
62
|
it "should return false" do
|
77
|
-
Rivet::Utils.load_definition("unit_test").should be_false
|
63
|
+
Rivet::Utils.load_definition("unit_test",AUTOSCALE_DIR).should be_false
|
78
64
|
end
|
79
65
|
end
|
80
66
|
|
81
67
|
context "and with a conf.yml" do
|
82
68
|
before do
|
83
|
-
FileUtils.mkdir_p
|
84
|
-
File.open(File.join(
|
69
|
+
FileUtils.mkdir_p DEFINITION_DIR
|
70
|
+
File.open(File.join(DEFINITION_DIR,"conf.yml"),'w') do |f|
|
85
71
|
f.write(unit_test_definition_hash.to_yaml)
|
86
72
|
end
|
87
73
|
end
|
88
74
|
describe "load_definition" do
|
89
75
|
it "returns a hash" do
|
90
|
-
loaded_def = Rivet::Utils.load_definition("unit_test")
|
76
|
+
loaded_def = Rivet::Utils.load_definition("unit_test",AUTOSCALE_DIR)
|
91
77
|
unit_test_definition_hash.each_pair { |k,v| loaded_def.should include(k => v) }
|
92
78
|
end
|
93
79
|
end
|
94
80
|
context "and with a defaults.yml" do
|
95
81
|
before do
|
96
|
-
File.open(File.join(
|
82
|
+
File.open(File.join(AUTOSCALE_DIR,"defaults.yml"),'w') do |f|
|
97
83
|
f.write(defaults_hash.to_yaml)
|
98
84
|
end
|
99
85
|
end
|
100
86
|
|
101
87
|
describe "consume_defaults" do
|
102
88
|
it "consume defaults returns a hash" do
|
103
|
-
results = Rivet::Utils.consume_defaults
|
89
|
+
results = Rivet::Utils.consume_defaults(AUTOSCALE_DIR)
|
104
90
|
defaults_hash.each_pair { |k,v| results.should include(k => v) }
|
105
91
|
end
|
106
92
|
end
|
107
93
|
|
108
94
|
describe "get_definition" do
|
109
95
|
it "returns a merged hash" do
|
110
|
-
result = Rivet::Utils.get_definition(
|
96
|
+
result = Rivet::Utils.get_definition(DEFINITION_NAME,AUTOSCALE_DIR)
|
111
97
|
merged_hash = defaults_hash.merge(unit_test_definition_hash)
|
112
98
|
result.should == defaults_hash.merge(unit_test_definition_hash)
|
113
99
|
end
|