clc-promote 0.7.11 → 0.8.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.
- checksums.yaml +4 -4
- data/lib/promote/promoter.rb +33 -25
- data/lib/promote/rake_tasks.rb +1 -1
- data/lib/promote/uploader.rb +20 -10
- data/lib/promote/version.rb +1 -1
- data/spec/unit/kitchen/provisioner/environment_spec.rb +4 -1
- data/spec/unit/promote/promoter_spec.rb +15 -2
- data/spec/unit/promote/uploader_spec.rb +9 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 51ac1711f235f79d4b72524866f866a3102fe775
|
4
|
+
data.tar.gz: 1b58e49d41e138be59c1740bead020ae83cdd8f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63359bcc4e3bb5347c9ecf0476bed57784b1da22c92a80bca824d66987cd127148ffcc917357989c105e2b3cac9666bea564f5257349486817f02c6d9df59879
|
7
|
+
data.tar.gz: 80827f613f6d462f7421ca8eb4e8520c9ff66c1a6fedd8389178b192b504b472cbd717730361c2057beaaf8235e029eb00eff0644bcd1f9703b4db7c7a861be3
|
data/lib/promote/promoter.rb
CHANGED
@@ -21,37 +21,17 @@ module Promote
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def monitor_promotion(source_environment, destination_environments, probe_interval, max_wait = 3600, ui = nil)
|
24
|
+
ui.info "Waiting for #{source_environment} to finish" if ui
|
25
|
+
check_promotion(source_environment, probe_interval, max_wait, ui)
|
26
|
+
|
24
27
|
uploader = Uploader.new(config)
|
25
28
|
|
26
29
|
destination_environments.each do |env|
|
27
30
|
ui.confirm "Promote #{source_environment} to #{env}" if ui
|
28
31
|
promote_to(source_environment, env, ui)
|
29
|
-
uploader.upload_environment(env)
|
30
|
-
start = Time.now.to_i
|
31
|
-
finder = NodeFinder.new("chef_environment:#{env}", config)
|
32
|
-
unconverged = nil
|
33
|
-
converged = []
|
34
|
-
until Time.now.to_i - start > max_wait
|
35
|
-
result = finder.search
|
36
|
-
unconverged = []
|
37
|
-
result.each do |node|
|
38
|
-
if node['ohai_time'].to_i < start
|
39
|
-
unconverged << node
|
40
|
-
elsif converged.grep(/#{node.name}/).empty?
|
41
|
-
converged << node.name
|
42
|
-
ui.info "#{node.name} has converged" if ui
|
43
|
-
end
|
44
|
-
end
|
45
|
-
break if unconverged.count == 0
|
46
|
-
|
47
|
-
ui.stdout.print "." if ui
|
48
|
-
|
49
|
-
sleep probe_interval
|
50
|
-
end
|
32
|
+
uploader.upload_environment(env, ui)
|
51
33
|
|
52
|
-
|
53
|
-
raise "Stopping promotion! Nodes (#{unconverged}) are not converging in #{env}"
|
54
|
-
end
|
34
|
+
check_promotion(env, probe_interval, max_wait, ui)
|
55
35
|
end
|
56
36
|
end
|
57
37
|
|
@@ -116,5 +96,33 @@ module Promote
|
|
116
96
|
)
|
117
97
|
Chef::ChefFS::FileSystem.copy_to(pattern, fs_config.chef_fs, local, nil, Chef::Config)
|
118
98
|
end
|
99
|
+
|
100
|
+
def check_promotion(environment_to_check, probe_interval, max_wait, ui)
|
101
|
+
start = Time.now.to_i
|
102
|
+
finder = NodeFinder.new("chef_environment:#{environment_to_check}", config)
|
103
|
+
unconverged = nil
|
104
|
+
converged = []
|
105
|
+
until Time.now.to_i - start > max_wait
|
106
|
+
result = finder.search
|
107
|
+
unconverged = []
|
108
|
+
result.each do |node|
|
109
|
+
if node['ohai_time'].to_i < start
|
110
|
+
unconverged << node
|
111
|
+
elsif converged.grep(/#{node.name}/).empty?
|
112
|
+
converged << node.name
|
113
|
+
ui.info "#{node.name} has converged" if ui
|
114
|
+
end
|
115
|
+
end
|
116
|
+
break if unconverged.count == 0
|
117
|
+
|
118
|
+
ui.stdout.print "." if ui
|
119
|
+
|
120
|
+
sleep probe_interval
|
121
|
+
end
|
122
|
+
|
123
|
+
if unconverged.count > 0
|
124
|
+
raise "Stopping promotion! Nodes (#{unconverged}) are not converging in #{environment_to_check}"
|
125
|
+
end
|
126
|
+
end
|
119
127
|
end
|
120
128
|
end
|
data/lib/promote/rake_tasks.rb
CHANGED
@@ -112,7 +112,7 @@ module Promote
|
|
112
112
|
task "promote_environments", :source_environment, :destination_environments do |task, args|
|
113
113
|
puts "Promoting constraints in #{args.source_environment} to #{args.destination_environments}"
|
114
114
|
ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
|
115
|
-
@promoter.monitor_promotion(args.source_environment, args.destination_environments, 5, 3600, ui)
|
115
|
+
@promoter.monitor_promotion(args.source_environment, args.destination_environments.split(' '), 5, 3600, ui)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
data/lib/promote/uploader.rb
CHANGED
@@ -59,8 +59,8 @@ module Promote
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
def upload_environment(environment_name)
|
63
|
-
upload_file("/environments/#{environment_name}.json")
|
62
|
+
def upload_environment(environment_name, ui = nil)
|
63
|
+
upload_file("/environments/#{environment_name}.json", nil, ui)
|
64
64
|
end
|
65
65
|
|
66
66
|
def upload_environments
|
@@ -73,11 +73,15 @@ module Promote
|
|
73
73
|
|
74
74
|
def upload_data_bags
|
75
75
|
data_bag_directory = File.join(config.temp_directory, "data_bags")
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
76
|
+
|
77
|
+
chef_fs_directory = nil
|
78
|
+
with_chef_server(config) do
|
79
|
+
chef_fs_directory = Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir.new(
|
80
|
+
{
|
81
|
+
'data_bags' => [data_bag_directory]
|
82
|
+
}
|
83
|
+
)
|
84
|
+
end
|
81
85
|
|
82
86
|
config.reset_temp_dir
|
83
87
|
|
@@ -135,16 +139,22 @@ module Promote
|
|
135
139
|
end
|
136
140
|
end
|
137
141
|
|
138
|
-
def upload_file(file_path, src =
|
142
|
+
def upload_file(file_path, src = nil, ui = nil)
|
143
|
+
ui.info "Uploading #{file_path} to #{config.chef_server_url}" if ui
|
139
144
|
pattern = Chef::ChefFS::FilePattern.new(file_path)
|
140
145
|
|
141
146
|
with_chef_server(config) do
|
147
|
+
fs_config = Chef::ChefFS::Config.new
|
148
|
+
src ||= fs_config.local_fs
|
149
|
+
|
142
150
|
Chef::ChefFS::FileSystem.copy_to(
|
143
151
|
pattern,
|
144
152
|
src,
|
145
|
-
|
153
|
+
fs_config.chef_fs,
|
146
154
|
nil,
|
147
|
-
Chef::Config
|
155
|
+
Chef::Config,
|
156
|
+
ui,
|
157
|
+
proc { |entry| fs_config.format_path(entry) }
|
148
158
|
)
|
149
159
|
end
|
150
160
|
|
data/lib/promote/version.rb
CHANGED
@@ -11,11 +11,14 @@ describe Kitchen::Provisioner::Environment do
|
|
11
11
|
let(:suite) do
|
12
12
|
double('suite', :name => "fries")
|
13
13
|
end
|
14
|
+
let(:platform) do
|
15
|
+
double('platform', :os_type => "shake")
|
16
|
+
end
|
14
17
|
let(:transport) do
|
15
18
|
double('transport', :sudo => config[:sudo], :shell => "bourne")
|
16
19
|
end
|
17
20
|
let(:instance) do
|
18
|
-
double('instance', :name => "coolbeans", :logger => logger, :suite => suite, :transport => transport, :verifier => {:test_base_path => 'base_path'})
|
21
|
+
double('instance', :name => "coolbeans", :logger => logger, :suite => suite, :platform => platform, :transport => transport, :verifier => {:test_base_path => 'base_path'})
|
19
22
|
end
|
20
23
|
let(:downloader) { double('downloader') }
|
21
24
|
let(:fake_berks) { double('berksfile', :install => nil, :update => nil, :list => [
|
@@ -87,12 +87,25 @@ describe Promote::Promoter do
|
|
87
87
|
it "promotes all nodes" do
|
88
88
|
%w{env2 env3 env4}.each do |env|
|
89
89
|
expect(subject).to receive(:promote_to).with("env1", env, ui)
|
90
|
-
expect(uploader).to receive(:upload_environment).with(env)
|
90
|
+
expect(uploader).to receive(:upload_environment).with(env, ui)
|
91
91
|
end
|
92
92
|
subject.monitor_promotion("env1", ["env2", "env3", "env4"], 0.25, 1, ui)
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
context "source environment does not fully converge" do
|
97
|
+
before {
|
98
|
+
allow(Promote::NodeFinder).to receive(:new).with("chef_environment:env1", config).and_return(finder_bad)
|
99
|
+
}
|
100
|
+
|
101
|
+
it "promotes no nodes" do
|
102
|
+
expect(subject).not_to receive(:promote_to)
|
103
|
+
expect(uploader).not_to receive(:upload_environment)
|
104
|
+
|
105
|
+
expect{ subject.monitor_promotion("env1", ["env2", "env3", "env4"], 0.25, 1, ui) }.to raise_error(/env1$/)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
96
109
|
context "stops promotion when promotion fails" do
|
97
110
|
before {
|
98
111
|
allow(Promote::NodeFinder).to receive(:new).with("chef_environment:env3", config).and_return(finder_bad)
|
@@ -101,7 +114,7 @@ describe Promote::Promoter do
|
|
101
114
|
it "stops on failure" do
|
102
115
|
%w{env2 env3}.each do |env|
|
103
116
|
expect(subject).to receive(:promote_to).with("env1", env, ui)
|
104
|
-
expect(uploader).to receive(:upload_environment).with(env)
|
117
|
+
expect(uploader).to receive(:upload_environment).with(env, ui)
|
105
118
|
end
|
106
119
|
expect(subject).not_to receive(:promote_to).with("env1", "env4", ui)
|
107
120
|
expect(uploader).not_to receive(:upload_environment).with("env4")
|
@@ -14,6 +14,7 @@ describe Promote::Uploader do
|
|
14
14
|
subject { Promote::Uploader.new(config) }
|
15
15
|
|
16
16
|
before {
|
17
|
+
Chef::Config[:chef_repo_path] = config.repo_root
|
17
18
|
allow(Chef::ChefFS::FileSystem).to receive(:copy_to)
|
18
19
|
}
|
19
20
|
|
@@ -186,7 +187,7 @@ describe Promote::Uploader do
|
|
186
187
|
let(:env_name) { "my_test" }
|
187
188
|
|
188
189
|
it "uploads the environment" do
|
189
|
-
expect(Chef::ChefFS::FileSystem).to receive(:copy_to).with(an_instance_of(Chef::ChefFS::FilePattern), anything(), anything(), anything(), anything()) do |arg|
|
190
|
+
expect(Chef::ChefFS::FileSystem).to receive(:copy_to).with(an_instance_of(Chef::ChefFS::FilePattern), anything(), anything(), anything(), anything(), anything(), anything()) do |arg|
|
190
191
|
expect(arg.pattern).to eq(File.join("/environments", "#{env_name}.json"))
|
191
192
|
end
|
192
193
|
subject.upload_environment(env_name)
|
@@ -202,7 +203,9 @@ describe Promote::Uploader do
|
|
202
203
|
an_instance_of(Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir),
|
203
204
|
anything(),
|
204
205
|
anything(),
|
205
|
-
anything()
|
206
|
+
anything(),
|
207
|
+
anything(),
|
208
|
+
anything()
|
206
209
|
) do |file_pattern, source|
|
207
210
|
expect(file_pattern.pattern).to eq(File.join("/environments/*.json"))
|
208
211
|
expect(source.child_paths["environments"]).to eq(local_environments)
|
@@ -220,6 +223,8 @@ describe Promote::Uploader do
|
|
220
223
|
an_instance_of(Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir),
|
221
224
|
anything(),
|
222
225
|
anything(),
|
226
|
+
anything(),
|
227
|
+
anything(),
|
223
228
|
anything()
|
224
229
|
) do |file_pattern, source|
|
225
230
|
expect(file_pattern.pattern).to eq(File.join("/roles/*.json"))
|
@@ -270,6 +275,8 @@ describe Promote::Uploader do
|
|
270
275
|
an_instance_of(Chef::ChefFS::FileSystem::ChefRepositoryFileSystemRootDir),
|
271
276
|
anything(),
|
272
277
|
anything(),
|
278
|
+
anything(),
|
279
|
+
anything(),
|
273
280
|
anything()
|
274
281
|
) do |file_pattern, source|
|
275
282
|
expect(file_pattern.pattern).to eq("/data_bags/**/*.json")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clc-promote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CenturyLink Cloud
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clc-git
|