chef-sugar-ng 4.2.2 → 5.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/chef/sugar/init.rb +1 -2
- data/lib/chef/sugar/version.rb +1 -1
- data/lib/chef/sugar/virtualization.rb +1 -1
- metadata +8 -68
- data/.github/lock.yml +0 -3
- data/.github/reaction.yml +0 -1
- data/.gitignore +0 -26
- data/.kitchen.yml +0 -16
- data/.travis.yml +0 -17
- data/CHANGELOG.md +0 -261
- data/CONTRIBUTING.md +0 -20
- data/Gemfile +0 -2
- data/README.md +0 -540
- data/Rakefile +0 -11
- data/chef-sugar-ng.gemspec +0 -33
- data/libraries/chef-sugar.rb +0 -1
- data/metadata.rb +0 -24
- data/recipes/default.rb +0 -20
- data/spec/spec_helper.rb +0 -25
- data/spec/support/shared_examples.rb +0 -20
- data/spec/unit/chef/sugar/architecture_spec.rb +0 -129
- data/spec/unit/chef/sugar/cloud_spec.rb +0 -149
- data/spec/unit/chef/sugar/constraints_spec.rb +0 -45
- data/spec/unit/chef/sugar/core_extensions/array_spec.rb +0 -10
- data/spec/unit/chef/sugar/core_extensions/object_spec.rb +0 -62
- data/spec/unit/chef/sugar/core_extensions/string_spec.rb +0 -48
- data/spec/unit/chef/sugar/data_bag_spec.rb +0 -118
- data/spec/unit/chef/sugar/docker_spec.rb +0 -39
- data/spec/unit/chef/sugar/init_spec.rb +0 -74
- data/spec/unit/chef/sugar/ip_spec.rb +0 -53
- data/spec/unit/chef/sugar/kernel_spec.rb +0 -16
- data/spec/unit/chef/sugar/kitchen_spec.rb +0 -18
- data/spec/unit/chef/sugar/node_spec.rb +0 -172
- data/spec/unit/chef/sugar/platform_family_spec.rb +0 -166
- data/spec/unit/chef/sugar/platform_spec.rb +0 -342
- data/spec/unit/chef/sugar/ruby_spec.rb +0 -39
- data/spec/unit/chef/sugar/run_context_spec.rb +0 -19
- data/spec/unit/chef/sugar/shell_spec.rb +0 -104
- data/spec/unit/chef/sugar/vagrant_spec.rb +0 -37
- data/spec/unit/chef/sugar/virtualization_spec.rb +0 -135
- data/spec/unit/recipes/default_spec.rb +0 -9
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'chef/sugar/core_extensions'
|
3
|
-
|
4
|
-
describe Object do
|
5
|
-
describe '#blank?' do
|
6
|
-
it 'includes the method' do
|
7
|
-
expect(described_class).to be_method_defined(:blank?)
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'returns true for nil' do
|
11
|
-
expect(nil).to be_blank
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns true for false' do
|
15
|
-
expect(false).to be_blank
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'returns true for the empty string' do
|
19
|
-
expect('').to be_blank
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'returns true for the empty array' do
|
23
|
-
expect([]).to be_blank
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns true for the empty hash' do
|
27
|
-
expect({}).to be_blank
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'returns false for a non-empty string' do
|
31
|
-
expect(' ').to_not be_blank
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'returns false for a non-empty string with unicode' do
|
35
|
-
expect("\u00a0").to_not be_blank
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'returns false for a non-empty string with special characters' do
|
39
|
-
expect("\n\t").to_not be_blank
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'returns false for any object' do
|
43
|
-
expect(Object.new).to_not be_blank
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'returns false for true' do
|
47
|
-
expect(true).to_not be_blank
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'returns false for a fixnum' do
|
51
|
-
expect(1).to_not be_blank
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'returns false for an array with items' do
|
55
|
-
expect(['foo']).to_not be_blank
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'returns false for an array with items' do
|
59
|
-
expect({'foo' => 'bar'}).to_not be_blank
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'chef/sugar/core_extensions'
|
3
|
-
|
4
|
-
describe String do
|
5
|
-
describe '#satisfies?' do
|
6
|
-
it 'includes the method' do
|
7
|
-
expect(described_class).to be_method_defined(:satisfies?)
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
describe '#satisfied_by?' do
|
12
|
-
it 'includes the method' do
|
13
|
-
expect(described_class).to be_method_defined(:satisfied_by?)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#flush' do
|
18
|
-
context 'when given a single-line string' do
|
19
|
-
it 'strips trailing whitespace' do
|
20
|
-
string = <<-EOH
|
21
|
-
This is a string
|
22
|
-
EOH
|
23
|
-
expect(string.flush).to eq('This is a string')
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when given a multi-line string' do
|
28
|
-
it 'removes the leading number of whitespaces' do
|
29
|
-
string = <<-EOH
|
30
|
-
def method
|
31
|
-
"This is a string!"
|
32
|
-
end
|
33
|
-
EOH
|
34
|
-
expect(string.flush).to eq(%Q(def method\n "This is a string!"\nend))
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'leaves a newline when given' do
|
38
|
-
string = <<-EOH
|
39
|
-
def method
|
40
|
-
"This is a string!"
|
41
|
-
end
|
42
|
-
|
43
|
-
EOH
|
44
|
-
expect(string.flush).to eq(%Q(def method\n "This is a string!"\nend\n))
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,118 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chef::Sugar::DataBag do
|
4
|
-
describe '#encrypted_data_bag_item' do
|
5
|
-
before { allow(Chef::EncryptedDataBagItem).to receive(:load) }
|
6
|
-
|
7
|
-
it 'loads the encrypted data bag item' do
|
8
|
-
expect(Chef::EncryptedDataBagItem).to receive(:load)
|
9
|
-
.with('accounts', 'github', 'secret_key')
|
10
|
-
|
11
|
-
described_class.encrypted_data_bag_item('accounts', 'github', 'secret_key')
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'when Chef::Config is set' do
|
15
|
-
it 'loads the secret key from the Chef::Config' do
|
16
|
-
allow(Chef::Config).to receive(:[]).with(:encrypted_data_bag_secret).and_return('/data/path')
|
17
|
-
allow(File).to receive(:read).with('/data/path').and_return('B@c0n')
|
18
|
-
|
19
|
-
expect(Chef::EncryptedDataBagItem).to receive(:load)
|
20
|
-
.with('accounts', 'github', 'B@c0n')
|
21
|
-
|
22
|
-
described_class.encrypted_data_bag_item('accounts', 'github')
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
context 'when Chef::Config is not set and no value is given' do
|
27
|
-
it 'raises an exception' do
|
28
|
-
expect {
|
29
|
-
described_class.encrypted_data_bag_item('accounts', 'github')
|
30
|
-
}.to raise_error(Chef::Sugar::DataBag::EncryptedDataBagSecretNotGiven)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe '#encrypted_data_bag_item_for_environment' do
|
36
|
-
let(:node) { double(:node, chef_environment: 'production') }
|
37
|
-
|
38
|
-
context 'when the environment exists' do
|
39
|
-
it 'loads the data from the environment' do
|
40
|
-
allow(Chef::EncryptedDataBagItem).to receive(:load).and_return(
|
41
|
-
'production' => {
|
42
|
-
'username' => 'sethvargo',
|
43
|
-
'password' => 'bacon',
|
44
|
-
}
|
45
|
-
)
|
46
|
-
|
47
|
-
expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github', 'secret_key')).to eq(
|
48
|
-
'password' => 'bacon',
|
49
|
-
'username' => 'sethvargo',
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context 'when the environment does not exist' do
|
55
|
-
it 'loads the data from the default bucket' do
|
56
|
-
allow(Chef::EncryptedDataBagItem).to receive(:load).and_return(
|
57
|
-
'staging' => {
|
58
|
-
'username' => 'sethvargo',
|
59
|
-
'password' => 'bacon',
|
60
|
-
},
|
61
|
-
'default' => {
|
62
|
-
'username' => 'schisamo',
|
63
|
-
'password' => 'ham',
|
64
|
-
}
|
65
|
-
)
|
66
|
-
|
67
|
-
expect(described_class.encrypted_data_bag_item_for_environment(node, 'accounts', 'github', 'secret_key')).to eq(
|
68
|
-
'password' => 'ham',
|
69
|
-
'username' => 'schisamo',
|
70
|
-
)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe '#data_bag_item_for_environment' do
|
76
|
-
let(:node) { double(:node, chef_environment: 'production') }
|
77
|
-
|
78
|
-
context 'when the environment exists' do
|
79
|
-
it 'loads the data from the environment' do
|
80
|
-
allow(Chef::DataBagItem).to receive(:load).and_return(
|
81
|
-
'production' => {
|
82
|
-
'username' => 'sethvargo',
|
83
|
-
'comment' => 'loves bacon',
|
84
|
-
},
|
85
|
-
'default' => {
|
86
|
-
'username' => 'schisamo',
|
87
|
-
'comment' => 'more of a ham guy',
|
88
|
-
}
|
89
|
-
)
|
90
|
-
|
91
|
-
expect(described_class.data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
|
92
|
-
'comment' => 'loves bacon',
|
93
|
-
'username' => 'sethvargo',
|
94
|
-
)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
context 'when the environment does not exist' do
|
99
|
-
it 'loads the data from the default bucket' do
|
100
|
-
allow(Chef::DataBagItem).to receive(:load).and_return(
|
101
|
-
'staging' => {
|
102
|
-
'username' => 'sethvargo',
|
103
|
-
'comment' => 'loves bacon',
|
104
|
-
},
|
105
|
-
'default' => {
|
106
|
-
'username' => 'schisamo',
|
107
|
-
'comment' => 'more of a ham guy',
|
108
|
-
}
|
109
|
-
)
|
110
|
-
|
111
|
-
expect(described_class.data_bag_item_for_environment(node, 'accounts', 'github')).to eq(
|
112
|
-
'comment' => 'more of a ham guy',
|
113
|
-
'username' => 'schisamo',
|
114
|
-
)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chef::Sugar::Docker do
|
4
|
-
it_behaves_like 'a chef sugar'
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
allow(File).to receive(:exist?)
|
8
|
-
.with("/.dockerenv")
|
9
|
-
.and_return(false)
|
10
|
-
allow(File).to receive(:exist?)
|
11
|
-
.with("/.dockerinit")
|
12
|
-
.and_return(false)
|
13
|
-
end
|
14
|
-
|
15
|
-
describe '#docker?' do
|
16
|
-
it 'is true when the file /.dockerenv is present' do
|
17
|
-
allow(File).to receive(:exist?)
|
18
|
-
.with("/.dockerenv")
|
19
|
-
.and_return(true)
|
20
|
-
|
21
|
-
node = { 'docker' => nil }
|
22
|
-
expect(described_class.docker?(node)).to be true
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'is true when the file /.dockerinit is present' do
|
26
|
-
allow(File).to receive(:exist?)
|
27
|
-
.with("/.dockerinit")
|
28
|
-
.and_return(true)
|
29
|
-
|
30
|
-
node = { 'docker' => nil }
|
31
|
-
expect(described_class.docker?(node)).to be true
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'is false when the node is not on cloud' do
|
35
|
-
node = { 'docker' => nil }
|
36
|
-
expect(described_class.docker?(node)).to be false
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chef::Sugar::Init do
|
4
|
-
it_behaves_like 'a chef sugar'
|
5
|
-
|
6
|
-
before(:each) do
|
7
|
-
allow(IO).to receive(:read)
|
8
|
-
.with("/proc/1/comm")
|
9
|
-
.and_return("init")
|
10
|
-
allow(File).to receive(:executable?)
|
11
|
-
.with("/sbin/initctl")
|
12
|
-
.and_return(false)
|
13
|
-
allow(File).to receive(:executable?)
|
14
|
-
.with("/sbin/runit-init")
|
15
|
-
.and_return(false)
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#systemd?' do
|
19
|
-
it 'is true when /proc/1/comm is systemd' do
|
20
|
-
allow(IO).to receive(:read)
|
21
|
-
.with("/proc/1/comm")
|
22
|
-
.and_return("systemd")
|
23
|
-
|
24
|
-
node = {}
|
25
|
-
expect(described_class.systemd?(node)).to be true
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'is false when /proc/1/comm is not systemd' do
|
29
|
-
node = {}
|
30
|
-
expect(described_class.systemd?(node)).to be false
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'is false when /proc/1/comm does not exist' do
|
34
|
-
allow(File).to receive(:exist?)
|
35
|
-
.with("/proc/1/comm")
|
36
|
-
.and_return(false)
|
37
|
-
|
38
|
-
node = {}
|
39
|
-
expect(described_class.systemd?(node)).to be false
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#upstart?' do
|
44
|
-
it 'is true when /sbin/initctl is executable' do
|
45
|
-
allow(File).to receive(:executable?)
|
46
|
-
.with("/sbin/initctl")
|
47
|
-
.and_return(true)
|
48
|
-
|
49
|
-
node = {}
|
50
|
-
expect(described_class.upstart?(node)).to be true
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'is false when /sbin/initctl is not executable' do
|
54
|
-
node = {}
|
55
|
-
expect(described_class.upstart?(node)).to be false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#runit?' do
|
60
|
-
it 'is true when /sbin/runit-init is executable' do
|
61
|
-
allow(File).to receive(:executable?)
|
62
|
-
.with("/sbin/runit-init")
|
63
|
-
.and_return(true)
|
64
|
-
|
65
|
-
node = {}
|
66
|
-
expect(described_class.runit?(node)).to be true
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'is false when /sbin/runit-init is not executable' do
|
70
|
-
node = {}
|
71
|
-
expect(described_class.runit?(node)).to be false
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chef::Sugar::IP do
|
4
|
-
it_behaves_like 'a chef sugar'
|
5
|
-
|
6
|
-
let(:node) { { 'ipaddress' => '1.2.3.4' } }
|
7
|
-
let(:other) { { 'ipaddress' => '5.6.7.8' } }
|
8
|
-
|
9
|
-
context 'when not on a cloud' do
|
10
|
-
it 'returns the default IP address' do
|
11
|
-
expect(described_class.best_ip_for(node, other)).to eq(other['ipaddress'])
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
context 'when the target is on the cloud' do
|
16
|
-
before do
|
17
|
-
other['cloud'] = {}
|
18
|
-
other['cloud']['provider'] = 'ec2'
|
19
|
-
other['cloud']['local_ipv4'] = '9.10.11.12'
|
20
|
-
other['cloud']['public_ipv4'] = '13.14.15.16'
|
21
|
-
|
22
|
-
node['cloud'] = nil
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'when the current node is not on the cloud' do
|
26
|
-
it 'uses the public ipv4' do
|
27
|
-
expect(described_class.best_ip_for(node, other)).to eq('13.14.15.16')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'when the current node is on a different cloud' do
|
32
|
-
before do
|
33
|
-
node['cloud'] = {}
|
34
|
-
node['cloud']['provider'] = 'rackspace'
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'uses the public ipv4' do
|
38
|
-
expect(described_class.best_ip_for(node, other)).to eq('13.14.15.16')
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
context 'when the current node is on the same cloud' do
|
43
|
-
before do
|
44
|
-
node['cloud'] = {}
|
45
|
-
node['cloud']['provider'] = 'ec2'
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'uses the local ipv4' do
|
49
|
-
expect(described_class.best_ip_for(node, other)).to eq('9.10.11.12')
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chef::Sugar::Kernel do
|
4
|
-
describe '.require_chef_gem' do
|
5
|
-
it 'raises an exception when the gem is not installed' do
|
6
|
-
expect {
|
7
|
-
described_class.require_chef_gem('bacon')
|
8
|
-
}.to raise_error(Chef::Sugar::Kernel::ChefGemLoadError)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'loads the gem' do
|
12
|
-
allow(Chef::Sugar::Kernel).to receive(:require).and_return(true)
|
13
|
-
expect(described_class.require_chef_gem('bacon')).to be true
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Chef::Sugar::Kitchen do
|
4
|
-
it_behaves_like 'a chef sugar'
|
5
|
-
|
6
|
-
describe '#kitchen?' do
|
7
|
-
it 'is true when the TEST_KITCHEN environment variable is set' do
|
8
|
-
allow(ENV).to receive(:[]).with('TEST_KITCHEN').and_return('1')
|
9
|
-
node = {}
|
10
|
-
expect(described_class.kitchen?(node)).to be true
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'is false when the TEST_KITCHEN environment variable is unset' do
|
14
|
-
node = {}
|
15
|
-
expect(described_class.kitchen?(node)).to be false
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|