[node-patches] Change in ovirt-node[master]: ovirt-ntpd: Adding ovirt-ntpd service

dougsland at redhat.com dougsland at redhat.com
Sat May 30 17:08:02 UTC 2015


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: ovirt-ntpd: Adding ovirt-ntpd service
......................................................................

ovirt-ntpd: Adding ovirt-ntpd service

Due the limitation that all services in the oVirt Node
must be enabled during the build time and there is
no option to disable the pre-configured ntp servers
from ntp.conf we introduce ovirt-ntpd service.
This service will run before ntpd service and can disabled
the pre-configured ntp servers before ntpd service run.

Change-Id: Ib7827ab15b23b71d18b4562a0f2fc8a475f16378
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1061081
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
---
M ovirt-node.spec.in
M recipe/centos7-install.ks
M recipe/ovirt17-install.ks
M recipe/rhevh7-install.ks
M services/Makefile.am
A services/ovirt-ntpd/ovirt-node-ntpd
A services/ovirt-ntpd/ovirt-ntpd.service
M src/ovirtnode/network.py
8 files changed, 162 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/17/41617/1

diff --git a/ovirt-node.spec.in b/ovirt-node.spec.in
index f1121d9..f724624 100644
--- a/ovirt-node.spec.in
+++ b/ovirt-node.spec.in
@@ -54,6 +54,7 @@
 %endif
 Requires:       glusterfs-client >= 2.0.1
 Requires:       system-release
+Requires:       systemd-python
 Requires:       augeas >= 0.3.5
 Requires:       bridge-utils
 Requires:       udev >= 147-2.34
@@ -1060,6 +1061,7 @@
 %{_unitdir}/ovirt-post.service
 %{_unitdir}/ovirt-early.service
 %{_unitdir}/ovirt-kdump.service
+%{_unitdir}/ovirt-ntpd.service
 %else
 %{_initrddir}/ovirt-awake
 %{_initrddir}/ovirt-early
@@ -1093,6 +1095,7 @@
 %{_bindir}/ovirt-node-features
 %{_bindir}/ovirt-node-config
 %{_bindir}/ovirt-node-config-password
+%{_bindir}/ovirt-node-ntpd
 
 
 
diff --git a/recipe/centos7-install.ks b/recipe/centos7-install.ks
index 3a1e55f..aac7927 100644
--- a/recipe/centos7-install.ks
+++ b/recipe/centos7-install.ks
@@ -1,3 +1,3 @@
-services --enabled=auditd,ntpd,ntpdate,iptables,network,rsyslog,multipathd,snmpd,ovirt-early,ovirt-post,ovirt-kdump,cgconfig,mcelog,tuned,libvirtd --disabled=netfs,ovirt-awake,libvirt-guests,kdump
+services --enabled=auditd,ntpd,ntpdate,iptables,network,rsyslog,multipathd,snmpd,ovirt-early,ovirt-post,ovirt-kdump,ovirt-ntpd,cgconfig,mcelog,tuned,libvirtd --disabled=netfs,ovirt-awake,libvirt-guests,kdump
 
 
diff --git a/recipe/ovirt17-install.ks b/recipe/ovirt17-install.ks
index 258cbdd..2bf256f 100644
--- a/recipe/ovirt17-install.ks
+++ b/recipe/ovirt17-install.ks
@@ -1 +1 @@
-services --enabled=auditd,ntpd,ntpdate,iptables,network,rsyslog,multipathd,snmpd,ovirt-early,ovirt,ovirt-post,ovirt-kdump,anyterm,collectd,libvirtd,cgconfig,mcelog,tuned --disabled=kdump
+services --enabled=auditd,ntpd,ntpdate,iptables,network,rsyslog,multipathd,snmpd,ovirt-early,ovirt,ovirt-post,ovirt-ntpd,ovirt-kdump,anyterm,collectd,libvirtd,cgconfig,mcelog,tuned --disabled=kdump
diff --git a/recipe/rhevh7-install.ks b/recipe/rhevh7-install.ks
index aafcff0..08c461b 100644
--- a/recipe/rhevh7-install.ks
+++ b/recipe/rhevh7-install.ks
@@ -1,3 +1,3 @@
-services --enabled=auditd,ntpd,ntpdate,iptables,network,rsyslog,multipathd,snmpd,ovirt-early,ovirt-post,ovirt-cim,ovirt-kdump,cgconfig,mcelog,tuned --disabled=netfs,ovirt-awake,libvirt-guests,libvirtd,kdump
+services --enabled=auditd,ntpd,ntpdate,iptables,network,rsyslog,multipathd,snmpd,ovirt-early,ovirt-ntpd,ovirt-post,ovirt-cim,ovirt-kdump,cgconfig,mcelog,tuned --disabled=netfs,ovirt-awake,libvirt-guests,libvirtd,kdump
 
 
diff --git a/services/Makefile.am b/services/Makefile.am
index 1dec6e0..cd53a91 100644
--- a/services/Makefile.am
+++ b/services/Makefile.am
@@ -18,6 +18,10 @@
 systemunitdir=$(prefix)/lib/systemd/system
 initddir=$(sysconfdir)/rc.d/init.d
 
+dist_bin_SCRIPTS = \
+  ovirt-ntpd/ovirt-node-ntpd \
+  $(NULL)
+
 if TARGET_SYSTEMD
 dist_systemunit_DATA = \
   ovirt-awake.service \
