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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f5633c6eb35655f0e48f3ca0c541518a2f77ca04
4
- data.tar.gz: 5175538852c4345a2b3d79c7fe91be9b89b57ab3
3
+ metadata.gz: ba0b9b13e41b7847ad771a60df668435e1f57535
4
+ data.tar.gz: 5a088cfa97247148ca799d5c9cd7716d916be6c4
5
5
  SHA512:
6
- metadata.gz: 0270705d80833cda8010dbac523b1265a3e853a3fc8e4b59207362f9834a2471f74496df0d948ebbb8dd6497c3c9f39bde5b0786b9243674c1a0fe1d75707a40
7
- data.tar.gz: 6e2a1384d06f75ef43b050ffa5540487e664bc4f68126b09345ace9017175cc4de06276a0416d35c51c9d58dc693daeef36c2900bd0298b67dacf672aa557a69
6
+ metadata.gz: 0812c0e3e59a7af1e456501e89aee87ec8851adaa9c02f4c5dea090002d19e6c63cf3712176c37b3d40fa9df6d8f94160bf4cbcd204f108778e6ec277e05a88c
7
+ data.tar.gz: b107b748207b37b47da4a9fc9881a9eee591bd15e9650450e450cbf37125cccdeb78a9f8aebad9bcaf1be35d5dd91577741947710235ad373ffdd0d5a8b3bc87
@@ -1,3 +1,4 @@
1
+ require 'promote/chef_server'
1
2
  require 'promote/config'
2
3
  require 'promote/cookbook'
3
4
  require 'promote/environment_file'
@@ -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
@@ -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
 
@@ -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
- @promoter.monitor_promotion(args.source_environment, args.destination_environments, 60 * 5)
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
@@ -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 #{Chef::Config[:chef_server_url]}"
47
+ ui.info "Uploading cookbooks from #{directory} to #{config.chef_server_url}"
50
48
  end
51
- knife = Chef::Knife::CookbookUpload.new()
52
- knife.config[:all] = true
53
- knife.config[:freeze] = true
54
- knife.config[:cookbook_path] = directory
55
- knife.run
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
- Chef::ChefFS::FileSystem.copy_to(
141
- pattern,
142
- src,
143
- Chef::ChefFS::Config.new.chef_fs,
144
- nil,
145
- Chef::Config
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
 
@@ -1,3 +1,3 @@
1
1
  module Promote
2
- VERSION = '0.7.10'
2
+ VERSION = '0.7.11'
3
3
  end
@@ -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
- expect(subject).to receive(:promote_to).with("env1", "env2", ui)
87
- expect(subject).to receive(:promote_to).with("env1", "env3", ui)
88
- expect(subject).to receive(:promote_to).with("env1", "env4", ui)
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
- expect(subject).to receive(:promote_to).with("env1", "env2", ui)
100
- expect(subject).to receive(:promote_to).with("env1", "env3", ui)
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.10
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-19 00:00:00.000000000 Z
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