diff options
| author | Ben Nemec <openstack@nemebean.com> | 2013-07-26 11:34:17 -0500 |
|---|---|---|
| committer | Ben Nemec <openstack@nemebean.com> | 2013-07-26 11:38:49 -0500 |
| commit | 7448e7e1df892cde1e7ab1cb61c24f62a4eae8da (patch) | |
| tree | 91157ae9476f11973e0d283b16e4772232692134 /openstack/common | |
| parent | d4d81262ff74ff54e51db4065192fd9a0119ec34 (diff) | |
| download | oslo-7448e7e1df892cde1e7ab1cb61c24f62a4eae8da.tar.gz oslo-7448e7e1df892cde1e7ab1cb61c24f62a4eae8da.tar.xz oslo-7448e7e1df892cde1e7ab1cb61c24f62a4eae8da.zip | |
Fix hostname conflict in config generator
When the system hostname is the same as a default value in the
config, the _sanitize_default function may replace it incorrectly.
This change checks that the name of the option contains the
substring 'host' to make sure it isn't changing non-hostname
defaults.
Fixes bug 1205411
Change-Id: I93edb2902304c5cd9bfa817b1bccdaec5d807e6c
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/config/generator.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/openstack/common/config/generator.py b/openstack/common/config/generator.py index 07aa296..1ae6c4d 100644 --- a/openstack/common/config/generator.py +++ b/openstack/common/config/generator.py @@ -181,24 +181,24 @@ def _get_my_ip(): return None -def _sanitize_default(s): +def _sanitize_default(name, value): """Set up a reasonably sensible default for pybasedir, my_ip and host.""" - if s.startswith(sys.prefix): + if value.startswith(sys.prefix): # NOTE(jd) Don't use os.path.join, because it is likely to think the # second part is an absolute pathname and therefore drop the first # part. - s = os.path.normpath("/usr/" + s[len(sys.prefix):]) - elif s.startswith(BASEDIR): - return s.replace(BASEDIR, '/usr/lib/python/site-packages') - elif BASEDIR in s: - return s.replace(BASEDIR, '') - elif s == _get_my_ip(): + value = os.path.normpath("/usr/" + value[len(sys.prefix):]) + elif value.startswith(BASEDIR): + return value.replace(BASEDIR, '/usr/lib/python/site-packages') + elif BASEDIR in value: + return value.replace(BASEDIR, '') + elif value == _get_my_ip(): return '10.0.0.1' - elif s == socket.gethostname(): + elif value == socket.gethostname() and 'host' in name: return 'oslo' - elif s.strip() != s: - return '"%s"' % s - return s + elif value.strip() != value: + return '"%s"' % value + return value def _print_opt(opt): @@ -219,7 +219,8 @@ def _print_opt(opt): print('#%s=<None>' % opt_name) elif opt_type == STROPT: assert(isinstance(opt_default, basestring)) - print('#%s=%s' % (opt_name, _sanitize_default(opt_default))) + print('#%s=%s' % (opt_name, _sanitize_default(opt_name, + opt_default))) elif opt_type == BOOLOPT: assert(isinstance(opt_default, bool)) print('#%s=%s' % (opt_name, str(opt_default).lower())) |
