86fc490cac
Implements blueprint argparse-based-cfg Sync the following changes from oslo-incubator: 479f19c Add deprecated --logdir common opt 27b2ff4 Add deprecated --logfile common opt. 9b81289 Allow nova and others to override some logging defaults 3557d84 Fix ListOpt to trim whitespace 01ab910 Fix set_default() with boolean CLI options af18eaa Improve cfg's argparse sub-parsers support f21e1d9 Fix regression with cfg CLI arguments ceb4aa7 Fix broken --help with CommonConfigOpts 5e9503b Hide the GroupAttr conf and group attributes b6d24bb updating sphinx documentation 403509e Don't reference argparse._StoreAction e17deb8 Fix minor coding style issue 0c29e1d Remove ConfigCliParser class 5b9cb41 Add support for positional arguments dbc72a6 Use stock argparse behaviour for optional args 768a147 Use stock argparse --usage behaviour ac180b9 Use stock argparse --version behaviour 0787e38 Remove add_option() method 5afead0 Completely remove cfg's disable_interspersed_args() 5f564b2 argparse support for cfg d7b6397 Add a missing comma in a docstring. aca1805 cfg: fix required if option has a dash Note: various utilities/services with command line parameters needed to be updated due to the changes mentioned above. The downside is that these are not backward compatible. Unknown arguments are no ignored. Only bound arguments will be treated. Thanks to Mark McLoughlin for migration cli code changes. Change-Id: Ia776e78cc55f4ed33ace5efa8d726b70e3fa4131
122 lines
3.5 KiB
Python
122 lines
3.5 KiB
Python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
|
#
|
|
# Copyright 2012 New Dream Network, LLC (DreamHost)
|
|
# All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
# @author Mark McClain (DreamHost)
|
|
|
|
import sys
|
|
|
|
import mock
|
|
import unittest2 as unittest
|
|
|
|
from quantum.db import migration
|
|
from quantum.db.migration import cli
|
|
|
|
|
|
class TestDbMigration(unittest.TestCase):
|
|
def test_should_run_plugin_in_list(self):
|
|
self.assertTrue(migration.should_run('foo', ['foo', 'bar']))
|
|
self.assertFalse(migration.should_run('foo', ['bar']))
|
|
|
|
def test_should_run_plugin_wildcard(self):
|
|
self.assertTrue(migration.should_run('foo', ['*']))
|
|
|
|
|
|
class TestCli(unittest.TestCase):
|
|
def setUp(self):
|
|
self.do_alembic_cmd_p = mock.patch.object(cli, 'do_alembic_command')
|
|
self.do_alembic_cmd = self.do_alembic_cmd_p.start()
|
|
|
|
def tearDown(self):
|
|
self.do_alembic_cmd_p.stop()
|
|
cli.CONF.reset()
|
|
|
|
def _main_test_helper(self, argv, func_name, exp_args=(), exp_kwargs={}):
|
|
with mock.patch.object(sys, 'argv', argv):
|
|
cli.main()
|
|
self.do_alembic_cmd.assert_has_calls(
|
|
[mock.call(mock.ANY, func_name, *exp_args, **exp_kwargs)]
|
|
)
|
|
|
|
def test_stamp(self):
|
|
self._main_test_helper(
|
|
['prog', 'stamp', 'foo'],
|
|
'stamp',
|
|
('foo',),
|
|
{'sql': False}
|
|
)
|
|
|
|
self._main_test_helper(
|
|
['prog', 'stamp', 'foo', '--sql'],
|
|
'stamp',
|
|
('foo',),
|
|
{'sql': True}
|
|
)
|
|
|
|
def test_current(self):
|
|
self._main_test_helper(['prog', 'current'], 'current')
|
|
|
|
def test_history(self):
|
|
self._main_test_helper(['prog', 'history'], 'history')
|
|
|
|
def test_check_migration(self):
|
|
self._main_test_helper(['prog', 'check_migration'], 'branches')
|
|
|
|
def test_database_sync_revision(self):
|
|
self._main_test_helper(
|
|
['prog', 'revision', '--autogenerate', '-m', 'message'],
|
|
'revision',
|
|
(),
|
|
{'message': 'message', 'sql': False, 'autogenerate': True}
|
|
)
|
|
|
|
self._main_test_helper(
|
|
['prog', 'revision', '--sql', '-m', 'message'],
|
|
'revision',
|
|
(),
|
|
{'message': 'message', 'sql': True, 'autogenerate': False}
|
|
)
|
|
|
|
def test_upgrade(self):
|
|
self._main_test_helper(
|
|
['prog', 'upgrade', '--sql', 'head'],
|
|
'upgrade',
|
|
('head',),
|
|
{'sql': True}
|
|
)
|
|
|
|
self._main_test_helper(
|
|
['prog', 'upgrade', '--delta', '3'],
|
|
'upgrade',
|
|
('+3',),
|
|
{'sql': False}
|
|
)
|
|
|
|
def test_downgrade(self):
|
|
self._main_test_helper(
|
|
['prog', 'downgrade', '--sql', 'folsom'],
|
|
'downgrade',
|
|
('folsom',),
|
|
{'sql': True}
|
|
)
|
|
|
|
self._main_test_helper(
|
|
['prog', 'downgrade', '--delta', '2'],
|
|
'downgrade',
|
|
('-2',),
|
|
{'sql': False}
|
|
)
|