Changeset 28 for trunk/provisioner.py
- Timestamp:
- 26/11/07 20:14:17 (4 years ago)
- Files:
-
- 1 modified
-
trunk/provisioner.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/provisioner.py
r27 r28 54 54 Back out a change that was applied to a specific device. 55 55 """ 56 57 class UserBailout(Exception): 58 """ 59 User denied a change command from executing in Authoritarian mode. 60 This causes the program to bail out complete at exactly that point. 61 """ 56 62 57 63 class Provisioner: … … 68 74 self.namespace = namespace 69 75 self.authoritarian = authoritarian 76 77 log.debug("My namespace is: %s", self.namespace) 70 78 71 79 def parse_config_node(self, node): … … 148 156 149 157 log.error("Change '%s' failed to apply", change.name) 150 e = failure.check( ChangeConditionFailure )158 e = failure.check( ChangeConditionFailure, UserBailout ) 151 159 if e: 152 160 log.error(" failure was: %s", failure.value ) 161 if isinstance(e, UserBailout): 162 log.info("User bailout detected.") 163 return defer.succeed('bailout') 153 164 else: 154 165 tlog.err(failure) … … 504 515 else: 505 516 log.info(" Bailing out at your command.") 506 self.waitingForCommand.errback("User requested manual bailout.") 517 raise UserBailout("Bailing out at your command") 518 #self.waitingForCommand.errback("User requested manual bailout.") 507 519 return 508 520 pass … … 572 584 for (expr, cmdstring) in expectset: 573 585 574 # Perform variable substitution on the command string 575 log.debug("determining commandstring from template: %s", cmdstring) 576 cmdstring = str(util.substituteVariables(cmdstring, namespace)) 577 log.debug("commandstring is: %s", cmdstring) 578 579 # add the cmdstring to the namespace 580 namespace['command.send'] = cmdstring 581 582 log.debug("Determining command base from template: %s", self.command) 583 command = str(util.substituteVariables(self.command, namespace)) 584 586 try: 587 # Perform variable substitution on the command string 588 log.debug("determining commandstring from template: %s", cmdstring) 589 cmdstring = str(util.substituteVariables(cmdstring, namespace)) 590 log.debug("commandstring is: %s", cmdstring) 591 592 # add the cmdstring to the namespace 593 namespace['command.send'] = cmdstring 594 595 log.debug("Determining command base from template: %s", self.command) 596 command = str(util.substituteVariables(self.command, namespace)) 597 except KeyError, e: 598 log.error("KeyError in commands: %s" % e) 599 self.all_commands_defer.errback( e ) 600 return self.all_commands_defer 601 585 602 #log.debug("checking expr: %s" % expr) 586 603 log.debug("cmdstring is: %s" % command) … … 605 622 log.debug("spawning command...") 606 623 self.waitingForCommand = defer.Deferred() 624 607 625 # If we're in authoritarian mode, wait for confirmation 608 626 # that we should execute the command. … … 617 635 self.exitcode = -1 618 636 self.cmdoutput = 'User requested manual bailout' 619 self.waitingForCommand.errback( Exception("User requested manual bailout.") ) 637 log.critical("User requested manual bailout") 638 self.waitingForCommand.errback( UserBailout("User requested manual bailout.") ) 620 639 return self.waitingForCommand 621 640 pass … … 638 657 self.cmdoutput += result[1] 639 658 log.debug("current results: exit '%d', output: %s", self.exitcode, self.cmdoutput) 640 log.error("Process: %s", self.p)641 659 642 660 def command_failed(self, failure): 643 661 errorstr = "%s: %s" % (self.exitcode, self.cmdoutput) 644 662 log.error("Command failed: %s", errorstr) 645 log.error("Process: %s", self.p)646 self.exitcode = result[0]647 self.cmdoutput += result[1]648 663 #self.all_commands_defer.errback( Exception(errorstr) ) 649 664 … … 704 719 self.parent.waitingForCommand.callback( (self.exitCode, self.databuf) ) 705 720 pass 721 722 except AlreadyCalled, AlreadyCancelled: 723 pass 706 724 707 725 except Exception, e: … … 713 731 714 732 def timedOut(self): 733 # FIXME: If the command times out, we need to ignore anything that comes 734 # back from the process, or we'll notify of error conditions more than once 735 # I'm hoping the AlreadyCalled an AlreadyCancelled catch above will take care of this. 715 736 log.error("Timed out waiting for command to exit") 716 737 self.transport.loseConnection()
