Skip to content

Commit 3dcac46

Browse files
committed
Merge pull request #2 from chef-cookbooks/jtimberman/product-names
Use product keys as the name attribute
2 parents 260b724 + efabfa7 commit 3dcac46

File tree

14 files changed

+142
-62
lines changed

14 files changed

+142
-62
lines changed

PRODUCT_MATRIX.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Update this in lockstep with `#product_matrix` in `libraries/helpers.rb`
2+
3+
| Product | Product Key | Package Name |
4+
| ---------- | ------------------ | -------------------- |
5+
| Chef Client | chef | chef |
6+
| Chef Development Kit | chefdk| chefdk |
7+
| Enterprise Chef (legacy) | private-chef | private-chef |
8+
| Chef Server | chef-server | chef-server (versions < 12.0.0) <br/> chef-server-core (versions >= 12.0.0) |
9+
| Chef Server High Availability addon | chef-ha | chef-ha |
10+
| Chef Server Replication addon | chef-sync | chef-sync |
11+
| Chef Server Reporting addon | reporting | opscode-reporting |
12+
| Management Console | manage | opscode-manage (versions < 2.0.0) <br/> chef-manage (versions >= 2.0.0) |
13+
| Push Jobs Server | chef-push-server | opscode-push-jobs-server |
14+
| Push Jobs Client | chef-push-client | opscode-push-jobs-client (versions < 2.0.0) <br/> chef-push-client (versions >= 2.0.0) |
15+
| Analytics Platform | analytics | opscode-analytics |
16+
| Delivery | delivery | delivery |
17+
| Delivery CLI | delivery-cli | delivery-cli |
18+
| Supermarket | supermarket | supermarket |

README.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ This cookbook provides primitives - helpers and resources - to manage Chef Softw
99

1010
It will perform component installation and configuration. It provides no recipes. Instead, wrapper cookbooks should be created using the resources that this cookbook provides.
1111

