diff --git a/.gitignore b/.gitignore index 7bcb779..83e970c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ build test/.* test/mongod.* test/fixtures/ -test/fixtures.replication/ \ No newline at end of file +test/fixtures.replication/ +*mongo.log \ No newline at end of file diff --git a/oplogutils/_core.py b/oplogutils/_core.py index f9f1e69..d6cd02b 100644 --- a/oplogutils/_core.py +++ b/oplogutils/_core.py @@ -62,8 +62,17 @@ def validate_options(self): pass + def connection(self): + return Connection(self.opts.host, self.opts.port) + + + def replication_enabled(self): + stat = self.connection().admin.command({ 'serverStatus': 1 }) + return 'repl' in stat + + def db_local(self): - return Connection(self.opts.host, self.opts.port).local + return self.connection().local def oplog(self): diff --git a/oplogutils/_trimmer.py b/oplogutils/_trimmer.py index 528f9d3..ef271b5 100644 --- a/oplogutils/_trimmer.py +++ b/oplogutils/_trimmer.py @@ -71,6 +71,8 @@ def should_continue(self): def run(self): + self.assert_replication_off() + q = CountQuery(start=self.opts.remove_after) self.affected_events = q.run(self.oplog()) @@ -86,5 +88,14 @@ def run(self): sys.exit(1) + def assert_replication_off(self): + if self.replication_enabled(): + print """ +In order to use this command, the master database must be restarted without +replication options. Back it up and restart it without the --master switch. +""" + sys.exit(-1) + + def trim(self): pass diff --git a/test/test_trimmer.py b/test/test_trimmer.py index f1cf9a6..dceecb8 100644 --- a/test/test_trimmer.py +++ b/test/test_trimmer.py @@ -115,10 +115,9 @@ def test_always_yes_skips_confirm(self): def test_aborts_if_mongo_running_with_replication_options(self): s = self.trim(port=settings.MONGOD_REPLICATION_PORT, expect_code=-1) - self.assertTrue('with no replication options' in s) + self.assertTrue('without replication options' in s.replace('\n', ' ')) def test_removing_events(self): pass -