From 042aeba46cec6253c11a43940de62795de3cb3e7 Mon Sep 17 00:00:00 2001 From: Andrea Tartaglia Date: Thu, 31 Jan 2019 10:20:33 +0000 Subject: [PATCH] Base integration test for gitlab modules (#51490) * Added basic integration test targets for gitlab modules * Removed cloud/gitlab config from aliases, it doesn't exist yet * Fixed CI issues --- .../cloud-config-gitlab.yml.template | 17 +++++ .../targets/gitlab_deploy_key/aliases | 3 + .../gitlab_deploy_key/defaults/main.yml | 2 + .../targets/gitlab_deploy_key/tasks/main.yml | 36 ++++++++++ test/integration/targets/gitlab_group/aliases | 3 + .../targets/gitlab_group/defaults/main.yml | 1 + .../targets/gitlab_group/tasks/main.yml | 44 ++++++++++++ test/integration/targets/gitlab_hooks/aliases | 3 + .../targets/gitlab_hooks/defaults/main.yml | 2 + .../targets/gitlab_hooks/tasks/main.yml | 67 ++++++++++++++++++ .../targets/gitlab_project/aliases | 3 + .../targets/gitlab_project/defaults/main.yml | 2 + .../targets/gitlab_project/tasks/main.yml | 40 +++++++++++ .../integration/targets/gitlab_runner/aliases | 3 + .../targets/gitlab_runner/defaults/main.yml | 3 + .../targets/gitlab_runner/tasks/main.yml | 68 +++++++++++++++++++ test/integration/targets/gitlab_user/aliases | 3 + .../targets/gitlab_user/defaults/main.yml | 3 + .../targets/gitlab_user/tasks/main.yml | 50 ++++++++++++++ 19 files changed, 353 insertions(+) create mode 100644 test/integration/cloud-config-gitlab.yml.template create mode 100644 test/integration/targets/gitlab_deploy_key/aliases create mode 100644 test/integration/targets/gitlab_deploy_key/defaults/main.yml create mode 100644 test/integration/targets/gitlab_deploy_key/tasks/main.yml create mode 100644 test/integration/targets/gitlab_group/aliases create mode 100644 test/integration/targets/gitlab_group/defaults/main.yml create mode 100644 test/integration/targets/gitlab_group/tasks/main.yml create mode 100644 test/integration/targets/gitlab_hooks/aliases create mode 100644 test/integration/targets/gitlab_hooks/defaults/main.yml create mode 100644 test/integration/targets/gitlab_hooks/tasks/main.yml create mode 100644 test/integration/targets/gitlab_project/aliases create mode 100644 test/integration/targets/gitlab_project/defaults/main.yml create mode 100644 test/integration/targets/gitlab_project/tasks/main.yml create mode 100644 test/integration/targets/gitlab_runner/aliases create mode 100644 test/integration/targets/gitlab_runner/defaults/main.yml create mode 100644 test/integration/targets/gitlab_runner/tasks/main.yml create mode 100644 test/integration/targets/gitlab_user/aliases create mode 100644 test/integration/targets/gitlab_user/defaults/main.yml create mode 100644 test/integration/targets/gitlab_user/tasks/main.yml diff --git a/test/integration/cloud-config-gitlab.yml.template b/test/integration/cloud-config-gitlab.yml.template new file mode 100644 index 0000000000..e9ff6d12d1 --- /dev/null +++ b/test/integration/cloud-config-gitlab.yml.template @@ -0,0 +1,17 @@ +# This is the configuration template for ansible-test Gitlab integration tests. +# +# You do not need this template if you are: +# +# 1) Running integration tests without using ansible-test. +# 2) Using the automatically provisioned gitlab docker container in ansible-test. +# +# If you do not want to use the automatically provided Gitlab container, +# fill in the @VAR placeholders below and save this file without the .template extension. +# This will cause ansible-test to use the given configuration and not launch the simulator. +# +# It is recommended that you DO NOT use this template unless you cannot use the simulator. + +gitlab_host: http://@HOST:@PORT +gitlab_login_token: @TOKEN +gitlab_runner_registration_token: @RUNNER_TOKEN +timeout: 60 diff --git a/test/integration/targets/gitlab_deploy_key/aliases b/test/integration/targets/gitlab_deploy_key/aliases new file mode 100644 index 0000000000..ef7ed2e3b5 --- /dev/null +++ b/test/integration/targets/gitlab_deploy_key/aliases @@ -0,0 +1,3 @@ +shippable/posix/group1 +gitlab/ci +disabled diff --git a/test/integration/targets/gitlab_deploy_key/defaults/main.yml b/test/integration/targets/gitlab_deploy_key/defaults/main.yml new file mode 100644 index 0000000000..4e47591941 --- /dev/null +++ b/test/integration/targets/gitlab_deploy_key/defaults/main.yml @@ -0,0 +1,2 @@ +gitlab_project_name: ansible_test_project +gitlab_deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJnTYY7CYk1F/wBklpdRxudxN6KeXgfhutkiCigSfPhe ansible_test" diff --git a/test/integration/targets/gitlab_deploy_key/tasks/main.yml b/test/integration/targets/gitlab_deploy_key/tasks/main.yml new file mode 100644 index 0000000000..1e7edca23f --- /dev/null +++ b/test/integration/targets/gitlab_deploy_key/tasks/main.yml @@ -0,0 +1,36 @@ +- name: Install required libs + pip: + name: python-gitlab + state: present + +- name: Create {{ gitlab_project_name }} + gitlab_project: + server_url: "{{ gitlab_host }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + name: "{{ gitlab_project_name }}" + state: present + +- name: Cleanup deploy key to {{ gitlab_project_name }} + gitlab_deploy_key: + login_token: "{{ gitlab_login_token }}" + project: "{{ gitlab_project_name }}" + server_url: "{{ gitlab_host }}" + title: "{{ gitlab_project_name }}" + key: "{{ gitlab_deploy_key }}" + state: absent + + +- name: Add deploy key to {{ gitlab_project_name }} + gitlab_deploy_key: + login_token: "{{ gitlab_login_token }}" + project: "root/{{ gitlab_project_name }}" + server_url: "{{ gitlab_host }}" + title: "{{ gitlab_project_name }}" + key: "{{ gitlab_deploy_key }}" + state: present + register: deploy_key_status + +- assert: + that: + - deploy_key_status is changed diff --git a/test/integration/targets/gitlab_group/aliases b/test/integration/targets/gitlab_group/aliases new file mode 100644 index 0000000000..ef7ed2e3b5 --- /dev/null +++ b/test/integration/targets/gitlab_group/aliases @@ -0,0 +1,3 @@ +shippable/posix/group1 +gitlab/ci +disabled diff --git a/test/integration/targets/gitlab_group/defaults/main.yml b/test/integration/targets/gitlab_group/defaults/main.yml new file mode 100644 index 0000000000..630926d922 --- /dev/null +++ b/test/integration/targets/gitlab_group/defaults/main.yml @@ -0,0 +1 @@ +gitlab_group: ansible_test_project diff --git a/test/integration/targets/gitlab_group/tasks/main.yml b/test/integration/targets/gitlab_group/tasks/main.yml new file mode 100644 index 0000000000..5499e98201 --- /dev/null +++ b/test/integration/targets/gitlab_group/tasks/main.yml @@ -0,0 +1,44 @@ +- name: Install required libs + pip: + name: python-gitlab + state: present + +- name: Cleanup Gitlab Group + gitlab_group: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + name: ansible_test_group + path: ansible_test_group + state: absent + +- name: Create Gitlab Group + gitlab_group: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + name: ansible_test_group + path: ansible_test_group + state: present + register: gitlab_group_state + +- name: Test group created + assert: + that: + - gitlab_group_state is changed + + +- name: Create Gitlab Group ( Idempotency test ) + gitlab_group: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + name: ansible_test_group + path: ansible_test_group + state: present + register: gitlab_group_state_again + +- name: Test module is idempotent + assert: + that: + - gitlab_group_state_again is not changed diff --git a/test/integration/targets/gitlab_hooks/aliases b/test/integration/targets/gitlab_hooks/aliases new file mode 100644 index 0000000000..ef7ed2e3b5 --- /dev/null +++ b/test/integration/targets/gitlab_hooks/aliases @@ -0,0 +1,3 @@ +shippable/posix/group1 +gitlab/ci +disabled diff --git a/test/integration/targets/gitlab_hooks/defaults/main.yml b/test/integration/targets/gitlab_hooks/defaults/main.yml new file mode 100644 index 0000000000..eda34a26e6 --- /dev/null +++ b/test/integration/targets/gitlab_hooks/defaults/main.yml @@ -0,0 +1,2 @@ +gitlab_project_name: ansible_test_project +gitlab_hook_url: http://gitlab.example.com/hook diff --git a/test/integration/targets/gitlab_hooks/tasks/main.yml b/test/integration/targets/gitlab_hooks/tasks/main.yml new file mode 100644 index 0000000000..3c429a826c --- /dev/null +++ b/test/integration/targets/gitlab_hooks/tasks/main.yml @@ -0,0 +1,67 @@ +- name: Install required libs + pip: + name: python-gitlab + state: present + +- name: Create {{ gitlab_project_name }} + gitlab_project: + server_url: "{{ gitlab_host }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + name: "{{ gitlab_project_name }}" + state: present + +- name: Cleanup Gitlab hook + gitlab_hooks: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + hook_url: "{{ gitlab_hook_url }}" + project: "{{ gitlab_project_name }}" + state: absent + +- name: Create Gitlab Hook + gitlab_hooks: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + hook_url: "{{ gitlab_hook_url }}" + project: "{{ gitlab_project_name }}" + state: present + register: gitlab_hook_state + +- name: Test group created + assert: + that: + - gitlab_hook_state is changed + + +- name: Create Gitlab Hook ( Idempotency test ) + gitlab_hooks: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + hook_url: "{{ gitlab_hook_url }}" + project: "{{ gitlab_project_name }}" + state: present + register: gitlab_hook_state_again + +- name: Test module is idempotent + assert: + that: + - gitlab_hook_state_again is not changed + +- name: Remove Gitlab hook + gitlab_hooks: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + hook_url: "{{ gitlab_hook_url }}" + project: "{{ gitlab_project_name }}" + state: absent + register: gitlab_hook_state_absent + +- name: Assert hook has been removed + assert: + that: + - gitlab_hook_state_absent is changed diff --git a/test/integration/targets/gitlab_project/aliases b/test/integration/targets/gitlab_project/aliases new file mode 100644 index 0000000000..ef7ed2e3b5 --- /dev/null +++ b/test/integration/targets/gitlab_project/aliases @@ -0,0 +1,3 @@ +shippable/posix/group1 +gitlab/ci +disabled diff --git a/test/integration/targets/gitlab_project/defaults/main.yml b/test/integration/targets/gitlab_project/defaults/main.yml new file mode 100644 index 0000000000..4e47591941 --- /dev/null +++ b/test/integration/targets/gitlab_project/defaults/main.yml @@ -0,0 +1,2 @@ +gitlab_project_name: ansible_test_project +gitlab_deploy_key: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJnTYY7CYk1F/wBklpdRxudxN6KeXgfhutkiCigSfPhe ansible_test" diff --git a/test/integration/targets/gitlab_project/tasks/main.yml b/test/integration/targets/gitlab_project/tasks/main.yml new file mode 100644 index 0000000000..4b8c4a4fd8 --- /dev/null +++ b/test/integration/targets/gitlab_project/tasks/main.yml @@ -0,0 +1,40 @@ +- name: Install required libs + pip: + name: python-gitlab + state: present + +- name: Clean up {{ gitlab_project_name }} + gitlab_project: + server_url: "{{ gitlab_host }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + name: "{{ gitlab_project_name }}" + state: absent + +- name: Create {{ gitlab_project_name }} + gitlab_project: + server_url: "{{ gitlab_host }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + name: "{{ gitlab_project_name }}" + state: present + register: gitlab_project_state + + +- assert: + that: + - gitlab_project_state is changed + +- name: Create {{ gitlab_project_name }} (Test idempotency) + gitlab_project: + server_url: "{{ gitlab_host }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + name: "{{ gitlab_project_name }}" + state: present + register: gitlab_project_state_again + + +- assert: + that: + - gitlab_project_state_again is not changed diff --git a/test/integration/targets/gitlab_runner/aliases b/test/integration/targets/gitlab_runner/aliases new file mode 100644 index 0000000000..ef7ed2e3b5 --- /dev/null +++ b/test/integration/targets/gitlab_runner/aliases @@ -0,0 +1,3 @@ +shippable/posix/group1 +gitlab/ci +disabled diff --git a/test/integration/targets/gitlab_runner/defaults/main.yml b/test/integration/targets/gitlab_runner/defaults/main.yml new file mode 100644 index 0000000000..bed980a238 --- /dev/null +++ b/test/integration/targets/gitlab_runner/defaults/main.yml @@ -0,0 +1,3 @@ +gitlab_project_name: ansible_test_project +gitlab_hook_url: http://gitlab.example.com/hook +gitlab_runner_name: ansible_test_runner diff --git a/test/integration/targets/gitlab_runner/tasks/main.yml b/test/integration/targets/gitlab_runner/tasks/main.yml new file mode 100644 index 0000000000..a8318f43f3 --- /dev/null +++ b/test/integration/targets/gitlab_runner/tasks/main.yml @@ -0,0 +1,68 @@ +- name: Install required libs + pip: + name: python-gitlab + state: present + +- name: Create {{ gitlab_project_name }} + gitlab_project: + server_url: "{{ gitlab_host }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + name: "{{ gitlab_project_name }}" + state: present + +- name: Cleanup Gitlab runner + gitlab_runner: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + description: "{{ gitlab_runner_name }}" + registration_token: "{{ gitlab_runner_registration_token }}" + state: absent + +- name: Create Gitlab Runner + gitlab_runner: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + description: "{{ gitlab_runner_name }}" + registration_token: "{{ gitlab_runner_registration_token }}" + state: present + register: gitlab_runner_state + +- name: Test group created + assert: + that: + - gitlab_runner_state is changed + + +#### COMMENTED AS MODULE WILL UPDATE THE RUNNER IF EXISTS. TO BE DISCUSSED #### +# - name: Create Gitlab Runner ( Idempotency test ) +# gitlab_runner: +# server_url: "{{ gitlab_host }}" +# validate_certs: false +# login_token: "{{ gitlab_login_token }}" +# description: "{{ gitlab_runner_name }}" +# registration_token: "{{ gitlab_runner_registration_token }}" +# state: present +# register: gitlab_runner_state_again + +# - name: Test module is idempotent +# assert: +# that: +# - gitlab_runner_state_again is not changed + +- name: Remove Gitlab Runner + gitlab_runner: + server_url: "{{ gitlab_host }}" + validate_certs: false + login_token: "{{ gitlab_login_token }}" + description: "{{ gitlab_runner_name }}" + registration_token: "{{ gitlab_runner_registration_token }}" + state: absent + register: gitlab_runner_state_absent + +- name: Assert runner has been removed + assert: + that: + - gitlab_runner_state_absent is changed diff --git a/test/integration/targets/gitlab_user/aliases b/test/integration/targets/gitlab_user/aliases new file mode 100644 index 0000000000..ef7ed2e3b5 --- /dev/null +++ b/test/integration/targets/gitlab_user/aliases @@ -0,0 +1,3 @@ +shippable/posix/group1 +gitlab/ci +disabled diff --git a/test/integration/targets/gitlab_user/defaults/main.yml b/test/integration/targets/gitlab_user/defaults/main.yml new file mode 100644 index 0000000000..a6755cf412 --- /dev/null +++ b/test/integration/targets/gitlab_user/defaults/main.yml @@ -0,0 +1,3 @@ +gitlab_user: ansible_test_user +gitlab_user_pass: Secr3tPassw00rd +gitlab_user_email: root@localhost diff --git a/test/integration/targets/gitlab_user/tasks/main.yml b/test/integration/targets/gitlab_user/tasks/main.yml new file mode 100644 index 0000000000..63ee923f16 --- /dev/null +++ b/test/integration/targets/gitlab_user/tasks/main.yml @@ -0,0 +1,50 @@ +- name: Install required libs + pip: + name: python-gitlab + state: present + +- name: Clean up gitlab user + gitlab_user: + server_url: "{{ gitlab_host }}" + name: ansible_test_user + username: ansible_test_user + password: Secr3tPassw00rd + email: root@localhost + validate_certs: false + login_token: "{{ gitlab_login_token }}" + state: absent + + +- name: Create gitlab user + gitlab_user: + server_url: "{{ gitlab_host }}" + email: "{{ gitlab_user_email }}" + name: "{{ gitlab_user }}" + username: "{{ gitlab_user }}" + password: "{{ gitlab_user_pass }}" + validate_certs: False + login_token: "{{ gitlab_login_token }}" + state: present + register: gitlab_user_state + +- name: Check user has been created correctly + assert: + that: + - gitlab_user_state is changed + +- name: Create gitlab user again + gitlab_user: + server_url: "{{ gitlab_host }}" + email: root@localhost + name: ansible_test_user + username: ansible_test_user + password: Secr3tPassw00rd + validate_certs: False + login_token: "{{ gitlab_login_token }}" + state: present + register: gitlab_user_state_again + +- name: Check state is not changed + assert: + that: + - gitlab_user_state_again is not changed