Merge "Deprecate LISTEN_PORT parameter"
This commit is contained in:
@@ -38,7 +38,7 @@ class Client(object):
|
||||
|
||||
self.debug = False
|
||||
self.root = "http://{server}:{port}".format(server=conf.SERVER_ADDRESS,
|
||||
port=conf.LISTEN_PORT)
|
||||
port=conf.SERVER_PORT)
|
||||
|
||||
self.keystone_base = urlparse.urljoin(self.root, "/keystone/v2.0")
|
||||
self.api_root = urlparse.urljoin(self.root, "/api/v1/")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Connection settings
|
||||
SERVER_ADDRESS: "127.0.0.1"
|
||||
LISTEN_PORT: "8000"
|
||||
SERVER_PORT: "8000"
|
||||
KEYSTONE_USER:
|
||||
KEYSTONE_PASS:
|
||||
HTTP_PROXY: null
|
||||
|
||||
@@ -26,6 +26,12 @@ from fuelclient.cli import error
|
||||
|
||||
_SETTINGS = None
|
||||
|
||||
# Format: old parameter: new parameter or None
|
||||
DEPRECATION_TABLE = {'LISTEN_PORT': 'SERVER_PORT'}
|
||||
|
||||
# Format: parameter: fallback parameter
|
||||
FALLBACK_TABLE = {'SERVER_PORT': 'LISTEN_PORT'}
|
||||
|
||||
|
||||
class FuelClientSettings(object):
|
||||
"""Represents a model of Fuel Clients settings
|
||||
@@ -78,6 +84,7 @@ class FuelClientSettings(object):
|
||||
raise error.SettingsException(msg)
|
||||
|
||||
self._update_from_env()
|
||||
self._check_deprecated()
|
||||
|
||||
def _add_file_if_exists(self, path_to_file, file_list):
|
||||
if path_to_file and os.access(path_to_file, os.R_OK):
|
||||
@@ -94,6 +101,26 @@ class FuelClientSettings(object):
|
||||
if k in os.environ:
|
||||
self.config[k] = os.environ[k]
|
||||
|
||||
def _check_deprecated(self):
|
||||
"""Looks for deprecated options and prints warnings if finds any."""
|
||||
|
||||
dep_msg = ('DEPRECATION WARNING: {old} parameter was deprecated and '
|
||||
'will not be supported in the next version of '
|
||||
'python-fuelclient.{repl}')
|
||||
repl_msg = ' Please replace this parameter with {0}'
|
||||
|
||||
dep_opts = [opt for opt in self.config if opt in DEPRECATION_TABLE]
|
||||
|
||||
for opt in dep_opts:
|
||||
replace = ''
|
||||
|
||||
if DEPRECATION_TABLE.get(opt) is not None:
|
||||
replace = repl_msg.format(DEPRECATION_TABLE.get(opt))
|
||||
|
||||
msg = dep_msg.format(old=opt, repl=replace)
|
||||
|
||||
six.print_(msg)
|
||||
|
||||
def populate_default_settings(self, source, destination):
|
||||
"""Puts default configuration file to a user's home directory."""
|
||||
|
||||
@@ -114,7 +141,14 @@ class FuelClientSettings(object):
|
||||
return yaml.dump(self.config)
|
||||
|
||||
def __getattr__(self, name):
|
||||
return self.config.get(name, None)
|
||||
if name in self.config:
|
||||
return self.config[name]
|
||||
|
||||
if name in FALLBACK_TABLE:
|
||||
return self.config[FALLBACK_TABLE[name]]
|
||||
|
||||
raise error.SettingsException('Value for {0} option is not '
|
||||
'configured'.format(name))
|
||||
|
||||
def __repr__(self):
|
||||
return '<settings object>'
|
||||
|
||||
@@ -26,6 +26,13 @@ from fuelclient.tests.unit.v1 import base
|
||||
|
||||
class TestSettings(base.UnitTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestSettings, self).setUp()
|
||||
|
||||
self.useFixture(fixtures.MockPatchObject(fuelclient_settings,
|
||||
'_SETTINGS',
|
||||
None))
|
||||
|
||||
@mock.patch('os.makedirs')
|
||||
@mock.patch('shutil.copy')
|
||||
@mock.patch('os.chmod')
|
||||
@@ -41,7 +48,6 @@ class TestSettings(base.UnitTestCase):
|
||||
conf_home = os.path.expanduser('~/.config/')
|
||||
conf_dir = os.path.dirname(expected_path)
|
||||
|
||||
fuelclient_settings._SETTINGS = None
|
||||
m_exists.return_value = False
|
||||
f_confdir = fixtures.EnvironmentVariable('XDG_CONFIG_HOME', conf_home)
|
||||
f_settings = fixtures.EnvironmentVariable('FUELCLIENT_CUSTOM_SETTINGS')
|
||||
@@ -58,7 +64,6 @@ class TestSettings(base.UnitTestCase):
|
||||
@mock.patch('os.makedirs')
|
||||
@mock.patch('os.path.exists')
|
||||
def test_config_generation_write_error(self, m_exists, m_makedirs):
|
||||
fuelclient_settings._SETTINGS = None
|
||||
m_exists.return_value = False
|
||||
m_makedirs.side_effect = OSError('[Errno 13] Permission denied')
|
||||
|
||||
@@ -67,3 +72,23 @@ class TestSettings(base.UnitTestCase):
|
||||
|
||||
self.assertRaises(error.SettingsException,
|
||||
fuelclient_settings.get_settings)
|
||||
|
||||
@mock.patch('six.print_')
|
||||
def test_deprecated_option_produces_warning(self, m_print):
|
||||
expected_waring = ('DEPRECATION WARNING: LISTEN_PORT parameter was '
|
||||
'deprecated and will not be supported in the next '
|
||||
'version of python-fuelclient. Please replace this '
|
||||
'parameter with SERVER_PORT')
|
||||
|
||||
m = mock.mock_open(read_data='LISTEN_PORT: 9000')
|
||||
with mock.patch('fuelclient.fuelclient_settings.open', m):
|
||||
fuelclient_settings.get_settings()
|
||||
|
||||
m_print.assert_called_once_with(expected_waring)
|
||||
|
||||
def test_fallback_to_deprecated_option(self):
|
||||
m = mock.mock_open(read_data='LISTEN_PORT: 9000')
|
||||
with mock.patch('fuelclient.fuelclient_settings.open', m):
|
||||
settings = fuelclient_settings.get_settings()
|
||||
|
||||
self.assertEqual(9000, settings.LISTEN_PORT)
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestAuthentication(base.UnitTestCase):
|
||||
self.assertEqual(args['tenant_name'], tenant_name)
|
||||
pr = urllib.parse.urlparse(args['auth_url'])
|
||||
self.assertEqual(conf.SERVER_ADDRESS, pr.hostname)
|
||||
self.assertEqual(int(conf.LISTEN_PORT), int(pr.port))
|
||||
self.assertEqual(int(conf.SERVER_PORT), int(pr.port))
|
||||
self.assertEqual('/keystone/v2.0', pr.path)
|
||||
|
||||
@patch('fuelclient.client.auth_client')
|
||||
|
||||
@@ -108,7 +108,7 @@ EOL
|
||||
cat > $FUELCLIENT_CUSTOM_SETTINGS <<EOL
|
||||
# Connection settings
|
||||
SERVER_ADDRESS: "127.0.0.1"
|
||||
LISTEN_PORT: "${NAILGUN_PORT}"
|
||||
SERVER_PORT: "${NAILGUN_PORT}"
|
||||
KEYSTONE_USER: "admin"
|
||||
KEYSTONE_PASS: "admin"
|
||||
EOL
|
||||
|
||||
Reference in New Issue
Block a user