Skip to content

Commit

Permalink
feat(testing): add devenv test
Browse files Browse the repository at this point in the history
Create a .devenv file and adjust the test.yml playbook to be able to test the role in local
  • Loading branch information
oyale committed Apr 22, 2024
1 parent 29ffc74 commit 9a06348
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 3 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,23 @@ Example Playbook
odoo_role_odoo_release: 20180424
```

Developing & Testing
-------

To test the role, you can use the `.devenv` file in `tests` folder to create a virtual machine with [`devenv`](https://github.com/coopdevs/devenv).

```bash
devenv
```

After the environment is created, you can test the role with the following command:

```bash
ansible-playbook test.yml -i inventory
```

It will provision a virtual machine with postgresql and then, execute the role.

Release
-------

Expand Down
10 changes: 10 additions & 0 deletions tests/.devenv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# File created with devenv init command

NAME="odoo-role-test"
DISTRIBUTION="ubuntu"
RELEASE="jammy"
ARCH="amd64"
HOST="$NAME.local"

# Select the python interpeter python2.7 or python3
PYTHON_INTERPRETER=python3
2 changes: 2 additions & 0 deletions tests/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[defaults]
roles_path = ../../
6 changes: 4 additions & 2 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
localhost

[devenv]
odoo-role-test.local ansible_host=odoo-role-test.local
[all]
localhost ansible_connection=local
2 changes: 2 additions & 0 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
odoo14-addon-web_responsive==14.0.1.2.3.dev4
odoo14-addon-web_environment_ribbon==14.0.1.0.1.dev11
37 changes: 37 additions & 0 deletions tests/setup_postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
- name: Install pip
apt:
name: python3-pip

- name: Install psycopg2
pip:
name: psycopg2-binary

- name: Install PostgreSQL
apt:
name: postgresql
state: present
update_cache: true
when: ansible_os_family == "Debian"

- name: Ensure PostgreSQL is running
service:
name: postgresql
state: started
enabled: true

- name: Create a database user for Odoo
become: true
become_user: postgres
postgresql_user:
name: odoo
state: present
role_attr_flags: LOGIN,CREATEDB

- name: Create a database for Odoo
become: true
become_user: postgres
postgresql_db:
name: odoo
owner: odoo
state: present
16 changes: 15 additions & 1 deletion tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
---
- hosts: localhost
- hosts: devenv
remote_user: root
become: true
# This is needed to be able to test the role without postgresql role
tasks:
- include_tasks: setup_postgresql.yml

- hosts: devenv
remote_user: root
become: true
roles:
- odoo-role
vars:
odoo_role_odoo_url: "https://git.coopdevs.org/coopdevs/odoo/OCB/-/archive/{{ odoo_role_odoo_release }}/OCB-{{ odoo_role_odoo_release }}.tar.gz"
odoo_role_odoo_version: "14.0"
odoo_role_odoo_release: "{{ odoo_role_odoo_version }}"
odoo_role_community_modules_requirements_path: requirements.txt
odoo_role_odoo_http_interface: 0.0.0.0

0 comments on commit 9a06348

Please sign in to comment.