[node-patches] Change in ovirt-node[master]: Fix SNMP

rbarry at redhat.com rbarry at redhat.com
Tue May 13 23:03:03 UTC 2014


Ryan Barry has uploaded a new change for review.

Change subject: Fix SNMP
......................................................................

Fix SNMP

Use the new config location and keep the SNMP service running
so it actually works

Change-Id: I488b99ea9308160420e3cf036fb8a6cced0f9196
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1096164
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/setup/snmp/snmp_model.py
1 file changed, 13 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/50/27650/1

diff --git a/src/ovirt/node/setup/snmp/snmp_model.py b/src/ovirt/node/setup/snmp/snmp_model.py
index f2a0ab2..492266f 100644
--- a/src/ovirt/node/setup/snmp/snmp_model.py
+++ b/src/ovirt/node/setup/snmp/snmp_model.py
@@ -20,7 +20,7 @@
 # also available at http://www.gnu.org/copyleft/gpl.html.
 from ovirt.node import utils
 from ovirt.node.config.defaults import NodeConfigFileSection
-from ovirt.node.utils import process, system
+from ovirt.node.utils import process, system, fs
 import os.path
 
 
@@ -28,8 +28,6 @@
 
 
 def enable_snmpd(password):
-    from ovirtnode.ovirtfunctions import ovirt_store_config
-
     system.service("snmpd", "stop")
 
     # get old password #
@@ -37,9 +35,9 @@
         conf = "/tmp/snmpd.conf"
     else:
         conf = snmp_conf
-    cmd = "cat %s|grep createUser|awk '{print $4}'" % conf
-    oldpwd, stderr = process.pipe(cmd, shell=True)
-    oldpwd = oldpwd.stdout.read().strip()
+    cmd = "cat %s|grep createUser| grep -v '^#' | awk '{print $4}'" % conf
+    oldpwd = process.pipe(cmd, shell=True).strip()
+    
     process.call("sed -c -ie '/^createUser root/d' %s" % snmp_conf, shell=True)
     f = open(snmp_conf, "a")
     # create user account
@@ -48,32 +46,32 @@
 
     # change existing password
     if len(oldpwd) > 0:
+        system.service("snmpd", "start")
         pwd_change_cmd = (("snmpusm -v 3 -u root -n \"\" -l authNoPriv -a " +
                            "SHA -A %s localhost passwd %s %s -x AES") %
                           (oldpwd, oldpwd, password))
         process.check_call(pwd_change_cmd, shell=True)
         # Only reached when no excepion occurs
         process.call(["rm", "-rf", "/tmp/snmpd.conf"])
-    ovirt_store_config(snmp_conf)
+        system.service("snmpd", "stop")
+    fs.Config().persist(snmp_conf)
 
     if not any([x for x in open('/etc/snmp/snmpd.conf').readlines()
                 if 'rwuser root' in x]):
         with open('/etc/snmp/snmpd.conf', 'a') as f:
             f.write("rwuser root")
-    ovirt_store_config('/etc/snmp/snmpd.conf')
+    fs.Config().persist("/etc/snmp/snmpd.conf")
 
     system.service("snmpd", "start")
 
 
 def disable_snmpd():
-    from ovirtnode.ovirtfunctions import remove_config
-
     system.service("snmpd", "stop")
     # copy to /tmp for enable/disable toggles w/o reboot
     process.check_call(["cp", "/etc/snmp/snmpd.conf", "/tmp"])
     process.check_call("sed -c -ie '/^createUser root/d' %s" % snmp_conf,
                        shell=True)
-    remove_config(snmp_conf)
+    fs.Config().unpersist(snmp_conf)
 
 
 class SNMP(NodeConfigFileSection):
@@ -110,14 +108,12 @@
             title = "%s SNMP and setting the password" % state
 
             def commit(self):
-                # FIXME snmp plugin needs to be placed somewhere else (in src)
-                # pylint: disable-msg=E0611
-                from ovirt_config_setup import snmp  # @UnresolvedImport
-                # pylint: enable-msg=E0611
                 if enabled and snmp_password:
-                    snmp.enable_snmpd(snmp_password)
+                    with open('/tmp/test', 'w') as f:
+                        f.write("%s\n" % snmp_password)
+                    enable_snmpd(snmp_password)
                 else:
-                    snmp.disable_snmpd()
+                    disable_snmpd()
 
         tx.append(ConfigureSNMP())
         return tx


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I488b99ea9308160420e3cf036fb8a6cced0f9196
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list