Commit 57956ec9 authored by Julien Muchembled's avatar Julien Muchembled

master: if upstream unset, reject request to backup rather than crashing

parent 0fc95175
...@@ -59,6 +59,8 @@ class Application(BaseApplication): ...@@ -59,6 +59,8 @@ class Application(BaseApplication):
backup_app = None backup_app = None
truncate_tid = None truncate_tid = None
no_upstream_msg = "No upstream cluster to backup defined in configuration"
def setUUID(self, uuid): def setUUID(self, uuid):
node = self.nm.getByUUID(uuid) node = self.nm.getByUUID(uuid)
if node is not self._node: if node is not self._node:
...@@ -171,7 +173,8 @@ class Application(BaseApplication): ...@@ -171,7 +173,8 @@ class Application(BaseApplication):
def run(self): def run(self):
try: try:
self._run() self._run()
except Exception: except BaseException, e:
if not isinstance(e, SystemExit) or e.code:
logging.exception('Pre-mortem data:') logging.exception('Pre-mortem data:')
self.log() self.log()
logging.flush() logging.flush()
...@@ -309,8 +312,7 @@ class Application(BaseApplication): ...@@ -309,8 +312,7 @@ class Application(BaseApplication):
# self.provideService only returns without raising # self.provideService only returns without raising
# when switching to backup mode. # when switching to backup mode.
if self.backup_app is None: if self.backup_app is None:
raise RuntimeError("No upstream cluster to backup" sys.exit(self.no_upstream_msg)
" defined in configuration")
truncate = Packets.Truncate( truncate = Packets.Truncate(
self.backup_app.provideService()) self.backup_app.provideService())
except StoppedOperation, e: except StoppedOperation, e:
......
...@@ -105,6 +105,8 @@ class AdministrationHandler(MasterHandler): ...@@ -105,6 +105,8 @@ class AdministrationHandler(MasterHandler):
if app.tm.hasPending() or app.nm.getClientList(True): if app.tm.hasPending() or app.nm.getClientList(True):
raise AnswerDenied("Can not switch to %s state with pending" raise AnswerDenied("Can not switch to %s state with pending"
" transactions or connected clients" % state) " transactions or connected clients" % state)
if app.backup_app is None:
raise AnswerDenied(app.no_upstream_msg)
conn.answer(Errors.Ack('Cluster state changed')) conn.answer(Errors.Ack('Cluster state changed'))
if state != app.cluster_state: if state != app.cluster_state:
......
...@@ -2851,6 +2851,11 @@ class Test(NEOThreadedTest): ...@@ -2851,6 +2851,11 @@ class Test(NEOThreadedTest):
with self.expectedFailure(): \ with self.expectedFailure(): \
self.assertFalse(s0m.isClosed()) self.assertFalse(s0m.isClosed())
@with_cluster()
def testUnsetUpsteam(self, cluster):
self.assertRaises(SystemExit, cluster.neoctl.setClusterState,
ClusterStates.STARTING_BACKUP)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment