Compare commits

...

No commits in common. 'i10cs' and 'c9' have entirely different histories.
i10cs ... c9

4
.gitignore vendored

@ -1 +1,3 @@
SOURCES/rhc-worker-playbook-0.2.2.tar.xz
SOURCES/ansible-collection-ansible-posix-1.3.0.tar.gz
SOURCES/ansible-collection-community-general-4.4.0.tar.gz
SOURCES/rhc-worker-playbook-0.1.8.tar.gz

@ -1 +1,3 @@
79fe52d8eeea96b459a639915fd6d3ddb4d1959b SOURCES/rhc-worker-playbook-0.2.2.tar.xz
7027d309191f35d3dafb3fc37d9fe25b195ef769 SOURCES/ansible-collection-ansible-posix-1.3.0.tar.gz
1f333c73866dd59f120a3576ab701555d0e9bdf5 SOURCES/ansible-collection-community-general-4.4.0.tar.gz
e1db71388a14032b902941426a0ab0dda71b2f43 SOURCES/rhc-worker-playbook-0.1.8.tar.gz

@ -0,0 +1,51 @@
From 701885f0f7173f2b0ae113618d15c9f73e9522d2 Mon Sep 17 00:00:00 2001
From: Link Dupont <link@sub-pop.net>
Date: Wed, 5 May 2021 14:10:49 -0400
Subject: [PATCH] fix: Execute playbook asynchronously
Run the playbook code in a coroutine that's scheduled onto a new event loop. Return a protobuf.Receipt message in the WorkerService Send implementation.
Resolves: rhbz#2020426
(cherry picked from commit 332d28d1bb636a5dc8ff5ddf3da8359a9a78b297)
Signed-off-by: Gael Chamoulaud (Strider) <gchamoul@redhat.com>
---
rhc_worker_playbook/server.py | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
index 985ea98..8fa393f 100644
--- a/rhc_worker_playbook/server.py
+++ b/rhc_worker_playbook/server.py
@@ -16,6 +16,7 @@ import time
import json
import uuid
import atexit
+import asyncio
from subprocess import Popen, PIPE
from requests import Request
from concurrent import futures
@@ -135,9 +136,13 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
'''
Act on messages sent to the WorkerService
'''
- # we have received it
- yggdrasil_pb2.Receipt()
+ loop = asyncio.new_event_loop()
+ loop.run_until_complete(self._run_data(request))
+
+ return yggdrasil_pb2.Receipt()
+
+ async def _run_data(self, request):
# load configuration
config = _loadConfig()
@@ -256,7 +261,6 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
_log("Posting events...")
response = self.dispatcher.Send(returnedEvents)
_log("Post complete.")
- return
def serve():
# load config to get directive

@ -0,0 +1,25 @@
From 1f417d0241af6fd15697da55ed3f44c655567f7e Mon Sep 17 00:00:00 2001
From: Jeremy Audet <audet.jeremy@pm.me>
Date: Thu, 4 Aug 2022 17:38:51 -0400
Subject: [PATCH] Do not busy-wait when playbook is running
JIRA: RHELPLAN-130334
Resolves: rhbz#2115848
(cherry picked from commit 579a67fba5ea60543a72b118e5644206c6ba720b)
---
rhc_worker_playbook/server.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
index 8fa393f..8e9826f 100644
--- a/rhc_worker_playbook/server.py
+++ b/rhc_worker_playbook/server.py
@@ -235,6 +235,7 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
elapsedTime = 0
startTime = time.time()
while runnerThread.is_alive():
+ time.sleep(1)
elapsedTime = time.time() - startTime
if elapsedTime >= response_interval:
# hit the interval, post events

