clc-promote 0.7.10 → 0.7.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/promote.rb +1 -0
- data/lib/promote/chef_server.rb +27 -0
- data/lib/promote/promoter.rb +5 -1
- data/lib/promote/rake_tasks.rb +2 -1
- data/lib/promote/uploader.rb +22 -18
- data/lib/promote/version.rb +1 -1
- data/spec/unit/promote/promoter_spec.rb +11 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba0b9b13e41b7847ad771a60df668435e1f57535
|
4
|
+
data.tar.gz: 5a088cfa97247148ca799d5c9cd7716d916be6c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0812c0e3e59a7af1e456501e89aee87ec8851adaa9c02f4c5dea090002d19e6c63cf3712176c37b3d40fa9df6d8f94160bf4cbcd204f108778e6ec277e05a88c
|
7
|
+
data.tar.gz: b107b748207b37b47da4a9fc9881a9eee591bd15e9650450e450cbf37125cccdeb78a9f8aebad9bcaf1be35d5dd91577741947710235ad373ffdd0d5a8b3bc87
|
data/lib/promote.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Promote
|
2
|
+
module ChefServer
|
3
|
+
# Accepts a code block to run in the context of a chef server and user
|
4
|
+
# and reverts the environment back to the previous settings when done
|
5
|
+
# @param [Promote::Config] config containing chef server properties
|
6
|
+
def with_chef_server(config, &block)
|
7
|
+
current_server_url = Chef::Config[:chef_server_url]
|
8
|
+
current_client_key = Chef::Config[:client_key]
|
9
|
+
current_node_name = Chef::Config[:node_name]
|
10
|
+
current_repo_root = Chef::Config[:chef_repo_path]
|
11
|
+
|
12
|
+
Chef::Config.reset
|
13
|
+
Chef::Config[:chef_server_url] = config.chef_server_url
|
14
|
+
Chef::Config[:client_key] = config.client_key
|
15
|
+
Chef::Config[:node_name] = config.node_name
|
16
|
+
Chef::Config[:chef_repo_path] = config.repo_root
|
17
|
+
|
18
|
+
yield
|
19
|
+
ensure
|
20
|
+
Chef::Config.reset
|
21
|
+
Chef::Config[:chef_server_url] = current_server_url
|
22
|
+
Chef::Config[:client_key] = current_client_key
|
23
|
+
Chef::Config[:node_name] = current_node_name
|
24
|
+
Chef::Config[:chef_repo_path] = current_repo_root
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/promote/promoter.rb
CHANGED
@@ -21,8 +21,12 @@ module Promote
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def monitor_promotion(source_environment, destination_environments, probe_interval, max_wait = 3600, ui = nil)
|
24
|
+
uploader = Uploader.new(config)
|
25
|
+
|
24
26
|
destination_environments.each do |env|
|
27
|
+
ui.confirm "Promote #{source_environment} to #{env}" if ui
|
25
28
|
promote_to(source_environment, env, ui)
|
29
|
+
uploader.upload_environment(env)
|
26
30
|
start = Time.now.to_i
|
27
31
|
finder = NodeFinder.new("chef_environment:#{env}", config)
|
28
32
|
unconverged = nil
|
@@ -41,7 +45,7 @@ module Promote
|
|
41
45
|
break if unconverged.count == 0
|
42
46
|
|
43
47
|
ui.stdout.print "." if ui
|
44
|
-
|
48
|
+
|
45
49
|
sleep probe_interval
|
46
50
|
end
|
47
51
|
|
data/lib/promote/rake_tasks.rb
CHANGED
@@ -111,7 +111,8 @@ module Promote
|
|
111
111
|
desc "Promote a list of environments from another"
|
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
116
|
end
|
116
117
|
end
|
117
118
|
end
|
data/lib/promote/uploader.rb
CHANGED
@@ -13,14 +13,12 @@ end
|
|
13
13
|
|
14
14
|
module Promote
|
15
15
|
class Uploader
|
16
|
+
|
17
|
+
include ChefServer
|
18
|
+
|
16
19
|
def initialize(config)
|
17
20
|
@config = config
|
18
21
|
validate_config
|
19
|
-
Chef::Config.reset
|
20
|
-
Chef::Config[:client_key] = config.client_key
|
21
|
-
Chef::Config[:chef_server_url] = config.chef_server_url
|
22
|
-
Chef::Config[:node_name] = config.node_name
|
23
|
-
Chef::Config[:chef_repo_path] = config.repo_root
|
24
22
|
end
|
25
23
|
|
26
24
|
def upload_cookbook(cookbook_name)
|
@@ -46,13 +44,16 @@ module Promote
|
|
46
44
|
def upload_cookbook_directory(directory, ui = nil)
|
47
45
|
if !Dir.glob(File.join(directory, "*")).empty?
|
48
46
|
if ui
|
49
|
-
ui.info "Uploading cookbooks from #{directory} to #{
|
47
|
+
ui.info "Uploading cookbooks from #{directory} to #{config.chef_server_url}"
|
50
48
|
end
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
with_chef_server(@config) do
|
50
|
+
knife = Chef::Knife::CookbookUpload.new()
|
51
|
+
knife.config[:all] = true
|
52
|
+
knife.config[:freeze] = true
|
53
|
+
knife.config[:cookbook_path] = directory
|
54
|
+
knife.run
|
55
|
+
end
|
56
|
+
|
56
57
|
elsif ui
|
57
58
|
ui.info "No cookbooks found in #{directory}"
|
58
59
|
end
|
@@ -137,13 +138,16 @@ module Promote
|
|
137
138
|
def upload_file(file_path, src = Chef::ChefFS::Config.new.local_fs)
|
138
139
|
pattern = Chef::ChefFS::FilePattern.new(file_path)
|
139
140
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
141
|
+
with_chef_server(config) do
|
142
|
+
Chef::ChefFS::FileSystem.copy_to(
|
143
|
+
pattern,
|
144
|
+
src,
|
145
|
+
Chef::ChefFS::Config.new.chef_fs,
|
146
|
+
nil,
|
147
|
+
Chef::Config
|
148
|
+
)
|
149
|
+
end
|
150
|
+
|
147
151
|
file_path
|
148
152
|
end
|
149
153
|
|
data/lib/promote/version.rb
CHANGED
@@ -75,17 +75,20 @@ describe Promote::Promoter do
|
|
75
75
|
node.default["ohai_time"] = Time.now.to_i - 3600
|
76
76
|
node
|
77
77
|
}
|
78
|
+
let(:uploader) { double('uploader') }
|
78
79
|
let(:ui) { nil }
|
79
80
|
|
80
81
|
before {
|
81
82
|
allow(Promote::NodeFinder).to receive(:new).and_return(finder_good)
|
83
|
+
allow(Promote::Uploader).to receive(:new).and_return(uploader)
|
82
84
|
}
|
83
85
|
|
84
86
|
context "all environments succeed" do
|
85
87
|
it "promotes all nodes" do
|
86
|
-
|
87
|
-
|
88
|
-
|
88
|
+
%w{env2 env3 env4}.each do |env|
|
89
|
+
expect(subject).to receive(:promote_to).with("env1", env, ui)
|
90
|
+
expect(uploader).to receive(:upload_environment).with(env)
|
91
|
+
end
|
89
92
|
subject.monitor_promotion("env1", ["env2", "env3", "env4"], 0.25, 1, ui)
|
90
93
|
end
|
91
94
|
end
|
@@ -96,9 +99,12 @@ describe Promote::Promoter do
|
|
96
99
|
}
|
97
100
|
|
98
101
|
it "stops on failure" do
|
99
|
-
|
100
|
-
|
102
|
+
%w{env2 env3}.each do |env|
|
103
|
+
expect(subject).to receive(:promote_to).with("env1", env, ui)
|
104
|
+
expect(uploader).to receive(:upload_environment).with(env)
|
105
|
+
end
|
101
106
|
expect(subject).not_to receive(:promote_to).with("env1", "env4", ui)
|
107
|
+
expect(uploader).not_to receive(:upload_environment).with("env4")
|
102
108
|
expect{ subject.monitor_promotion("env1", ["env2", "env3", "env4"], 0.25, 1, ui) }.to raise_error(/env3$/)
|
103
109
|
end
|
104
110
|
end
|
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.7.
|
4
|
+
version: 0.7.11
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clc-git
|
@@ -124,6 +124,7 @@ files:
|
|
124
124
|
- lib/chef/knife/promote.rb
|
125
125
|
- lib/kitchen/provisioner/environment.rb
|
126
126
|
- lib/promote.rb
|
127
|
+
- lib/promote/chef_server.rb
|
127
128
|
- lib/promote/config.rb
|
128
129
|
- lib/promote/cookbook.rb
|
129
130
|
- lib/promote/environment_file.rb
|