Dan Kenigsberg has posted comments on this change.

Change subject: bootstrap: use yum API
......................................................................


Patch Set 8: I would prefer that you didn't submit this

(18 inline comments)

I'm not sure I understand everything you do, but it's lookin' good.

....................................................
File vds_bootstrap/miniyum.py
Line 1: #!/usr/bin/python
our lawyers loves the GPL boilerplate. Let's make them happy.
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
this belongs to the non-stdlib part of imports
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: 
please add the new file to PEP8_WHITELIST
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?
sorry, I don't understand the comment here.
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))
Why do we need this big try block? Suppose that

  self._yb.history_undo()

explodes. Do we really want to go on as if nothing happened? In any case, would 
you log the traceback, too?
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"
calling str() can be a problem if s in unicode. I don't know if that's probable.

However, I do not know how important is this adding of newlines. from what I 
see in yum.Errors.YumBaseError.__str__, using

 "%s" % e

has reasonable defaults.
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))
needless call to str(). %s does it better.

p.s. I love tracebacks.
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
pardon my blasphemy, but why replace selinux_role() with running

  chcon -t rpm_exec_t vds_bootstrap ...

from setup?
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:
being specific is generally safer

 except ImportError
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):
I don't understand why you don't list ignoreErrors=False here, and drop kwargs. 
_queue is not accepting any other arg.
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)
I suppose that returning None here was unintentional.

How about

  return self.install() or self.update()

(notice the lazy eval, you do not need an update if install succeeded)
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):
wouldn't it be nicer to run this *always*, on a successful __exit__ from a 
transaction with queued operations?

please consider in a future rewrite.
Line 502:         """Build transaction.
Line 503: 
Line 504:         returns False if empty.
Line 505: 


Line 524:                 for s in e.value:
Line 525:                     msg += str(s) + "\n"
Line 526:             else:
Line 527:                 msg = str(e.value)
Line 528:             self._sink.error(msg)
here too: I had bad experience with using str(). unicode() is safer, and in my 
opinion, "%s"%e is even better.
Line 529:             raise
Line 530: 
Line 531:         except Exception, e:
Line 532:             self._sink.error(str(e))


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":
I don't understand the example. why should other exceptions be swallowed?
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:
now it is never None
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
I'm sure that you've thought this through, but wouldn't it be more prudent to 
fail installation if we see an unknown gpg key?
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)
cman is not conflicting for a long long time.
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
cannot parse the English, sorry.
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 <[email protected]>
Gerrit-Reviewer: Alon Bar-Lev <[email protected]>
Gerrit-Reviewer: Barak Azulay <[email protected]>
Gerrit-Reviewer: Dan Kenigsberg <[email protected]>
Gerrit-Reviewer: Doron Fediuck <[email protected]>
Gerrit-Reviewer: Douglas Schilling Landgraf <[email protected]>
Gerrit-Reviewer: Igor Lvovsky <[email protected]>
Gerrit-Reviewer: Juan Hernandez <[email protected]>
Gerrit-Reviewer: Pradipta Banerjee <[email protected]>
Gerrit-Reviewer: Rodrigo Trujillo <[email protected]>
Gerrit-Reviewer: Saggi Mizrahi <[email protected]>
Gerrit-Reviewer: Shireesh Anjal <[email protected]>
Gerrit-Reviewer: Yaniv Bronhaim <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to