poise-application 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'net/http'
18
+
19
+ require 'serverspec'
20
+ set :backend, :exec
21
+
22
+ describe file('/home/app') do
23
+ it { is_expected.to be_a_directory }
24
+ end
25
+
26
+ describe file('/home/app/plugin') do
27
+ it { is_expected.to be_a_file }
28
+ its(:content) { is_expected.to eq 'test plugin' }
29
+ end
30
+
31
+ describe 'restarter' do
32
+ describe port(2000) do
33
+ it { is_expected.to be_listening }
34
+ end
35
+
36
+ let(:http) { Net::HTTP.new('localhost', 2000) }
37
+
38
+ describe '/' do
39
+ subject { http.get('/') }
40
+ its(:code) { is_expected.to eq '200' }
41
+ its(:body) { is_expected.to eq 'Two' }
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseApplication::AppMixin do
20
+ describe '#app_state_environment' do
21
+ resource(:mixin_test) do
22
+ include described_class
23
+ end
24
+ provider(:mixin_test) do
25
+ include described_class
26
+ def action_run
27
+ new_resource.app_state_environment[:key] = new_resource.name
28
+ end
29
+ end
30
+ recipe do
31
+ application '/srv/mixintest' do
32
+ mixin_test 'one'
33
+ mixin_test 'two'
34
+ end
35
+ end
36
+
37
+ it { is_expected.to deploy_application('/srv/mixintest').with(app_state: {'environment' => {'key' => 'two'}}) }
38
+
39
+ context 'with no parent' do
40
+ recipe do
41
+ mixin_test 'one'
42
+ mixin_test 'two'
43
+ end
44
+
45
+ it { is_expected.to run_mixin_test('one').with(app_state: {'environment' => {'key' => 'one'}}) }
46
+ it { is_expected.to run_mixin_test('two').with(app_state: {'environment' => {'key' => 'two'}}) }
47
+ end # /context with no parent
48
+ end # /describe #app_state_environment
49
+ end
@@ -0,0 +1,148 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+ require 'poise'
19
+
20
+ class ApplicationTestRealClass < Chef::Resource
21
+ include Poise
22
+ provides(:application_test_other_name)
23
+ actions(:run)
24
+ end
25
+
26
+ describe PoiseApplication::Resources::Application::Resource do
27
+ step_into(:application)
28
+ recipe do
29
+ application '/home/app' do
30
+ remote_directory do
31
+ source 'myapp'
32
+ end
33
+ end
34
+ end
35
+
36
+ it { is_expected.to deploy_application('/home/app').with(environment: {}) }
37
+ it { is_expected.to create_directory('/home/app') }
38
+ it { is_expected.to create_remote_directory('/home/app').with(source: 'myapp') }
39
+
40
+ context 'with a plugin application_test_plugin' do
41
+ resource(:application_test_plugin) do
42
+ include Poise(parent: :application)
43
+ end
44
+ provider(:application_test_plugin)
45
+ recipe do
46
+ application '/home/app' do
47
+ test_plugin 'plugin'
48
+ end
49
+ end
50
+
51
+ it { is_expected.to run_application_test_plugin('plugin') }
52
+ end # /context with a plugin application_test_plugin
53
+
54
+ context 'with a plugin test_plugin' do
55
+ resource(:test_plugin) do
56
+ include Poise(parent: :application)
57
+ end
58
+ provider(:test_plugin)
59
+ recipe do
60
+ application '/home/app' do
61
+ test_plugin 'plugin'
62
+ end
63
+ end
64
+
65
+ it { is_expected.to run_test_plugin('plugin') }
66
+ end # /context with a plugin test_plugin
67
+
68
+ context 'with a plugin application_test_test_plugin' do
69
+ resource(:application_test_test_plugin) do
70
+ include Poise(parent: :application)
71
+ end
72
+ provider(:application_test_test_plugin)
73
+ recipe do
74
+ extend RSpec::Mocks::ExampleMethods
75
+ allow(run_context.cookbook_collection).to receive(:keys).and_return(%w{application_test})
76
+ application '/home/app' do
77
+ test_test_plugin 'plugin'
78
+ end
79
+ end
80
+
81
+ it { is_expected.to run_application_test_test_plugin('plugin') }
82
+ end # /context with a plugin application_test_test_plugin
83
+
84
+ context 'with an LWRP application_test_test_plugin' do
85
+ resource(:application_test_test_plugin, parent: Chef::Resource::LWRPBase) do
86
+ include Poise(parent: :application)
87
+ end
88
+ provider(:application_test_test_plugin)
89
+ recipe do
90
+ extend RSpec::Mocks::ExampleMethods
91
+ allow(run_context.cookbook_collection).to receive(:keys).and_return(%w{application_test})
92
+ application '/home/app' do
93
+ test_plugin 'plugin'
94
+ end
95
+ end
96
+
97
+ it { is_expected.to run_application_test_test_plugin('plugin') }
98
+ end # /context with an LWRP application_test_test_plugin
99
+
100
+ context 'with a plugin that has no name' do
101
+ resource(:test_plugin) do
102
+ include Poise(parent: :application)
103
+ end
104
+ provider(:test_plugin)
105
+ recipe do
106
+ application '/home/app' do
107
+ test_plugin
108
+ end
109
+ end
110
+
111
+ it { is_expected.to run_test_plugin('/home/app') }
112
+ end # /context with a plugin that has no name
113
+
114
+ context 'with a resource that does not match the class name' do
115
+ recipe do
116
+ application '/home/app' do
117
+ test_other_name
118
+ end
119
+ end
120
+
121
+ it { is_expected.to run_application_test_other_name('/home/app') }
122
+ end # /context with a resource that does not match the class name
123
+
124
+ context 'with a subresource that has an update' do
125
+ step_into(:application)
126
+ step_into(:ruby_block)
127
+ resource(:test_plugin) do
128
+ include Poise(parent: :application)
129
+ actions(:run, :restart)
130
+ end
131
+ provider(:test_plugin) do
132
+ def action_restart
133
+ node.run_state['did_restart'] = true
134
+ end
135
+ end
136
+ recipe do
137
+ application '/home/app' do
138
+ ruby_block { block {} }
139
+ test_plugin
140
+ end
141
+ end
142
+
143
+ it { is_expected.to run_ruby_block('/home/app') }
144
+ it { expect(chef_run.ruby_block('/home/app').updated?).to be true }
145
+ it { is_expected.to run_test_plugin('/home/app') }
146
+ it { expect(chef_run.node.run_state['did_restart']).to be true }
147
+ end # /context with a subresource that has an update
148
+ end
@@ -0,0 +1,76 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseApplication::ServiceMixin do
20
+ resource(:mixin_test) do
21
+ include described_class
22
+ end
23
+ provider(:mixin_test) do
24
+ include described_class
25
+ end
26
+ let(:service_resource) { subject.mixin_test('/srv/mixintest').provider_for_action(:enable).send(:service_resource) }
27
+
28
+ context 'with an application parent' do
29
+ recipe do
30
+ application '/srv/mixintest' do
31
+ owner 'myuser'
32
+ mixin_test
33
+ end
34
+ end
35
+
36
+ it { is_expected.to enable_mixin_test('/srv/mixintest').with(service_name: 'mixintest', user: 'myuser') }
37
+ it { expect(service_resource.service_name).to eq 'mixintest' }
38
+ it { expect(service_resource.user).to eq 'myuser' }
39
+ it { expect(service_resource.directory).to eq '/srv/mixintest' }
40
+ it { expect(service_resource.environment).to eq({}) }
41
+
42
+ context 'with app_state environment data' do
43
+ resource(:state_test) do
44
+ include Poise(parent: :application)
45
+ end
46
+ provider(:state_test) do
47
+ def action_run
48
+ new_resource.parent.app_state[:environment] = {'ENVKEY' => 'envvalue'}
49
+ end
50
+ end
51
+ recipe do
52
+ application '/srv/mixintest' do
53
+ state_test
54
+ mixin_test
55
+ end
56
+ end
57
+
58
+ it { is_expected.to enable_mixin_test('/srv/mixintest').with(service_name: 'mixintest') }
59
+ it { expect(service_resource.service_name).to eq 'mixintest' }
60
+ it { expect(service_resource.directory).to eq '/srv/mixintest' }
61
+ it { expect(service_resource.environment).to eq({'ENVKEY' => 'envvalue'}) }
62
+ end # /context with app_state environment data
63
+ end # /context with an application parent
64
+
65
+ context 'without an application parent' do
66
+ recipe do
67
+ mixin_test '/srv/mixintest'
68
+ end
69
+
70
+ it { is_expected.to enable_mixin_test('/srv/mixintest').with(service_name: 'mixintest', user: 'root') }
71
+ it { expect(service_resource.service_name).to eq 'mixintest' }
72
+ it { expect(service_resource.user).to eq 'root' }
73
+ it { expect(service_resource.directory).to eq '/srv/mixintest' }
74
+ it { expect(service_resource.environment).to eq({}) }
75
+ end # /context withput an application parent
76
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'poise_boiler/spec_helper'
18
+ require 'poise_application'
@@ -0,0 +1,65 @@
1
+ #
2
+ # Copyright 2015, Noah Kantrowitz
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ describe PoiseApplication::Utils do
20
+ describe '.primary_group_for' do
21
+ let(:user) { nil }
22
+ let(:fake_user) { double('fake user', gid: 123, to_s: user) }
23
+ let(:fake_group) { double('fake group', name: 'mygroup' )}
24
+ subject { described_class.primary_group_for(user) }
25
+ before do
26
+ allow(Etc).to receive(:endpwent)
27
+ allow(Etc).to receive(:endgrent)
28
+ end
29
+
30
+ context 'with an integer' do
31
+ let(:user) { 1 }
32
+ it do
33
+ expect(Etc).to receive(:getpwuid).with(1).and_return(fake_user)
34
+ expect(Etc).to receive(:getgrgid).with(123).and_return(fake_group)
35
+ is_expected.to eq 'mygroup'
36
+ end
37
+ end # /context with an integer
38
+
39
+ context 'with a string' do
40
+ let(:user) { 'myuser' }
41
+ it do
42
+ expect(Etc).to receive(:getpwnam).with('myuser').and_return(fake_user)
43
+ expect(Etc).to receive(:getgrgid).with(123).and_return(fake_group)
44
+ is_expected.to eq 'mygroup'
45
+ end
46
+ end # /context with a string
47
+
48
+ context 'with an invalid user' do
49
+ let(:user) { 'myuser' }
50
+ it do
51
+ expect(Etc).to receive(:getpwnam).with('myuser').and_raise(ArgumentError)
52
+ is_expected.to eq 'myuser'
53
+ end
54
+ end # /context with an invalid user
55
+
56
+ context 'with an invalid group' do
57
+ let(:user) { 'myuser' }
58
+ it do
59
+ expect(Etc).to receive(:getpwnam).with('myuser').and_return(fake_user)
60
+ expect(Etc).to receive(:getgrgid).with(123).and_raise(ArgumentError)
61
+ is_expected.to eq 'myuser'
62
+ end
63
+ end # /context with an invalid group
64
+ end # /describe .primary_group_for
65
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: poise-application
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Noah Kantrowitz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: halite
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: poise
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: poise-service
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: poise-boiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ description: A Chef cookbook for deploying application code.
70
+ email:
71
+ - noah@coderanger.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".kitchen.travis.yml"
78
+ - ".kitchen.yml"
79
+ - ".travis.yml"
80
+ - Berksfile
81
+ - CHANGELOG.md
82
+ - Gemfile
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - SUPPORTERS.md
87
+ - lib/poise_application.rb
88
+ - lib/poise_application/app_mixin.rb
89
+ - lib/poise_application/cheftie.rb
90
+ - lib/poise_application/error.rb
91
+ - lib/poise_application/resources.rb
92
+ - lib/poise_application/resources/application.rb
93
+ - lib/poise_application/service_mixin.rb
94
+ - lib/poise_application/utils.rb
95
+ - lib/poise_application/version.rb
96
+ - poise-application.gemspec
97
+ - test/cookbooks/application_test/metadata.rb
98
+ - test/cookbooks/application_test/providers/test_plugin.rb
99
+ - test/cookbooks/application_test/recipes/default.rb
100
+ - test/cookbooks/application_test/resources/test_plugin.rb
101
+ - test/docker/docker.ca
102
+ - test/docker/docker.pem
103
+ - test/gemfiles/chef-12.2.gemfile
104
+ - test/gemfiles/chef-12.3.gemfile
105
+ - test/gemfiles/chef-12.gemfile
106
+ - test/gemfiles/master.gemfile
107
+ - test/integration/default/serverspec/default_spec.rb
108
+ - test/spec/app_mixin_spec.rb
109
+ - test/spec/resources/application_spec.rb
110
+ - test/spec/service_mixin_spec.rb
111
+ - test/spec/spec_helper.rb
112
+ - test/spec/utils_spec.rb
113
+ homepage: https://github.com/poise/application
114
+ licenses:
115
+ - Apache 2.0
116
+ metadata:
117
+ halite_name: application
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.8
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: A Chef cookbook for deploying application code.
138
+ test_files:
139
+ - test/cookbooks/application_test/metadata.rb
140
+ - test/cookbooks/application_test/providers/test_plugin.rb
141
+ - test/cookbooks/application_test/recipes/default.rb
142
+ - test/cookbooks/application_test/resources/test_plugin.rb
143
+ - test/docker/docker.ca
144
+ - test/docker/docker.pem
145
+ - test/gemfiles/chef-12.2.gemfile
146
+ - test/gemfiles/chef-12.3.gemfile
147
+ - test/gemfiles/chef-12.gemfile
148
+ - test/gemfiles/master.gemfile
149
+ - test/integration/default/serverspec/default_spec.rb
150
+ - test/spec/app_mixin_spec.rb
151
+ - test/spec/resources/application_spec.rb
152
+ - test/spec/service_mixin_spec.rb
153
+ - test/spec/spec_helper.rb
154
+ - test/spec/utils_spec.rb
155
+ has_rdoc: