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
63 changes: 63 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
driver:
name: docker

provisioner:
#name: shell

verifier:
name: inspec
sudo: true
# not working
# test_base_root: tests

platforms:

- name: ubuntu-12.04
driver_config:
image: ubuntu:12.04
platform: ubuntu
driver:
provision_command:
- apt-get install -y python-pip git
- sudo pip install flask

# Mind the difference 12.04 and 14.04 - both works, but ...
- name: ubuntu-14.04
driver:
provision_command:
- apt-get install -y python-pip git
- sudo pip install flask

- name: centos # NOTE, there is an issue if centos-7 as name is used
driver:
provision_command:
- sed -i -e "s/Defaults requiretty.*/#Defaults requiretty/g" /etc/sudoers
- yum install -y git
- curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
- python get-pip.py
- sudo pip install flask

suites:

# assumed to be used with kitchen-docker (but I failed to upload a local/repo directory)
# using shell provisioner, but you have to script install dependencies
- name: simpliest
test_base_root: tests
driver:
volume:
- <%= ENV['PWD'] %>:/srv/hello
provisioner:
name: shell
script: tests/run_test.sh

# require to add Berksfile in repo
# require to add metadata.rb in repo
# require to add recipes/default.rb in repo
# install platform independent all prerequisites
- name: default-recipe
run_list:
- recipe[python-flask-demo::default]
# NOTE, chef allow to run chef-apply 'recipe.rb' to do the miracle (ie as provisioner part), but in this case we need one external cookbook to get
# env. ready (ie virtualenv; however pip install etc could be system wide and as part of recipe.rb)

3 changes: 3 additions & 0 deletions Berksfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://supermarket.chef.io"

metadata
4 changes: 4 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name 'python-flask-demo'
version '0.1.0'

depends 'poise-python'
24 changes: 24 additions & 0 deletions recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@


%w(curl git).each do |p|
package p
end

git '/srv/hello' do
repository 'https://github.com/tcpcloud/python-flask-hello'
action :sync
end

python_runtime '2'
python_virtualenv '/srv/hello/.env'

python_package 'flask' do
virtualenv '/srv/hello/.env'
#version '1.8'
end

pip_requirements '/srv/hello/requirements.txt' if ::File.exist?('srv/hello/requirements.txt')




1 change: 1 addition & 0 deletions test
23 changes: 23 additions & 0 deletions tests/integration/default-recipe/bats/flask.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bats


# NOTE MAY LOAD HELPER FUNCTIONS ../TEST_HELPER.BASH
# example https://github.com/dokku/dokku/blob/fc63061eafffc93ec13503c36dcade0339fe0bff/tests/unit/test_helper.bash


#run_app() {
#source /srv/hello/.env/bin/activate
#nohup python /srv/hello/hello.py
#}


@test "flask app is running" {
#run_app
#run /bin/bash -c "curl -s -D - localhost:8000 -o /dev/null | egrep '^Server' | egrep '[0-9]+'"
run /bin/bash -c "hostname"
echo "output: "$output
echo "status: "$status
[ "$status" -eq 0 ]
}


44 changes: 44 additions & 0 deletions tests/integration/default-recipe/inspec/hello_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

# better to start is in background and check it's running only
# better to avoid shell scripting check proc/port/output using inspec as shown below
describe command('bash -c "source /srv/hello/.env/bin/activate && cd /srv/hello && ./tests/run_test.sh"') do
its('exit_status') { should eq 0 }
end


#cmd = <<-EOH
## script something
#EOH

#describe command(cmd) do
#its('exit_status') { should eq 0 }
#end

## check port
#describe port(5000) do
#it { should be_listening }
#end

#describe command('curl -m 10 -s -v -f http://127.0.0.1:5000/') do
#its('stdout') { should eq 'Hello World!' }
#its('exit_status') { should eq 0 }
#end

## BUT BE AWARE OF NOT YET IMPLEMENTED F ON DOCKER ENV BELOW
#return if ::File.exist?('/.dockerenv')

## check that ssh runs
#if os.unix?
#describe port(5000) do
#it { should be_listening }
#its('protocols') { should include('tcp') }
#end
#end
## extra test for linux
#if os.linux?
#describe port(5000) do
#its('processes') { should include 'python' }
#its('protocols') { should include 'tcp' }
#its('addresses') {should include '0.0.0.0'}
#end
#end
46 changes: 46 additions & 0 deletions tests/integration/simpliest/inspec/hello_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

# better to start is in background and check it's running only
# better to avoid shell scripting check proc/port/output using inspec as shown below
describe command('bash -c "cd /srv/hello && ./tests/run_test.sh"') do
its('exit_status') { should eq 0 }
end


#cmd = <<-EOH
## script something
## script something
## script something
#EOH

#describe command(cmd) do
#its('exit_status') { should eq 0 }
#end

## check port
#describe port(5000) do
#it { should be_listening }
#end

#describe command('curl -m 10 -s -v -f http://127.0.0.1:5000/') do
#its('stdout') { should eq 'Hello World!' }
#its('exit_status') { should eq 0 }
#end

## BUT BE AWARE OF NOT YET IMPLEMENTED F ON DOCKER ENV BELOW
#return if ::File.exist?('/.dockerenv')

## check that ssh runs
#if os.unix?
#describe port(5000) do
#it { should be_listening }
#its('protocols') { should include('tcp') }
#end
#end
## extra test for linux
#if os.linux?
#describe port(5000) do
#its('processes') { should include 'python' }
#its('protocols') { should include 'tcp' }
#its('addresses') {should include '0.0.0.0'}
#end
#end
2 changes: 2 additions & 0 deletions tests/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

RET=1

cd /srv/hello

check_proc() {
if [ ! -d /proc/$1 ]; then
echo "ERROR: Process did not start" 1>&2
Expand Down