cheffish 0.2.2 → 0.3

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: c768248960ee1fe2711d0207f64fe5490d2954f7
4
- data.tar.gz: 4afe8736f72242618444b6cccfc7445332951551
3
+ metadata.gz: 5f6b8abbcddf03b097bc9380a4bad5367f760f2f
4
+ data.tar.gz: 3f17d2781c140a66a869ecbedfd4c0c74326f1f9
5
5
  SHA512:
6
- metadata.gz: 40cd6c19536b07623598b3e65cf6a5ddb710484c034dcc024f57905f03c1fb19f475bcc6dd93834b6e4adaee0e25efcd8376451c42fee8edd10140518e2b2e8c
7
- data.tar.gz: 7f88593e7f4fb9b7473cb24a7ff9a4242a7f497778785cfc608e695c84e4f21624a88ea71adea2ba86cf957adba1c3aa72c83c70d8fe631f4499c7adef84f4c2
6
+ metadata.gz: 798aeb7bfd711164e71e613c2a3124aaf2cb2a8a344010aa6b97e17637802fc6ded341525677f97adc388f96360f7c28ce67145e519cf2ccc5b22fc199acd9b7
7
+ data.tar.gz: 0cbe97227f83d68327b8023f4ba23eaa81459f034fe31f5ee3e9a69bdb395cfdaaf7785b3dc1a458513312d32ff8a984ef10a6a210133d4462f3a77728f5433a
@@ -47,12 +47,15 @@ class Chef::Provider::ChefNode < Cheffish::ChefProviderBase
47
47
  end
48
48
 
49
49
  def augment_new_json(json)
50
+ # Preserve tags even if "attributes" was overwritten directly
51
+ json['normal']['tags'] = current_json['normal']['tags'] unless json['normal']['tags']
50
52
  # Apply modifiers
51
53
  json['run_list'] = apply_run_list_modifiers(new_resource.run_list_modifiers, new_resource.run_list_removers, json['run_list'])
52
- json['default'] = apply_modifiers(new_resource.default_modifiers, json['default'])
53
- json['normal'] = apply_modifiers(new_resource.normal_modifiers, json['normal'])
54
- json['override'] = apply_modifiers(new_resource.override_modifiers, json['override'])
55
- json['automatic'] = apply_modifiers(new_resource.automatic_modifiers, json['automatic'])
54
+ json['normal'] = apply_modifiers(new_resource.attribute_modifiers, json['normal'])
55
+ # Preserve default/override/automatic even when "complete true"
56
+ json['default'] = current_json['default']
57
+ json['override'] = current_json['override']
58
+ json['automatic'] = current_json['automatic']
56
59
  json
57
60
  end
58
61
 
@@ -73,10 +76,7 @@ class Chef::Provider::ChefNode < Cheffish::ChefProviderBase
73
76
  'name' => :name,
74
77
  'chef_environment' => :chef_environment,
75
78
  'run_list' => :run_list,
76
- 'default' => :default_attributes,
77
- 'normal' => :normal_attributes,
78
- 'override' => :override_attributes,
79
- 'automatic' => :automatic_attributes
79
+ 'normal' => :attributes
80
80
  }
81
81
  end
82
82
  end
@@ -69,8 +69,10 @@ module Cheffish
69
69
  def json_to_resource(json)
70
70
  resource = resource_class.new(new_resource.name)
71
71
  keys.each do |json_key, resource_key|
72
- resource.send(resource_key, json[json_key])
72
+ resource.send(resource_key, json.delete(json_key))
73
73
  end
74
+ # Set the leftover to raw_json
75
+ resource.raw_json json
74
76
  resource
75
77
  end
76
78
 
@@ -94,5 +94,18 @@ class Chef
94
94
 
95
95
  with_chef_server(chef_zero_server.url, &block)
96
96
  end
97
+
98
+ def self.stop_local_servers
99
+ # Just in case we're running this out of order:
100
+ @@local_servers ||= []
101
+
102
+ # Stop the servers
103
+ @@local_servers.each do |server|
104
+ server.stop
105
+ end
106
+
107
+ # Clean up after ourselves (don't want to stop a server twice)
108
+ @@local_servers = []
109
+ end
97
110
  end
98
111
  end
@@ -1,4 +1,3 @@
1
1
  module Cheffish
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3'
3
3
  end
4
-
data/lib/cheffish.rb CHANGED
@@ -60,10 +60,7 @@ module Cheffish
60
60
  attribute :name, :kind_of => String, :regex => Cheffish::NAME_REGEX, :name_attribute => true
61
61
  attribute :chef_environment, :kind_of => String, :regex => Cheffish::NAME_REGEX
62
62
  attribute :run_list, :kind_of => Array # We should let them specify it as a series of parameters too
63
- attribute :default_attributes, :kind_of => Hash
64
- attribute :normal_attributes, :kind_of => Hash
65
- attribute :override_attributes, :kind_of => Hash
66
- attribute :automatic_attributes, :kind_of => Hash
63
+ attribute :attributes, :kind_of => Hash
67
64
 
