rivet 1.4.0 → 2.0.0
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.
- data/.rubocop.yml +18 -0
- data/.travis.yml +3 -5
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +27 -35
- data/README.md +71 -46
- data/autoscale/defaults.rb +23 -0
- data/bin/rivet +24 -20
- data/example/autoscale/defaults.rb +22 -0
- data/example/autoscale/example_group.rb +10 -0
- data/lib/rivet/autoscale.rb +77 -89
- data/lib/rivet/aws_autoscale_wrapper.rb +82 -0
- data/lib/rivet/aws_utils.rb +10 -8
- data/lib/rivet/bootstrap.rb +13 -58
- data/lib/rivet/client.rb +26 -20
- data/lib/rivet/config.rb +87 -0
- data/lib/rivet/config_proxy.rb +28 -0
- data/lib/rivet/deep_merge.rb +3 -1
- data/lib/rivet/launch_config.rb +45 -34
- data/lib/rivet/logger.rb +3 -1
- data/lib/rivet/open_state.rb +44 -0
- data/lib/rivet/utils.rb +11 -46
- data/lib/rivet/version.rb +3 -1
- data/lib/rivet.rb +12 -6
- data/rivet.gemspec +1 -1
- data/spec/aws_autoscale_wrapper_spec.rb +123 -0
- data/spec/bootstrap_spec.rb +38 -0
- data/spec/config_proxy_spec.rb +34 -0
- data/spec/config_spec.rb +168 -0
- data/spec/launch_config_spec.rb +30 -0
- data/spec/open_state_spec.rb +67 -0
- data/spec/spec_setup.rb +112 -0
- data/spec/util_spec.rb +34 -0
- metadata +28 -12
- data/spec/rivet_bootstrap_spec.rb +0 -80
- data/spec/rivet_launch_config_spec.rb +0 -37
- data/spec/rivet_spec_setup.rb +0 -68
- data/spec/rivet_util_spec.rb +0 -108
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative './spec_setup'
|
3
|
+
|
4
|
+
include SpecHelpers
|
5
|
+
|
6
|
+
describe 'rivet launch config' do
|
7
|
+
let(:config) { generate_config_mock(double('config_mock'), DSL_VALUES) }
|
8
|
+
let(:launch_config) { Rivet::LaunchConfig.new(config) }
|
9
|
+
|
10
|
+
context 'with a sane config' do
|
11
|
+
before do
|
12
|
+
user_data_mock = double('user_data_mock')
|
13
|
+
user_data_mock.stub(:user_data).and_return('unit_test_user_data')
|
14
|
+
Rivet::Bootstrap.stub(:new).and_return(user_data_mock)
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#build_identity_string' do
|
18
|
+
it 'should return a valid identity_string' do
|
19
|
+
launch_config.send(:build_identity_string).should == SpecHelpers::AUTOSCALE_IDENTITY_STRING
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#identity' do
|
24
|
+
it 'should return a deterministic identity' do
|
25
|
+
launch_config.identity.should == "rivet_#{Digest::SHA1.hexdigest(SpecHelpers::AUTOSCALE_IDENTITY_STRING)}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative './spec_setup'
|
3
|
+
|
4
|
+
include SpecHelpers
|
5
|
+
|
6
|
+
describe 'Rivet OpenState' do
|
7
|
+
let(:openstate) { Rivet::OpenState.new }
|
8
|
+
|
9
|
+
describe '#install_get_or_set' do
|
10
|
+
before do
|
11
|
+
openstate.install_get_or_set(:tortilla)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'installs a getter' do
|
15
|
+
openstate.should respond_to(:tortilla)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'installs a setter' do
|
19
|
+
openstate.tortilla 'shells'
|
20
|
+
openstate.tortilla.should == 'shells'
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'adds the getter setter to generated attributes' do
|
24
|
+
openstate.generated_attributes.should include(:tortilla)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#method_missing' do
|
29
|
+
it 'adds an attribute when sent a message with an argument' do
|
30
|
+
openstate.car %w(car horse tank)
|
31
|
+
openstate.car.should == %w(car horse tank)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'raises an exception if sent a message that was not defined' do
|
35
|
+
expect { openstate.sloth }.to raise_error
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#validate' do
|
40
|
+
before do
|
41
|
+
openstate.required_fields = {
|
42
|
+
:pickle => 'donkey',
|
43
|
+
:donut => nil,
|
44
|
+
:cake => 'chocolate'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'raises an exception if a required attribute is not defined' do
|
49
|
+
openstate.cake 'chocolate'
|
50
|
+
openstate.pickle 'donkey'
|
51
|
+
expect { openstate.validate }.to raise_error
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'sets a default value if one is provided' do
|
55
|
+
openstate.donut 'strawberry'
|
56
|
+
openstate.validate
|
57
|
+
openstate.pickle.should == 'donkey'
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns true if all required fields have values' do
|
61
|
+
openstate.cake 'chocolate'
|
62
|
+
openstate.pickle 'donkey'
|
63
|
+
openstate.donut 'strawberry'
|
64
|
+
openstate.validate.should be_true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/spec_setup.rb
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require 'rspec'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'pathname'
|
6
|
+
require 'base64'
|
7
|
+
require_relative '../lib/rivet'
|
8
|
+
|
9
|
+
Rivet::Log.level(Logger::FATAL)
|
10
|
+
|
11
|
+
module SpecHelpers
|
12
|
+
AUTOSCALE_DIR = File.join('.', 'autoscale')
|
13
|
+
CONFIG_FILE = File.join(AUTOSCALE_DIR, 'unit_test.rb')
|
14
|
+
TEMPLATE_FILE = File.join(AUTOSCALE_DIR, 'default.erb')
|
15
|
+
BOOTSTRAP_TEMPLATE = '<%= "bar" %>'\
|
16
|
+
|
17
|
+
DSL_VALUES = {
|
18
|
+
:min_size => '1',
|
19
|
+
:desired_capacity => '1',
|
20
|
+
:max_size => '3',
|
21
|
+
:region => "'us-west-2'",
|
22
|
+
:availability_zones => '%w(b c a)',
|
23
|
+
:key_name => "'UnitTests'",
|
24
|
+
:instance_type => "'m1.large'",
|
25
|
+
:security_groups => '%w(unit_test3 unit_tests1 unit_tests2)',
|
26
|
+
:image_id => "'ami-12345678'",
|
27
|
+
:iam_instance_profile => "'unit_test_profile'",
|
28
|
+
:default_cooldown => '300',
|
29
|
+
:placement_group => "'unit test placement group'",
|
30
|
+
:health_check_type => ':ec2',
|
31
|
+
:termination_policies => '%w(policy2 policy1)',
|
32
|
+
:load_balancers => '%w(balancer2 balancer1)',
|
33
|
+
:health_check_grace_period => '100',
|
34
|
+
:associate_public_ip_address => 'true',
|
35
|
+
:detailed_instance_monitoring => 'true',
|
36
|
+
:block_device_mappings => "[{:device_name => '/dev/sda1', :virtual_name => 'ephemeral0'}]",
|
37
|
+
:kernel_id => "'aki-12345678'",
|
38
|
+
:ramdisk_id => "'ari-12345678'",
|
39
|
+
:spot_price => "'0.01'",
|
40
|
+
:bootstrap => {
|
41
|
+
:template => "'#{TEMPLATE_FILE}'",
|
42
|
+
:foo => "'bar'"
|
43
|
+
}
|
44
|
+
}
|
45
|
+
DSL_CONFIG_CONTENT = DSL_VALUES.inject(String.new) do |a, (k, v)|
|
46
|
+
if k == :bootstrap
|
47
|
+
v.each_pair do |bootstrap_attr, bootstrap_value|
|
48
|
+
a << "bootstrap.#{bootstrap_attr} #{bootstrap_value}\n"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
a << "#{k} #{v}\n"
|
52
|
+
end
|
53
|
+
a
|
54
|
+
end
|
55
|
+
|
56
|
+
AUTOSCALE_IDENTITY_STRING = "bootstrap#{Base64.encode64('unit_test_user_data')}"\
|
57
|
+
"iam_instance_profile#{Base64.encode64(eval(DSL_VALUES[:iam_instance_profile]))}"\
|
58
|
+
"image_id#{Base64.encode64(eval(DSL_VALUES[:image_id]))}"\
|
59
|
+
"instance_type#{Base64.encode64(eval(DSL_VALUES[:instance_type]))}"\
|
60
|
+
"key_name#{Base64.encode64(eval(DSL_VALUES[:key_name]))}"\
|
61
|
+
"security_groups#{Base64.encode64(eval(DSL_VALUES[:security_groups]).join("\t"))}"\
|
62
|
+
"associate_public_ip_address#{Base64.encode64(eval(DSL_VALUES[:associate_public_ip_address]).to_s)}"\
|
63
|
+
"detailed_instance_monitoring#{Base64.encode64(eval(DSL_VALUES[:detailed_instance_monitoring]).to_s)}"\
|
64
|
+
"block_device_mappings#{Base64.encode64(eval(DSL_VALUES[:block_device_mappings]).join("\t"))}"\
|
65
|
+
"kernel_id#{Base64.encode64(eval(DSL_VALUES[:kernel_id]))}"\
|
66
|
+
"ramdisk_id#{Base64.encode64(eval(DSL_VALUES[:ramdisk_id]))}"\
|
67
|
+
"spot_price#{Base64.encode64(eval(DSL_VALUES[:spot_price]))}"
|
68
|
+
|
69
|
+
def tempdir_context(name, &block)
|
70
|
+
context name do
|
71
|
+
before do
|
72
|
+
@origin_dir = Dir.pwd
|
73
|
+
@temp_dir = ::Pathname.new(::File.expand_path(::Dir.mktmpdir))
|
74
|
+
Dir.chdir @temp_dir
|
75
|
+
end
|
76
|
+
|
77
|
+
after do
|
78
|
+
Dir.chdir @origin_dir
|
79
|
+
FileUtils.remove_entry(@temp_dir)
|
80
|
+
end
|
81
|
+
|
82
|
+
instance_eval &block
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def dsl_from_hash(hash)
|
87
|
+
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def generate_config_mock(mock, attrs)
|
92
|
+
attrs.each_pair do |a, v|
|
93
|
+
if v.respond_to? :each_pair
|
94
|
+
sub_mock = generate_config_mock(double("#{a} mock"), v)
|
95
|
+
mock.stub(a).and_return(sub_mock)
|
96
|
+
else
|
97
|
+
mock.stub(a).and_return(eval(v))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
mock
|
101
|
+
end
|
102
|
+
|
103
|
+
def valid_config?(config, dsl_values)
|
104
|
+
dsl_values.each_pair do |k, v|
|
105
|
+
if v.respond_to? :each_pair
|
106
|
+
valid_config?(config.send(k), v)
|
107
|
+
else
|
108
|
+
config.send(k).should == eval(v)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
require_relative './spec_setup'
|
3
|
+
|
4
|
+
include SpecHelpers
|
5
|
+
|
6
|
+
describe 'rivet utils' do
|
7
|
+
tempdir_context 'with an autoscale directory' do
|
8
|
+
before do
|
9
|
+
FileUtils.mkdir_p AUTOSCALE_DIR
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'without an existing configuration' do
|
13
|
+
describe '#get_config' do
|
14
|
+
it 'should return false' do
|
15
|
+
Rivet::Utils.get_config('unit_test', AUTOSCALE_DIR).should be_false
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with a configuration file' do
|
21
|
+
before do
|
22
|
+
File.open(CONFIG_FILE, 'w') { |f| f.write(DSL_CONFIG_CONTENT) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#get_config' do
|
26
|
+
it 'should return a valid configuration' do
|
27
|
+
config = Rivet::Utils.get_config('unit_test', AUTOSCALE_DIR)
|
28
|
+
valid_config?(config, DSL_VALUES)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rivet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-06-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 2.14.1
|
78
78
|
description: Rivet allows you to define autoscaling groups and launch configurations
|
79
|
-
as
|
79
|
+
as configuration and SYNC that to AWS
|
80
80
|
email:
|
81
81
|
- brian.bianco@gmail.com
|
82
82
|
executables:
|
@@ -85,6 +85,7 @@ extensions: []
|
|
85
85
|
extra_rdoc_files: []
|
86
86
|
files:
|
87
87
|
- .gitignore
|
88
|
+
- .rubocop.yml
|
88
89
|
- .travis.yml
|
89
90
|
- CHANGELOG.md
|
90
91
|
- Gemfile
|
@@ -92,22 +93,33 @@ files:
|
|
92
93
|
- LICENSE
|
93
94
|
- README.md
|
94
95
|
- Rakefile
|
96
|
+
- autoscale/defaults.rb
|
95
97
|
- bin/rivet
|
98
|
+
- example/autoscale/defaults.rb
|
99
|
+
- example/autoscale/example_group.rb
|
96
100
|
- lib/rivet.rb
|
97
101
|
- lib/rivet/autoscale.rb
|
102
|
+
- lib/rivet/aws_autoscale_wrapper.rb
|
98
103
|
- lib/rivet/aws_utils.rb
|
99
104
|
- lib/rivet/bootstrap.rb
|
100
105
|
- lib/rivet/client.rb
|
106
|
+
- lib/rivet/config.rb
|
107
|
+
- lib/rivet/config_proxy.rb
|
101
108
|
- lib/rivet/deep_merge.rb
|
102
109
|
- lib/rivet/launch_config.rb
|
103
110
|
- lib/rivet/logger.rb
|
111
|
+
- lib/rivet/open_state.rb
|
104
112
|
- lib/rivet/utils.rb
|
105
113
|
- lib/rivet/version.rb
|
106
114
|
- rivet.gemspec
|
107
|
-
- spec/
|
108
|
-
- spec/
|
109
|
-
- spec/
|
110
|
-
- spec/
|
115
|
+
- spec/aws_autoscale_wrapper_spec.rb
|
116
|
+
- spec/bootstrap_spec.rb
|
117
|
+
- spec/config_proxy_spec.rb
|
118
|
+
- spec/config_spec.rb
|
119
|
+
- spec/launch_config_spec.rb
|
120
|
+
- spec/open_state_spec.rb
|
121
|
+
- spec/spec_setup.rb
|
122
|
+
- spec/util_spec.rb
|
111
123
|
homepage: http://www.github.com/brianbianco/rivet
|
112
124
|
licenses:
|
113
125
|
- Apache2
|
@@ -129,12 +141,16 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
141
|
version: 1.3.6
|
130
142
|
requirements: []
|
131
143
|
rubyforge_project:
|
132
|
-
rubygems_version: 1.8.
|
144
|
+
rubygems_version: 1.8.23
|
133
145
|
signing_key:
|
134
146
|
specification_version: 3
|
135
147
|
summary: A tool for managing autoscaling groups
|
136
148
|
test_files:
|
137
|
-
- spec/
|
138
|
-
- spec/
|
139
|
-
- spec/
|
140
|
-
- spec/
|
149
|
+
- spec/aws_autoscale_wrapper_spec.rb
|
150
|
+
- spec/bootstrap_spec.rb
|
151
|
+
- spec/config_proxy_spec.rb
|
152
|
+
- spec/config_spec.rb
|
153
|
+
- spec/launch_config_spec.rb
|
154
|
+
- spec/open_state_spec.rb
|
155
|
+
- spec/spec_setup.rb
|
156
|
+
- spec/util_spec.rb
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require_relative './rivet_spec_setup'
|
2
|
-
|
3
|
-
include SpecHelpers
|
4
|
-
|
5
|
-
describe 'rivet bootstrap' do
|
6
|
-
let (:bootstrap) { Rivet::Bootstrap.new(SpecHelpers::AUTOSCALE_DEF['bootstrap']) }
|
7
|
-
let (:bootstrap_def) { SpecHelpers::AUTOSCALE_DEF['bootstrap'] }
|
8
|
-
|
9
|
-
tempdir_context 'with all necessary files in place' do
|
10
|
-
before do
|
11
|
-
FileUtils.mkdir_p bootstrap_def['config_dir']
|
12
|
-
|
13
|
-
validator_file = File.join(
|
14
|
-
bootstrap_def['config_dir'],
|
15
|
-
"#{bootstrap_def['environment']}-validator.pem")
|
16
|
-
|
17
|
-
FileUtils.touch(validator_file)
|
18
|
-
|
19
|
-
template_dir = File.join(
|
20
|
-
bootstrap_def['config_dir'],
|
21
|
-
Rivet::Bootstrap::TEMPLATE_SUB_DIR)
|
22
|
-
|
23
|
-
FileUtils.mkdir_p template_dir
|
24
|
-
|
25
|
-
template_file = File.join(template_dir, bootstrap_def['template'])
|
26
|
-
File.open(template_file, 'w') { |f| f.write(SpecHelpers::BOOTSTRAP_TEMPLATE) }
|
27
|
-
end
|
28
|
-
|
29
|
-
describe "#user_data" do
|
30
|
-
it 'returns a string that contains the chef organization' do
|
31
|
-
org = bootstrap_def['chef_organization']
|
32
|
-
bootstrap.user_data.should =~ /chef_organization\s+.*\'#{org}\'.*/
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'returns a string that contains the chef username' do
|
36
|
-
org = bootstrap_def['chef_username']
|
37
|
-
bootstrap.user_data.should =~ /chef_username\s+.*\'#{org}\'.*/
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'returns a string that contains the environment' do
|
41
|
-
env = bootstrap_def['environment']
|
42
|
-
bootstrap.user_data.should =~ /environment\s+.*\'#{env}\'.*/
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns a string that contains the region' do
|
46
|
-
region = bootstrap_def['region']
|
47
|
-
bootstrap.user_data.should =~ /#{region}/
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns a string that contains the name' do
|
51
|
-
name = bootstrap_def['name']
|
52
|
-
bootstrap.user_data.should =~ /#{name}/
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'returns a string that contains the elastic_ip' do
|
56
|
-
elastic_ip = bootstrap_def['elastic_ip']
|
57
|
-
bootstrap.user_data.should =~ /#{elastic_ip}/
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'returns a string that contains the run_list as json' do
|
61
|
-
run_list = { :run_list => bootstrap_def['run_list'].flatten }.to_json
|
62
|
-
bootstrap.user_data.should =~ /#{Regexp.escape(run_list)}/
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'returns a string that contains each gem to install' do
|
66
|
-
bootstrap_def['gems'].each do |g|
|
67
|
-
if g.size > 1
|
68
|
-
gem_regexp = /gem\s+install\s+#{g[0]}.+#{g[1]}/
|
69
|
-
else
|
70
|
-
gem_regexp = /gem\s+install\s+#{g[0]}/
|
71
|
-
end
|
72
|
-
bootstrap.user_data.should =~ gem_regexp
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require_relative './rivet_spec_setup'
|
2
|
-
|
3
|
-
include SpecHelpers
|
4
|
-
|
5
|
-
describe "rivet launch config" do
|
6
|
-
let (:launch_config) { Rivet::LaunchConfig.new(SpecHelpers::AUTOSCALE_DEF) }
|
7
|
-
|
8
|
-
context "with a valid autoscale definition" do
|
9
|
-
before do
|
10
|
-
user_data_mock = double('user_data_mock')
|
11
|
-
user_data_mock.stub(:user_data).and_return("unit_test_user_data")
|
12
|
-
Rivet::Bootstrap.stub(:new).and_return(user_data_mock)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "#build_identity_string" do
|
16
|
-
it "should return a valid identity_string" do
|
17
|
-
launch_config.send(:build_identity_string).should == SpecHelpers::AUTOSCALE_IDENTITY_STRING
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe "#identity" do
|
22
|
-
it "should return a deterministic identity" do
|
23
|
-
launch_config.identity.should == "rivet_#{Digest::SHA1.hexdigest(SpecHelpers::AUTOSCALE_IDENTITY_STRING)}"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#normalize_security_groups" do
|
28
|
-
it "returns a sorted array of groups" do
|
29
|
-
unsorted_groups = %w(group3 group1 group2)
|
30
|
-
sorted_groups = unsorted_groups.sort
|
31
|
-
returned_groups = launch_config.send(:normalize_security_groups, unsorted_groups)
|
32
|
-
returned_groups.should == sorted_groups
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
data/spec/rivet_spec_setup.rb
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
require 'rspec'
|
2
|
-
require 'fileutils'
|
3
|
-
require 'tempfile'
|
4
|
-
require 'pathname'
|
5
|
-
require 'base64'
|
6
|
-
require_relative '../lib/rivet'
|
7
|
-
|
8
|
-
Rivet::Log.level(Logger::FATAL)
|
9
|
-
|
10
|
-
module SpecHelpers
|
11
|
-
|
12
|
-
BOOTSTRAP_TEMPLATE = '<%= install_gems %>'\
|
13
|
-
'<%= region %>' + "\n"\
|
14
|
-
'<%= name %>' + "\n"\
|
15
|
-
'<%= elastic_ip %>' + "\n"\
|
16
|
-
'<%= knife_content %>'\
|
17
|
-
'<%= first_boot %>'\
|
18
|
-
"\n"\
|
19
|
-
'<%= chef_command %>'
|
20
|
-
|
21
|
-
AUTOSCALE_DEF = {
|
22
|
-
'min_size' => 1,
|
23
|
-
'max_size' => 3,
|
24
|
-
'region' => 'us-west-2',
|
25
|
-
'availability_zones' => %w(a b c),
|
26
|
-
'key_name' => 'UnitTests',
|
27
|
-
'instance_type' => 'm1.large',
|
28
|
-
'security_groups' => %w(unit_tests1 unit_tests2),
|
29
|
-
'image_id' => 'ami-12345678',
|
30
|
-
'iam_instance_profile' => 'unit_test_profile',
|
31
|
-
'bootstrap' => {
|
32
|
-
'chef_organization' => 'unit_tests',
|
33
|
-
'chef_username' => 'unit_tests_user',
|
34
|
-
'template' => 'default.erb',
|
35
|
-
'config_dir' => 'unit_tests',
|
36
|
-
'environment' => 'unit_tests',
|
37
|
-
'region' => 'us-west-2',
|
38
|
-
'name' => 'unit_tests_name',
|
39
|
-
'elastic_ip' => '10.0.0.1',
|
40
|
-
'gems' => [ ['gem1', '0.0.1'], ['gem2', '0.0.2'] ],
|
41
|
-
'run_list' => ['unit_tests']
|
42
|
-
}
|
43
|
-
}
|
44
|
-
|
45
|
-
AUTOSCALE_IDENTITY_STRING = "key_name#{Base64.encode64(AUTOSCALE_DEF['key_name'])}"\
|
46
|
-
"image_id#{Base64.encode64(AUTOSCALE_DEF['image_id'])}"\
|
47
|
-
"instance_type#{Base64.encode64(AUTOSCALE_DEF['instance_type'])}"\
|
48
|
-
"security_groups#{Base64.encode64(AUTOSCALE_DEF['security_groups'].join("\t"))}"\
|
49
|
-
"iam_instance_profile#{Base64.encode64(AUTOSCALE_DEF['iam_instance_profile'])}"\
|
50
|
-
"bootstrap#{Base64.encode64('unit_test_user_data')}"\
|
51
|
-
|
52
|
-
def tempdir_context(name, &block)
|
53
|
-
context name do
|
54
|
-
before do
|
55
|
-
@origin_dir = Dir.pwd
|
56
|
-
@temp_dir = ::Pathname.new(::File.expand_path(::Dir.mktmpdir))
|
57
|
-
Dir.chdir @temp_dir
|
58
|
-
end
|
59
|
-
|
60
|
-
after do
|
61
|
-
Dir.chdir @origin_dir
|
62
|
-
FileUtils.remove_entry(@temp_dir)
|
63
|
-
end
|
64
|
-
|
65
|
-
instance_eval &block
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
data/spec/rivet_util_spec.rb
DELETED
@@ -1,108 +0,0 @@
|
|
1
|
-
require_relative './rivet_spec_setup'
|
2
|
-
|
3
|
-
include SpecHelpers
|
4
|
-
|
5
|
-
AUTOSCALE_DIR = '.'
|
6
|
-
DEFINITION_NAME = 'unit_test'
|
7
|
-
DEFINITION_DIR = File.join(AUTOSCALE_DIR, DEFINITION_NAME)
|
8
|
-
LAUNCH_CONFIG_PARAMS = %w(ssh_key instance_size security_groups ami bootstrap)
|
9
|
-
|
10
|
-
defaults_hash = {
|
11
|
-
'min_size' => 0,
|
12
|
-
'max_size' => 0,
|
13
|
-
'region' => 'us-west-2',
|
14
|
-
'zones' => %w(a b c),
|
15
|
-
'key_name' => 'unit_tests',
|
16
|
-
'instance_type' => 'm1.large',
|
17
|
-
'security_groups' => %w(unit_tests),
|
18
|
-
'image_id' => 'ami-unit_tests',
|
19
|
-
'bootstrap' => {
|
20
|
-
'run_list' => ['role[unit_tests]']
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
unit_test_definition_hash = {
|
25
|
-
'min_size' => 1,
|
26
|
-
'max_size' => 5,
|
27
|
-
'bootstrap' => {
|
28
|
-
'run_list' => ['role[merging_test']
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
describe "rivet utils" do
|
33
|
-
tempdir_context "with an autoscaling directory" do
|
34
|
-
before do
|
35
|
-
FileUtils.mkdir_p AUTOSCALE_DIR
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "consume_defaults" do
|
39
|
-
it "should return false" do
|
40
|
-
Rivet::Utils.consume_defaults(AUTOSCALE_DIR).should be_false
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "load_definition" do
|
45
|
-
it "should return false" do
|
46
|
-
Rivet::Utils.load_definition('unit_test', AUTOSCALE_DIR).should be_false
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
describe "get_definition" do
|
51
|
-
it "should return false" do
|
52
|
-
Rivet::Utils.get_definition('unit_test', AUTOSCALE_DIR)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "and with a group directory" do
|
57
|
-
before do
|
58
|
-
FileUtils.mkdir_p DEFINITION_DIR
|
59
|
-
end
|
60
|
-
|
61
|
-
describe "load_definition" do
|
62
|
-
it "should return false" do
|
63
|
-
Rivet::Utils.load_definition('unit_test', AUTOSCALE_DIR).should be_false
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "and with a conf.yml" do
|
68
|
-
before do
|
69
|
-
FileUtils.mkdir_p DEFINITION_DIR
|
70
|
-
File.open(File.join(DEFINITION_DIR, 'conf.yml'), 'w') do |f|
|
71
|
-
f.write(unit_test_definition_hash.to_yaml)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
describe "load_definition" do
|
75
|
-
it "returns a hash" do
|
76
|
-
loaded_def = Rivet::Utils.load_definition('unit_test', AUTOSCALE_DIR)
|
77
|
-
unit_test_definition_hash.each_pair { |k,v| loaded_def.should include(k => v) }
|
78
|
-
end
|
79
|
-
end
|
80
|
-
context "and with a defaults.yml" do
|
81
|
-
before do
|
82
|
-
File.open(File.join(AUTOSCALE_DIR, 'defaults.yml'), 'w') do |f|
|
83
|
-
f.write(defaults_hash.to_yaml)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "consume_defaults" do
|
88
|
-
it "consume defaults returns a hash" do
|
89
|
-
results = Rivet::Utils.consume_defaults(AUTOSCALE_DIR)
|
90
|
-
defaults_hash.each_pair { |k,v| results.should include(k => v) }
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe "get_definition" do
|
95
|
-
it "returns a merged hash" do
|
96
|
-
result = Rivet::Utils.get_definition(DEFINITION_NAME, AUTOSCALE_DIR)
|
97
|
-
merged_hash = defaults_hash.merge(unit_test_definition_hash)
|
98
|
-
result.should == defaults_hash.merge(unit_test_definition_hash)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|