@@ -27,6 +31,7 @@
   ovirt-firstboot.service \
   ovirt-cim.service \
   ovirt-kdump.service \
+  ovirt-ntpd/ovirt-ntpd.service \
   ovirt-node-igor-slave.service
 else
 dist_initd_SCRIPTS = \
diff --git a/services/ovirt-ntpd/ovirt-node-ntpd b/services/ovirt-ntpd/ovirt-node-ntpd
new file mode 100755
index 0000000..4d837c5
--- /dev/null
+++ b/services/ovirt-ntpd/ovirt-node-ntpd
@@ -0,0 +1,136 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA  02110-1301, USA.  A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+import logging
+import os
+import sys
+import tempfile
+
+from ovirt.node import utils
+from ovirt.node.utils import system
+from systemd import journal
+
+
+class OvirtNtp(object):
+
+    def __init__(self):
+        self.kargs = None
+        self.logger = self._set_logger()
+
+    def is_set(self):
+        """
+        Validate OVIRT_NODE_NTP in /etc/default/ovirt
+        if already set, no need to execute auto-register
+
+        Return True or False
+        """
+
+        with open('/etc/default/ovirt', 'r') as f:
+            for line in f:
+                if "OVIRT_NODE_NTP_AUTO_SERVERS=no" in line:
+                    return True
+
+        return False
+
+    def get_kargs(self):
+        """
+        Find in the boot kernel arguments from /var/log/dmesg,
+        the key ntp
+
+        Return a dict with the keys
+        """
+        key_word_karg = "Command line"
+        with open('/var/log/messages', 'r') as f:
+            for line in f:
+                if key_word_karg in line and "ntp" in line:
+                    self.kargs = system.kernel_cmdline_arguments(
+                        line.split(key_word_karg)[1]
+                    )
+                    break
+
+        return self.kargs
+
+    def comment_servers(self):
+        """
+        Comment the server entries from /etc/ntp.conf
+        """
+        _ntp_conf = "/etc/ntp.conf"
+        _ntp_buff = ""
+        with open(_ntp_conf, 'r') as f:
+            for line in f:
+                if "server" in line:
+                    _ntp_buff += "# {s}".format(s=line)
+                else:
+                    _ntp_buff += line
+
+        with tempfile.NamedTemporaryFile(
+            dir=os.path.dirname("/etc/"),
+            delete=False
+        ) as f:
+            f.write(_ntp_buff)
+
+        os.chmod(f.name, 0o644)
+        os.rename(f.name, _ntp_conf)
+        utils.fs.Config().persist(_ntp_conf)
+        self.logger.info("Commented the server entries from ntp.conf")
+
+    def write_changes(self):
+        """
+        Save OVIRT_NODE_NTP_AUTO_SERVERS into /etc/default/ovirt
+        for next service start check
+        """
+        with open('/etc/default/ovirt', 'a') as f:
+            f.write("OVIRT_NODE_NTP_AUTO_SERVERS=no")
+        self.logger.info("Saved OVIRT_NODE_NTP_AUTO_SERVERS=no")
+
+    def _set_logger(self):
+        """
+        Set the logging schema
+        """
+        log = logging.getLogger(__name__)
+        log.propagate = False
+        log.setLevel(logging.DEBUG)
+        log.addHandler(journal.JournalHandler())
+        log.addHandler(
+            journal.JournalHandler(SYSLOG_IDENTIFIER='ovirt-node-ntp')
+        )
+ 
+        return log
+
+
+def main():
+    ntp = OvirtNtp()
+    ntp.logger.info("Staring ovirt-node-ntp service..")
+
+    if not ntp.is_set():
+        ntp.logger.info("OVIRT_NODE_NTP not found in /etc/default/ovirt")
+
+        if ntp.get_kargs() is None:
+            ntp.logger.info("No ntp in the kernel arguments, exiting")
+            return 0
+    else:
+        ntp.logger.info("Found OVIRT_NODE_NTP in /etc/default/ovirt, exiting")
+        return 0
+
+    ntp.comment_servers()
+    ntp.write_changes()
+    return 0
+
+if __name__ == '__main__':
+    sys.exit(main())
diff --git a/services/ovirt-ntpd/ovirt-ntpd.service b/services/ovirt-ntpd/ovirt-ntpd.service
new file mode 100644
index 0000000..2923809
--- /dev/null
+++ b/services/ovirt-ntpd/ovirt-ntpd.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=oVirt Network Time Service
+Before=ntpd.service
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/bin/ovirt-node-ntpd
+Nice=-20
+User=root
+Group=root
+PermissionsStartOnly=true
+
+[Install]
+WantedBy=multi-user.target
diff --git a/src/ovirtnode/network.py b/src/ovirtnode/network.py
index 39fc0dc..f05a41c 100644
--- a/src/ovirtnode/network.py
+++ b/src/ovirtnode/network.py
@@ -81,7 +81,4 @@
         mdns = Nameservers()
         txs += mdns.transaction()
 
-        mntp = Timeservers()
-        txs += mntp.transaction()
-
     return txs


-- 
To view, visit https://gerrit.ovirt.org/41617
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib7827ab15b23b71d18b4562a0f2fc8a475f16378
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list