Skip to content

Commit

Permalink
validating that the database is not in a replication mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfunley committed May 20, 2010
1 parent 808bcac commit e9b7639
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -6,4 +6,5 @@ build
test/.*
test/mongod.*
test/fixtures/
test/fixtures.replication/
test/fixtures.replication/
*mongo.log
11 changes: 10 additions & 1 deletion oplogutils/_core.py
Expand Up @@ -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):
Expand Down
11 changes: 11 additions & 0 deletions oplogutils/_trimmer.py
Expand Up @@ -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())

Expand All @@ -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
3 changes: 1 addition & 2 deletions test/test_trimmer.py
Expand Up @@ -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


0 comments on commit e9b7639

Please sign in to comment.