Skip to content

Commit 6908be2

Browse files
committed
tests: apply #6784
1 parent bbe6058 commit 6908be2

14 files changed

Lines changed: 146 additions & 20 deletions

File tree

.gitlab-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ variables:
230230
.test_job:
231231
stage: test
232232
dependencies: []
233+
artifacts:
234+
expire_in: 1 day
235+
paths:
236+
- results/*
233237
tags:
234238
- inverse.ca
235239
- shell

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# PacketFence
22

3-
[![pipeline status](https://gitlab.com/inverse-inc/packetfence/badges/devel/pipeline.svg)](https://gitlab.com/inverse-inc/packetfence/commits/devel)
4-
53
## What is PacketFence?
64

75
PacketFence is a fully supported, trusted, Free and Open Source

addons/vagrant/Vagrantfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ DOMAIN_PREFIX = "vagrant-" + BRANCH_OR_TAG_NAME + "-#{SecureRandom.hex(3)}-"
88

99
Vagrant.configure("2") do |config|
1010
### Global settings for all VMS
11-
config.vagrant.sensitive = [ ENV['PSONO_CI_API_KEY_ID'], ENV['PSONO_CI_API_SECRET_KEY_HEX'] ]
12-
1311
# disable synced folders
1412
config.vm.synced_folder ".", "/vagrant", disabled: true
1513

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
venom_dir: '/usr/local/pf/t/venom'
3+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- hosts: pfservers, service_venom, nodes
2+
name: Get Venom logs on all VM
3+
become: True
4+
tags: logs
5+
6+
vars:
7+
# result_dir = full path to 'results' directory at root of PF sources tree
8+
result_dir: '{{ lookup("env", "RESULT_DIR") }}'
9+
10+
tasks:
11+
- name: Sanitize logs
12+
shell: '{{ venom_dir }}/utils/sanitize-venom-logs.sh'
13+
args:
14+
executable: '/bin/bash'
15+
no_log: True
16+
# to make Psono variables available
17+
environment: '{{ inventory__group_environment | d({}) }}'
18+
19+
# Store archive into result_dir/results/results-$(hostname).tar.gz
20+
- name: Get logs on runner
21+
fetch:
22+
src: '{{ venom_dir }}/results-{{ inventory_hostname }}.tar.gz'
23+
dest: '{{ result_dir }}/'
24+
flat: True

addons/vagrant/playbooks/tasks/register_rhel_subscription_tasks.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,30 @@
22
- name: Get RHEL username using psonoci
33
ansible.builtin.command:
44
cmd: 'psonoci secret get {{ rhel_sub_psono_secret_id }} username'
5-
register: reg_rhel_sub_register_username
65
when: rhel_sub_psono_secret_id
76
no_log: True
7+
register: reg_rhel_sub_register_username
8+
retries: 3
9+
delay: 1
10+
until: reg_rhel_sub_register_username is successful
811

912
- name: Get RHEL password using psonoci
1013
ansible.builtin.command:
1114
cmd: 'psonoci secret get {{ rhel_sub_psono_secret_id }} password'
12-
register: reg_rhel_sub_register_password
1315
when: rhel_sub_psono_secret_id
1416
no_log: True
17+
register: reg_rhel_sub_register_password
18+
retries: 3
19+
delay: 1
20+
until: reg_rhel_sub_register_password is successful
1521

1622
- name: Register RHEL subscription
1723
community.general.redhat_subscription:
1824
state: present
1925
username: '{{ reg_rhel_sub_register_username.stdout | d(rhel_subscription_user) }}'
2026
password: '{{ reg_rhel_sub_register_password.stdout | d(rhel_subscription_password) }}'
2127
auto_attach: true
28+
register: reg_rhel_sub_register_el
29+
retries: 3
30+
delay: 1
31+
until: reg_rhel_sub_register_el is successful

addons/vagrant/playbooks/tasks/unregister_rhel_subscription_tasks.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
- name: Get RHEL username using psonoci
33
ansible.builtin.command:
44
cmd: 'psonoci secret get {{ rhel_sub_psono_secret_id }} username'
5-
register: unreg_rhel_sub_register_username
65
when: rhel_sub_psono_secret_id
76
no_log: True
7+
register: unreg_rhel_sub_register_username
8+
retries: 3
9+
delay: 1
10+
until: unreg_rhel_sub_register_username is successful
811

912
- name: Get RHEL password using psonoci
1013
ansible.builtin.command:
1114
cmd: 'psonoci secret get {{ rhel_sub_psono_secret_id }} password'
12-
register: unreg_rhel_sub_register_password
1315
when: rhel_sub_psono_secret_id
1416
no_log: True
17+
register: unreg_rhel_sub_register_password
18+
retries: 3
19+
delay: 1
20+
until: unreg_rhel_sub_register_password is successful
1521

1622
# username and password are necessary to unregister system
1723
- name: Unregister RHEL subscription
@@ -20,3 +26,7 @@
2026
username: '{{ unreg_rhel_sub_register_username.stdout | d(rhel_subscription_user) }}'
2127
password: '{{ unreg_rhel_sub_register_password.stdout | d(rhel_subscription_password) }}'
2228
auto_attach: true
29+
register: unreg_rhel_sub_register_el
30+
retries: 3
31+
delay: 1
32+
until: unreg_rhel_sub_register_el is successful

addons/vagrant/teardown.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
22
- import_playbook: playbooks/unregister_rhel_subscription.yml
3+
- import_playbook: playbooks/get_logs.yml
4+

ci/lib/check/run-pipeline-if-necessary.sh

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,23 @@ FUNCTIONS_FILE=${PF_SRC_DIR}/ci/lib/common/functions.sh
1212

1313
source ${FUNCTIONS_FILE}
1414

15+
# GitLab API: https://docs.gitlab.com/ee/api/
16+
1517
configure_and_check() {
1618
CI_PROJECT_ID=${CI_PROJECT_ID:-}
19+
CI_PIPELINE_ID=${CI_PIPELINE_ID:-}
1720
CI_COMMIT_REF_NAME=${CI_COMMIT_REF_NAME:-}
21+
GITLAB_API_TOKEN=${GITLAB_API_TOKEN:-}
1822

1923
COMMIT_REF_NAME_ENCODED=$(urlencode "$CI_COMMIT_REF_NAME")
2024
COMMIT_SHA=$(git rev-parse HEAD~0)
25+
26+
[ -z "${GITLAB_API_TOKEN}" ] && die "not set: GITLAB_API_TOKEN"
2127

2228
# get SHA of latest pipeline scheduled with status=succes for that branch
23-
SHA_LATEST_PIPELINE=$(curl -s "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/pipelines?status=success&source=schedule&ref=${COMMIT_REF_NAME_ENCODED}" | jq -r '.[0].sha')
29+
SHA_LATEST_PIPELINE=$(curl --header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" \
30+
-s "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/pipelines?status=success&source=schedule&ref=${COMMIT_REF_NAME_ENCODED}" \
31+
| jq -r '.[0].sha')
2432

2533
RUN_PIPELINE=yes
2634

@@ -36,20 +44,32 @@ configure_and_check() {
3644
declare -p RUN_PIPELINE
3745
}
3846

39-
set_exit_code() {
47+
cancel_pipeline() {
48+
curl --request POST \
49+
--header "PRIVATE-TOKEN: ${GITLAB_API_TOKEN}" \
50+
-s "https://gitlab.com/api/v4/projects/${CI_PROJECT_ID}/pipelines/${CI_PIPELINE_ID}/cancel" \
51+
| jq -r '.status'
52+
}
53+
54+
define_next_action() {
4055
if [ "$RUN_PIPELINE" = "yes" ]; then
4156
echo "We need to run a pipeline"
4257
exit 0
4358
else
44-
# GitLab job will failed and prevent execution of next job
45-
echo "No need to run a pipeline"
46-
exit 1
59+
echo "No need to run a pipeline, cancelling pipeline"
60+
if [ $(cancel_pipeline) = "canceled" ]; then
61+
echo "Pipeline canceled"
62+
exit 0
63+
else
64+
echo "Unable to cancel pipeline"
65+
# job will failed and pipeline will be stopped
66+
exit 1
67+
fi
4768
fi
4869
}
4970

50-
5171
log_section "Configure and check"
5272
configure_and_check
5373

54-
log_section "Set exit code"
55-
set_exit_code
74+
log_section "Define next action"
75+
define_next_action

debian/rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ binary-arch: build install
343343
chmod 0755 $(CURDIR)/debian/packetfence-test$(PREFIX)/$(NAME)/t/unittest/Authentication/Source/*.t
344344
# Venom
345345
chmod 0755 $(CURDIR)/debian/packetfence-test$(PREFIX)/$(NAME)/t/venom/*.sh
346+
chmod 0755 $(CURDIR)/debian/packetfence-test$(PREFIX)/$(NAME)/t/venom/utils/*.sh
346347
# packetfence pkg
347348
chmod 0755 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/addons/*.pl
348349
chmod 0755 $(CURDIR)/debian/packetfence$(PREFIX)/$(NAME)/addons/*.sh

0 commit comments

Comments
 (0)