Skip to content

Commit

Permalink
Change tests syntax to key: value, change cwd to working_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawid Wolski committed Sep 14, 2018
1 parent 73d82cd commit 8227e4c
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 28 deletions.
18 changes: 10 additions & 8 deletions lib/ansible/modules/database/misc/sqitch.py
Expand Up @@ -56,7 +56,7 @@
description:
- Database engine.
required: no
cwd:
working_directory:
description:
- Path to directory with config file.
required: no
Expand Down Expand Up @@ -117,7 +117,7 @@
sqitch:
command: deploy
plan_file: sqitch.plan
top_dir: /opt/sqitch
working_directory: /opt/sqitch
target: test_db
- name: Revert all changes in test_db database
Expand All @@ -135,7 +135,7 @@
sqitch:
command: rebase
plan_file: sqitch.plan
top_dir: /opt/sqitch
working_directory: /opt/sqitch
target: test_db
set:
- defuser='Homer Simpson'
Expand Down Expand Up @@ -224,7 +224,7 @@ def main():
plan_file=dict(),
target=dict(),
engine=dict(),
cwd=dict(),
working_directory=dict(),
to_change=dict(),
from_change=dict(),
verify=dict(type='bool'),
Expand All @@ -243,7 +243,7 @@ def main():
plan_file = module.params['plan_file']
target = module.params['target']
engine = module.params['engine']
cwd = module.params['cwd']
working_directory = module.params['working_directory']
to_change = module.params['to_change']
from_change = module.params['from_change']
verify = module.params['verify']
Expand Down Expand Up @@ -311,10 +311,12 @@ def main():
get_set(cmd, set)

if module.check_mode:
module.exit_json(changed=False, msg="%s will be run in %s directory" % (' '.join(cmd),
cwd if cwd else 'current'))
module.exit_json(changed=False,
msg="%s will be run in %s directory" % (' '.join(cmd),
working_directory if working_directory \
else 'current'))
else:
(rc, out, err) = module.run_command(cmd, cwd=cwd)
(rc, out, err) = module.run_command(cmd, cwd=working_directory)

if rc is not None and rc != 0:
module.fail_json(msg=err, rc=rc)
Expand Down
31 changes: 24 additions & 7 deletions test/integration/targets/sqitch/tasks/setup.yml
@@ -1,19 +1,32 @@
---
- name: Create dir for resources
file: path={{ output_dir }} state=directory mode=0755
file:
path: "{{ output_dir }}"
state: directory
mode: 0755

- name: Copy resources to tmp dir
copy: src=files/ dest={{ output_dir }}
copy:
src: files/
dest: "{{ output_dir }}"

- name: Create DB for tests
postgresql_db: name=anstest encoding='UTF-8' state=present template=template0
postgresql_db:
name: anstest
encoding: 'UTF-8'
state: present
template: template0

- name: Install sqitch
package: name=sqitch state=present
package:
name: sqitch
state: present
when: ansible_os_family == "Debian"

- name: Install CPAN
package: name={{ item }} state=present
package:
name: {{ item }}
state: present
with_items:
- perl-devel
- perl-CPAN
Expand All @@ -25,9 +38,13 @@
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == '6'

- name: Install cpanminus
package: name=cpanminus state=present
package:
name: cpanminus
state: present
when: ansible_os_family == "RedHat" and not (ansible_distribution == "CentOS" and ansible_distribution_major_version == '6')

- name: Install sqitch
cpanm: name=App::Sqitch notest=true
cpanm:
name: App::Sqitch
notest: true
when: ansible_os_family == "RedHat"
71 changes: 58 additions & 13 deletions test/integration/targets/sqitch/tasks/test.yml
@@ -1,40 +1,85 @@
---
- name: Deploy in check mode with cwd
sqitch: command=deploy cwd={{ output_dir }} plan_file=sqitch.plan target=anstest verify=true to_change=types
- name: Deploy in check mode with working_directory
sqitch:
command: deploy
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest
verify: true
to_change: types
check_mode: yes

- name: Deploy in check mode without cwd
sqitch: command=deploy plan_file=sqitch.plan target=anstest verify=true to_change=types
- name: Deploy in check mode without working_directory
sqitch:
command: deploy
plan_file: sqitch.plan
target: anstest
verify: true
to_change: types
check_mode: yes

- name: Deploy to change
sqitch: command=deploy cwd={{ output_dir }} plan_file=sqitch.plan target=anstest verify=true to_change=types
sqitch:
command: deploy
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest
verify: true
to_change: types

- name: Rebase
sqitch:
command: rebase
cwd: "{{ output_dir }}"
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest
verify: true

- name: Revert to change
sqitch: command=revert cwd={{ output_dir }} plan_file=sqitch.plan target=anstest to_change=schemas
sqitch:
command: revert
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest
to_change: schemas

- name: Deploy whole plan
sqitch: command=deploy cwd={{ output_dir }} plan_file=sqitch.plan target=anstest
sqitch:
command: deploy
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest

- name: Verify
sqitch: command=verify cwd={{ output_dir }} plan_file=sqitch.plan target=anstest from_change=types to_change=tests
sqitch:
command: verify
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest
from_change: types
to_change: tests

- name: Check status
sqitch: command=status cwd={{ output_dir }} plan_file=sqitch.plan target=anstest
sqitch:
command: status
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest

- name: Revert whole plan to change
sqitch: command=revert cwd={{ output_dir }} plan_file=sqitch.plan target=anstest to_change=schemas
sqitch:
command: revert
working_directory: "{{ output_dir }}"
plan_file: sqitch.plan
target: anstest
to_change: schemas

- name: Destroy DB
postgresql_db: name=anstest state=absent
postgresql_db:
name: anstest
state: absent

- name: Remove resources
file: path={{ output_dir }} state=absent
file:
path: "{{ output_dir }}"
state: absent

0 comments on commit 8227e4c

Please sign in to comment.