Skip to content

Commit

Permalink
Sanity and unit tests fixes for new ubuntu image (#361)
Browse files Browse the repository at this point in the history
Sanity and unit test for latest ansible versions
  • Loading branch information
domendobnikar authored Sep 4, 2023
1 parent 31bf629 commit 1a7072a
Show file tree
Hide file tree
Showing 34 changed files with 146 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .ansible-lint-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file contains ignores rule violations for ansible-lint
roles/agent/tasks/start.yml schema[tasks]
74 changes: 61 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,23 @@ workflows:
matrix: &matrix
parameters:
# ansible is branch name in ansible/ansible git repo
ansible:
- stable-2.9
- stable-2.10
- stable-2.11
- stable-2.12
- stable-2.13
- stable-2.14

ansible: ["stable-2.9", "stable-2.10", "stable-2.11", "stable-2.12", "stable-2.13", "stable-2.14", "stable-2.15"]
image_ubuntu: ["ubuntu-2004:202101-01", "ubuntu-2204:2023.07.2"]
exclude:
- ansible: "stable-2.9"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.10"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.11"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.12"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.13"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.14"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.15"
image_ubuntu: "ubuntu-2004:202101-01"

- unit_test:
matrix: *matrix
Expand All @@ -24,13 +33,34 @@ workflows:
requires:
- sanity_test
- unit_test
matrix: *matrix
matrix: &integration_matrix
parameters:
# ansible is branch name in ansible/ansible git repo
ansible: ["stable-2.9", "stable-2.10", "stable-2.11", "stable-2.12", "stable-2.13", "stable-2.14", "stable-2.15"]
image_ubuntu: ["ubuntu-2004:202101-01", "ubuntu-2204:2023.07.2"]
exclude:
- ansible: "stable-2.9"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.10"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.11"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.12"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.13"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.14"
image_ubuntu: "ubuntu-2204:2023.07.2"
- ansible: "stable-2.15"
image_ubuntu: "ubuntu-2004:202101-01"
- ansible: "stable-2.15"
image_ubuntu: "ubuntu-2204:2023.07.2"

- integration_test_galaxy:
filters: { branches: { only: [ stable ] } }
requires:
- integration_test_git
matrix: *matrix
matrix: *integration_matrix

cron_master:
triggers:
Expand All @@ -39,7 +69,7 @@ workflows:
filters: { branches: { only: [ master ] } }
jobs:
- integration_test_git:
matrix: *matrix
matrix: *integration_matrix

cron_released:
triggers:
Expand All @@ -48,7 +78,7 @@ workflows:
filters: { branches: { only: [ stable ] } }
jobs:
- integration_test_galaxy:
matrix: *matrix
matrix: *integration_matrix

cron_ansible_devel:
triggers:
Expand All @@ -60,6 +90,7 @@ workflows:
matrix: &devel-matrix
parameters:
ansible: [ devel ]
image_ubuntu: [ "ubuntu-2204:2023.07.2" ]

- unit_test:
matrix: *devel-matrix
Expand All @@ -84,8 +115,11 @@ jobs:
ansible:
description: Ansible version to use
type: string
image_ubuntu:
description: Ubuntu image
type: string
machine: &ci-machine
image: ubuntu-2004:202101-01
image: << parameters.image_ubuntu >>
working_directory: ~/ansible_collections/sensu/sensu_go
steps:
- wrapper:
Expand All @@ -99,6 +133,9 @@ jobs:
ansible:
description: Ansible version to use
type: string
image_ubuntu:
description: Ubuntu image
type: string
machine: *ci-machine
working_directory: ~/ansible_collections/sensu/sensu_go
steps:
Expand All @@ -119,9 +156,17 @@ jobs:
ansible:
description: Ansible version to use
type: string
image_ubuntu:
description: Ubuntu image
type: string
machine: *ci-machine
working_directory: ~/sensu_go
steps:
- run:
command: |
sudo apt-get update
sudo apt-get install -y dbus
# service dbus start # Start D-Bus service
- wrapper:
ansible: << parameters.ansible >>
kind: integration
Expand All @@ -136,6 +181,9 @@ jobs:
ansible:
description: Ansible version to use
type: string
image_ubuntu:
description: Ubuntu image
type: string
machine: *ci-machine
working_directory: ~/sensu_go
steps:
Expand Down
1 change: 1 addition & 0 deletions docker/centos-7.docker
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN ( \
/usr/bin/python /usr/bin/python2-config sudo \
yum-plugin-ovl bash iproute; \
sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf; \
yum -y update systemd; \
yum clean all; \
chmod 777 /root;

Expand Down
3 changes: 2 additions & 1 deletion integration.requirements
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
molecule ~= 5.0.1
molecule ~= 6.0.1; python_version >= "3.10"
molecule ~= 5.0.1; python_version < "3.10"
molecule-docker ~= 2.1.0
pytest
pytest-molecule ~= 2.0.0
1 change: 1 addition & 0 deletions plugins/modules/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
- The maximum number of connections to hold in the PostgreSQL connection
pool.
type: int
default: 0
max_conn_lifetime:
description:
- Maximum time a connection can persist before being destroyed.
Expand Down
4 changes: 2 additions & 2 deletions roles/agent/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- name: Restart Linux agent
service:
ansible.builtin.service:
name: sensu-agent
state: restarted
when: manage_sensu_agent_service | default(False)

- name: Restart Windows agent
action:
module: win_service
module: ansible.windows.win_service
name: SensuAgent
state: restarted
when: manage_sensu_agent_service | default(False)
Expand Down
4 changes: 2 additions & 2 deletions roles/agent/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
- name: Configure agent (Linux)
include_tasks: linux/configure.yml
ansible.builtin.include_tasks: linux/configure.yml
when: ansible_facts.os_family != "Windows"

- name: Configure agent (Windows)
include_tasks: windows/configure.yml
ansible.builtin.include_tasks: windows/configure.yml
when: ansible_facts.os_family == "Windows"
6 changes: 3 additions & 3 deletions roles/agent/tasks/linux/configure.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
---
- name: Load Linux locations
include_vars: linux.yml
ansible.builtin.include_vars: linux.yml

- name: Install agent communication PKI
copy:
ansible.builtin.copy:
src: "{{ agent_trusted_ca_file }}"
dest: "{{ trusted_ca_file_path }}"
# Keep this in sync with what the backend service is running as from packager
Expand All @@ -13,7 +13,7 @@
when: agent_trusted_ca_file is defined

- name: Configure sensu-agent ({{ agent_config_path }})
template:
ansible.builtin.template:
src: agent.yml.j2
dest: "{{ agent_config_path }}"
owner: *sensu_user
Expand Down
10 changes: 5 additions & 5 deletions roles/agent/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
- name: Install sensu-go-agent binary
include_role:
ansible.builtin.include_role:
name: install
vars:
components: [sensu-go-agent]
components: [sensu-go-agent] # noqa: var-naming[no-role-prefix]

- name: Inform restart handler that we are in charge of the agent service
set_fact:
ansible.builtin.set_fact:
manage_sensu_agent_service: true

- name: Configure the agent
include_tasks: configure.yml
ansible.builtin.include_tasks: configure.yml

- name: Start the agent
include_tasks: start.yml
ansible.builtin.include_tasks: start.yml
4 changes: 2 additions & 2 deletions roles/agent/tasks/start.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
- name: Start sensu-agent (Linux)
service:
ansible.builtin.service:
name: sensu-agent
state: started
enabled: true
when: ansible_facts.os_family != "Windows"

- name: Start sensu-agent (Windows)
action:
module: win_service
module: ansible.windows.win_service
name: SensuAgent
path: C:\Program Files\sensu\sensu-agent\bin\sensu-agent.exe service run
state: started
Expand Down
6 changes: 3 additions & 3 deletions roles/agent/tasks/windows/configure.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
- name: Load Windows locations
include_vars: windows.yml
ansible.builtin.include_vars: windows.yml

- name: Install agent communication PKI
win_copy:
ansible.windows.win_copy:
src: "{{ agent_trusted_ca_file }}"
dest: "{{ trusted_ca_file_path }}"
when: agent_trusted_ca_file is defined

- name: Configure sensu-agent ({{ agent_config_path }})
win_template:
ansible.windows.win_template:
src: agent.yml.j2
dest: "{{ agent_config_path }}"
notify: Restart Windows agent
2 changes: 1 addition & 1 deletion roles/backend/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Restart backend
service:
ansible.builtin.service:
name: sensu-backend
state: restarted
when: manage_sensu_backend_service | default(False)
8 changes: 4 additions & 4 deletions roles/backend/tasks/configure.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Install etcd communication PKI
copy:
ansible.builtin.copy:
src: "{{ item.source }}"
dest: "/etc/sensu/{{ item.filename }}"
# Keep this in sync with what the backend service is running as from packager
Expand All @@ -27,7 +27,7 @@
etcd_peer_key_file is defined

- name: Install API communication PKI
copy:
ansible.builtin.copy:
src: "{{ item.source }}"
dest: "/etc/sensu/{{ item.filename }}"
owner: *sensu_user
Expand All @@ -45,7 +45,7 @@
api_trusted_ca_file is defined

- name: Install dashboard communication PKI
copy:
ansible.builtin.copy:
src: "{{ item.source }}"
dest: "/etc/sensu/{{ item.filename }}"
owner: *sensu_user
Expand All @@ -61,7 +61,7 @@
when: dashboard_cert_file is defined or dashboard_key_file is defined

- name: Configure sensu-backend (/etc/sensu/backend.yml)
template:
ansible.builtin.template:
src: backend.yml.j2
dest: /etc/sensu/backend.yml
owner: *sensu_user
Expand Down
10 changes: 5 additions & 5 deletions roles/backend/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
- name: Install sensu-go-backend binary
include_role:
ansible.builtin.include_role:
name: install
vars:
components: [sensu-go-backend]
components: [sensu-go-backend] # noqa: var-naming[no-role-prefix]

- name: Inform restart handler that we are in charge of the backend service
set_fact:
ansible.builtin.set_fact:
manage_sensu_backend_service: true

- name: Configure the backend
include_tasks: configure.yml
ansible.builtin.include_tasks: configure.yml

- name: Start the backend
include_tasks: start.yml
ansible.builtin.include_tasks: start.yml
6 changes: 3 additions & 3 deletions roles/backend/tasks/start.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
---
- name: Start sensu-backend
service:
ansible.builtin.service:
name: sensu-backend
state: started
enabled: true

- name: Check for sensu-backend init command
command:
ansible.builtin.command:
cmd: sensu-backend init -h
register: init_command_test
failed_when: false # Never fail, we just want to know if init exists.
changed_when: false # Displaying help is read-only operation.
check_mode: false # We do not modify the system, so we can always run

- name: Initialize backend
command:
ansible.builtin.command:
cmd: sensu-backend init
environment:
SENSU_BACKEND_CLUSTER_ADMIN_USERNAME: "{{ cluster_admin_username }}"
Expand Down
2 changes: 1 addition & 1 deletion roles/install/tasks/apt/install.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- name: Install component
apt:
ansible.builtin.apt:
name: "{{ 'apt' | sensu.sensu_go.package_name(item, version, build) }}"
state: "{{ (version == 'latest') | ternary('latest', 'present') }}"
# FIXME(@tadeboro): This is a temporary "fix" for
Expand Down
Loading

0 comments on commit 1a7072a

Please sign in to comment.