diff --git a/rhn-client-tools.spec b/rhn-client-tools.spec index a01d876e48..c78d864687 100644 --- a/rhn-client-tools.spec +++ b/rhn-client-tools.spec @@ -5,7 +5,7 @@ Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar. URL: https://fedorahosted.org/spacewalk Name: rhn-client-tools Version: 2.0.2 -Release: 18%{?dist} +Release: 19%{?dist} BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) BuildArch: noarch %if 0%{?suse_version} @@ -361,6 +361,12 @@ make -f Makefile.rhn-client-tools test %endif %changelog +* Mon Oct 09 2017 Tomas Kasparek 2.0.2-19 +- Related: #1494389 - detect if action has been picked up for 2nd time + (tkasparek@redhat.com) +- Resolves: #1494389 - revert previous reboot loop changes + (tkasparek@redhat.com) + * Thu Sep 21 2017 Tomas Kasparek 2.0.2-18 - Resolves: #1430298 - rhnreg_ks man page missing documentation for some options (ogajduse@redhat.com) diff --git a/src/bin/rhn_check.py b/src/bin/rhn_check.py index 54cb9242bf..1dc0e90ef4 100755 --- a/src/bin/rhn_check.py +++ b/src/bin/rhn_check.py @@ -28,6 +28,8 @@ # do not wish to do so, delete this exception statement from your # version. If you delete this exception statement from all source # files in the program, then also delete it here. + +import base64 import os import sys import socket @@ -48,39 +50,23 @@ from up2date_client import config from up2date_client import clientCaps from up2date_client import capabilities from up2date_client import rhncli, rhnserver -import signal -from rhn import SSL -from rhn import rhnLockfile - -import base64 -import time - -try: # python2 - import xmlrpclib -except ImportError: # python3 - import xmlrpc.client as xmlrpclib - long = int -if 'sgmlop' in sys.modules: - del sys.modules['sgmlop'] +from rhn import rhnLockfile +import xmlrpclib cfg = config.initUp2dateConfig() log = up2dateLog.initLog() + # action version we understand ACTION_VERSION = 2 -# Stop execution of future actions -TERMINATE = False - -# SystemExit exception error code -SYSEXIT_CODE = 3 - # lock file to check if we're disabled at the server's request DISABLE_FILE = "/etc/sysconfig/rhn/disable" # Actions that will run each time we execute. LOCAL_ACTIONS = [("packages.checkNeedUpdate", ("rhnsd=1",))] + class CheckCli(rhncli.RhnCli): def __init__(self): @@ -205,7 +191,6 @@ class CheckCli(rhncli.RhnCli): sys.exit(1) self.handle_action(action) - action = self.__get_action(status_report) def __verify_server_capabilities(self, caps): @@ -261,15 +246,33 @@ class CheckCli(rhncli.RhnCli): log.log_debug("handle_action", action) log.log_debug("handle_action actionid = %s, version = %s" % ( action['id'], action['version'])) - + + data = {} + action_lock = '/var/lib/up2date/action.%s' % str(action['id']) + if os.path.exists(action_lock): + ret = 255 + if not cache_only: + if os.path.getsize(action_lock) > 0: + data['base64enc'] = 1 + data['return_code'] = 255 + data['process_start'] = '1970-01-01 00:00:00' # dummy values as we have no idea of start + data['process_end'] = '1970-01-01 00:00:00' # and especially about the end + with open(action_lock) as f: + data['output'] = base64.encodestring(f.read()) + log.log_debug("Sending back response", (255, "Previous run of action didn't completed sucessfully, aborting.", data)) + ret = self.submit_response(action['id'], 255, "Previous run of action didn't completed sucessfully, aborting.", data) + os.remove(action_lock) + return ret + + open(action_lock, 'a').close() + (method, params) = self.__parse_action_data(action) (status, message, data) = CheckCli.__run_action(method, params, {'cache_only': cache_only}) ret = 0 if not cache_only: log.log_debug("Sending back response", (status, message, data)) ret = self.submit_response(action['id'], status, message, data) - if TERMINATE: - sys.exit(0) + os.remove(action_lock) return ret @@ -369,23 +372,6 @@ class CheckCli(rhncli.RhnCli): def __run_action(method, params, kwargs={}): try: (status, message, data) = CheckCli.__do_call(method, params, kwargs) - except SystemExit: - e = sys.exc_info()[1] - global TERMINATE - TERMINATE = True - # Are we dealing with shutdown script? If yes, send some response - # to server ASAP - if e.code == SYSEXIT_CODE: - extras = { - 'output': '', - 'base64enc': 0, - 'return_code': 0, - 'process_start': '', - 'process_end': '' - } - for key in ('process_start', 'process_end'): - extras[key] = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime()) - return 0, "Script executed. Termination signal occurred during execution", extras except getMethod.GetMethodException: log.log_debug("Attempt to call an unsupported action ", method, params)