Vinzenz Feenstra has uploaded a new change for review.

Change subject: Implement default configuration values
......................................................................

Implement default configuration values

When adding new config values to the configuration files, it's possible
that due to the installation the configuration files won't get updated,
when they are modified by an user/administrator on that given system.

By using defaults, we can override this problem and ensure a proper
application start, when config values are missing which are mandatory,
to the functionality.

Change-Id: I5ce9d457e826448aad205ce4abda5dc4b0210804
Signed-off-by: Vinzenz Feenstra <[email protected]>
Bug-Url: https://bugzilla.redhat.com/1100249
---
M Makefile.am
A configurations/Makefile.am
A configurations/default-logger.conf
R configurations/default-logger.ini
A configurations/default.conf
A configurations/default.ini
A configurations/ovirt-guest-agent.conf
A configurations/ovirt-guest-agent.ini
M configure.ac
M ovirt-guest-agent.rhel6.spec
M ovirt-guest-agent.spec
M ovirt-guest-agent/Makefile.am
M ovirt-guest-agent/Makefile.el5
M ovirt-guest-agent/OVirtGuestService.py
A ovirt-guest-agent/bytesio.py
D ovirt-guest-agent/ovirt-guest-agent.conf
M ovirt-guest-agent/ovirt-guest-agent.py
M ovirt-guest-agent/win-guest-agent-build-exe.bat
18 files changed, 304 insertions(+), 90 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent 
refs/changes/37/28137/1

diff --git a/Makefile.am b/Makefile.am
index ff73c6a..acc2eee 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,7 @@
 ACLOCAL_AMFLAGS=-I m4
 
 SUBDIRS =                \
+    configurations       \
     ovirt-guest-agent    \
     GinaSSO              \
     tests                \
diff --git a/configurations/Makefile.am b/configurations/Makefile.am
new file mode 100644
index 0000000..2f2864e
--- /dev/null
+++ b/configurations/Makefile.am
@@ -0,0 +1,16 @@
+
+EXTRA_DIST= \
+    ovirt-guest-agent.ini \
+    default.ini \
+    default-logger.ini \
+    $(NULL)
+
+agentconfdir=$(sysconfdir)
+dist_agentconf_DATA=ovirt-guest-agent.conf
+
+agentdefaultconfdir=$(datadir)/ovirt-guest-agent
+dist_agentdefaultconf_DATA=\
+    default.conf \
+    default-logger.conf \
+    $(NULL)
+
diff --git a/configurations/default-logger.conf 
b/configurations/default-logger.conf
new file mode 100644
index 0000000..898fb92
--- /dev/null
+++ b/configurations/default-logger.conf
@@ -0,0 +1,41 @@
+[loggers]
+keys=root
+
+[handlers]
+keys=console,syslog,logfile
+
+[formatters]
+keys=long,simple,none,sysform
+
+[logger_root]
+level=INFO
+handlers=logfile
+propagate=0
+
+[handler_syslog]
+class=handlers.SysLogHandler
+formatter=sysform
+args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
+
+[handler_logfile]
+class=handlers.RotatingFileHandler
+args=('/var/log/ovirt-guest-agent/ovirt-guest-agent.log', 'a', 100*1024, 5)
+formatter=long
+
+[handler_console]
+class: StreamHandler
+args: []
+formatter: none
+
+[formatter_simple]
+format: %(name)s:%(levelname)s:  %(message)s
+
+[formatter_none]
+format: %(message)s
+
+[formatter_long]
+format: 
%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s
+
+[formatter_sysform]
+format= %(asctime)s %(levelname)s %(message)s
+datefmt=
diff --git a/ovirt-guest-agent/ovirt-guest-agent.ini 
b/configurations/default-logger.ini
similarity index 70%
rename from ovirt-guest-agent/ovirt-guest-agent.ini
rename to configurations/default-logger.ini
index ea517c5..223874f 100644
--- a/ovirt-guest-agent/ovirt-guest-agent.ini
+++ b/configurations/default-logger.ini
@@ -1,19 +1,3 @@
-#
-# rhev-agent.ini - RHEV-agent/Windows configuration file
-#
-
-[general]
-
-heart_beat_rate = 5
-report_user_rate = 10
-report_num_cpu_rate = 60
-report_application_rate = 120
-report_disk_usage = 300
-
-[virtio]
-
-device = \\.\Global\com.redhat.rhevm.vdsm
-
 [loggers]
 keys=root
 
