def testReturnOnFailureInterface(self): client = conaryclient.ConaryClient(self.cfg) repos = client.getRepos() self.addComponent("foo:runtime", "1.0-1-1") self.updatePkg(self.rootDir, ["foo:runtime"]) self.logFilter.add() ret = rollbacks.applyRollback(client, "r.2", returnOnError=True) self.assertEqual(ret, 1) self.logFilter.compare("error: rollback 'r.2' not present") self.logFilter.add() try: rollbacks.applyRollback(client, "r.2") except database.RollbackDoesNotExist, e: self.assertEqual(str(e), "rollback r.2 does not exist")
def testReturnOnFailureInterface(self): client = conaryclient.ConaryClient(self.cfg) repos = client.getRepos() self.addComponent('foo:runtime', '1.0-1-1') self.updatePkg(self.rootDir, [ 'foo:runtime' ]) self.logFilter.add() ret = rollbacks.applyRollback(client, 'r.2', returnOnError = True) self.assertEqual(ret, 1) self.logFilter.compare("error: rollback 'r.2' not present") self.logFilter.add() try: rollbacks.applyRollback(client, 'r.2') except database.RollbackDoesNotExist, e: self.assertEqual(str(e), 'rollback r.2 does not exist')
def applyRollback(self, rollbackSpec, replaceFiles=None, callback=None, tagScript=None, justDatabase=None, transactionCounter=None, showInfoOnly=False, abortOnError=False, noScripts=False, capsuleChangesets=[], replaceManagedFiles=False, replaceModifiedFiles=False, replaceUnmanagedFiles=False, ): """ Apply a rollback. @param rollbackSpec: Rollback specififier. This is either a number (in which case it refers to the absolute position in the rollback stack, with 0 being the oldest rollback) or a string like C{r.128}, as listed by C{conary rblist}. @type rollbackSpec: string @param replaceFiles: @type replaceFiles: bool @param callback: Callback for communicating information back to the invoker of this method. @type callback: L{callbacks.UpdateCallback} @param tagScript: A tag script. @type tagScript: path @param justDatabase: Change only the database, do not revert the filesystem. @type justDatabase: bool @param noScripts: Do not run trove scripts, including rpm scripts. @type noScripts: bool @param transactionCounter: The Conary database contains a counter that gets incremented with every change. This argument is the counter's value at the time the rollback was computed from the specifier. It is used to ensure that no uninteded rollbacks are performed, if a concurrent update happens between the moment of reading the database state and the moment of performing the rollback. @type transactionCounter: int @param abortOnError: Abort the rollback if any pre-rollback scripts fail. Normally, the rollback continues even if there are pre-rollback script failures. @type abortOnError: bool @param capsuleChangesets: List of paths to changesets. Any capsules included in those changesets are made available to the rollback in case they are needed. If a directory is given, every changeset in that directory is included (nonrecursively) while non-changeset files are ignored. @type capsuleChangesets: list of str @raise UpdateError: Generic update error. Can occur if the root is not writeable by the user running the command. @raise RollbackError: Generic rollback error. Finer grained rollback errors are L{RollbackDoesNotExist<database.RollbackDoesNotExist>} (raised if the rollback specifier was invalid) and L{RollbackOrderError<database.RollbackOrderError>} (if the rollback was attempted not following the rollback stack order). It can also be raised if the database state has changed between the moment the rollback was computed and the moment of performing the rollback. See also the description for C{transactionCounter}. @raise ConaryError: Generic Conary error. Raised if the user running the command does not have permissions to access the rollback directory, or the directory is missing. """ # We used to pass a **kwargs to this function, but that makes it hard # to document the keyword arguments. d = dict(tagScript = tagScript, justDatabase = justDatabase, noScripts = noScripts, transactionCounter = transactionCounter, callback = callback, replaceFiles = replaceFiles, showInfoOnly = showInfoOnly, abortOnError = abortOnError, capsuleChangesets = capsuleChangesets, replaceManagedFiles=replaceManagedFiles, replaceModifiedFiles=replaceModifiedFiles, replaceUnmanagedFiles=replaceUnmanagedFiles, ) # If any of these arguments are None, don't even pass them, the # defaults are going to apply d = dict((x, y) for (x, y) in d.items() if y is not None) return rollbacks.applyRollback(self, rollbackSpec, **d)
self.logFilter.add() ret = rollbacks.applyRollback(client, "r.2", returnOnError=True) self.assertEqual(ret, 1) self.logFilter.compare("error: rollback 'r.2' not present") self.logFilter.add() try: rollbacks.applyRollback(client, "r.2") except database.RollbackDoesNotExist, e: self.assertEqual(str(e), "rollback r.2 does not exist") else: self.fail("Should have raised exception") self.logFilter.compare("error: rollback 'r.2' not present") self.logFilter.add() ret = rollbacks.applyRollback(client, "r.r", returnOnError=True) self.assertEqual(ret, 1) self.logFilter.compare("error: rollback 'r.r' not present") self.logFilter.add() try: rollbacks.applyRollback(client, "r.r") except database.RollbackDoesNotExist, e: self.assertEqual(str(e), "rollback r.r does not exist") else: self.fail("Should have raised exception") self.logFilter.compare("error: rollback 'r.r' not present") self.logFilter.add() ret = rollbacks.applyRollback(client, "abc", returnOnError=True) self.assertEqual(ret, 1) self.logFilter.compare("error: integer rollback count expected instead of 'abc'")
self.logFilter.add() ret = rollbacks.applyRollback(client, 'r.2', returnOnError = True) self.assertEqual(ret, 1) self.logFilter.compare("error: rollback 'r.2' not present") self.logFilter.add() try: rollbacks.applyRollback(client, 'r.2') except database.RollbackDoesNotExist, e: self.assertEqual(str(e), 'rollback r.2 does not exist') else: self.fail("Should have raised exception") self.logFilter.compare("error: rollback 'r.2' not present") self.logFilter.add() ret = rollbacks.applyRollback(client, 'r.r', returnOnError = True) self.assertEqual(ret, 1) self.logFilter.compare("error: rollback 'r.r' not present") self.logFilter.add() try: rollbacks.applyRollback(client, 'r.r') except database.RollbackDoesNotExist, e: self.assertEqual(str(e), 'rollback r.r does not exist') else: self.fail("Should have raised exception") self.logFilter.compare("error: rollback 'r.r' not present") self.logFilter.add() ret = rollbacks.applyRollback(client, 'abc', returnOnError = True) self.assertEqual(ret, 1) self.logFilter.compare("error: integer rollback count expected instead of 'abc'")