Improve abort mechanism to support same functionality as stable/mitaka
Closes-bug: 1615662 Change-Id: Ifb5f312d4718329c1afad6c384fba1854e2b10ba
This commit is contained in:
parent
6683ead4c8
commit
95278ac06c
@ -30,7 +30,6 @@ from freezer.scheduler import arguments
|
||||
from freezer.scheduler import scheduler_job
|
||||
from freezer.scheduler import shell
|
||||
from freezer.scheduler import utils
|
||||
from freezer.utils import utils as freezer_utils
|
||||
from freezer.utils import winutils
|
||||
|
||||
|
||||
@ -162,13 +161,10 @@ class FreezerScheduler(object):
|
||||
work_job_id_list.append(job_id)
|
||||
job = self.jobs.get(job_id, None) or self.create_job(job_doc)
|
||||
if job:
|
||||
|
||||
# check for abort status
|
||||
if (job_doc['job_schedule']['event'] == 'abort' and
|
||||
job_doc['job_schedule']['result'] != 'aborted'):
|
||||
|
||||
if job_doc['job_schedule']['event'] == 'abort':
|
||||
pid = int(job_doc['job_schedule']['current_pid'])
|
||||
freezer_utils.terminate_subprocess(pid, 'freezer-agent')
|
||||
utils.terminate_subprocess(pid, 'freezer-agent')
|
||||
|
||||
job.process_event(job_doc)
|
||||
|
||||
|
@ -357,7 +357,10 @@ class Job(object):
|
||||
self.upload_metadata(output)
|
||||
|
||||
if self.process.returncode == -15:
|
||||
# This means the job action was aborted by the scheduler.
|
||||
# This means the job action was aborted by the scheduler
|
||||
LOG.warning('Freezer-agent was killed by the scheduler. '
|
||||
'Cleanup should be done manually: container, '
|
||||
'mountpoint and lvm snapshots.')
|
||||
return Job.ABORTED_RESULT
|
||||
|
||||
elif self.process.returncode:
|
||||
|
@ -17,11 +17,18 @@ limitations under the License.
|
||||
|
||||
import json
|
||||
import os
|
||||
import psutil
|
||||
import signal
|
||||
import socket
|
||||
import uuid
|
||||
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
import freezer.apiclient.exceptions
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
CONFIG_FILE_EXT = '.conf'
|
||||
|
||||
|
||||
@ -99,3 +106,15 @@ def get_active_jobs_from_api(client):
|
||||
break
|
||||
offset += len(jobs)
|
||||
return job_list
|
||||
|
||||
|
||||
def terminate_subprocess(pid, name):
|
||||
try:
|
||||
process = psutil.Process(pid)
|
||||
if process.name.startswith(name):
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
else:
|
||||
LOG.warning('The name {} does not match the pid {}'.format(
|
||||
name, pid))
|
||||
except Exception:
|
||||
LOG.debug('Process {} does not exists anymore'.format(pid))
|
||||
|
@ -30,8 +30,6 @@ from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from six.moves import configparser
|
||||
|
||||
import psutil
|
||||
|
||||
CONF = cfg.CONF
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
@ -512,15 +510,3 @@ def set_max_process_priority():
|
||||
])
|
||||
except Exception as priority_error:
|
||||
LOG.warning('Priority: {0}'.format(priority_error))
|
||||
|
||||
|
||||
def terminate_subprocess(pid, name):
|
||||
try:
|
||||
process = psutil.Process(pid)
|
||||
if process.name.startswith(name):
|
||||
process.terminate()
|
||||
else:
|
||||
LOG.warning('The name {} does not match the pid {}'.format(
|
||||
name, pid))
|
||||
except Exception:
|
||||
LOG.error('Process {} does not exists anymore'.format(pid))
|
||||
|
@ -23,4 +23,4 @@ six>=1.9.0 # MIT
|
||||
# Not in global-requirements
|
||||
apscheduler # MIT License
|
||||
|
||||
psutil<2.0.0,>=1.1.1 # BSD
|
||||
psutil>=1.1.1,<2.0.0 # BSD
|
||||
|
Loading…
x
Reference in New Issue
Block a user