Change in vdsm[master]: bootstrap: use yum API
Alon Bar-Lev
alonbl at redhat.com
Wed Sep 26 23:56:00 UTC 2012
Alon Bar-Lev has posted comments on this change.
Change subject: bootstrap: use yum API
......................................................................
Patch Set 8: (17 inline comments)
Thank you!
Some questions inside.
....................................................
File vds_bootstrap/miniyum.py
Line 1: #!/usr/bin/python
Done
Line 2:
Line 3: import os
Line 4: import sys
Line 5: import logging
Line 3: import os
Line 4: import sys
Line 5: import logging
Line 6: import time
Line 7: import yum
Done
Line 8:
Line 9:
Line 10: from yum.rpmtrans import RPMBaseCallback
Line 11: from yum.callbacks import PT_MESSAGES, PT_DOWNLOAD_PKGS
Line 4: import sys
Line 5: import logging
Line 6: import time
Line 7: import yum
Line 8:
Done
Line 9:
Line 10: from yum.rpmtrans import RPMBaseCallback
Line 11: from yum.callbacks import PT_MESSAGES, PT_DOWNLOAD_PKGS
Line 12: from yum.Errors import YumBaseError
Line 308: if (
Line 309: transactionCurrent.altered_lt_rpmdb or
Line 310: transactionCurrent.altered_gt_rpmdb
Line 311: ):
Line 312: # safe guard?
I don't understand the above condition, I copied this from yum... so I left a note.
Line 313: pass
Line 314: else:
Line 315: if self._yb.history_undo(transactionCurrent):
Line 316: self._yb.processTransaction()
Line 314: else:
Line 315: if self._yb.history_undo(transactionCurrent):
Line 316: self._yb.processTransaction()
Line 317: except Exception, e:
Line 318: self._sink.error(str(e))
I just don't want to lost the original exception, and there are no parents in python, right?
I will log to verbose log.
Line 319: finally:
Line 320: self._transactionBase = None
Line 321: del self._yb.tsInfo # forget current transaction
Line 322: self._yb.doUnlock()
Line 336: ret = False
Line 337: msg = ""
Line 338: if type(e.value) is list:
Line 339: for s in e.value:
Line 340: msg += str(s) + "\n"
So what do you recommend? I did not like the raw python output of array.
Line 341: else:
Line 342: msg = str(e.value)
Line 343:
Line 344: self._sink.error(
Line 349: raise
Line 350:
Line 351: except Exception, e:
Line 352: self._sink.error(
Line 353: "cannot queue package %s: %s" % (package, str(e))
I raise the exception for you do do whatever you love with it.
Are you sure value cannot be none str? For exmaple YumError inherit from Exception and put a list?
Or you meen that '%s' always calls str(x)?
Line 354: )
Line 355: raise
Line 356:
Line 357: return ret
Line 402: to adjust proper roles for selinux.
Line 403: it will re-execute the process with same arguments.
Line 404:
Line 405: This has similar effect of:
Line 406: # chcon -t rpm_exec_t miniyum.py
Access denied on worse case...
And... none extended attribute filesystem at best case.
Line 407:
Line 408: We must do this dynamic as this class is to be
Line 409: used at bootstrap stage, so we cannot put any
Line 410: persistent selinux policy changes.
Line 412: """
Line 413:
Line 414: try:
Line 415: import selinux
Line 416: except:
Done
Line 417: with self.transaction():
Line 418: self.install(['libselinux-python'])
Line 419: if self.buildTransaction():
Line 420: self.processTransaction()
Line 456: self._yb.cleanMetadata()
Line 457: self._yb.cleanPackages()
Line 458: self._yb.cleanSqlite()
Line 459:
Line 460: def install(self, packages, **kwargs):
Because if I add more arguments to queue most probably these should be escalated to all functions that use _queue... and I don't like to update....
I thought of doing the **args as well...
Line 461: """Install packages.
Line 462:
Line 463: Keyword arguments:
Line 464: packages -- packages to install.
Line 485: ignoreErrors - to ignore errors, will return False
Line 486:
Line 487: """
Line 488: self.install(packages, **kwargs)
Line 489: self.update(packages, **kwargs)
Done
Line 490:
Line 491: def remove(self, packages, **kwargs):
Line 492: """Remove packages.
Line 493:
Line 497:
Line 498: """
Line 499: return self._queue("remove", self._yb.remove, packages, **kwargs)
Line 500:
Line 501: def buildTransaction(self):
No... we should be able to enable skipping this or run code after.
Line 502: """Build transaction.
Line 503:
Line 504: returns False if empty.
Line 505:
Line 628: if miniyum.buildTransaction():
Line 629: miniyum.processTransaction()
Line 630: raise Exception("Fail please")
Line 631: except Exception, e:
Line 632: if str(e) != "Fail please":
No... only this one... all the other are rethrown, or I missed something.
Line 633: raise
Line 634:
Line 635: if __name__ == "__main__":
....................................................
File vds_bootstrap/vds_bootstrap.py
Line 82: self._stream = os.dup(sys.stdout.fileno())
Line 83: self._touch()
Line 84:
Line 85: def __del__(self):
Line 86: if self._stream is not None:
What if os.dup throws an exception? Excuse me for my low python knowledge...
Line 87: os.close(self._stream)
Line 88:
Line 89: def _touch(self):
Line 90: self._last = time.time()
Line 126: hexkeyid
Line 127: )
Line 128: logging.warning("MiniYum: WARN: %s", msg)
Line 129: self._status('WARN', msg)
Line 130: return True
In future, I will communicate this to server so it can reply True...
If I fail, we cannot bootstrap vergine machine.
Line 131:
Line 132:
Line 133: rhel6based = deployUtil.versionCompare(deployUtil.getOSVersion(), "6.0") >= 0
Line 134:
Line 975: with miniyum.transaction():
Line 976: miniyum.clean()
Line 977:
Line 978: with miniyum.transaction():
Line 979: miniyum.remove(('cman',), ignoreErrors=True)
Done
Line 980: miniyum.install(('qemu-kvm-tools',))
Line 981: miniyum.installUpdate(('vdsm', 'vdsm-cli'))
Line 982:
Line 983: if installGlusterService:
Line 1081: print main.__doc__
Line 1082: return False
Line 1083:
Line 1084: #
Line 1085: # miniyum setup must be 1st as process
Done
Line 1086: # is probably going to be reexecute with
Line 1087: # proper selinux role
Line 1088: #
Line 1089: miniyum = None
--
To view, visit http://gerrit.ovirt.org/8039
To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment
Gerrit-Change-Id: I65796801bc2db7c5abf71c1e9e4ad8ca308138b9
Gerrit-PatchSet: 8
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <alonbl at redhat.com>
Gerrit-Reviewer: Alon Bar-Lev <alonbl at redhat.com>
Gerrit-Reviewer: Barak Azulay <bazulay at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Doron Fediuck <dfediuck at redhat.com>
Gerrit-Reviewer: Douglas Schilling Landgraf <dougsland at redhat.com>
Gerrit-Reviewer: Igor Lvovsky <ilvovsky at redhat.com>
Gerrit-Reviewer: Juan Hernandez <juan.hernandez at redhat.com>
Gerrit-Reviewer: Pradipta Banerjee <bpradip at in.ibm.com>
Gerrit-Reviewer: Rodrigo Trujillo <trujillo.unicamp at gmail.com>
Gerrit-Reviewer: Saggi Mizrahi <smizrahi at redhat.com>
Gerrit-Reviewer: Shireesh Anjal <sanjal at redhat.com>
Gerrit-Reviewer: Yaniv Bronhaim <ybronhei at redhat.com>
More information about the vdsm-patches
mailing list