@ -0,0 +1,41 @@
From cd4ceb514130328a0365688ce9ace7bf8cde0103 Mon Sep 17 00:00:00 2001
From: Derek Horton <dehort@redhat.com>
Date: Fri, 5 Aug 2022 15:02:37 -0500
Subject: [PATCH] Use thread.join(timeout) to avoid busy waiting and simplify
interval event posting logic
Resolves: rhbz#2115848
(cherry picked from commit 478930cca7a8d4acf21aef0715e42052315cb24e)
---
rhc_worker_playbook/server.py | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/rhc_worker_playbook/server.py b/rhc_worker_playbook/server.py
index 8e9826f..e41482d 100644
--- a/rhc_worker_playbook/server.py
+++ b/rhc_worker_playbook/server.py
@@ -231,20 +231,14 @@ class WorkerService(yggdrasil_pb2_grpc.WorkerServicer):
artifact_dir=RUNNER_ARTIFACTS_DIR,
rotate_artifacts=RUNNER_ROTATE_ARTIFACTS)
- # initialize elapsed counter
- elapsedTime = 0
- startTime = time.time()
+ # wait for the thread to finish
while runnerThread.is_alive():
- time.sleep(1)
- elapsedTime = time.time() - startTime
- if elapsedTime >= response_interval:
+ runnerThread.join(response_interval)
+ if runnerThread.is_alive():
# hit the interval, post events
_log("Hit the response interval. Posting current status...")
returnedEvents = _composeDispatcherMessage(events, return_url, response_to)
response = self.dispatcher.Send(returnedEvents)
- # reset interval timer
- elapsedTime = 0
- startTime = time.time()
if runner.status == 'failed':
# last event sould be the failure, find the reason

