Alex Lourie has posted comments on this change.
Change subject: [WIP] packaging: added DB validation functions on upgrade
......................................................................
Patch Set 4: (29 inline comments)
....................................................
File packaging/setup/plugins/ovirt-engine-setup/upgrade/asynctasks.py
Line 36: @util.export
Line 37: class Plugin(plugin.PluginBase):
Line 38: """ DB Async tasks handling plugin."""
Line 39:
Line 40: _CLEANUP_WAIT_SECONDS = 180
Done
Line 41:
Line 42: class _engineInMaintenance(base.Base):
Line 43: (
Line 44: _OP_NORMAL,
Line 42: class _engineInMaintenance(base.Base):
Line 43: (
Line 44: _OP_NORMAL,
Line 45: _OP_MAINTENANCE,
Line 46: ) = range(2)
Done
Line 47:
Line 48: def __init__(
Line 49: self,
Line 50: parent,
Line 49: self,
Line 50: parent,
Line 51: dbstatement,
Line 52: ):
Line 53: self.services = parent.services
Done
Line 54: self._origTimeout = 0
Line 55: self._dbstatement = dbstatement
Line 56:
Line 57: def _setEngineMode(self, mode=self._OP_NORMAL):
Line 63: try:
Line 64: self._dbstatement.updateVDCOption(
Line 65: {
Line 66: 'name': 'EngineMode',
Line 67: 'value': op,
Done
Line 68: }
Line 69: )
Line 70: except:
Line 71: raise RuntimeError(
Line 66: 'name': 'EngineMode',
Line 67: 'value': op,
Line 68: }
Line 69: )
Line 70: except:
Done
Line 71: raise RuntimeError(
Line 72: _(
Line 73: 'Failed to set engine to {op} mode. '
Line 74: 'Please check that engine is in correct state '
Line 77: op=op,
Line 78: )
Line 79: )
Line 80:
Line 81: def _configureTasksTimeout(self, timeout):
Done
Line 82:
Line 83: # First, get the originalTimeout value
Line 84: originalTimeout = self._dbstatement.getVDCOption(
Line 85: name='AsyncTaskZombieTaskLifeInMinutes'
Line 82:
Line 83: # First, get the originalTimeout value
Line 84: originalTimeout = self._dbstatement.getVDCOption(
Line 85: name='AsyncTaskZombieTaskLifeInMinutes'
Line 86: )
Done
Line 87:
Line 88: # Now, set the value to timeout
Line 89: self._dbstatement.updateVDCOption(
Line 90: {
Line 89: self._dbstatement.updateVDCOption(
Line 90: {
Line 91: 'name': 'AsyncTaskZombieTaskLifeInMinutes',
Line 92: 'value': timeout,
Line 93: }
Done
Line 94: )
Line 95:
Line 96: # If everything went fine, return the original value
Line 97: return originalTimeout
Line 99: def __enter__(self):
Line 100: self._origTimeout = self._configureTasksTimeout(
Line 101: timeout=0
Line 102: )
Line 103: self.logger.debug(
Done
Line 104: 'Setting engine into maintenance mode'
Line 105: )
Line 106: self._setEngineMode(self._OP_MAINTENANCE)
Line 107:
Line 114: )
Line 115:
Line 116: def __exit__(self, exc_type, exc_value, traceback):
Line 117: # Restore previous engine configuration
Line 118: self.logger.debug(
Done
Line 119: 'Restoring engine to normal mode'
Line 120: )
Line 121: # Stop the engine first
Line 122: self.services.state(
Line 124: osetupcons.Const.ENGINE_SERVICE_NAME
Line 125: ],
Line 126: state=False,
Line 127: )
Line 128: # Restore normal mode
Done
Line 129: self._setEngineMode(self._OP_NORMAL)
Line 130: # Restore previous zombie timeout
Line 131: self._configureTasksTimeout(
Line 132: timeout=self._origTimeout
Line 138:
Line 139: def _clearZombieTasks(self):
Line 140: args = [
Line 141: osetupcons.FileLocations.OVIRT_ENGINE_TASKCLEANER,
Line 142: '-u', self.environment[osetupcons.DBEnv.USER],
DB params support both, but options do not. It's either all short, or some
short some long. I think it's better to keep them unified as short.
Line 143: '-s', self.environment[osetupcons.DBEnv.HOST],
Line 144: '-p', self.environment[osetupcons.DBEnv.PORT],
Line 145: '-d', self.environment[osetupcons.DBEnv.DATABASE],
Line 146: '-R',
Line 160: 'Failed to clear zombie tasks. Please try running
the '
Line 161: 'following command manually and repeat the
upgrade: '
Line 162: '\t{command}'
Line 163: ).format(
Line 164: command=' '.join(args)
Done
Line 165: )
Line 166: )
Line 167:
Line 168:
Line 173: select
Line 174: a.action_type,
Line 175: a.task_id,
Line 176: a.started_at,
Line 177: b.name
Done
Line 178: from async_tasks a, storage_pool b
Line 179: where a.storage_pool_id = b.id
Line 180: """,
Line 181: ownConnection=True,
Line 181: ownConnection=True,
Line 182: transaction=False,
Line 183: )[0]
Line 184:
Line 185: from async_tasks_map import async_tasks_map
forgot to include it in the src. It is the map that translates async object
codes into human-readable text.
Line 186: return '\n'.join(
Line 187: [
Line 188: '\n---- Task ID: {task_id:30} ------- \n'
Line 189: 'Task Name: {task_name:30}\n'
Line 184:
Line 185: from async_tasks_map import async_tasks_map
Line 186: return '\n'.join(
Line 187: [
Line 188: '\n---- Task ID: {task_id:30} ------- \n'
Done
Line 189: 'Task Name: {task_name:30}\n'
Line 190: 'Task Description: {task_desc:30}\n'
Line 191: 'Started at: {started_at:30}\n'
Line 192: 'DC Name: {name:30}\n'.format(
Line 204:
Line 205: compensations = dbstatement.execute(
Line 206: statement="""
Line 207: select
Line 208: command_type, entity_type
Done
Line 209: from business_entity_snapshot
Line 210: """,
Line 211: ownConnection=True,
Line 212: transaction=False,
Line 218: for entry in compensations
Line 219: ]
Line 220: )
Line 221:
Line 222: def _stopTasks(self, runningTasks, compensations):
Done
Line 223: now = datetime.datetime.now()
Line 224: timestamp = now.strftime('%b %d %H:%M:%S')
Line 225: return self.dialog.queryBoolean(
Line 226: dialog=self.dialog,
Line 264: if runningTasks or compensations:
Line 265:
Line 266: if not self._stopTasks(runningTasks, compensations):
Line 267: raise RuntimeError(
Line 268: _('User decided not to stop running tasks.
Exiting.')
removed, not relevant.
Line 269: )
Line 270:
Line 271: self.dialog.note(
Line 272: text=self._infoStoppingTasks()
Line 276: dbstatement=dbstatement,
Line 277: parent=self,
Line 278: ):
Line 279: # Pull tasks in a loop for some time
Line 280: # _CLEANUP_WAIT_SECONDS = 180 (seconds, between
trials)
Done
Line 281: waited = 0
Line 282: while runningTasks or compensations:
Line 283: time.sleep(1)
Line 284: waited += 1
Line 291: )
Line 292:
Line 293: # If not waited complete cycle, go for next
round
Line 294: if waited < self._CLEANUP_WAIT_SECONDS:
Line 295: continue
redone.
Line 296:
Line 297: # Should we continue?
Line 298: if not self._stopTasks(runningTasks,
compensations):
Line 299: # If not, break the loop
Line 294: if waited < self._CLEANUP_WAIT_SECONDS:
Line 295: continue
Line 296:
Line 297: # Should we continue?
Line 298: if not self._stopTasks(runningTasks,
compensations):
Done
Line 299: # If not, break the loop
Line 300: # There are still tasks running, so exit
and tell
Line 301: # to resolve before user continues.
Line 302: raise RuntimeError(
Line 326: stage=plugin.Stages.STAGE_INIT,
Line 327: )
Line 328: def _init(self):
Line 329: self.environment.setdefault(
Line 330: osetupcons.DBEnv.IGNORE_TASKS,
Done
Line 331: False
Line 332: )
Line 333:
Line 334: @plugin.event(
Line 339: osetupcons.DBEnv.IGNORE_TASKS
Line 340: ] == False
Line 341:
Line 342: @plugin.event(
Line 343: stage=plugin.Stages.STAGE_VALIDATION,
Done
Line 344: after=[
Line 345: osetupcons.Stages.FIX_DB_VIOLATIONS
Line 346: ],
Line 347: #before yum update
Line 341:
Line 342: @plugin.event(
Line 343: stage=plugin.Stages.STAGE_VALIDATION,
Line 344: after=[
Line 345: osetupcons.Stages.FIX_DB_VIOLATIONS
Done
Line 346: ],
Line 347: #before yum update
Line 348: condition=lambda self: self._enabled,
Line 349: )
Line 343: stage=plugin.Stages.STAGE_VALIDATION,
Line 344: after=[
Line 345: osetupcons.Stages.FIX_DB_VIOLATIONS
Line 346: ],
Line 347: #before yum update
Done
Line 348: condition=lambda self: self._enabled,
Line 349: )
Line 350: def _validation(self):
Line 351:
....................................................
File packaging/setup/plugins/ovirt-engine-setup/upgrade/dbvalidations.py
Line 74:
Line 75: rc, stdout, stderr = self._dbUtil()
Line 76: if rc != 0:
Line 77: raise Exception(
Line 78: 'Error: failed checking DB:\n{output}\n'.format(
Done
Line 79: output=stdout,
Line 80: )
Line 81: )
Line 82:
Line 79: output=stdout,
Line 80: )
Line 81: )
Line 82:
Line 83: result = (
Done, leftovers.
Line 84: '{content}'
Line 85: ).format(
Line 86: dbname=dbname,
Line 87: content=stdout,
Line 123: if issues_found:
Line 124: if self.environment[
Line 125: osetupcons.DBEnv.FIX_DB_VIOLATIONS
Line 126: ] is None:
Line 127: self.dialog.note(
Done
Line 128: text=_(
Line 129: 'The following inconsistencies were found '
Line 130: 'in the DB: {violations}. '
Line 131: ).format(
--
To view, visit http://gerrit.ovirt.org/15970
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I25979acbf54d980168be929638ff4aed800bf6d3
Gerrit-PatchSet: 4
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alex Lourie <[email protected]>
Gerrit-Reviewer: Alex Lourie <[email protected]>
Gerrit-Reviewer: Alon Bar-Lev <[email protected]>
Gerrit-Reviewer: Moran Goldboim <[email protected]>
Gerrit-Reviewer: Ofer Schreiber <[email protected]>
Gerrit-Reviewer: Sandro Bonazzola <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches