chef-container 0.0.1 → 0.0.2.pre.dev
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/chef-container.gemspec +2 -0
- data/lib/chef/container.rb +12 -6
- data/lib/chef/container/runit.rb +3 -99
- data/lib/chef/container/version.rb +1 -1
- data/lib/chef/provider/container_service_runit.rb +84 -0
- data/lib/chef/provider/service/{chef_container.rb → container.rb} +12 -8
- data/lib/chef/resource/container_service_runit.rb +36 -0
- data/spec/data/cookbooks/foo/recipes/default.rb +1 -1
- data/spec/data/cookbooks/foo/recipes/runit.rb +6 -0
- data/spec/functional/container_service_runit_spec.rb +21 -0
- data/spec/functional/container_service_spec.rb +13 -0
- data/spec/spec_helper.rb +0 -1
- metadata +27 -10
- data/LICENSE.txt +0 -22
- data/spec/container_init_recipe_spec.rb +0 -61
- data/spec/container_init_resource_spec.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d71498b231ebf09e380f743f26230be576ca6e9b
|
4
|
+
data.tar.gz: 8df8ffc772c998c64aae9548a2963244853e1670
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d0450ec3edafaeb03f8e704e46741785e972ad572fbd74eb829111f2ce6cf71a6dd1f15e8e3b40805c5013df820931516b021566f824d156b866c93183ef7c4
|
7
|
+
data.tar.gz: b7821cac01ff4497e334a2077432d0f9e552365b81a80cb020d65df17148ba7ef28a0ec65049e5f71e66d75ddb38261ff09bc9b9be92f9043dc992bf197ad6cb
|
data/chef-container.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_runtime_dependency 'chef', '~> 11.0'
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
24
|
spec.add_development_dependency "rake"
|
23
25
|
end
|
data/lib/chef/container.rb
CHANGED
@@ -1,16 +1,22 @@
|
|
1
1
|
require 'chef/container/version'
|
2
|
-
require 'chef/
|
2
|
+
require 'chef/resource/container_service_runit'
|
3
|
+
require 'chef/provider/container_service_runit'
|
4
|
+
require 'chef/provider/service/container'
|
3
5
|
|
4
6
|
class Chef
|
5
7
|
class Recipe
|
6
|
-
def
|
8
|
+
def container_service(name, &block)
|
7
9
|
begin
|
8
10
|
# Find the corresponding `service` resource and override the provider
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
service_resource = resources("service[#{name}]")
|
12
|
+
service_resource.provider = Chef::Provider::Service::ChefContainer
|
13
|
+
|
14
|
+
# Setup the runit service
|
15
|
+
runit_service = Chef::Resource::ContainerServiceRunit.new(service_resource.service_name, @run_context)
|
16
|
+
runit_service.instance_eval(&block) if block
|
17
|
+
runit_service.run_action(:enable)
|
12
18
|
rescue Chef::Exceptions::ResourceNotFound => e
|
13
|
-
Chef::Log.info "Resource service[#{
|
19
|
+
Chef::Log.info "Resource service[#{name}] not found."
|
14
20
|
raise e
|
15
21
|
else
|
16
22
|
# other exception
|
data/lib/chef/container/runit.rb
CHANGED
@@ -1,106 +1,10 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
1
|
|
18
2
|
class Chef
|
19
3
|
module Container
|
20
4
|
module Runit
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
def setup
|
26
|
-
@sv_bin = '/opt/chef/embedded/bin/sv'
|
27
|
-
@sv_dir = '/opt/chef/embedded/sv'
|
28
|
-
@service_dir = '/opt/chef/embedded/service'
|
29
|
-
|
30
|
-
Chef::Log.debug "Creating sv_dir for #{new_resource.name}"
|
31
|
-
sv_dir.run_action(:create)
|
32
|
-
|
33
|
-
Chef::Log.debug "Creating run_script for #{new_resource.name}"
|
34
|
-
run_script.run_action(:create)
|
35
|
-
|
36
|
-
Chef::Log.debug "Setting up svlog for #{new_resource.name}"
|
37
|
-
default_log_dir.run_action(:create)
|
38
|
-
log_dir.run_action(:create)
|
39
|
-
log_run_script.run_action(:create)
|
40
|
-
end
|
41
|
-
|
42
|
-
#
|
43
|
-
# Helper Resource Methods
|
44
|
-
#
|
45
|
-
def sv_dir_name
|
46
|
-
::File.join(@service_resource.sv_dir, new_resource.service_name)
|
47
|
-
end
|
48
|
-
|
49
|
-
def service_dir_name
|
50
|
-
::File.join(new_resource.service_dir, new_resource.service_name)
|
51
|
-
end
|
52
|
-
|
53
|
-
def run_script_content(command)
|
54
|
-
"#!/bin/sh\n#{command} 2&>1"
|
55
|
-
end
|
56
|
-
|
57
|
-
def log_run_script_content
|
58
|
-
"#!/bin/sh\nexec svlogd -tt /var/log/#{new_resource.service_name}"
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# Helper Resources
|
63
|
-
#
|
64
|
-
def sv_dir
|
65
|
-
return @sv_dir unless @sv_dir.nil?
|
66
|
-
@sv_dir = Chef::Resource::Directory.new(sv_dir_name, run_context)
|
67
|
-
@sv_dir.recursive(true)
|
68
|
-
@sv_dir.mode(00755)
|
69
|
-
@sv_dir
|
70
|
-
end
|
71
|
-
|
72
|
-
def run_script
|
73
|
-
return @run_script unless @run_script.nil?
|
74
|
-
@run_script = Chef::Resource::File.new(::File.join(sv_dir_name, 'run'), run_context)
|
75
|
-
@run_script.content(run_script_content(new_resource.command))
|
76
|
-
@run_script.mode(00755)
|
77
|
-
@run_script
|
78
|
-
end
|
79
|
-
|
80
|
-
def default_log_dir
|
81
|
-
return @default_log_dir unless @default_log_dir.nil?
|
82
|
-
@default_log_dir = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context)
|
83
|
-
@default_log_dir.recursive(true)
|
84
|
-
@default_log_dir.mode(00755)
|
85
|
-
@default_log_dir
|
86
|
-
end
|
87
|
-
|
88
|
-
def log_dir
|
89
|
-
return @log_dir unless @log_dir.nil?
|
90
|
-
@log_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context)
|
91
|
-
@log_dir.recursive(true)
|
92
|
-
@log_dir.mode(00755)
|
93
|
-
@log_dir
|
94
|
-
end
|
95
|
-
|
96
|
-
def log_run_script
|
97
|
-
return @log_run_script unless @log_run_script.nil?
|
98
|
-
@log_run_script = Chef::Resource::File.new(::File.join(sv_dir_name, 'log', 'run'))
|
99
|
-
@log_run_script.content(log_run_script_content)
|
100
|
-
@log_run_script.mode(00755)
|
101
|
-
@log_run_script
|
102
|
-
end
|
103
|
-
|
5
|
+
SV_BIN = '/opt/chef/embedded/bin/sv'
|
6
|
+
SV_DIR = '/opt/chef/embedded/sv'
|
7
|
+
SERVICE_DIR = '/opt/chef/embedded/service'
|
104
8
|
end
|
105
9
|
end
|
106
10
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
require 'chef/provider/lwrp_base'
|
18
|
+
|
19
|
+
class Chef
|
20
|
+
class Provider
|
21
|
+
class ContainerServiceRunit < Chef::Provider::LWRPBase
|
22
|
+
|
23
|
+
def whyrun_supported?
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
use_inline_resources
|
28
|
+
|
29
|
+
action :enable do
|
30
|
+
converge_by "Creating sv_dir for #{new_resource.name}" do
|
31
|
+
directory sv_dir_name do
|
32
|
+
recursive true
|
33
|
+
mode '0755'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
converge_by "Creating run_script for #{new_resource.name}" do
|
38
|
+
file ::File.join(sv_dir_name, 'run') do
|
39
|
+
content run_script_content
|
40
|
+
mode '0755'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
converge_by "Setting up svlog for #{new_resource.name}" do
|
45
|
+
directory "/var/log/#{new_resource.service_name}" do
|
46
|
+
recursive true
|
47
|
+
mode '0755'
|
48
|
+
end
|
49
|
+
|
50
|
+
directory ::File.join(sv_dir_name, 'log') do
|
51
|
+
recursive true
|
52
|
+
mode '0755'
|
53
|
+
end
|
54
|
+
|
55
|
+
file ::File.join(sv_dir_name, 'log', 'run') do
|
56
|
+
content log_run_script_content
|
57
|
+
mode '0755'
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
#
|
64
|
+
# Helper Resource Methods
|
65
|
+
#
|
66
|
+
def sv_dir_name
|
67
|
+
::File.join(new_resource.sv_dir, new_resource.service_name)
|
68
|
+
end
|
69
|
+
|
70
|
+
def service_dir_name
|
71
|
+
::File.join(new_resource.service_dir, new_resource.service_name)
|
72
|
+
end
|
73
|
+
|
74
|
+
def run_script_content
|
75
|
+
"#!/bin/sh\n#{new_resource.command} 2&>1"
|
76
|
+
end
|
77
|
+
|
78
|
+
def log_run_script_content
|
79
|
+
"#!/bin/sh\nexec svlogd -tt /var/log/#{new_resource.service_name}"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -26,8 +26,12 @@ require 'chef/container/runit'
|
|
26
26
|
class Chef
|
27
27
|
class Provider
|
28
28
|
class Service
|
29
|
+
# container_service
|
29
30
|
class ChefContainer < Chef::Provider::Service
|
30
|
-
|
31
|
+
|
32
|
+
def initialize(*args)
|
33
|
+
super
|
34
|
+
end
|
31
35
|
|
32
36
|
#
|
33
37
|
# Override Service Actions
|
@@ -51,25 +55,25 @@ class Chef
|
|
51
55
|
end
|
52
56
|
|
53
57
|
def disable_service
|
54
|
-
shell_out("#{
|
58
|
+
shell_out("#{Chef::Container::Runit::SV_BIN} down #{service_dir_name}")
|
55
59
|
Chef::Log.debug("#{new_resource} down")
|
56
60
|
FileUtils.rm(service_dir_name)
|
57
61
|
Chef::Log.debug("#{new_resource} service symlink removed")end
|
58
62
|
|
59
63
|
def start_service
|
60
|
-
shell_out!("#{
|
64
|
+
shell_out!("#{Chef::Container::Runit::SV_BIN} start #{service_dir_name}")
|
61
65
|
end
|
62
66
|
|
63
67
|
def stop_service
|
64
|
-
shell_out!("#{
|
68
|
+
shell_out!("#{Chef::Container::Runit::SV_BIN} stop #{service_dir_name}")
|
65
69
|
end
|
66
70
|
|
67
71
|
def restart_service
|
68
|
-
shell_out!("#{
|
72
|
+
shell_out!("#{Chef::Container::Runit::SV_BIN} restart #{service_dir_name}")
|
69
73
|
end
|
70
74
|
|
71
75
|
def reload_service
|
72
|
-
shell_out!("#{
|
76
|
+
shell_out!("#{Chef::Container::Runit::SV_BIN} force-reload #{service_dir_name}")
|
73
77
|
end
|
74
78
|
|
75
79
|
|
@@ -77,11 +81,11 @@ class Chef
|
|
77
81
|
# Helper Resource Methods
|
78
82
|
#
|
79
83
|
def sv_dir_name
|
80
|
-
::File.join(
|
84
|
+
::File.join(Chef::Container::Runit::SV_DIR, new_resource.service_name)
|
81
85
|
end
|
82
86
|
|
83
87
|
def service_dir_name
|
84
|
-
::File.join(
|
88
|
+
::File.join(Chef::Container::Runit::SERVICE_DIR, new_resource.service_name)
|
85
89
|
end
|
86
90
|
|
87
91
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
#
|
17
|
+
require 'chef/resource/lwrp_base'
|
18
|
+
require 'chef/container/runit'
|
19
|
+
|
20
|
+
class Chef
|
21
|
+
class Resource
|
22
|
+
class ContainerServiceRunit < Chef::Resource::LWRPBase
|
23
|
+
self.resource_name = "container_service_runit"
|
24
|
+
|
25
|
+
actions :enable, :disable
|
26
|
+
default_action :enable
|
27
|
+
|
28
|
+
attribute :service_name, :kind_of => String, :name_attribute => true
|
29
|
+
attribute :command, :kind_of => String, :required => true
|
30
|
+
attribute :sv_bin, :kind_of => String, :default => Chef::Container::Runit::SV_BIN
|
31
|
+
attribute :sv_dir, :kind_of => String, :default => Chef::Container::Runit::SV_DIR
|
32
|
+
attribute :service_dir, :kind_of => String, :default => Chef::Container::Runit::SERVICE_DIR
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'chefspec'
|
3
|
+
|
4
|
+
describe "container_service_runit" do
|
5
|
+
cookbook_dir = ::File.expand_path("../../data/cookbooks", __FILE__)
|
6
|
+
let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04', cookbook_path: cookbook_dir, step_into: ['container_service_runit']).converge('foo::runit') }
|
7
|
+
|
8
|
+
it "should create sv_dir" do
|
9
|
+
expect(chef_run).to create_directory "/opt/chef/embedded/sv/apache2"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create run_script" do
|
13
|
+
expect(chef_run).to create_file "/opt/chef/embedded/sv/apache2/run"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should setup svlog" do
|
17
|
+
expect(chef_run).to create_directory "/var/log/apache2"
|
18
|
+
expect(chef_run).to create_directory "/opt/chef/embedded/sv/apache2/log"
|
19
|
+
expect(chef_run).to create_file "/opt/chef/embedded/sv/apache2/log/run"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'chefspec'
|
3
|
+
|
4
|
+
describe "container_service" do
|
5
|
+
cookbook_dir = ::File.expand_path("../../data/cookbooks", __FILE__)
|
6
|
+
let(:chef_run) { ChefSpec::Runner.new(platform: 'ubuntu', version: '12.04', cookbook_path: cookbook_dir) }
|
7
|
+
|
8
|
+
it "replaces the provider of the corresponding service resource with Chef::Provider::Service::ChefContainer" do
|
9
|
+
chef_run.converge('foo::default')
|
10
|
+
service_resource = chef_run.run_context.resource_collection.find("service[apache2]")
|
11
|
+
expect(service_resource.provider).to eql(Chef::Provider::Service::ChefContainer)
|
12
|
+
end
|
13
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-container
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2.pre.dev
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Duffield
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: chef
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '11.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '11.0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -50,18 +64,20 @@ files:
|
|
50
64
|
- ".gitignore"
|
51
65
|
- Gemfile
|
52
66
|
- LICENSE
|
53
|
-
- LICENSE.txt
|
54
67
|
- README.md
|
55
68
|
- Rakefile
|
56
69
|
- chef-container.gemspec
|
57
70
|
- lib/chef/container.rb
|
58
71
|
- lib/chef/container/runit.rb
|
59
72
|
- lib/chef/container/version.rb
|
60
|
-
- lib/chef/provider/
|
61
|
-
-
|
62
|
-
-
|
73
|
+
- lib/chef/provider/container_service_runit.rb
|
74
|
+
- lib/chef/provider/service/container.rb
|
75
|
+
- lib/chef/resource/container_service_runit.rb
|
63
76
|
- spec/data/cookbooks/foo/metadata.rb
|
64
77
|
- spec/data/cookbooks/foo/recipes/default.rb
|
78
|
+
- spec/data/cookbooks/foo/recipes/runit.rb
|
79
|
+
- spec/functional/container_service_runit_spec.rb
|
80
|
+
- spec/functional/container_service_spec.rb
|
65
81
|
- spec/spec_helper.rb
|
66
82
|
homepage: https://github.com/opscode/chef-container
|
67
83
|
licenses:
|
@@ -78,9 +94,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
94
|
version: '0'
|
79
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
96
|
requirements:
|
81
|
-
- - "
|
97
|
+
- - ">"
|
82
98
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
99
|
+
version: 1.3.1
|
84
100
|
requirements: []
|
85
101
|
rubyforge_project:
|
86
102
|
rubygems_version: 2.2.2
|
@@ -88,8 +104,9 @@ signing_key:
|
|
88
104
|
specification_version: 4
|
89
105
|
summary: A library for controlling services using Chef's chef-container package.
|
90
106
|
test_files:
|
91
|
-
- spec/container_init_recipe_spec.rb
|
92
|
-
- spec/container_init_resource_spec.rb
|
93
107
|
- spec/data/cookbooks/foo/metadata.rb
|
94
108
|
- spec/data/cookbooks/foo/recipes/default.rb
|
109
|
+
- spec/data/cookbooks/foo/recipes/runit.rb
|
110
|
+
- spec/functional/container_service_runit_spec.rb
|
111
|
+
- spec/functional/container_service_spec.rb
|
95
112
|
- spec/spec_helper.rb
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Tom Duffield
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,61 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright (c) 2012-2014 Chef Software, Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
#
|
17
|
-
|
18
|
-
require 'spec_helper'
|
19
|
-
require 'chef/container'
|
20
|
-
|
21
|
-
describe Chef::Recipe do
|
22
|
-
|
23
|
-
before(:each) do
|
24
|
-
@cookbook_repo = File.expand_path(File.join(File.dirname(__FILE__), "..", "data", "cookbooks"))
|
25
|
-
cl = Chef::CookbookLoader.new(@cookbook_repo)
|
26
|
-
cl.load_cookbooks
|
27
|
-
@cookbook_collection = Chef::CookbookCollection.new(cl)
|
28
|
-
@node = Chef::Node.new
|
29
|
-
@node.normal[:tags] = Array.new
|
30
|
-
@events = Chef::EventDispatch::Dispatcher.new
|
31
|
-
@run_context = Chef::RunContext.new(@node, @cookbook_collection, @events)
|
32
|
-
@recipe = Chef::Recipe.new("foo", "bar", @run_context)
|
33
|
-
|
34
|
-
# Stubs
|
35
|
-
sv_bin = '/opt/chef/embedded/bin/sv'
|
36
|
-
File.stub(:exist?).with(sv_bin).and_return(true)
|
37
|
-
File.stub(:executable?).with(sv_bin).and_return(true)
|
38
|
-
Chef::Mixin::ShellOut.stub(:shell_out).with("#{sv_bin} status /opt/chef/embedded/service/apache2")
|
39
|
-
|
40
|
-
|
41
|
-
# Shell/ext.rb is on the run path, and it defines
|
42
|
-
# Chef::Recipe#resources to call pp, which we don't want when
|
43
|
-
# we're running tests.
|
44
|
-
@recipe.stub(:pp)
|
45
|
-
end
|
46
|
-
|
47
|
-
describe "container_init" do
|
48
|
-
it "replaces the provider of the corresponding service resource with Chef::Provider::Service::ChefContainer" do
|
49
|
-
@recipe.service "apache2" do
|
50
|
-
action [:enable, :start]
|
51
|
-
end
|
52
|
-
|
53
|
-
@recipe.container_init "apache2" do
|
54
|
-
action :enable
|
55
|
-
end
|
56
|
-
|
57
|
-
service_resource = @run_context.resource_collection.find("service[apache2]")
|
58
|
-
expect(service_resource.provider).to eql(Chef::Provider::Service::ChefContainer)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
File without changes
|