From 4415569438ab1ab4495a204a985d3cada7ae9f1e Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Mon, 11 Sep 2017 18:18:17 -0400 Subject: [PATCH 1/3] tests: Support IRC notifications Add an 'irc_channel_notice' role to help post messages in a somewhat generic way. It verifies it's own required variables and is able to translate between commit-author names and irc nicks. The message itself is generated via a jinja2 template, making it easy to swap in alternate messages for different situations. The intent is this role is applied during different stages of the crio-integration-playbook. As long as at least one variable differs between references (e.g. verb), it will execute multiple times. Test with: - hosts: localhost gather_subset: network roles: - role: irc_channel_notice verb: testing commit_author: willgates pullrequest: 889 Signed-off-by: Chris Evich --- .../irc_channel_notice/defaults/main.yml | 29 ++++++++++++ .../files/author_to_nick.csv | 2 + .../roles/irc_channel_notice/tasks/main.yml | 45 +++++++++++++++++++ .../templates/crio-integration-playbook.j2 | 7 +++ 4 files changed, 83 insertions(+) create mode 100644 contrib/test/roles/irc_channel_notice/defaults/main.yml create mode 100644 contrib/test/roles/irc_channel_notice/files/author_to_nick.csv create mode 100644 contrib/test/roles/irc_channel_notice/tasks/main.yml create mode 100644 contrib/test/roles/irc_channel_notice/templates/crio-integration-playbook.j2 diff --git a/contrib/test/roles/irc_channel_notice/defaults/main.yml b/contrib/test/roles/irc_channel_notice/defaults/main.yml new file mode 100644 index 00000000..3a85084d --- /dev/null +++ b/contrib/test/roles/irc_channel_notice/defaults/main.yml @@ -0,0 +1,29 @@ +--- + +irc_server: "chat.freenode.net" +irc_port: 6665 +irc_channel: "cri-o" + +# Nick to join / send message +irc_from: "kry-oh" + +# To whom should the message be addressed. +irc_to: + +# If non-empty, use irc_nick_xlation file to set irc_to +commit_author: + +# Author to nick translation file (in files subdir). CSV commit_author,irc_nick mapping +irc_nick_xlation: "author_to_nick.csv" + +# jinja2 template filename (in templates subdir) to use for producing the message +irc_msg_template: "crio-integration-playbook.j2" + +# Assertion-strings that must pass for above template +irc_msg_tmpl_asserts: + - 'verb | default()' + - 'irc_to | default()' + - 'commit | default() | trim | search("[0-9A-Fa-f]+")' + - 'pullrequest | default(0) | string | search("\d+")' + - 'irc_from | default()' # nick of sender + - 'commit_author | default() or irc_to | default()' # PR author / nick of recipient diff --git a/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv b/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv new file mode 100644 index 00000000..e4eea4f3 --- /dev/null +++ b/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv @@ -0,0 +1,2 @@ +willgates:cevich +rhatdan:dwalsh diff --git a/contrib/test/roles/irc_channel_notice/tasks/main.yml b/contrib/test/roles/irc_channel_notice/tasks/main.yml new file mode 100644 index 00000000..1bd036dd --- /dev/null +++ b/contrib/test/roles/irc_channel_notice/tasks/main.yml @@ -0,0 +1,45 @@ +--- + +- block: # delegate_to: localhost b/c 'is_file()', 'csvfile' and 'template' lookups + + - name: All role assertions pass + assert: + that: # All are defined and non-empty + - 'irc_server | default()' + - 'irc_channel | default()' + - 'irc_from | default()' + - 'irc_to | default() or commit_author | default()' + - 'irc_msg_template | default()' + - 'irc_nick_xlation | default()' + + - name: Relative paths are made absolute + set_fact: + _irc_msg_template: '{{ role_path ~ "/templates/" ~ irc_msg_template }}' + _irc_nick_xlation: '{{ role_path ~ "/files/" ~ irc_nick_xlation }}' + + - name: Message recipient name is translated + set_fact: + irc_to: > + {{ lookup("csvfile", + commit_author ~ + " file=" ~ _irc_nick_xlation ~ + " col=1 delimiter=: default=" ~ irc_to) }} + when: commit_author | default() and _irc_nick_xlation | is_file + + - name: All template assertions pass + assert: + that: '{{ irc_msg_tmpl_asserts }}' + + - debug: + msg: 'Sending - {{ irc_server | trim }}#{{ irc_channel | trim }}: {{ irc_to |trim }}, {{ lookup("template", _irc_msg_template) | trim }}' + + - name: Irc notification is sent + irc: + server: '{{ irc_server | trim }}' + port: '{{ irc_port | default(omit) }}' + channel: '{{ irc_channel | trim }}' + nick_to: '{{ irc_to | trim }}' + nick: '{{ irc_from | trim }}' + msg: '{{ lookup("template", _irc_msg_template) | trim }}' + + delegate_to: localhost diff --git a/contrib/test/roles/irc_channel_notice/templates/crio-integration-playbook.j2 b/contrib/test/roles/irc_channel_notice/templates/crio-integration-playbook.j2 new file mode 100644 index 00000000..d464b48a --- /dev/null +++ b/contrib/test/roles/irc_channel_notice/templates/crio-integration-playbook.j2 @@ -0,0 +1,7 @@ +{{ irc_to | trim }}, crio-integration-playbook {{ verb }} on {{ + ansible_distribution ~ "-" ~ ansible_distribution_version }} for: {% + if pullrequest|default() + %}https://github.com/kubernetes-incubator/cri-o/pull/{{ pullrequest | trim }}{% + else + %}https://github.com/kubernetes-incubator/cri-o/commit/{{ commit | trim }}{% + endif %} From e67ee8ec28a091cd5988a90ef8f1eff2d87ad87c Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Wed, 13 Sep 2017 11:25:02 -0400 Subject: [PATCH 2/3] fixup! tests: Support IRC notifications Add tom to author/nick translation file --- contrib/test/roles/irc_channel_notice/files/author_to_nick.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv b/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv index e4eea4f3..9813d117 100644 --- a/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv +++ b/contrib/test/roles/irc_channel_notice/files/author_to_nick.csv @@ -1,2 +1,3 @@ willgates:cevich rhatdan:dwalsh +TomSweeneyRedHat:tsweeney From 7278808d18f8be73c032c23b1de8a2800747555d Mon Sep 17 00:00:00 2001 From: Chris Evich Date: Wed, 13 Sep 2017 11:25:02 -0400 Subject: [PATCH 3/3] fixup! tests: Support IRC notifications Add FIXME comment w/ link --- contrib/test/roles/irc_channel_notice/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/test/roles/irc_channel_notice/tasks/main.yml b/contrib/test/roles/irc_channel_notice/tasks/main.yml index 1bd036dd..27dc7360 100644 --- a/contrib/test/roles/irc_channel_notice/tasks/main.yml +++ b/contrib/test/roles/irc_channel_notice/tasks/main.yml @@ -33,6 +33,8 @@ - debug: msg: 'Sending - {{ irc_server | trim }}#{{ irc_channel | trim }}: {{ irc_to |trim }}, {{ lookup("template", _irc_msg_template) | trim }}' + # FIXME: This is broken WRT freenode in Ansible 2.3 + # possibly https://github.com/ansible/ansible/issues/24023 - name: Irc notification is sent irc: server: '{{ irc_server | trim }}'