diff --git a/configurations/default.conf b/configurations/default.conf
new file mode 100644
index 0000000..64987b6
--- /dev/null
+++ b/configurations/default.conf
@@ -0,0 +1,19 @@
+#
+# default.conf
+#
+
+[general]
+
+heart_beat_rate = 5
+report_user_rate = 10
+report_num_cpu_rate = 60
+report_application_rate = 120
+report_disk_usage = 300
+
+# RHEL/Fedora Packages: kernel ovirt-guest-agent-common xorg-x11-drv-qxl
+# Debian Packages:      linux-image xserver-xorg-video-qxl
+applications_list = kernel ovirt-guest-agent-common xorg-x11-drv-qxl 
linux-image xserver-xorg-video-qxl
+ignored_fs = rootfs tmpfs autofs cgroup selinuxfs udev mqueue nfsd proc sysfs 
devtmpfs hugetlbfs rpc_pipefs devpts securityfs debugfs binfmt_misc 
fuse.gvfsd-fuse fuse.gvfs-fuse-daemon fusectl usbfs
+
+[virtio]
+device = /dev/virtio-ports/com.redhat.rhevm.vdsm
diff --git a/configurations/default.ini b/configurations/default.ini
new file mode 100644
index 0000000..ee40e7b
--- /dev/null
+++ b/configurations/default.ini
@@ -0,0 +1,13 @@
+#
+# default.ini - ovirt-guest-agent/Windows default configuration file
+#
+
+[general]
+heart_beat_rate = 5
+report_user_rate = 10
+report_num_cpu_rate = 60
+report_application_rate = 120
+report_disk_usage = 300
+
+[virtio]
+device = \\.\Global\com.redhat.rhevm.vdsm
diff --git a/configurations/ovirt-guest-agent.conf 
b/configurations/ovirt-guest-agent.conf
new file mode 100644
index 0000000..80509f5
--- /dev/null
+++ b/configurations/ovirt-guest-agent.conf
@@ -0,0 +1,63 @@
+#
+# ovirt-guest-agent.conf
+#
+
+[general]
+
+# heart_beat_rate = 5
+# report_user_rate = 10
+# report_num_cpu_rate = 60
+# report_application_rate = 120
+# report_disk_usage = 300
+
+## Generic:              ovirt-guest-agent
+## RHEL/Fedora Packages: kernel ovirt-guest-agent-common xorg-x11-drv-qxl
+## Debian Packages:      linux-image xserver-xorg-video-qxl
+## openSUSE Packages:    xf86-video-qxl kernel-desktop kernel-default 
kernel-trace kernel-vanilla kernel-debug kernel-ec2 kernel-xen
+# applications_list = kernel ovirt-guest-agent ovirt-guest-agent-common 
xorg-x11-drv-qxl linux-image xserver-xorg-video-qxl xf86-video-qxl 
kernel-desktop kernel-default kernel-trace kernel-vanilla kernel-debug 
kernel-ec2 kernel-xen
+# ignored_fs = rootfs tmpfs autofs cgroup selinuxfs udev mqueue nfsd proc 
sysfs devtmpfs hugetlbfs rpc_pipefs devpts securityfs debugfs binfmt_misc 
fuse.gvfsd-fuse fuse.gvfs-fuse-daemon fusectl usbfs
+
+[virtio]
+# device = /dev/virtio-ports/com.redhat.rhevm.vdsm
+
+#[loggers]
+#keys=root
+
+#[handlers]
+#keys=console,syslog,logfile
+
+#[formatters]
+#keys=long,simple,none,sysform
+
+#[logger_root]
+#level=INFO
+#handlers=logfile
+#propagate=0
+
+#[handler_syslog]
+#class=handlers.SysLogHandler
+#formatter=sysform
+#args=(('localhost', handlers.SYSLOG_UDP_PORT), 
handlers.SysLogHandler.LOG_USER)
+
+#[handler_logfile]
+#class=handlers.RotatingFileHandler
+#args=('/var/log/ovirt-guest-agent/ovirt-guest-agent.log', 'a', 100*1024, 5)
+#formatter=long
+
+#[handler_console]
+#class: StreamHandler
+#args: []
+#formatter: none
+
+#[formatter_simple]
+#format: %(name)s:%(levelname)s:  %(message)s
+
+#[formatter_none]
+#format: %(message)s
+
+#[formatter_long]
+#format: 
%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s
+
+#[formatter_sysform]
+#format= %(asctime)s %(levelname)s %(message)s
+#datefmt=
diff --git a/configurations/ovirt-guest-agent.ini 
b/configurations/ovirt-guest-agent.ini
new file mode 100644
index 0000000..a45afde
--- /dev/null
+++ b/configurations/ovirt-guest-agent.ini
@@ -0,0 +1,52 @@
+#
+# ovirt-guest-agent.ini - ovirt-guest-agent/Windows configuration file
+#
+
+[general]
+
+# heart_beat_rate = 5
+# report_user_rate = 10
+# report_num_cpu_rate = 60
+# report_application_rate = 120
+# report_disk_usage = 300
+
+[virtio]
+
+# device = \\.\Global\com.redhat.rhevm.vdsm
+
+#[loggers]
+#keys=root
+
+#[handlers]
+#keys=console,logfile
+
+#[formatters]
+#keys=long,simple,none,sysform
+
+#[logger_root]
+#level=INFO
+#handlers=logfile
+#propagate=0
+
+#[handler_logfile]
+#class=handlers.RotatingFileHandler
+#args=('rhev-agent.log', 'a', 100*1024, 5)
+#formatter=long
+
+#[handler_console]
+#class: StreamHandler
+#args: []
+#formatter: none
+
+#[formatter_simple]
+#format: %(name)s:%(levelname)s:  %(message)s
+
+#[formatter_none]
+#format: %(message)s
+
+#[formatter_long]
+#format: 
%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s
+
+#[formatter_sysform]
+#format= %(asctime)s %(levelname)s %(message)s
+#datefmt=
diff --git a/configure.ac b/configure.ac
index 75183fa..fc3d7cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -208,6 +208,7 @@
 
 AC_CONFIG_FILES([
     Makefile
+    configurations/Makefile
     GinaSSO/Makefile
     ovirt-guest-agent/Makefile
     ovirt-guest-agent/ovirt-guest-agent
diff --git a/ovirt-guest-agent.rhel6.spec b/ovirt-guest-agent.rhel6.spec
index 7cff303..e5997d6 100644
--- a/ovirt-guest-agent.rhel6.spec
+++ b/ovirt-guest-agent.rhel6.spec
@@ -123,6 +123,9 @@
 %{_datadir}/ovirt-guest-agent/ovirt-shutdown
 %{_datadir}/ovirt-guest-agent/ovirt-hibernate
 
+%attr (644,root,root) %{_datadir}/ovirt-guest-agent/default.conf
+%attr (644,root,root) %{_datadir}/ovirt-guest-agent/default-logger.conf
+
 %attr (755,root,root) %{_datadir}/ovirt-guest-agent/LockActiveSession.py*
 %attr (755,root,root) %{_datadir}/ovirt-guest-agent/hibernate
 
diff --git a/ovirt-guest-agent.spec b/ovirt-guest-agent.spec
index 454eea8..245586a 100644
--- a/ovirt-guest-agent.spec
+++ b/ovirt-guest-agent.spec
@@ -197,6 +197,9 @@
 %attr (755,root,root) %{_datadir}/ovirt-guest-agent/LockActiveSession.py*
 %attr (755,root,root) %{_datadir}/ovirt-guest-agent/hibernate
 
+%attr (644,root,root) %{_datadir}/ovirt-guest-agent/default.conf
+%attr (644,root,root) %{_datadir}/ovirt-guest-agent/default-logger.conf
+
 %{_unitdir}/ovirt-guest-agent.service
 
 %files pam-module
diff --git a/ovirt-guest-agent/Makefile.am b/ovirt-guest-agent/Makefile.am
index 9257363..f5dca4e 100644
--- a/ovirt-guest-agent/Makefile.am
+++ b/ovirt-guest-agent/Makefile.am
@@ -21,12 +21,9 @@
     $(NULL)
 
 dist_pkgdata_SCRIPTS= \
-       hibernate \
+    hibernate \
     LockActiveSession.py \
-       $(NULL)
-
-agentconfdir=$(sysconfdir)
-agentconf_DATA=ovirt-guest-agent.conf
+    $(NULL)
 
 dbusconfdir=$(sysconfdir)/dbus-1/system.d
 dbusconf_DATA=org.ovirt.vdsm.Credentials.conf
@@ -55,7 +52,6 @@
     Makefile.el5 \
     README-windows.txt \
     win-guest-agent-build-exe.bat \
-    ovirt-guest-agent.ini \
     $(NULL)
 
 CLEANFILES = \
diff --git a/ovirt-guest-agent/Makefile.el5 b/ovirt-guest-agent/Makefile.el5
index de3b60e..69d69f7 100644
--- a/ovirt-guest-agent/Makefile.el5
+++ b/ovirt-guest-agent/Makefile.el5
@@ -4,7 +4,8 @@
 #
 
 FILES=ovirt-guest-agent.py OVirtAgentLogic.py VirtIoChannel.py \
-       GuestAgentLinux2.py hibernate
+       GuestAgentLinux2.py hibernate bytesio.py ../configurations/default.conf 
\
+       ../configurations/default-logger.conf
 
 AGENTDIR=/usr/share/ovirt-guest-agent
 CONFDIR=/etc
diff --git a/ovirt-guest-agent/OVirtGuestService.py 
b/ovirt-guest-agent/OVirtGuestService.py
index 3206e8a..e5e3952 100644
--- a/ovirt-guest-agent/OVirtGuestService.py
+++ b/ovirt-guest-agent/OVirtGuestService.py
@@ -8,11 +8,16 @@
 import logging
 import logging.config
 import servicemanager
-import ConfigParser
 import os
+import os.path
 import _winreg
+import ConfigParser
+import io
+import cStringIO
 
 AGENT_CONFIG = 'ovirt-guest-agent.ini'
+AGENT_DEFAULT_CONFIG = 'default.ini'
+AGENT_DEFAULT_LOG_CONFIG = 'default-logger.ini'
 
 # Values from WM_WTSSESSION_CHANGE message
 # (http://msdn.microsoft.com/en-us/library/aa383828.aspx)
@@ -32,7 +37,7 @@
         win32serviceutil.ServiceFramework.__init__(self, args)
         self._shutting_down = False
 
-        global AGENT_CONFIG
+        global AGENT_CONFIG, AGENT_DEFAULT_CONFIG, AGENT_DEFAULT_LOG_CONFIG
         regKey = "System\\CurrentControlSet\\services\\%s" % self._svc_name_
         hkey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, regKey)
         filePath = _winreg.QueryValueEx(hkey, "ImagePath")[0].replace('"', '')
@@ -44,8 +49,20 @@
             hkey.Close()
         filePath = os.path.dirname(filePath)
         AGENT_CONFIG = os.path.join(filePath, AGENT_CONFIG)
+        AGENT_DEFAULT_CONFIG = os.path.join(filePath, AGENT_DEFAULT_CONFIG)
+        AGENT_DEFAULT_LOG_CONFIG = os.path.join(filePath,
+                                                AGENT_DEFAULT_LOG_CONFIG)
 
-        logging.config.fileConfig(AGENT_CONFIG)
+        cparser = ConfigParser.ConfigParser()
+        if os.path.exists(AGENT_DEFAULT_LOG_CONFIG):
+            cparser.read(AGENT_DEFAULT_LOG_CONFIG)
+        cparser.read(AGENT_CONFIG)
+        strio = cStringIO.StringIO()
+        cparser.write(strio)
+        bio = io.BytesIO(strio.getvalue())
+        logging.config.fileConfig(bio)
+        bio.close()
+        strio.close()
 
     # Overriding this method in order to accept session change notifications.
     def GetAcceptedControls(self):
@@ -61,8 +78,9 @@
         # Write a 'started' event to the event log...
         self.ReportEvent(servicemanager.PYS_SERVICE_STARTED)
         logging.info("Starting OVirt Guest Agent service")
-
         config = ConfigParser.ConfigParser()
+        if os.path.exists(AGENT_DEFAULT_CONFIG):
+            config.read(AGENT_DEFAULT_CONFIG)
         config.read(AGENT_CONFIG)
 
         self.vdsAgent = WinVdsAgent(config)
diff --git a/ovirt-guest-agent/bytesio.py b/ovirt-guest-agent/bytesio.py
new file mode 100644
index 0000000..37aef50
--- /dev/null
+++ b/ovirt-guest-agent/bytesio.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python
+
+class BytesIO:
+    def __init__(self, buffer):
+        self._data = buffer
+        if not self._data:
+            self._data = str()
+        self._pos = 0
+
+    def getvalue(self):
+        return self._data
+
+    def close(self):
+        pass
+
+    def readline(self):
+        return self.read(self._data[self._pos:].find('\n') + 1)
+
+    def read(self, n=None):
+        if n == None:
+            n = -1
+        if not isinstance(n, (int, long)):
+            raise TypeError("Argument must be an integer")
+        if n < 0:
+            n = len(self._data)
+        if len(self._data) <= self._pos:
+            return ''
+        newpos = min(len(self._data), self._pos + n)
+        b = self._data[self._pos : newpos]
+        self._pos = newpos
+        return b
+
+    def readable(self):
+        return True
+
+    def writable(self):
+        return True
+
+    def seekable(self):
+        return False
diff --git a/ovirt-guest-agent/ovirt-guest-agent.conf 
b/ovirt-guest-agent/ovirt-guest-agent.conf
deleted file mode 100644
index e40036f..0000000
--- a/ovirt-guest-agent/ovirt-guest-agent.conf
+++ /dev/null
@@ -1,61 +0,0 @@
-#
-# ovirt-guest-agent.conf
-#
-
-[general]
-
-heart_beat_rate = 5
-report_user_rate = 10
-report_num_cpu_rate = 60
-report_application_rate = 120
-report_disk_usage = 300
-# RHEL/Fedora Packages: kernel ovirt-guest-agent-common xorg-x11-drv-qxl
-# Debian Packages:      linux-image xserver-xorg-video-qxl
-applications_list = kernel ovirt-guest-agent-common xorg-x11-drv-qxl 
linux-image xserver-xorg-video-qxl
-ignored_fs = rootfs tmpfs autofs cgroup selinuxfs udev mqueue nfsd proc sysfs 
devtmpfs hugetlbfs rpc_pipefs devpts securityfs debugfs binfmt_misc 
fuse.gvfsd-fuse fuse.gvfs-fuse-daemon fusectl usbfs
-
-[virtio]
-
-device = /dev/virtio-ports/com.redhat.rhevm.vdsm
-
-[loggers]
-keys=root
-
-[handlers]
-keys=console,syslog,logfile
-
-[formatters]
-keys=long,simple,none,sysform
-
-[logger_root]
-level=INFO
-handlers=logfile
-propagate=0
-
-[handler_syslog]
-class=handlers.SysLogHandler
-formatter=sysform
-args=(('localhost', handlers.SYSLOG_UDP_PORT), handlers.SysLogHandler.LOG_USER)
-
-[handler_logfile]
-class=handlers.RotatingFileHandler 
-args=('/var/log/ovirt-guest-agent/ovirt-guest-agent.log', 'a', 100*1024, 5)
-formatter=long
-
-[handler_console]
-class: StreamHandler
-args: []
-formatter: none
-
-[formatter_simple]
-format: %(name)s:%(levelname)s:  %(message)s
-
-[formatter_none]
-format: %(message)s
-
-[formatter_long]
-format: 
%(threadName)s::%(levelname)s::%(asctime)s::%(module)s::%(lineno)d::%(name)s::%(message)s
-
-[formatter_sysform]
-format= %(asctime)s %(levelname)s %(message)s
-datefmt=
diff --git a/ovirt-guest-agent/ovirt-guest-agent.py 
b/ovirt-guest-agent/ovirt-guest-agent.py
index c7d60c8..173ff6b 100644
--- a/ovirt-guest-agent/ovirt-guest-agent.py
+++ b/ovirt-guest-agent/ovirt-guest-agent.py
@@ -22,21 +22,42 @@
 import sys
 import getopt
 import ConfigParser
+import cStringIO
+
+io = None
+try:
+    import io as modio
+    io = modio
+except ImportError:
+    import bytesio as modio
+    io = modio
+
 from GuestAgentLinux2 import LinuxVdsAgent
 
 AGENT_CONFIG = '/etc/ovirt-guest-agent.conf'
+AGENT_DEFAULT_CONFIG = '/usr/share/ovirt-guest-agent/default.conf'
+AGENT_DEFAULT_LOG_CONFIG = '/usr/share/ovirt-guest-agent/default-logger.conf'
 AGENT_PIDFILE = '/run/ovirt-guest-agent.pid'
 
 
 class OVirtAgentDaemon:
 
     def __init__(self):
-        logging.config.fileConfig(AGENT_CONFIG)
+        cparser = ConfigParser.ConfigParser()
+        cparser.read(AGENT_DEFAULT_LOG_CONFIG)
+        cparser.read(AGENT_CONFIG)
+        strio = cStringIO.StringIO()
+        cparser.write(strio)
+        bio = io.BytesIO(strio.getvalue())
+        logging.config.fileConfig(bio)
+        bio.close()
+        strio.close()
 
     def run(self, daemon, pidfile):
         logging.info("Starting oVirt guest agent")
-
         config = ConfigParser.ConfigParser()
+        config.read(AGENT_DEFAULT_CONFIG)
+        config.read(AGENT_DEFAULT_LOG_CONFIG)
         config.read(AGENT_CONFIG)
 
         self.agent = LinuxVdsAgent(config)
diff --git a/ovirt-guest-agent/win-guest-agent-build-exe.bat 
b/ovirt-guest-agent/win-guest-agent-build-exe.bat
index 7305151..402fe90 100644
--- a/ovirt-guest-agent/win-guest-agent-build-exe.bat
+++ b/ovirt-guest-agent/win-guest-agent-build-exe.bat
@@ -1,3 +1,6 @@
 @echo off
 echo "Building the executable"
 python setup.py py2exe -b 1
+copy ../configurations/default.ini default.ini
+copy ../configurations/default-logger.ini default-logger.ini
+copy ../configurations/ovirt-guest-agent.ini ovirt-guest-agent.ini


-- 
To view, visit http://gerrit.ovirt.org/28137
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5ce9d457e826448aad205ce4abda5dc4b0210804
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-guest-agent
Gerrit-Branch: ovirt-3.4
Gerrit-Owner: Vinzenz Feenstra <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to