summaryrefslogtreecommitdiffstats
path: root/tools/conf
diff options
context:
space:
mode:
authorYosef Berman <yosef@cloudscaling.com>2012-09-11 10:32:47 -0700
committerYosef Berman <yosef@cloudscaling.com>2012-09-18 13:36:03 -0700
commitc5d724ff577132e8f23fbff61041c86fc94a4f97 (patch)
tree51ef9c11cdd573d483b6b880b23725af5548db3d /tools/conf
parent3a671cd7dee8f084d72f8fad9897e46225be7069 (diff)
downloadnova-c5d724ff577132e8f23fbff61041c86fc94a4f97.tar.gz
nova-c5d724ff577132e8f23fbff61041c86fc94a4f97.tar.xz
nova-c5d724ff577132e8f23fbff61041c86fc94a4f97.zip
Added script to find unused config options.
The script analyze_opts.py is added to identify unused options and options which are set to default values in the nova.conf file. Change-Id: Iec42781a56f73b7d0960bdd569f5dd06edbb88df
Diffstat (limited to 'tools/conf')
-rw-r--r--tools/conf/README13
-rwxr-xr-xtools/conf/analyze_opts.py80
2 files changed, 92 insertions, 1 deletions
diff --git a/tools/conf/README b/tools/conf/README
index a76efb2a7..fc2465272 100644
--- a/tools/conf/README
+++ b/tools/conf/README
@@ -1,4 +1,4 @@
-This tool is used to generate etc/nova/nova.conf.sample
+This generate_sample.sh tool is used to generate etc/nova/nova.conf.sample
Run it from the top-level working directory i.e.
@@ -7,3 +7,14 @@ Run it from the top-level working directory i.e.
Watch out for warnings about modules like libvirt, qpid and zmq not
being found - these warnings are significant because they result
in options not appearing in the generated config file.
+
+
+The analyze_opts.py tool is used to find options which appear in
+/etc/nova/nova.conf but not in etc/nova/nova.conf.sample
+This helps identify options in the nova.conf file which are not used by nova.
+The tool also identifies any options which are set to the default value.
+
+Run it from the top-level working directory i.e.
+
+ $> ./tools/conf/analyze_opts.py
+
diff --git a/tools/conf/analyze_opts.py b/tools/conf/analyze_opts.py
new file mode 100755
index 000000000..f78169a8c
--- /dev/null
+++ b/tools/conf/analyze_opts.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright (c) 2012, Cloudscaling
+# 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.
+'''
+find_unused_options.py
+
+Compare the nova.conf file with the nova.conf.sample file to find any unused
+options or default values in nova.conf
+'''
+import argparse
+import os
+import sys
+
+sys.path.append(os.getcwd())
+from nova.openstack.common import iniparser
+
+
+class PropertyCollecter(iniparser.BaseParser):
+ def __init__(self):
+ super(PropertyCollecter, self).__init__()
+ self.key_value_pairs = {}
+
+ def assignment(self, key, value):
+ self.key_value_pairs[key] = value
+
+ def new_section(self, section):
+ pass
+
+ @classmethod
+ def collect_properties(cls, lineiter, sample_format=False):
+ def clean_sample(f):
+ for line in f:
+ if line.startswith("# ") and line != '# nova.conf sample #\n':
+ line = line[2:]
+ yield line
+ pc = cls()
+ if sample_format:
+ lineiter = clean_sample(lineiter)
+ pc.parse(lineiter)
+ return pc.key_value_pairs
+
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser(description='''Compare the nova.conf
+ file with the nova.conf.sample file to find any unused options or
+ default values in nova.conf''')
+
+ parser.add_argument('-c', action='store',
+ default='/etc/nova/nova.conf',
+ help='path to nova.conf\
+ (defaults to /etc/nova/nova.conf)')
+ parser.add_argument('-s', default='./etc/nova/nova.conf.sample',
+ help='path to nova.conf.sample\
+ (defaults to ./etc/nova/nova.conf.sample')
+ options = parser.parse_args()
+
+ conf_file_options = PropertyCollecter.collect_properties(open(options.c))
+ sample_conf_file_options = PropertyCollecter.collect_properties(
+ open(options.s), sample_format=True)
+
+ for k, v in sorted(conf_file_options.items()):
+ if k not in sample_conf_file_options:
+ print "Unused:", k
+ for k, v in sorted(conf_file_options.items()):
+ if k in sample_conf_file_options and v == sample_conf_file_options[k]:
+ print "Default valued:", k