68
65
  # Specifies that this is a complete specification for the environment (i.e. attributes you don't specify will be
69
66
  # reset to their defaults)
@@ -72,82 +69,28 @@ module Cheffish
72
69
  attribute :raw_json, :kind_of => Hash
73
70
  attribute :chef_server, :kind_of => Hash
74
71
 
75
- # default 'ip_address', '127.0.0.1'
76
- # default [ 'pushy', 'port' ], '9000'
77
- # default 'ip_addresses' do |existing_value|
72
+ # attribute 'ip_address', '127.0.0.1'
73
+ # attribute [ 'pushy', 'port' ], '9000'
74
+ # attribute 'ip_addresses' do |existing_value|
78
75
  # (existing_value || []) + [ '127.0.0.1' ]
79
76
  # end
80
- # default 'ip_address', :delete
81
- attr_accessor :default_modifiers
82
- def default(attribute_path, value=Cheffish.NOT_PASSED, &block)
83
- @default_modifiers ||= []
84
- if value != Cheffish.NOT_PASSED
85
- @default_modifiers << [ attribute_path, value ]
86
- elsif block
87
- @default_modifiers << [ attribute_path, block ]
88
- else
89
- raise "default requires either a value or a block"
90
- end
91
- end
92
-
93
- # normal 'ip_address', '127.0.0.1'
94
- # normal [ 'pushy', 'port' ], '9000'
95
- # normal 'ip_addresses' do |existing_value|
96
- # (existing_value || []) + [ '127.0.0.1' ]
97
- # end
98
- # normal 'ip_address', :delete
99
- attr_accessor :normal_modifiers
100
- def normal(attribute_path, value=NOT_PASSED, &block)
101
- @normal_modifiers ||= []
77
+ # attribute 'ip_address', :delete
78
+ attr_accessor :attribute_modifiers
79
+ def attribute(attribute_path, value=NOT_PASSED, &block)
80
+ @attribute_modifiers ||= []
102
81
  if value != NOT_PASSED
103
- @normal_modifiers << [ attribute_path, value ]
82
+ @attribute_modifiers << [ attribute_path, value ]
104
83
  elsif block
105
- @normal_modifiers << [ attribute_path, block ]
84
+ @attribute_modifiers << [ attribute_path, block ]
106
85
  else
107
- raise "normal requires either a value or a block"
108
- end
109
- end
110
-
111
- # override 'ip_address', '127.0.0.1'
112
- # override [ 'pushy', 'port' ], '9000'
113
- # override 'ip_addresses' do |existing_value|
114
- # (existing_value || []) + [ '127.0.0.1' ]
115
- # end
116
- # override 'ip_address', :delete
117
- attr_accessor :override_modifiers
118
- def override(attribute_path, value=NOT_PASSED, &block)
119
- @override_modifiers ||= []
120
- if value != NOT_PASSED
121
- @override_modifiers << [ attribute_path, value ]
122
- elsif block
123
- @override_modifiers << [ attribute_path, block ]
124
- else
125
- raise "override requires either a value or a block"
126
- end
127
- end
128
-
129
- # automatic 'ip_address', '127.0.0.1'
130
- # automatic [ 'pushy', 'port' ], '9000'
131
- # automatic 'ip_addresses' do |existing_value|
132
- # (existing_value || []) + [ '127.0.0.1' ]
133
- # end
134
- # automatic 'ip_address', :delete
135
- attr_accessor :automatic_modifiers
136
- def automatic(attribute_path, value=NOT_PASSED, &block)
137
- @automatic_modifiers ||= []
138
- if value != NOT_PASSED
139
- @automatic_modifiers << [ attribute_path, value ]
140
- elsif block
141
- @automatic_modifiers << [ attribute_path, block ]
142
- else
143
- raise "automatic requires either a value or a block"
86
+ raise "attribute requires either a value or a block"
144
87
  end
145
88
  end
146
89
 
147
90
  # Patchy tags
148
91
  # tag 'webserver', 'apache', 'myenvironment'
149
92
  def tag(*tags)
150
- normal 'tags' do |existing_tags|
93
+ attribute 'tags' do |existing_tags|
151
94
  existing_tags ||= []
152
95
  tags.each do |tag|
153
96
  if !existing_tags.include?(tag.to_s)
@@ -158,7 +101,7 @@ module Cheffish
158
101
  end
159
102
  end
160
103
  def remove_tag(*tags)
161
- normal 'tags' do |existing_tags|
104
+ attribute 'tags' do |existing_tags|
162
105
  if existing_tags
163
106
  tags.each do |tag|
164
107
  existing_tags.delete(tag.to_s)
@@ -172,17 +115,13 @@ module Cheffish
172
115
  # tags :a, :b, :c # removes all other tags
173
116
  def tags(*tags)
174
117
  if tags.size == 0
175
- normal('tags')
118
+ attribute('tags')
176
119
  else
177
120
  tags = tags[0] if tags.size == 1 && tags[0].kind_of?(Array)
178
- normal 'tags', tags.map { |tag| tag.to_s }
121
+ attribute 'tags', tags.map { |tag| tag.to_s }
179
122
  end