12+
For a product to package matrix, see [PRODUCT_MATRIX.md](https://github.com/chef-cookbooks/chef-ingredient/blob/master/PRODUCT_MATRIX.md)
13+
1214
## Requirements
1315

1416
- apt
@@ -37,7 +39,8 @@ A "chef ingredient" is the core package itself, or products or add-on components
3739
- `reconfigure` - Performs the `ctl reconfigure` command for the package.
3840

3941
#### Properties
40-
- `package_name`: (name attribute) The name of the package. Should correspond to the published package names (chef-server-core, opscode-manage, etc).
42+
- `product_name`: (name attribute) The product name. See the [PRODUCT_MATRIX.md](https://github.com/chef-cookbooks/chef-ingredient/blob/master/PRODUCT_MATRIX.md). For example, `chef-server`, `analytics`, `delivery`, `manage`, etc.
43+
- `package_name`: The name of the package in the repository. Should correspond to the published package names (`chef-server-core`, `opscode-manage`, etc).
4144
- `ctl_command`: The "ctl" command, e.g., `chef-server-ctl`. This should be automatically detected by the library helper method `chef_ctl_command`, but may need to be specified if something changes, like a new add-on is made available.
4245
- `options`: Options passed to the `package` resource used for installation.
4346
- `version`: Package version, e.g., `12.0.4`. Do not use if specifying `package_source`. Default `nil`.
@@ -55,7 +58,7 @@ This delegates to the ctl command the service management command specified in th
5558
#### Properties
5659

5760
- `ctl_command`: The "ctl" command, e.g. `chef-server-ctl`. This should be automatically detected by the library helper method `chef_ctl_command`, but may need to be specified if something changes, like a new add-on is made available.
58-
- `service_name`: (name attribute) The name of the service to manage. Specify this like `package_name/service`, for example, `chef-server-core/rabbitmq`.
61+
- `service_name`: (name attribute) The name of the service to manage. Specify this like `product_name/service`, for example, `chef-server/rabbitmq`.
5962

6063
#### Examples
6164

libraries/chef_ingredient_provider.rb

+16-11
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,30 @@ def whyrun_supported?
3434
end
3535

3636
action :install do
37-
if new_resource.version
38-
# We need Mixlib::Versioning in the library helpers for
39-
# parsing the version string. But only if the version is
40-
# specified!
41-
chef_gem 'mixlib-versioning' do
42-
compile_time true
43-
end
44-
45-
require 'mixlib/versioning'
37+
# We need Mixlib::Versioning in the library helpers for
38+
# parsing the version string.
39+
chef_gem "#{new_resource.product_name}-mixlib-versioning" do
40+
package_name 'mixlib-versioning'
41+
compile_time true
4642
end
4743

44+
require 'mixlib/versioning'
45+
4846
cleanup_old_repo_config if ::File.exist?(old_ingredient_repo_file)
4947
include_recipe "#{package_repo_type}-chef" if new_resource.package_source.nil?
5048

5149
package_resource = new_resource.package_source.nil? ? :package : local_package_resource
5250

53-
declare_resource package_resource, new_resource.package_name do
51+
pkg_name = if new_resource.package_name
52+
new_resource.package_name
53+
else
54+
product_lookup(new_resource.product_name, new_resource.version)['package-name']
55+
end
56+
57+
declare_resource package_resource, new_resource.product_name do
58+
package_name pkg_name
5459
options new_resource.options
55-
version install_version if new_resource.version
60+
version install_version if Mixlib::Versioning.parse(new_resource.version) > '0.0.0'
5661
source new_resource.package_source
5762
timeout new_resource.timeout
5863
end

libraries/chef_ingredient_resource.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,21 @@ class ChefIngredient < Chef::Resource::LWRPBase
2323
default_action :install
2424
state_attrs :installed
2525

26-
attribute :package_name, kind_of: String, name_attribute: true
26+
attribute :product_name, kind_of: String, name_attribute: true
27+
attribute :package_name, kind_of: String
2728
attribute :installed, kind_of: [TrueClass, FalseClass, NilClass], default: false
2829
attribute :reconfigure, kind_of: [TrueClass, FalseClass], default: false
2930
attribute :config, kind_of: [Hash, Mash], default: {}
3031

31-
# Attributes to install package from local file
32+
# Attribute to install package from local file
3233
attribute :package_source, kind_of: String, default: nil
3334

3435
# Attributes for reconfigure step
3536
attribute :ctl_command, kind_of: String
3637

3738
# Attributes for package
3839
attribute :options, kind_of: String
39-
attribute :version, kind_of: String, default: nil
40+
attribute :version, kind_of: String, default: '0.0.0'
4041
attribute :timeout, kind_of: [Integer, String, NilClass], default: nil
4142
end
4243
end

libraries/helpers.rb

+67-14
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,12 @@
1717

1818
module ChefIngredientCookbook
1919
module Helpers
20-
# FIXME: (jtimberman) make this data we can change / use without
21-
# having to update the library code (e.g., if we create new
22-
# add-ons, or change any of these in the future).
23-
def chef_ctl_command(pkg)
24-
ctl_cmds = {
25-
'chef-server-core' => 'chef-server-ctl',
26-
'opscode-manage' => 'opscode-manage-ctl',
27-
'opscode-push-jobs-server' => 'opscode-push-jobs-server-ctl',
28-
'opscode-reporting' => 'opscode-reporting-ctl',
29-
'opscode-analytics' => 'opscode-analytics-ctl',
30-
'chef-sync' => 'chef-sync-ctl',
31-
'supermarket' => 'supermarket-ctl'
32-
}
33-
ctl_cmds[pkg]
20+
def chef_ctl_command(product)
21+
if new_resource.respond_to?(:version)
22+
product_lookup(product, new_resource.version)['ctl-command']
23+
else
24+
product_lookup(product)['ctl-command']
25+
end
3426
end
3527

3628
def local_package_resource
@@ -86,6 +78,67 @@ def reconfigure
8678
command "#{ctl_cmd} reconfigure"
8779
end
8880
end
81+
82+
# When updating this, also update PRODUCT_MATRIX.md
83+
def product_matrix
84+
{
85+
'analytics' => {'package-name' => 'opscode-analytics', 'ctl-command' => 'opscode-analytics-ctl' },
86+
'chef' => {'package-name' => 'chef', 'ctl-command' => nil },
87+
'chef-ha' => {'package-name' => 'chef-ha', 'ctl-command' => nil },
88+
'chef-server' => {'package-name' => 'chef-server-core', 'ctl-command' => 'chef-server-ctl' },
89+
'chef-sync' => {'package-name' => 'chef-sync', 'ctl-command' => 'chef-sync-ctl' },
90+
'chefdk' => {'package-name' => 'chefdk', 'ctl-command' => nil },
91+
'delivery' => {'package-name' => 'delivery', 'ctl-command' => 'delivery-ctl' },
92+
'delivery-cli' => {'package-name' => 'delivery-cli', 'ctl-command' => nil },
93+
'manage' => {'package-name' => 'chef-manage', 'ctl-command' => 'chef-manage-ctl' },
94+
'private-chef' => {'package-name' => 'private-chef', 'ctl-command' => 'private-chef-ctl' },
95+
'push-client' => {'package-name' => 'chef-push-client', 'ctl-command' => nil },
96+
'push-server' => {'package-name' => 'chef-push-server', 'ctl-command' => 'chef-push-ctl' },
97+
'reporting' => {'package-name' => 'opscode-reporting', 'ctl-command' => 'opscode-reporting-ctl' },
98+
'supermarket' => {'package-name' => 'supermarket', 'ctl-command' => 'supermarket-ctl' },
99+
}
100+
end
101+
102+
# Version has a default value of 0.0.0 so that it is a valid
103+
# string for the Mixlib::Versioning.parse method. This implies
104+
# "latest", but "latest" is not a value that is valid for
105+
# mixlib/versioning.
106+
def product_lookup(product, version = '0.0.0')
107+
unless product_matrix.has_key?(product)
108+
Chef::Log.fatal("We don't have a product, '#{product}'. Please specify a valid product name:")
109+
Chef::Log.fatal(product_matrix.keys.join(' '))
110+
fail
111+
end
112+
113+
require 'mixlib/versioning'
114+
v = Mixlib::Versioning.parse(version)
115+
116+
data = product_matrix[product]
117+
118+
# We want to validate that we're getting a version that is valid
119+
# for the Chef Server. However, since the default is 0.0.0,
120+
# implying latest, we need to additionally ensure that the
121+
# bottom version is something valid. If we don't have the check
122+
# in the elsif, it will say that 0.0.0 is not a valid version.
123+
if (product == 'chef-server')
124+
if (v < Mixlib::Versioning.parse('12.0.0') && v > Mixlib::Versioning.parse('11.0.0'))
125+
data['package-name'] = 'chef-server'
126+
elsif (v < Mixlib::Versioning.parse('11.0.0')) && (v > Mixlib::Versioning.parse('1.0.0'))
127+
Chef::Log.fatal("Invalid version specified, '#{version}' for #{product}!")
128+
fail
129+
end
130+
elsif (product == 'manage') && (v < Mixlib::Versioning.parse('2.0.0'))
131+
data['package-name'] = 'opscode-manage'
132+
data['ctl-command'] = 'opscode-manage-ctl'
133+
elsif (product == 'push-server') && (v < Mixlib::Versioning.parse('2.0.0'))
134+
data['package-name'] = 'chef-push-server'
135+
data['ctl-command'] = 'chef-push-ctl'
136+
elsif (product == 'push-client') && (v < Mixlib::Versioning.parse('2.0.0'))
137+
data['package-name'] = 'chef-push-client'
138+
end
139+
140+
data
141+
end
89142
end
90143
end
91144

spec/centos_65_spec.rb

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@
1212
end.converge('test::repo')
1313
end
1414

15-
it 'installs chef_ingredient[chef-server-core]' do
16-
expect(centos_65).to install_chef_ingredient('chef-server-core')
15+
it 'installs chef_ingredient[chef-server]' do
16+
expect(centos_65).to install_chef_ingredient('chef-server')
1717
end
1818

19-
it 'installs yum_package[chef-server-core]' do
19+
it 'installs yum_package[chef-server]' do
2020
expect(centos_65).to install_yum_package('chef-server-core')
2121
end
2222

2323
it 'creates file[/tmp/chef-server-core.firstrun]' do
2424
expect(centos_65).to create_file('/tmp/chef-server-core.firstrun')
2525
end
2626

27-
it 'installs chef_server_ingredient[opscode-manage]' do
28-
expect(centos_65).to install_chef_server_ingredient('opscode-manage')
27+
it 'installs chef_server_ingredient[manage]' do
28+
expect(centos_65).to install_chef_server_ingredient('manage')
2929
end
3030

3131
it 'installs yum_package[opscode-manage]' do
@@ -60,23 +60,23 @@
6060
end
6161

6262
context 'package iteration version specified' do
63-
cached(:ubuntu_1404) do
63+
cached(:centos_65) do
6464
ChefSpec::SoloRunner.new(
65-
platform: 'ubuntu',
66-
version: '14.04',
65+
platform: 'centos',
66+
version: '6.5',
6767
step_into: ['chef_ingredient']
6868
) do |node|
6969
node.set['test']['chef-server-core']['version'] = '12.0.4-1'
7070
end.converge('test::repo')
7171
end
7272

7373
it 'installs the mixlib-versioning gem' do
74-
expect(ubuntu_1404).to install_chef_gem('mixlib-versioning')
74+
expect(centos_65).to install_chef_gem('mixlib-versioning')
7575
end
7676

7777
it 'installs the package with the release version string' do
78-
expect(ubuntu_1404).to install_apt_package('chef-server-core').with(
79-
version: '12.0.4-1'
78+
expect(centos_65).to install_yum_package('chef-server-core').with(
79+
version: '12.0.4-1.el6'
8080
)
8181
end
8282
end
@@ -117,7 +117,7 @@
117117
end
118118

119119
it 'installs chef_ingredient[chef-server-core]' do
120-
expect(centos_65).to install_chef_ingredient('chef-server-core')
120+
expect(centos_65).to install_chef_ingredient('chef-server')
121121
end
122122

123123
it 'uses the rpm_package provider instead of yum_package' do

spec/omnibus_service_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
let(:log_message) { chef_run.log('I tell nginx to stop')}
1111

1212
it 'allows the chef-server-core/rabbitmq service to restart' do
13-
expect(chef_run).to restart_omnibus_service('chef-server-core/rabbitmq')
13+
expect(chef_run).to restart_omnibus_service('chef-server/rabbitmq')
1414
end
1515

1616
it 'restarts the rabbitmq service' do
1717
expect(chef_run).to run_execute('chef-server-ctl restart rabbitmq')
1818
end
1919

2020
it 'has a log service that notifies the chef server nginx' do
21-
expect(log_message).to notify('omnibus_service[chef-server-core/nginx]').to(:stop)
21+
expect(log_message).to notify('omnibus_service[chef-server/nginx]').to(:stop)
2222
end
2323

2424
it 'starts with a made up service' do

spec/ubuntu_1404_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
end
1414

1515
it 'installs chef_ingredient[chef-server-core]' do
16-
expect(ubuntu_1404).to install_chef_ingredient('chef-server-core')
16+
expect(ubuntu_1404).to install_chef_ingredient('chef-server')
1717
end
1818

1919
it 'installs apt_package[chef-server-core]' do
@@ -24,8 +24,8 @@
2424
expect(ubuntu_1404).to create_file('/tmp/chef-server-core.firstrun')
2525
end
2626

27-
it 'installs chef_server_ingredient[opscode-manage]' do
28-
expect(ubuntu_1404).to install_chef_server_ingredient('opscode-manage')
27+
it 'installs chef_server_ingredient[manage]' do
28+
expect(ubuntu_1404).to install_chef_server_ingredient('manage')
2929
end
3030

3131
it 'installs apt_package[opscode-manage]' do
@@ -116,8 +116,8 @@
116116
end.converge('test::local')
117117
end
118118

119-
it 'installs chef_ingredient[chef-server-core]' do
120-
expect(ubuntu_1404).to install_chef_ingredient('chef-server-core')
119+
it 'installs chef_ingredient[chef-server]' do
120+
expect(ubuntu_1404).to install_chef_ingredient('chef-server')
121121
end
122122

123123
it 'uses the dpkg_package provider instead of apt_package' do

test/fixtures/cookbooks/test/recipes/local.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
mode '0644'
1010
end
1111

12-
chef_ingredient 'chef-server-core' do
12+
chef_ingredient 'chef-server' do
1313
package_source "#{cache_path}/#{pkgname}"
1414
action :install
1515
end
1616

1717
file '/tmp/chef-server-core.firstrun' do
1818
content 'ilovechef\n'
19-
notifies :reconfigure, 'chef_ingredient[chef-server-core]'
19+
notifies :reconfigure, 'chef_ingredient[chef-server]'
2020
action :create
2121
end

test/fixtures/cookbooks/test/recipes/omnibus_service.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# we probably don't need/want to add this to a test kitchen suite.
22
# This here so we can test with chefspec, really.
3-
omnibus_service 'chef-server-core/rabbitmq' do
3+
omnibus_service 'chef-server/rabbitmq' do
44
action :restart
55
end
66

7-
omnibus_service 'chef-server-core/nginx' do
7+
omnibus_service 'chef-server/nginx' do
88
action :nothing
99
end
1010

1111
log 'I tell nginx to stop' do
12-
notifies :stop, 'omnibus_service[chef-server-core/nginx]'
12+
notifies :stop, 'omnibus_service[chef-server/nginx]'
1313
end
1414

1515
omnibus_service 'never-never/land' do
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Chef Server Core
2-
chef_ingredient 'chef-server-core' do
2+
chef_ingredient 'chef-server' do
33
version node['test']['chef-server-core']['version']
44
action :install
55
end
66

77
file '/tmp/chef-server-core.firstrun' do
88
content 'ilovechef\n'
9-
notifies :reconfigure, 'chef_ingredient[chef-server-core]'
9+
notifies :reconfigure, 'chef_ingredient[chef-server]'
1010
action :create
1111
end
1212

1313
# Management Console - using the compat shim resource
14-
chef_server_ingredient 'opscode-manage' do
14+
chef_server_ingredient 'manage' do
1515
action :install
1616
end
1717

1818
file '/tmp/opscode-manage.firstrun' do
1919
content 'ilovechef\n'
20-
notifies :reconfigure, 'chef_server_ingredient[opscode-manage]'
20+
notifies :reconfigure, 'chef_server_ingredient[manage]'
2121
action :create
2222
end

0 commit comments

Comments
 (0)