Merge "[CLI] Add rally db ensure command"
This commit is contained in:
commit
6706f6560d
@ -19,6 +19,7 @@ _rally()
|
||||
declare -A OPTS
|
||||
|
||||
OPTS["db_create"]=""
|
||||
OPTS["db_ensure"]=""
|
||||
OPTS["db_recreate"]=""
|
||||
OPTS["db_revision"]=""
|
||||
OPTS["db_show"]=""
|
||||
@ -96,4 +97,4 @@ _rally()
|
||||
return 0
|
||||
}
|
||||
|
||||
complete -o filenames -F _rally rally
|
||||
complete -o filenames -F _rally rally
|
@ -37,6 +37,14 @@ class DBCommands(object):
|
||||
"""Create Rally database."""
|
||||
db.schema_create()
|
||||
|
||||
def ensure(self, api):
|
||||
"""Creates Rally database if it doesn't exists."""
|
||||
if not db.schema_revision():
|
||||
db.schema_create()
|
||||
print("Database created successfully")
|
||||
else:
|
||||
print("Database already exists, nothing to do")
|
||||
|
||||
def upgrade(self, api):
|
||||
"""Upgrade Rally database to the latest state."""
|
||||
print("Upgrading...")
|
||||
|
@ -43,6 +43,21 @@ class DBCommandsTestCase(test.TestCase):
|
||||
calls = [mock.call.schema_create()]
|
||||
self.assertEqual(calls, mock_db.mock_calls)
|
||||
|
||||
@mock.patch("rally.cli.commands.db.db")
|
||||
def test_ensure_create(self, mock_db):
|
||||
mock_db.schema_revision.return_value = None
|
||||
self.db_commands.ensure(self.fake_api)
|
||||
calls = [mock.call.schema_revision(),
|
||||
mock.call.schema_create()]
|
||||
self.assertEqual(calls, mock_db.mock_calls)
|
||||
|
||||
@mock.patch("rally.cli.commands.db.db")
|
||||
def test_ensure_exists(self, mock_db):
|
||||
mock_db.schema_revision.return_value = "revision"
|
||||
self.db_commands.ensure(self.fake_api)
|
||||
calls = [mock.call.schema_revision()]
|
||||
self.assertEqual(calls, mock_db.mock_calls)
|
||||
|
||||
@mock.patch("rally.cli.commands.db.db")
|
||||
def test_upgrade(self, mock_db):
|
||||
self.db_commands.upgrade(self.fake_api)
|
||||
|
Loading…
x
Reference in New Issue
Block a user