@ -1,137 +1,125 @@
## START: Set by rpmautospec
## (rpmautospec version 0.6.5)
## RPMAUTOSPEC: autorelease, autochangelog
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
release_number = 2;
base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec
%bcond_without check
%global goipath github.com/redhatinsights/rhc-worker-playbook
Version: 0.2.2
%global tag v%{version}
%gometa -f
%global common_description %{expand:
A worker for yggdrasil that receives Ansible playbooks and executes them against
the local host.}
%global golicenses LICENSE
%global godocs CONTRIBUTING.md README.md
%define debug_package %{nil}
%define community_general_version 4.4.0
%define ansible_posix_version 1.3.0
Name: rhc-worker-playbook
Release: %autorelease
Summary: Ansible playbook yggdrasil worker
License: GPL-2.0-or-later
URL: %{gourl}
Source: %{url}/releases/download/%{tag}/rhc-worker-playbook-%{version}.tar.xz
BuildRequires: ansible-core
BuildRequires: golang >= 1.18
BuildRequires: jq
BuildRequires: meson
BuildRequires: pkgconfig(dbus-1)
BuildRequires: pkgconfig(systemd)
BuildRequires: pkgconfig(yggdrasil)
BuildRequires: python3dist(pip)
BuildRequires: systemd-rpm-macros
BuildRequires: python3-rpm-macros
%if %{with check}
BuildRequires: insights-client
%endif
Version: 0.1.8
Release: 4%{?dist}
Summary: Python worker for Red Hat connector that launches Ansible Runner
License: GPLv2+
URL: https://github.com/redhatinsights/rhc-worker-playbook
Source: rhc-worker-playbook-0.1.8.tar.gz
Source1: https://github.com/ansible-collections/community.general/archive/%{community_general_version}/ansible-collection-community-general-%{community_general_version}.tar.gz
Source2: https://github.com/ansible-collections/ansible.posix/archive/%{ansible_posix_version}/ansible-collection-ansible-posix-%{ansible_posix_version}.tar.gz
#
# patches_ignore=DROP-IN-RPM
# patches_base=8ddc5ccfc97290a021b4c4de673b92fedc38cbfb
Patch0001: 0001-fix-Execute-playbook-asynchronously.patch
Patch0002: 0002-Do-not-busy-wait-when-playbook-is-running.patch
Patch0003: 0003-Use-thread.join-timeout-to-avoid-busy-waiting-and-si.patch
%{?__python3:Requires: %{__python3}}
Requires: insights-client
Requires: python3dist(requests)
Requires: python3dist(pyyaml)
Requires: ansible-core
BuildRequires: rhc
BuildRequires: pkgconfig
BuildRequires: python3-devel
BuildRequires: python3dist(pip)
BuildRequires: python3dist(wheel)
BuildRequires: python3dist(setuptools)
BuildRequires: openssl-devel
BuildRequires: c-ares-devel
BuildRequires: zlib-devel
BuildRequires: python3dist(cython)
BuildRequires: gcc
BuildRequires: gcc-c++
%description %common_description
%global setup_flags -Dvendor=True
ExclusiveArch: x86_64 s390x ppc64 ppc64le
%gopkg
%description
Python-based worker for Red Hat connect, used to launch Ansible playbooks via Ansible Runner.
%prep
%goprep %{?rhel:-k}
%if %{undefined rhel}
%generate_buildrequires
%go_generate_buildrequires
%endif
%setup -q -a1 -a2 -n %{name}-%{version}
%patch0001 -p1
%patch0002 -p1
%patch0003 -p1
pushd community.general-%{community_general_version}
rm -vr .github .azure-pipelines
rm -rvf tests/ hacking/
find -type f ! -executable -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{}' +
find -type f -name '.gitignore' -print -delete
popd
pushd ansible.posix-%{ansible_posix_version}
rm -vr tests/{integration,utils} .github changelogs/fragments/.keep {test-,}requirements.txt shippable.yml
rm -vr .azure-pipelines
rm -rvf tests/
find -type f ! -executable -name '*.py' -print -exec sed -i -e '1{\@^#!.*@d}' '{}' +
find -type f -name '.gitignore' -print -delete
popd
%build
%undefine _auto_set_build_flags
export %gomodulesmode
%{?gobuilddir:export GOPATH="%{gobuilddir}:${GOPATH:+${GOPATH}:}%{?gopath}"}
%meson %setup_flags "-Dgobuildflags=[%(echo %{expand:%gocompilerflags} | sed -e s/"^"/"'"/ -e s/" "/"', '"/g -e s/"$"/"'"/), '-tags', '"rpm_crashtraceback\ ${BUILDTAGS:-}"', '-a', '-v', '-x']" -Dgoldflags='%{?currentgoldflags} -B 0x%(head -c20 /dev/urandom|od -An -tx1|tr -d " \n") -compressdwarf=false -linkmode=external -extldflags "%{build_ldflags} %{?__golang_extldflags}"'
%meson_build
export GRPC_PYTHON_BUILD_WITH_CYTHON=True
export GRPC_PYTHON_BUILD_SYSTEM_OPENSSL=True
export GRPC_PYTHON_BUILD_SYSTEM_ZLIB=True
export GRPC_PYTHON_BUILD_SYSTEM_CARES=True
export GRPC_PYTHON_DISABLE_LIBC_COMPATIBILITY=True
# TODO(gchamoul): Remove workaround
# once https://bugzilla.redhat.com/show_bug.cgi?id=2056959 is fixed
#%define rhc_config_dir $(pkg-config rhc --variable workerconfdir)
%define rhc_config_dir /etc/rhc/workers
%define _lto_cflags %{nil}
%set_build_flags
%{__make} PREFIX=%{_prefix} LIBDIR=%{_libdir} CONFIG_DIR=%{rhc_config_dir} PYTHON_PKGDIR=%{python3_sitelib} installed-lib-dir
%{make_build} build
# Building the Ansible Collections
pushd community.general-%{community_general_version}
tar -cf %{_tmppath}/community-general-%{community_general_version}.tar.gz .
popd
pushd ansible.posix-%{ansible_posix_version}
tar -cf %{_tmppath}/ansible-posix-%{ansible_posix_version}.tar.gz .
popd
%install
%meson_install
%py3_shebang_fix \
%{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/ansible/posix/.azure-pipelines/scripts/*.py \
%{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/ansible/posix/tests/utils/shippable/*.py \
%{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/community/general/.azure-pipelines/scripts/*.py \
%{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/community/general/tests/*/extra/*.py \
%{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/community/general/tests/integration/targets/django_manage/files/base_test/1045-single-app-project/single_app_project/*.py \
%{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/community/general/tests/integration/targets/django_manage/files/base_test/simple_project/p1/*.py \
%{nil}
%{__install} --directory %{buildroot}%{_localstatedir}/lib/%{name}
%if %{with check}
%check
%meson_test
%endif
%post
%systemd_post com.redhat.Yggdrasil1.Worker1.rhc_worker_playbook.service
%preun
%systemd_preun com.redhat.Yggdrasil1.Worker1.rhc_worker_playbook.service
%postun
%systemd_postun_with_restart com.redhat.Yggdrasil1.Worker1.rhc_worker_playbook.service
%files
%license LICENSE
%if %{defined rhel}
%license vendor/modules.txt
%endif
%doc CONTRIBUTING.md README.md
%{_libexecdir}/*
%config(noreplace) %{_sysconfdir}/%{name}/%{name}.toml
%{_unitdir}/*
%{_datadir}/dbus-1/{interfaces,system-services,system.d}/*
%{_datadir}/%{name}
%{_libdir}/%{name}
%dir %attr(700, root, yggdrasil-worker) %{_localstatedir}/lib/%{name}
%{make_install} PREFIX=%{_prefix} LIBDIR=%{_libdir} CONFIG_DIR=%{rhc_config_dir} PYTHON_PKGDIR=%{python3_sitelib}
%changelog
## START: Generated by rpmautospec
* Tue Oct 29 2024 Troy Dawson <tdawson@redhat.com> - 0.2.2-2
- Bump release for October 2024 mass rebuild:
# Installing the Ansible Collections
mkdir -p %{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/community/general
mkdir -p %{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/ansible/posix
* Fri Oct 25 2024 MSVSphere Packaging Team <packager@msvsphere-os.ru> - 0.2.2-1
- Rebuilt for MSVSphere 10
pushd %{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/community/general
tar -xf %{_tmppath}/community-general-%{community_general_version}.tar.gz
popd
* Thu Oct 03 2024 Link Dupont <link@sub-pop.net> - 0.2.2-1
- Update to 0.2.2
pushd %{buildroot}%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/ansible/posix
tar -xf %{_tmppath}/ansible-posix-%{ansible_posix_version}.tar.gz
popd
* Thu May 30 2024 Jiri Hnidek <jhnidek@redhat.com> 0.1.8-8
- Use SPDX format of GPLv2+ license in .spec file
# Creating the logs directory for ansible-runner
mkdir -p %{buildroot}%{_localstatedir}/log/rhc-worker-playbook/ansible/
* Fri Dec 08 2023 Pino Toscano <ptoscano@redhat.com> 0.1.8-7
- Avoid writing Python bytecode (RHEL-14277)
* Wed Mar 22 2023 Link Dupont <link@redhat.com> 0.1.8-6
- Enable stripping of debug symbols into a debuginfo package.
%files
%{_libexecdir}/rhc/rhc-worker-playbook.worker
%{python3_sitelib}/rhc_worker_playbook/
%{python3_sitelib}/rhc_worker_playbook*.egg-info/
%{_libdir}/rhc-worker-playbook/
%{_datadir}/rhc-worker-playbook/ansible/collections/ansible_collections/
%{_localstatedir}/log/rhc-worker-playbook/ansible/
%config(noreplace) %{_sysconfdir}/rhc/workers/rhc-worker-playbook.toml
* Fri Mar 03 2023 Link Dupont <link@redhat.com> 0.1.8-5
- Drop ExclusiveArch, but exclude i686 (RHBZ#2178692)
%doc
%changelog
* Thu Oct 20 2022 Gael Chamoulaud <gchamoul@redhat.com> 0.1.8-4
- Use thread.join(timeout) to avoid busy waiting and simplify interval event posting logic (rhbz#2115848)
@ -173,5 +161,3 @@ export %gomodulesmode
- Enhancements to playbook validation
- Fixes for regular execution status updates
- Configuration fixes
## END: Generated by rpmautospec

Loading…
Cancel
Save