chef-ab 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -19
- data/chef_ab.gemspec +1 -1
- data/lib/chef-ab/base_upgrader.rb +5 -4
- data/lib/chef-ab/time_ipbased_upgrader.rb +6 -5
- data/lib/chef-ab/time_linear_upgrader.rb +5 -5
- data/spec/base_upgrader_spec.rb +2 -2
- data/spec/time_ipbased_spec.rb +18 -12
- data/spec/time_linear_spec.rb +20 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f941833b7b4fe75090a0c98ef524d49bccf72588
|
4
|
+
data.tar.gz: 17240bd5f539b85ec8f17f28db9b650e3fdec454
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1f49e9230833de64e993c2ad78b892219aa959d89dd4fceaa34dd8dd940e8280c0ecc94e28ccc3a18d4cbe6919fcfa0286357db41f201dba0a329d717b65a49
|
7
|
+
data.tar.gz: 0c2a99eb2fd61742c0d5b272fee54b4e93808f739d7dd179ba5ee90d7ef6b3395fafbe9b03c4d2d590780763d6e61f76682cc3af1861ecae8bbd4c74e99086cf
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -15,19 +15,13 @@ Very simple example in attribute file of :
|
|
15
15
|
# value before upgrade
|
16
16
|
default[:a_cookbook][:activate_experimental_feature] = false
|
17
17
|
|
18
|
-
# plumbing
|
19
|
-
one_week_in_secs = 7 * 86400
|
20
|
-
start_time = Time.new(2014, 02, 11, 8, 30, 00, "+01:00")
|
21
|
-
end_time = start_time + one_week_in_secs
|
22
|
-
|
23
18
|
upgrade = ChefAB::TimeLinearUpgrader.new(
|
24
|
-
node['fqdn'], # we use fqdn as id for the migration
|
25
|
-
start_time,
|
26
|
-
end_time
|
19
|
+
node_id: node['fqdn'], # we use fqdn as id for the migration
|
20
|
+
start_time: Time.new(2014, 02, 11, 8, 30, 00, "+01:00"),
|
21
|
+
end_time: Time.new(2014, 02, 18, 8, 30, 00, "+01:00")
|
27
22
|
)
|
28
23
|
|
29
24
|
upgrade.execute do
|
30
|
-
# value after upgrade
|
31
25
|
default[:a_cookbook][:activate_experimental_feature] = true
|
32
26
|
end
|
33
27
|
|
@@ -42,18 +36,14 @@ Another example, upgrading nodes exponentially depending on distance to a given
|
|
42
36
|
# value before upgrade
|
43
37
|
default[:a_cookbook][:activate_experimental_feature] = false
|
44
38
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
start_time,
|
52
|
-
period,
|
53
|
-
first_node
|
39
|
+
upgrade = ChefAB::TimeIPBasedUpgrader.new(
|
40
|
+
node_id: node['ipaddress'],
|
41
|
+
start_time: Time.new(2014, 02, 11, 8, 30, 00, "+01:00"),
|
42
|
+
period: 3600, #going larger every hour
|
43
|
+
first_node: "10.11.12.13"
|
44
|
+
)
|
54
45
|
|
55
46
|
upgrade.execute do
|
56
|
-
# value after upgrade
|
57
47
|
default[:a_cookbook][:activate_experimental_feature] = true
|
58
48
|
end
|
59
49
|
```
|
data/chef_ab.gemspec
CHANGED
@@ -4,12 +4,13 @@ module ChefAB
|
|
4
4
|
class BaseUpgrader
|
5
5
|
attr_accessor :node_id, :hash
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@node_id = node_id
|
9
|
-
|
7
|
+
def initialize(options)
|
8
|
+
@node_id = options[:node_id]
|
9
|
+
raise "node_id is a mandatory options" unless @node_id
|
10
|
+
if @node_id.is_a? Integer
|
10
11
|
@hash = node_id
|
11
12
|
else
|
12
|
-
@hash = Zlib.crc32 (node_id.to_s)
|
13
|
+
@hash = Zlib.crc32 (@node_id.to_s)
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -8,11 +8,12 @@ module ChefAB
|
|
8
8
|
attr_accessor :start_time, :period
|
9
9
|
attr_accessor :initial_ip
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@
|
11
|
+
def initialize(options)
|
12
|
+
options[:node_id] = ip_metric(options[:initial_ip], options[:node_id])
|
13
|
+
super(options)
|
14
|
+
@start_time = options[:start_time].to_i
|
15
|
+
@period = options[:period]
|
16
|
+
@end_time = 31 * @period + @start_time
|
16
17
|
end
|
17
18
|
|
18
19
|
def should_execute?(time = nil)
|
@@ -5,11 +5,11 @@ module ChefAB
|
|
5
5
|
|
6
6
|
attr_accessor :start_time, :end_time
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
super(
|
10
|
-
@start_time = start_time.to_i
|
11
|
-
@end_time = end_time.to_i
|
12
|
-
upgrade_span = end_time - start_time
|
8
|
+
def initialize(options)
|
9
|
+
super(options)
|
10
|
+
@start_time = options[:start_time].to_i
|
11
|
+
@end_time = options[:end_time].to_i
|
12
|
+
upgrade_span = @end_time - @start_time
|
13
13
|
@hash = @hash % upgrade_span
|
14
14
|
end
|
15
15
|
|
data/spec/base_upgrader_spec.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative '../lib/chef-ab.rb'
|
|
3
3
|
|
4
4
|
describe ChefAB::BaseUpgrader do
|
5
5
|
it 'should have an integer hash' do
|
6
|
-
up = ChefAB::BaseUpgrader.new 5
|
6
|
+
up = ChefAB::BaseUpgrader.new(node_id: 5)
|
7
7
|
expect(up.hash).to be_a_kind_of(Integer)
|
8
8
|
end
|
9
9
|
it 'should have an integer hash in any case' do
|
10
|
-
up = ChefAB::BaseUpgrader.new "testing node"
|
10
|
+
up = ChefAB::BaseUpgrader.new(node_id: "testing node")
|
11
11
|
expect(up.hash).to be_a_kind_of(Integer)
|
12
12
|
end
|
13
13
|
end
|
data/spec/time_ipbased_spec.rb
CHANGED
@@ -14,16 +14,20 @@ end
|
|
14
14
|
describe ChefAB::TimeIPBasedUpgrader do
|
15
15
|
|
16
16
|
def future_upgrade
|
17
|
-
ChefAB::TimeIPBasedUpgrader.new
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
ChefAB::TimeIPBasedUpgrader.new(
|
18
|
+
node_id: "192.168.17.1",
|
19
|
+
start_time: Time.now + 10,
|
20
|
+
period: 3600,
|
21
|
+
initial_ip: "192.168.17.1"
|
22
|
+
)
|
21
23
|
end
|
22
24
|
def past_upgrade
|
23
|
-
ChefAB::TimeIPBasedUpgrader.new
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
ChefAB::TimeIPBasedUpgrader.new(
|
26
|
+
node_id: "192.168.17.1",
|
27
|
+
start_time: Time.now - 10,
|
28
|
+
period: 3600,
|
29
|
+
initial_ip: "192.168.17.1"
|
30
|
+
)
|
27
31
|
end
|
28
32
|
|
29
33
|
it 'should not execute before start of upgrade' do
|
@@ -45,10 +49,12 @@ describe ChefAB::TimeIPBasedUpgrader do
|
|
45
49
|
it 'should not call block before expected_activation and should always do after' do
|
46
50
|
start_time = 42 #any timestamp
|
47
51
|
period = 10
|
48
|
-
up = ChefAB::TimeIPBasedUpgrader.new
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
+
up = ChefAB::TimeIPBasedUpgrader.new(
|
53
|
+
node_id: "192.168.18.23",
|
54
|
+
start_time: start_time,
|
55
|
+
period: period,
|
56
|
+
initial_ip: "192.168.17.1"
|
57
|
+
)
|
52
58
|
|
53
59
|
end_time = 42 + 32 * period
|
54
60
|
|
data/spec/time_linear_spec.rb
CHANGED
@@ -14,10 +14,18 @@ end
|
|
14
14
|
describe ChefAB::TimeLinearUpgrader do
|
15
15
|
|
16
16
|
def future_upgrade
|
17
|
-
ChefAB::TimeLinearUpgrader.new
|
17
|
+
ChefAB::TimeLinearUpgrader.new(
|
18
|
+
node_id: "testing node",
|
19
|
+
start_time: Time.now + 10,
|
20
|
+
end_time: Time.now + 3600
|
21
|
+
)
|
18
22
|
end
|
19
23
|
def past_upgrade
|
20
|
-
ChefAB::TimeLinearUpgrader.new
|
24
|
+
ChefAB::TimeLinearUpgrader.new(
|
25
|
+
node_id: "testing node",
|
26
|
+
start_time: Time.now - 10,
|
27
|
+
end_time: Time.now - 5
|
28
|
+
)
|
21
29
|
end
|
22
30
|
|
23
31
|
it 'should not execute before start of upgrade' do
|
@@ -39,7 +47,11 @@ describe ChefAB::TimeLinearUpgrader do
|
|
39
47
|
it 'should not call block before expected_activation and should always do after' do
|
40
48
|
start_time = 42 #any timestamp
|
41
49
|
end_time = 60
|
42
|
-
up = ChefAB::TimeLinearUpgrader.new
|
50
|
+
up = ChefAB::TimeLinearUpgrader.new(
|
51
|
+
node_id: "testing node",
|
52
|
+
start_time: start_time,
|
53
|
+
end_time: end_time
|
54
|
+
)
|
43
55
|
|
44
56
|
first_execute_time = up.expected_activation
|
45
57
|
|
@@ -56,7 +68,11 @@ describe ChefAB::TimeLinearUpgrader do
|
|
56
68
|
it 'should return correct expected_activation' do
|
57
69
|
start_time = 42 #any timestamp
|
58
70
|
end_time = 50
|
59
|
-
up = ChefAB::TimeLinearUpgrader.new
|
71
|
+
up = ChefAB::TimeLinearUpgrader.new(
|
72
|
+
node_id: 5,
|
73
|
+
start_time: start_time,
|
74
|
+
end_time: end_time
|
75
|
+
)
|
60
76
|
expect(up.expected_activation).to eq(42 + 5 +1)
|
61
77
|
end
|
62
78
|
end
|