poise-application-python 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +11 -0
  3. data/.kitchen.travis.yml +9 -0
  4. data/.kitchen.yml +10 -0
  5. data/.travis.yml +20 -0
  6. data/.yardopts +3 -0
  7. data/Berksfile +35 -0
  8. data/CHANGELOG.md +71 -0
  9. data/Gemfile +37 -0
  10. data/LICENSE +201 -0
  11. data/README.md +334 -0
  12. data/Rakefile +17 -0
  13. data/SUPPORTERS.md +81 -0
  14. data/chef/templates/celeryconfig.py.erb +5 -0
  15. data/chef/templates/settings.py.erb +13 -0
  16. data/lib/poise_application_python.rb +23 -0
  17. data/lib/poise_application_python/app_mixin.rb +67 -0
  18. data/lib/poise_application_python/cheftie.rb +17 -0
  19. data/lib/poise_application_python/error.rb +25 -0
  20. data/lib/poise_application_python/resources.rb +26 -0
  21. data/lib/poise_application_python/resources/celery_beat.rb +43 -0
  22. data/lib/poise_application_python/resources/celery_config.rb +109 -0
  23. data/lib/poise_application_python/resources/celery_worker.rb +77 -0
  24. data/lib/poise_application_python/resources/django.rb +355 -0
  25. data/lib/poise_application_python/resources/gunicorn.rb +127 -0
  26. data/lib/poise_application_python/resources/pip_requirements.rb +47 -0
  27. data/lib/poise_application_python/resources/python.rb +57 -0
  28. data/lib/poise_application_python/resources/python_execute.rb +89 -0
  29. data/lib/poise_application_python/resources/python_package.rb +62 -0
  30. data/lib/poise_application_python/resources/virtualenv.rb +75 -0
  31. data/lib/poise_application_python/service_mixin.rb +57 -0
  32. data/lib/poise_application_python/version.rb +19 -0
  33. data/poise-application-python.gemspec +45 -0
  34. data/test/cookbooks/application_python_test/attributes/default.rb +17 -0
  35. data/test/cookbooks/application_python_test/metadata.rb +20 -0
  36. data/test/cookbooks/application_python_test/recipes/default.rb +83 -0
  37. data/test/cookbooks/application_python_test/recipes/django.rb +32 -0
  38. data/test/cookbooks/application_python_test/recipes/flask.rb +25 -0
  39. data/test/gemfiles/chef-12.gemfile +19 -0
  40. data/test/gemfiles/master.gemfile +27 -0
  41. data/test/integration/default/serverspec/default_spec.rb +81 -0
  42. data/test/integration/default/serverspec/django_spec.rb +56 -0
  43. data/test/integration/default/serverspec/flask_spec.rb +39 -0
  44. data/test/spec/app_mixin_spec.rb +69 -0
  45. data/test/spec/resources/celery_config_spec.rb +58 -0
  46. data/test/spec/resources/django_spec.rb +303 -0
  47. data/test/spec/resources/gunicorn_spec.rb +96 -0
  48. data/test/spec/resources/python_execute_spec.rb +46 -0
  49. data/test/spec/resources/python_spec.rb +44 -0
  50. data/test/spec/resources/virtualenv_spec.rb +44 -0
  51. data/test/spec/spec_helper.rb +19 -0
  52. metadata +216 -0
