pcp
[Top] [All Lists]

pmrep: config file version

To: pcp developers <pcp@xxxxxxxxxxx>
Subject: pmrep: config file version
From: Marko Myllynen <myllynen@xxxxxxxxxx>
Date: Thu, 3 Dec 2015 23:43:08 +0200
Delivered-to: pcp@xxxxxxxxxxx
Organization: Red Hat
Reply-to: myllynen@xxxxxxxxxx
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0
Define config file format version. Will catch semantics changes.

---
 src/pmrep/TODO       | 1 -
 src/pmrep/pmrep.conf | 1 +
 src/pmrep/pmrep.py   | 9 +++++++--
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/pmrep/TODO b/src/pmrep/TODO
index 960235d..741ebc5 100644
--- a/src/pmrep/TODO
+++ b/src/pmrep/TODO
@@ -1,6 +1,5 @@
 -  after first release: drop all compat code
 -  after first release: check all code marked with BZ references
--  versioned configuration
 -  fix get_cmd_line_metrics
 -  allow defining instances to display
 -  opt to write cols per row with stdout output
diff --git a/src/pmrep/pmrep.conf b/src/pmrep/pmrep.conf
index 665a9ab..2254080 100644
--- a/src/pmrep/pmrep.conf
+++ b/src/pmrep/pmrep.conf
@@ -4,6 +4,7 @@
 
 # General options
 [options]
+#version = 1
 #source = localhost
 #output = stdout
 #derived = /path/derived.conf
diff --git a/src/pmrep/pmrep.py b/src/pmrep/pmrep.py
index b7cc9f9..4bd81ca 100644
--- a/src/pmrep/pmrep.py
+++ b/src/pmrep/pmrep.py
@@ -71,7 +71,7 @@ if sys.version_info[0] >= 3:
 # Default config
 DEFAULT_CONFIG = "./pmrep.conf"
 
-# Default field separators, time formats, missing/truncated values
+# Default field separators, config/time formats, missing/truncated values
 CSVSEP  = ","
 CSVTIME = "%Y-%m-%d %H:%M:%S"
 OUTSEP  = "  "
@@ -80,6 +80,7 @@ ZBXPORT = 10051
 ZBXPRFX = "pcp."
 NO_VAL  = "N/A"
 TRUNC   = "xxx"
+VERSION = 1
 
 # Output targets
 OUTPUT_ARCHIVE = "archive"
@@ -161,7 +162,6 @@ class PMReporter(object):
     def __init__(self):
         """ Construct object, prepare for command line handling """
         self.context = None
-        self.version = 1
         self.check = 0
         self.format = None # output format
         self.opts = self.options()
@@ -183,6 +183,7 @@ class PMReporter(object):
         # 2 - parameters from configuration file(s)
         # 3 - built-in defaults defined below
         self.config = self.set_config_file()
+        self.version = VERSION
         self.source = "local:"
         self.output = OUTPUT_STDOUT
         self.archive = None # output archive
@@ -563,6 +564,10 @@ class PMReporter(object):
 
     def validate_config(self):
         """ Validate configuration parameters """
+        if self.version != VERSION:
+            sys.stderr.write("Incompatible configuration file version (read 
v%s, need v%d).\n" % (self.version, VERSION))
+            sys.exit(1)
+
         if self.context.type == PM_CONTEXT_ARCHIVE:
             self.source = self.opts.pmGetOptionArchives()[0] # RHBZ#1262723
         if self.context.type == PM_CONTEXT_HOST:

Thanks,

-- 
Marko Myllynen

<Prev in Thread] Current Thread [Next in Thread>
  • pmrep: config file version, Marko Myllynen <=