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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3aebb2e9a4778eb4ffc77c8620d385b360378621
4
- data.tar.gz: 0b7ff68f22a22eefc7408b8b143186133c75f72d
3
+ metadata.gz: f941833b7b4fe75090a0c98ef524d49bccf72588
4
+ data.tar.gz: 17240bd5f539b85ec8f17f28db9b650e3fdec454
5
5
  SHA512:
6
- metadata.gz: abc1624e92a5ec34f8c139ee48b03fa598fd0cece96f2a5e3beaae60db2acbe54853f24c0dd249ab851a90844dad42c891df6694053109f78a383b8314363bb8
7
- data.tar.gz: 956354c9bf5954621022a34f3861afc291fd76618199de5aab4b0a09aac1f52b3e6ba6e34282e88a26d505f7a37b3b99b268930053bc058e5309dbf7b6045cd3
6
+ metadata.gz: c1f49e9230833de64e993c2ad78b892219aa959d89dd4fceaa34dd8dd940e8280c0ecc94e28ccc3a18d4cbe6919fcfa0286357db41f201dba0a329d717b65a49
7
+ data.tar.gz: 0c2a99eb2fd61742c0d5b272fee54b4e93808f739d7dd179ba5ee90d7ef6b3395fafbe9b03c4d2d590780763d6e61f76682cc3af1861ecae8bbd4c74e99086cf
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chef-ab (0.1.1)
4
+ chef-ab (0.2.0)
5
5
  backports
6
6
  ipaddress
7
7
 
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
- # plumbing
46
- start_time = Time.new(2014, 02, 11, 8, 30, 00, "+01:00")
47
- period = 3600 # going larger every hour
48
- first_node = "10.11.12.13"
49
-
50
- upgrade = ChefAB::TimeIPBasedUpgrader.new node['ipaddress'],
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
  ```
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "chef-ab"
6
- s.version = '0.1.1'
6
+ s.version = '0.2.0'
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Grégoire Seux"]
9
9
  s.license = "Apache License v2"
@@ -4,12 +4,13 @@ module ChefAB
4
4
  class BaseUpgrader
5
5
  attr_accessor :node_id, :hash
6
6
 
7
- def initialize(node_id)
8
- @node_id = node_id
9
- if node_id.is_a? Integer
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(node_ip, start_time, period, initial_ip)
12
- super(ip_metric(initial_ip, node_ip))
13
- @start_time = start_time.to_i
14
- @period = period
15
- @end_time = 31 * period + @start_time
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(node_id, start_time, end_time)
9
- super(node_id)
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
 
@@ -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
@@ -14,16 +14,20 @@ end
14
14
  describe ChefAB::TimeIPBasedUpgrader do
15
15
 
16
16
  def future_upgrade
17
- ChefAB::TimeIPBasedUpgrader.new "192.168.17.1",
18
- (Time.now + 10),
19
- 3600,
20
- "192.168.17.1"
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 "192.168.17.1",
24
- (Time.now - 10),
25
- 3600,
26
- "192.168.17.1"
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 "192.168.18.23",
49
- start_time,
50
- period,
51
- "192.168.17.1"
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
 
@@ -14,10 +14,18 @@ end
14
14
  describe ChefAB::TimeLinearUpgrader do
15
15
 
16
16
  def future_upgrade
17
- ChefAB::TimeLinearUpgrader.new "testing node", (Time.now + 10), (Time.now + 3600)
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 "testing node", (Time.now - 10), (Time.now - 5)
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 "testing node", start_time, end_time
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 5, start_time, end_time
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-ab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grégoire Seux