@@ -0,0 +1,17 @@
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
+ override['poise-service']['provider'] = 'dummy'
@@ -0,0 +1,20 @@
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
+ name 'application_python_test'
18
+ depends 'application_git'
19
+ depends 'application_python'
20
+ depends 'build-essential'
@@ -0,0 +1,83 @@
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
+ include_recipe 'poise-python'
18
+
19
+ # For netstat in serverspec.
20
+ package 'net-tools'
21
+
22
+ application '/opt/wsgi1' do
23
+ file '/opt/wsgi1/main.py' do
24
+ content <<-'EOH'
25
+ def application(environ, start_response):
26
+ status = '200 OK'
27
+ response_headers = [('Content-type', 'text/plain')]
28
+ start_response(status, response_headers)
29
+ return ['Hello world!\n']
30
+ EOH
31
+ end
32
+ gunicorn do
33
+ port 8000
34
+ end
35
+ gunicorn 'wsgi1b' do
36
+ path parent.path
37
+ service_name 'wsgi1b'
38
+ app_module 'main'
39
+ port 8001
40
+ end
41
+ end
42
+
43
+ application '/opt/wsgi2' do
44
+ file "#{path}/main.py" do
45
+ content <<-'EOH'
46
+ import sys
47
+ def application(environ, start_response):
48
+ status = '200 OK'
49
+ response_headers = [('Content-type', 'text/plain')]
50
+ start_response(status, response_headers)
51
+ return ['\n'.join(sys.path)]
52
+ EOH
53
+ end
54
+ gunicorn do
55
+ port 8002
56
+ end
57
+ end
58
+
59
+ application '/opt/wsgi3' do
60
+ file "#{path}/requirements.txt" do
61
+ content <<-EOH
62
+ requests
63
+ six
64
+ EOH
65
+ end
66
+ virtualenv
67
+ pip_requirements
68
+ file "#{path}/main.py" do
69
+ content <<-'EOH'
70
+ import sys
71
+ import requests
72
+ def application(environ, start_response):
73
+ status = '200 OK'
74
+ response_headers = [('Content-type', 'text/plain')]
75
+ start_response(status, response_headers)
76
+ return ['\n'.join(sys.path)]
77
+ EOH
78
+ end
79
+ gunicorn do
80
+ port 8003
81
+ end
82
+ end
83
+
@@ -0,0 +1,32 @@
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
+ include_recipe 'build-essential'
18
+ include_recipe 'poise-python'
19
+
20
+ application '/opt/test_django' do
21
+ git 'https://github.com/poise/test_django.git'
22
+ python 'pypy3'
23
+ virtualenv
24
+ pip_requirements
25
+ django do
26
+ database 'sqlite:///test_django.db'
27
+ migrate true
28
+ end
29
+ gunicorn do
30
+ port 9000
31
+ end
32
+ end
@@ -0,0 +1,25 @@
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
+ include_recipe 'poise-python'
18
+
19
+ application '/opt/test_flask' do
20
+ git 'https://github.com/poise/test_flask.git'
21
+ pip_requirements
22
+ gunicorn do
23
+ port 9001
24
+ end
25
+ end
@@ -0,0 +1,19 @@
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
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', '~> 12.0'
@@ -0,0 +1,27 @@
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
+ eval_gemfile File.expand_path('../../../Gemfile', __FILE__)
18
+
19
+ gem 'chef', github: 'chef/chef'
20
+ gem 'halite', github: 'poise/halite'
21
+ gem 'poise', github: 'poise/poise'
22
+ # gem 'poise-application', github: 'poise/application'
23
+ gem 'poise-application-git', github: 'poise/application_git'
24
+ gem 'poise-boiler', github: 'poise/poise-boiler'
25
+ gem 'poise-languages', github: 'poise/poise-languages'
26
+ gem 'poise-python', github: 'poise/poise-python'
27
+ gem 'poise-service', github: 'poise/poise-service'
@@ -0,0 +1,81 @@
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 'wsgi1' do
23
+ describe port(8000) do
24
+ it { is_expected.to be_listening }
25
+ end
26
+
27
+ let(:http) { Net::HTTP.new('localhost', 8000) }
28
+
29
+ describe '/' do
30
+ subject { http.get('/') }
31
+ its(:code) { is_expected.to eq '200' }
32
+ its(:body) { is_expected.to eq "Hello world!\n" }
33
+ end
34
+ end
35
+
36
+ describe 'wsgi1b' do
37
+ describe port(8001) do
38
+ it { is_expected.to be_listening }
39
+ end
40
+
41
+ let(:http) { Net::HTTP.new('localhost', 8001) }
42
+
43
+ describe '/' do
44
+ subject { http.get('/') }
45
+ its(:code) { is_expected.to eq '200' }
46
+ its(:body) { is_expected.to eq "Hello world!\n" }
47
+ end
48
+ end
49
+
50
+ describe 'wsgi2' do
51
+ describe port(8002) do
52
+ it { is_expected.to be_listening }
53
+ end
54
+
55
+ let(:http) { Net::HTTP.new('localhost', 8002) }
56
+
57
+ describe '/' do
58
+ subject { http.get('/') }
59
+ its(:code) { is_expected.to eq '200' }
60
+ its(:body) { is_expected.to include '/opt/wsgi2' }
61
+ its(:body) { is_expected.to include '/lib/python2.7' }
62
+ its(:body) { is_expected.to match %r'/(opt/rh|usr)/.*?/lib/python2.7/(site|dist)-packages' }
63
+ end
64
+ end
65
+
66
+ describe 'wsgi3' do
67
+ describe port(8003) do
68
+ it { is_expected.to be_listening }
69
+ end
70
+
71
+ let(:http) { Net::HTTP.new('localhost', 8003) }
72
+
73
+ describe '/' do
74
+ subject { http.get('/') }
75
+ its(:code) { is_expected.to eq '200' }
76
+ its(:body) { is_expected.to include '/opt/wsgi3' }
77
+ its(:body) { is_expected.to include '/lib/python2.7' }
78
+ its(:body) { is_expected.to include '/opt/wsgi3/.virtualenv/lib/python2.7' }
79
+ its(:body) { is_expected.to_not match %r'/(opt/rh|usr)/.*?/lib/python2.7/(site|dist)-packages' }
80
+ end
81
+ end
@@ -0,0 +1,56 @@
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 'django' do
23
+ describe port(9000) do
24
+ it { is_expected.to be_listening }
25
+ end
26
+
27
+ let(:http) { Net::HTTP.new('localhost', 9000) }
28
+
29
+ describe '/foo' do
30
+ subject { http.get('/foo') }
31
+ its(:code) { is_expected.to eq '404' }
32
+ end
33
+
34
+ describe '/admin/login/' do
35
+ subject { http.get('/admin/login/') }
36
+ its(:code) { is_expected.to eq '200' }
37
+ its(:body) { is_expected.to include 'Polls Administration' }
38
+ end
39
+
40
+ describe '/polls/' do
41
+ subject { http.get('/polls/') }
42
+ its(:code) { is_expected.to eq '200' }
43
+ its(:body) { is_expected.to include 'No polls are available.' }
44
+ end
45
+
46
+ describe '/static/polls/style.css' do
47
+ subject { http.get('/static/polls/style.css') }
48
+ its(:code) { is_expected.to eq '200' }
49
+ its(:body) { is_expected.to include 'color: green;' }
50
+ end
51
+
52
+ describe '/static/polls/images/background.gif' do
53
+ subject { http.get('/static/polls/images/background.gif') }
54
+ its(:code) { is_expected.to eq '200' }
55
+ end
56
+ end
@@ -0,0 +1,39 @@
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 'flask' do
23
+ describe port(9001) do
24
+ it { is_expected.to be_listening }
25
+ end
26
+
27
+ let(:http) { Net::HTTP.new('localhost', 9001) }
28
+
29
+ describe '/foo' do
30
+ subject { http.get('/foo') }
31
+ its(:code) { is_expected.to eq '404' }
32
+ end
33
+
34
+ describe '/hi' do
35
+ subject { http.get('/hi') }
36
+ its(:code) { is_expected.to eq '200' }
37
+ its(:body) { is_expected.to eq 'Hello World!' }
38
+ end
39
+ end
@@ -0,0 +1,69 @@
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_application/cheftie'
19
+ require 'poise_python/cheftie'
20
+
21
+ describe PoiseApplicationPython::AppMixin do
22
+ describe '#parent_python' do
23
+ resource(:poise_test) do
24
+ include described_class
25
+ end
26
+ provider(:poise_test)
27
+
28
+ context 'with an app_state python' do
29
+ recipe do
30
+ python_runtime 'outer'
31
+ application '/test' do
32
+ app_state[:python] = PoisePython::Resources::PythonRuntime::Resource.new('inner', run_context)
33
+ poise_test
34
+ end
35
+ python_runtime 'after'
36
+ poise_test 'after'
37
+ application '/other'
38
+ poise_test 'other'
39
+ end
40
+ let(:python) { chef_run.application('/test').app_state[:python] }
41
+
42
+ it { is_expected.to run_poise_test('/test').with(parent_python: python) }
43
+ it { is_expected.to run_poise_test('after').with(parent_python: python) }
44
+ it { is_expected.to run_poise_test('other').with(parent_python: chef_run.python_runtime('after')) }
45
+ it { expect(python).to be_a Chef::Resource }
46
+ end # /context with an app_state python
47
+
48
+ context 'with a global python' do
49
+ recipe do
50
+ python_runtime 'outer'
51
+ application '/test' do
52
+ poise_test
53
+ end
54
+ end
55
+
56
+ it { is_expected.to run_poise_test('/test').with(parent_python: chef_run.python_runtime('outer')) }
57
+ end # /context with a global python
58
+
59
+ context 'with no python' do
60
+ recipe do
61
+ application '/test' do
62
+ poise_test
63
+ end
64
+ end
65
+
66
+ it { is_expected.to run_poise_test('/test').with(parent_python: nil) }
67
+ end # /context with no python
68
+ end # /describe #parent_python
69
+ end