Skip to content

Commit e405add

Browse files
authored
Merge pull request #1 from jasonheecs/test-kitchen
Added test kitchen
2 parents 194bf72 + 645fe13 commit e405add

File tree

9 files changed

+101
-9
lines changed

9 files changed

+101
-9
lines changed

.kitchen.yml

+16-5
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@ provisioner:
1212
idempotency_test: true
1313

1414
platforms:
15+
- name: ubuntu-18.04
1516
- name: ubuntu-16.04
16-
driver_config:
17-
image: williamyeh/ansible:ubuntu16.04-onbuild
18-
platform: ubuntu
17+
- name: ubuntu-14.04
18+
- name: ubuntu-12.04
1919

2020
verifier:
2121
name: serverspec
2222

2323
suites:
24-
- name: default
24+
- name: python3
2525
driver:
26-
provision_command: export LC_ALL=C
26+
provision_command:
27+
- export LC_ALL=C
28+
- mkdir -p /run/sshd
29+
verifier:
30+
default_pattern: true
31+
bundler_path: '/usr/local/bin'
32+
rspec_path: '/usr/local/bin'
33+
- name: python2
34+
driver:
35+
provision_command:
36+
- export LC_ALL=C
37+
- mkdir -p /run/sshd
2738
verifier:
2839
default_pattern: true
2940
bundler_path: '/usr/local/bin'

.travis.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
sudo: required
3+
services:
4+
- docker
5+
6+
language: python
7+
python: "2.7"
8+
9+
env:
10+
- UBUNTU_VERSION: ubuntu-18
11+
- UBUNTU_VERSION: ubuntu-16
12+
- UBUNTU_VERSION: ubuntu-14
13+
- UBUNTU_VERSION: ubuntu-12
14+
15+
cache:
16+
pip: true
17+
directories:
18+
- $HOME/.rvm/gems
19+
20+
before_install:
21+
- sudo apt-get update -qq
22+
- sleep 5
23+
- sudo apt-get install -qq python-apt python-pycurl
24+
- gem install bundler
25+
26+
install:
27+
- bundle install
28+
- pip install ansible
29+
30+
script:
31+
- ansible --version
32+
- docker version
33+
- export LC_ALL=C
34+
- bundle show
35+
- bundle exec kitchen test '${UBUNTU_VERSION}' -c
36+
37+
notifications:
38+
email:
39+
on_success: never
40+
webhooks: https://galaxy.ansible.com/api/v1/notifications/

tasks/main.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
- name: Install Python 3.x
3-
raw: which python3 || sudo apt-get update && sudo apt-get install -qq -y python3-minimal
3+
raw: dpkg-query --showformat='${Status}' -W python3 | grep -E "(hold|install) ok installed" || (sudo apt-get update && sudo apt-get install -qq -y python3)
44
register: python_check
5-
changed_when: not python_check.stdout is search('/usr/bin/python3')
5+
changed_when: not python_check.stdout | regex_search('ok installed')
66
when: python_version == 3
77

88
- name: Install Python 2.x
9-
raw: which python || sudo apt-get update && sudo apt-get install -qq -y python-minimal
9+
raw: dpkg-query --showformat='${Status}' -W python | grep -E "(hold|install) ok installed" || (sudo apt-get update && sudo apt-get install -qq -y python)
1010
register: python_check
11-
changed_when: not python_check.stdout is search('/usr/bin/python')
11+
changed_when: not python_check.stdout | regex_search('ok installed')
1212
when: python_version == 2

test/integration/default/default.yml renamed to test/integration/python2/default.yml

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
gather_facts: false
66
roles:
77
- { role: ansible-ubuntu-python-raw }
8+
vars:
9+
- python_version: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require_relative 'spec_helper'
2+
3+
describe package('python') do
4+
it { should be_installed }
5+
end

test/integration/python3/default.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
- name: Run setup tasks for testing
3+
hosts: all
4+
tasks:
5+
- name: Check for idempotency flag
6+
stat: path=/root/.test-kitchen-ran-once
7+
register: flag
8+
9+
- name: Uninstall Python 3.x for testing
10+
raw: dpkg-query --showformat='${Status}' -W python3 | grep -E "unknown ok not-installed" || sudo apt-get -y remove --purge python3
11+
register: python_installed
12+
changed_when: not python_installed.stdout | regex_search('unknown ok not-installed')
13+
when: not flag.stat.exists
14+
15+
- name: Create flag for idempotency tests
16+
hosts: all
17+
gather_facts: false
18+
tasks:
19+
- copy:
20+
content: ""
21+
dest: /root/.test-kitchen-ran-once
22+
force: yes
23+
mode: 0644
24+
25+
- name: Setup
26+
hosts: all
27+
become: yes
28+
gather_facts: false
29+
roles:
30+
- { role: ansible-ubuntu-python-raw }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Encoding: utf-8
2+
require 'serverspec'
3+
4+
set :backend, :exec

0 commit comments

Comments
 (0)