Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ source 'https://supermarket.chef.io'

metadata

group :test do
cookbook 'chef-services',
'>= 4.0.0',
git: 'https://github.com/stephenlauck/chef-services.git',
branch: 'ad/simplify_pkgs'
end
cookbook 'chef_test', path: 'test/fixtures/cookbooks/chef_test'
57 changes: 57 additions & 0 deletions libraries/matchers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
if defined?(ChefSpec)
def create_chef_automate(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_automate, :create, name)
end

def create_backend_cluster(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_backend, :create, name)
end

def join_backend_cluster(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_backend, :join, name)
end

def create_chef_org(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_org, :create, name)
end

def delete_chef_org(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_org, :delete, name)
end

def create_chef_user(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_user, :create, name)
end

def delete_chef_user(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_user, :delete, name)
end

def install_chef_client(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_client, :install, name)
end

def register_chef_client(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_client, :register, name)
end

def run_chef_client(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_client, :run, name)
end

def create_chef_file(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_file, :create, name)
end

def create_chef_server(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_server, :create, name)
end

def create_chef_supermarket(name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_supermarket, :create, name)
end

def create_build_node(name)
ChefSpec::Matchers::ResourceMatcher.new(:workflow_builder, :create, name)
end
end
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
long_description 'Resource Cookbook for Managing Chef Software Inc Product Suite'
issues_url 'https://github.com/ncerny/chef_stack/issues' if respond_to?(:issues_url)
source_url 'https://github.com/ncerny/chef_stack' if respond_to?(:source_url)
version '0.6.1'
version '0.6.2'

depends 'chef-ingredient'
19 changes: 9 additions & 10 deletions resources/automate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@
platform_version new_resource.platform_version if new_resource.platform_version
end

directory '/etc/delivery'
directory '/etc/chef'

directory '/var/opt/delivery/license/' do
recursive true
%w(/etc/delivery /etc/chef /var/opt/delivery/license).each do |dir|
directory dir do
recursive true
end
end