180
123
  end
181
124
 
182
-
183
- alias :attributes :normal_attributes
184
- alias :attribute :normal
185
-
186
125
  # Order matters--if two things here are in the wrong order, they will be flipped in the run list
187
126
  # recipe 'apache', 'mysql'
188
127
  # recipe 'recipe@version'
@@ -68,8 +68,78 @@ describe Chef::Resource::ChefNode do
68
68
  chef_node 'blah'
69
69
  end
70
70
 
71
- it 'the node "blah" does not get created or updated' do
71
+ it 'chef_node "blah" does not get created or updated' do
72
72
  chef_run.should_not have_updated 'chef_node[blah]', :create
73
73
  end
74
74
  end
75
+
76
+ when_the_chef_server 'has a node named "blah" with tags' do
77
+ node 'blah', {
78
+ 'normal' => { 'tags' => [ 'a', 'b' ] }
79
+ }
80
+
81
+ context 'with chef_node "blah" that sets attributes' do
82
+ with_recipe do
83
+ chef_node 'blah' do
84
+ attributes({})
85
+ end
86
+ end
87
+
88
+ it 'the tags in attributes are used' do
89
+ get('/nodes/blah')['normal']['tags'].should == [ 'a', 'b' ]
90
+ end
91
+ end
92
+
93
+ context 'with chef_node "blah" that sets attributes with tags in them' do
94
+ with_recipe do
95
+ chef_node 'blah' do
96
+ attributes 'tags' => [ 'c', 'd' ]
97
+ end
98
+ end
99
+
100
+ it 'the tags in attributes are used' do
101
+ get('/nodes/blah')['normal']['tags'].should == [ 'c', 'd' ]
102
+ end
103
+ end
104
+ end
105
+
106
+ when_the_chef_server 'has a node named "blah" with everything in it' do
107
+ node 'blah', {
108
+ 'chef_environment' => 'blah',
109
+ 'run_list' => [ 'recipe[bjork]' ],
110
+ 'normal' => { 'foo' => 'bar', 'tags' => [ 'a', 'b' ] },
111
+ 'default' => { 'foo2' => 'bar2' },
112
+ 'automatic' => { 'foo3' => 'bar3' },
113
+ 'override' => { 'foo4' => 'bar4' }
114
+ }
115
+
116
+ context 'with chef_node "blah"' do
117
+ with_recipe do
118
+ chef_node 'blah'
119
+ end
120
+
121
+ it 'nothing gets updated' do
122
+ chef_run.should_not have_updated 'chef_node[blah]', :create
123
+ end
124
+ end
125
+
126
+ context 'with chef_node "blah" with complete true' do
127
+ with_recipe do
128
+ chef_node 'blah' do
129
+ complete true
130
+ end
131
+ end
132
+
133
+ it 'default, automatic and override attributes are left alone' do
134
+ chef_run.should have_updated 'chef_node[blah]', :create
135
+ node = get('/nodes/blah')
136
+ node['chef_environment'].should == '_default'
137
+ node['run_list'].should == []
138
+ node['normal'].should == { 'tags' => [ 'a', 'b' ] }
139
+ node['default'].should == { 'foo2' => 'bar2' }
140
+ node['automatic'].should == { 'foo3' => 'bar3' }
141
+ node['override'].should == { 'foo4' => 'bar4' }
142
+ end
143
+ end
144
+ end
75
145
  end
@@ -87,6 +87,7 @@ require 'chef/platform'
87
87
  require 'chef/provider/service/simple'
88
88
  require 'chef/provider/service/init'
89
89
 
90
+ require 'chef/provider/batch'
90
91
  require 'chef/provider/cron'
91
92
  require 'chef/provider/cron/aix'
92
93
  require 'chef/provider/cron/solaris'
@@ -125,6 +126,7 @@ require 'chef/provider/package/solaris'
125
126
  require 'chef/provider/package/smartos'
126
127
  require 'chef/provider/package/yum'
127
128
  require 'chef/provider/package/zypper'
129
+ require 'chef/provider/powershell_script'
128
130
  require 'chef/provider/remote_directory'
129
131
  require 'chef/provider/route'
130
132
  require 'chef/provider/ruby_block'
@@ -138,6 +140,7 @@ require 'chef/provider/service/insserv'
138
140
  require 'chef/provider/service/macosx'
139
141
  require 'chef/provider/service/redhat'
140
142
  require 'chef/provider/service/solaris'
143
+ require 'chef/provider/service/systemd'
141
144
  require 'chef/provider/service/upstart'
142
145
  require 'chef/provider/service/windows'
143
146
  require 'chef/provider/template'
@@ -146,3 +149,4 @@ require 'chef/provider/user/pw'
146
149
  require 'chef/provider/user/useradd'
147
150
  require 'chef/provider/user/solaris'
148
151
  require 'chef/provider/user/windows'
152
+ require 'chef/provider/whyrun_safe_ruby_block'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cheffish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Keiser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-13 00:00:00.000000000 Z
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef