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):
backup_app = None
truncate_tid = None
no_upstream_msg = "No upstream cluster to backup defined in configuration"
def setUUID(self, uuid):
node = self.nm.getByUUID(uuid)
if node is not self._node:
......@@ -171,7 +173,8 @@ class Application(BaseApplication):
def run(self):
try:
self._run()
except Exception:
except BaseException, e:
if not isinstance(e, SystemExit) or e.code:
logging.exception('Pre-mortem data:')
self.log()
logging.flush()
......@@ -309,8 +312,7 @@ class Application(BaseApplication):
# self.provideService only returns without raising
# when switching to backup mode.
if self.backup_app is None:
raise RuntimeError("No upstream cluster to backup"
" defined in configuration")
sys.exit(self.no_upstream_msg)
truncate = Packets.Truncate(
self.backup_app.provideService())
except StoppedOperation, e:
......
......@@ -105,6 +105,8 @@ class AdministrationHandler(MasterHandler):
if app.tm.hasPending() or app.nm.getClientList(True):
raise AnswerDenied("Can not switch to %s state with pending"
" transactions or connected clients" % state)
if app.backup_app is None:
raise AnswerDenied(app.no_upstream_msg)
conn.answer(Errors.Ack('Cluster state changed'))
if state != app.cluster_state:
......
......@@ -2851,6 +2851,11 @@ class Test(NEOThreadedTest):
with self.expectedFailure(): \
self.assertFalse(s0m.isClosed())
@with_cluster()
def testUnsetUpsteam(self, cluster):
self.assertRaises(SystemExit, cluster.neoctl.setClusterState,
ClusterStates.STARTING_BACKUP)
if __name__ == "__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