{
Expand All @@ -89,16 +88,16 @@
mode '0644'
end

directory '/var/opt/delivery/nginx/etc/addon.d/' do
directory '/var/opt/delivery/nginx/etc/addon.d' do
recursive true
end

file '/var/opt/delivery/nginx/etc/addon.d/99-installer_internal.conf' do
content <<-EOF
location /installer {
alias /opt/delivery/embedded/service/omnibus-ctl/installer;
}
EOF
location /installer {
alias /opt/delivery/embedded/service/omnibus-ctl/installer;
}
EOF
end

ingredient_config 'automate' do
Expand Down
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
require 'chefspec'
require 'chefspec/berkshelf'

at_exit { ChefSpec::Coverage.report! }
141 changes: 141 additions & 0 deletions spec/unit/chef_automate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#
# Cookbook Name:: chef_stack
# Spec:: chef_automate
#
# Copyright 2016 Chef Software Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

insecure_key = <<-EOS
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd
ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1
Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf
TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK
iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A
sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf
4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP
cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk
EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN
CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX
3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG
YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj
3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+
dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz
6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC
P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF
llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ
kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
+vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
-----END RSA PRIVATE KEY-----
EOS

require 'spec_helper'

describe 'chef_test::automate' do
cached(:centos_7_2) do
stub_command('delivery-ctl list-enterprises --ssh-pub-key-file=/etc/delivery/builder_key.pub | grep -w test').and_return(false)
stub_command('delivery-ctl status').and_return(true)
ChefSpec::ServerRunner.new(
step_into: 'chef_automate',
platform: 'centos',
version: '7.2.1511'
).converge(described_recipe)
end

context 'compiling the recipe' do
it 'creates chef_automate[automate.chefstack.local]' do
expect(centos_7_2).to create_chef_automate('automate.chefstack.local')
end
end

context 'stepping into chef_automate' do
it 'upgrades chef_ingredient[automate]' do
expect(centos_7_2).to upgrade_chef_ingredient('automate')
.with(
channel: :current,
version: '0.6.64',
accept_license: true,
enterprise: ['test'],
license: 'license',
chef_user: 'chef_user',
chef_user_pem: insecure_key,
validation_pem: insecure_key,
builder_pem: insecure_key
)
end

it 'creates required directories' do
[
'/var/opt/delivery/license',
'/etc/delivery',
'/etc/chef',
].each do |dir|
expect(centos_7_2).to create_directory(dir)
end
end

it 'creates automate keys' do
{
'/var/opt/delivery/license/delivery.license' => 'license',
'/etc/delivery/chef_user.pem' => insecure_key,
'/etc/chef/validation.pem' => insecure_key,
'/etc/delivery/builder_key' => insecure_key,
}.each do |file, src|
expect(centos_7_2).to create_chef_file(file)
.with(
source: src,
user: 'root',
group: 'root',
mode: '0600'
)
end
end

it 'creates the builder public key' do
expect(centos_7_2).to create_file('/etc/delivery/builder_key.pub')
.with(
user: 'root',
group: 'root',
mode: '0644'
)
end

it 'configures nginx to host installation files' do
expect(centos_7_2).to create_directory('/var/opt/delivery/nginx/etc/addon.d')
expect(centos_7_2).to create_file('/var/opt/delivery/nginx/etc/addon.d/99-installer_internal.conf')
.with(
content: <<-EOF
location /installer {
alias /opt/delivery/embedded/service/omnibus-ctl/installer;
}
EOF
)
end

it 'reconfigures automate' do
expect(centos_7_2).to render_ingredient_config('automate')
expect(centos_7_2.ingredient_config('automate')).to notify('chef_ingredient[automate]').to(:reconfigure).immediately
end

it 'configures automate enterprises' do
expect(centos_7_2).to run_execute('create enterprise test')
end
end
end
73 changes: 73 additions & 0 deletions spec/unit/chef_file_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
# Cookbook Name:: chef_stack
# Spec:: chef_file
#
# Copyright 2016 Chef Software Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'spec_helper'

describe 'chef_test::file' do
cached(:centos_7_2) do
ChefSpec::ServerRunner.new(
step_into: 'chef_file',
platform: 'centos',
version: '7.2.1511'
).converge(described_recipe)
end

context 'compiling the recipe' do
it 'creates chef_file[/tmp/uri.test]' do
expect(centos_7_2).to create_chef_file('/tmp/remote_file')
end
it 'creates chef_file[/tmp/cookbook.test]' do
expect(centos_7_2).to create_chef_file('/tmp/cookbook_file')
end
it 'creates chef_file[/tmp/content.test]' do
expect(centos_7_2).to create_chef_file('/tmp/file')
end
end

context 'stepping into chef_file' do
it 'correctly creates cookbook_files' do
expect(centos_7_2).to create_cookbook_file('/tmp/cookbook_file')
.with(
source: 'testfile',
cookbook: 'chef_test',
user: 'root',
group: 'root',
mode: '0600'
)
end
it 'correctly creates remote_files' do
expect(centos_7_2).to create_remote_file('/tmp/remote_file')
.with(
source: 'https://www.example.com/test',
user: 'root',
group: 'root',
mode: '0600'
)
end
it 'correctly creates files' do
expect(centos_7_2).to create_file('/tmp/file')
.with(
content: 'abcdef',
user: 'root',
group: 'root',
mode: '0600'
)
expect(centos_7_2).to render_file('/tmp/file').with_content('abcdef')
end
end
end
32 changes: 0 additions & 32 deletions spec/unit/recipes/default_spec.rb

This file was deleted.

4 changes: 4 additions & 0 deletions test/fixtures/cookbooks/chef_test/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name 'chef_test'
version '0.1.0'

depends 'chef_stack'
Loading