All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] rteval cross-distribution patch
@ 2012-10-23 15:45 Raphaël Beamonte
  2012-10-23 15:45 ` [PATCH 1/3] Rewrite of the get_kthreads method to make it cross-distribution Raphaël Beamonte
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Raphaël Beamonte @ 2012-10-23 15:45 UTC (permalink / raw)
  To: williams; +Cc: linux-rt-users, Raphaël Beamonte

Hi Clark,

Here are the patches to make rteval working independently of the used
distribution.

Let me know if you have any comments/corrections,

-- Raphaël

---

Raphaël Beamonte (3):
  Rewrite of the get_kthreads method to make it cross-distribution
  Adds getcmdpath method to use which to locate the used commands
  Rewrite of the get_services method to make it cross-distribution

 rteval/rteval.py |   91 ++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 72 insertions(+), 19 deletions(-)

-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/3] Rewrite of the get_kthreads method to make it cross-distribution
  2012-10-23 15:45 [PATCH 0/3] rteval cross-distribution patch Raphaël Beamonte
@ 2012-10-23 15:45 ` Raphaël Beamonte
  2012-10-23 15:45 ` [PATCH 2/3] Adds getcmdpath method to use which to locate the used commands Raphaël Beamonte
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Raphaël Beamonte @ 2012-10-23 15:45 UTC (permalink / raw)
  To: williams; +Cc: linux-rt-users, Raphaël Beamonte

Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
---
 rteval/rteval.py |    7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/rteval/rteval.py b/rteval/rteval.py
index 5ecc20f..a432233 100644
--- a/rteval/rteval.py
+++ b/rteval/rteval.py
@@ -248,16 +248,15 @@ class RtEval(object):
     def get_kthreads(self):
         policies = {'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown' }
         ret_kthreads = {}
-        if not os.path.exists('/etc/rc.d/init.d/rtctl'):
-            return ret_kthreads
         self.debug("getting kthread status")
-        cmd = '/sbin/service rtctl status'
+        cmd = '/bin/ps -eocommand,pid,policy,rtprio,comm'
         self.debug("cmd: %s" % cmd)
         c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
         for p in c.stdout:
             v = p.strip().split()
+            kcmd = v.pop(0)
             try:
-                if int(v[0]) > 0:
+                if int(v[0]) > 0 and kcmd.startswith('[') and kcmd.endswith(']'):
                     ret_kthreads[v[0]] = {'policy' : policies[v[1]], 
                                           'priority' : v[2], 'name' : v[3] }
             except ValueError:
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] Adds getcmdpath method to use which to locate the used commands
  2012-10-23 15:45 [PATCH 0/3] rteval cross-distribution patch Raphaël Beamonte
  2012-10-23 15:45 ` [PATCH 1/3] Rewrite of the get_kthreads method to make it cross-distribution Raphaël Beamonte
@ 2012-10-23 15:45 ` Raphaël Beamonte
  2012-10-23 15:45 ` [PATCH 3/3] Rewrite of the get_services method to make it cross-distribution Raphaël Beamonte
  2012-10-23 17:26 ` [PATCH 0/3] rteval cross-distribution patch Clark Williams
  3 siblings, 0 replies; 5+ messages in thread
From: Raphaël Beamonte @ 2012-10-23 15:45 UTC (permalink / raw)
  To: williams; +Cc: linux-rt-users, Raphaël Beamonte

Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
---
 rteval/rteval.py |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/rteval/rteval.py b/rteval/rteval.py
index a432233..f54c1f4 100644
--- a/rteval/rteval.py
+++ b/rteval/rteval.py
@@ -63,6 +63,17 @@ import rtevalMailer
 from cputopology import CPUtopology
 
 
+pathSave={}
+def getcmdpath(which):
+    if not pathSave.has_key(which):
+        cmd = '/usr/bin/which %s' % which
+        c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
+        pathSave[which] = c.stdout.read().strip()
+        if not pathSave[which]:
+            raise RuntimeError, "Command '%s' is unknown on this system" % which
+    return pathSave[which]
+
+
 sigint_received = False
 def sigint_handler(signum, frame):
     global sigint_received
@@ -249,7 +260,7 @@ class RtEval(object):
         policies = {'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown' }
         ret_kthreads = {}
         self.debug("getting kthread status")
-        cmd = '/bin/ps -eocommand,pid,policy,rtprio,comm'
+        cmd = '%s -eocommand,pid,policy,rtprio,comm' % getcmdpath('ps')
         self.debug("cmd: %s" % cmd)
         c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
         for p in c.stdout:
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] Rewrite of the get_services method to make it cross-distribution
  2012-10-23 15:45 [PATCH 0/3] rteval cross-distribution patch Raphaël Beamonte
  2012-10-23 15:45 ` [PATCH 1/3] Rewrite of the get_kthreads method to make it cross-distribution Raphaël Beamonte
  2012-10-23 15:45 ` [PATCH 2/3] Adds getcmdpath method to use which to locate the used commands Raphaël Beamonte
@ 2012-10-23 15:45 ` Raphaël Beamonte
  2012-10-23 17:26 ` [PATCH 0/3] rteval cross-distribution patch Clark Williams
  3 siblings, 0 replies; 5+ messages in thread
From: Raphaël Beamonte @ 2012-10-23 15:45 UTC (permalink / raw)
  To: williams; +Cc: linux-rt-users, Raphaël Beamonte

Changes the get_services method to call the new created
__get_services_sysvinit and __get_services_systemd methods
to be able to manage the two different init daemons.

Signed-off-by: Raphaël Beamonte <raphael.beamonte@gmail.com>
---
 rteval/rteval.py |   73 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 58 insertions(+), 15 deletions(-)

diff --git a/rteval/rteval.py b/rteval/rteval.py
index f54c1f4..829a49b 100644
--- a/rteval/rteval.py
+++ b/rteval/rteval.py
@@ -48,6 +48,9 @@ import signal
 import rtevalclient
 import ethtool
 import xmlrpclib
+import platform
+import fnmatch
+import glob
 from datetime import datetime
 from distutils import sysconfig
 
@@ -92,6 +95,7 @@ class RtEval(object):
         self.inifile = None
         self.cmd_options = {}
         self.start = datetime.now()
+        self.init = 'unknown'
 
         default_config = {
             'rteval': {
@@ -239,22 +243,61 @@ class RtEval(object):
                     topology.getCPUsockets()))
         return topology.getXMLdata()
 
-
-
-    def get_services(self):
-        rejects = ('capi', 'firstboot', 'functions', 'halt', 'iptables', 'ip6tables', 
-                   'killall', 'lm_sensors', 'microcode_ctl', 'network', 'ntpdate', 
-                   'rtctl', 'udev-post')
-        service_list = filter(lambda x: x not in rejects, os.listdir('/etc/rc.d/init.d'))
+    def __get_services_sysvinit(self):
+        reject = ('functions', 'halt', 'killall', 'single', 'linuxconf', 'kudzu',
+                  'skeleton', 'README', '*.dpkg-dist', '*.dpkg-old', 'rc', 'rcS',
+                  'single', 'reboot', 'bootclean.sh')
+        for sdir in ('/etc/init.d', '/etc/rc.d/init.d'):
+            if os.path.isdir(sdir):
+                servicesdir = sdir
+                break
+        if not servicesdir:
+            raise RuntimeError, "No services dir (init.d) found on your system"
+        self.debug("Services located in %s, going through each service file to check status" % servicesdir)
         ret_services = {}
-        self.debug("getting services status")
-        for s in service_list:
-            cmd = ['/sbin/service', s, 'status']
-            c = subprocess.Popen(cmd, stdout=subprocess.PIPE)
-            status = c.stdout.read().strip().translate(self.transtable, self.junk)
-            ret_services[s] = status
+        for service in glob.glob(os.path.join(servicesdir, '*')):
+            servicename = os.path.basename(service)
+            if not [1 for p in reject if fnmatch.fnmatch(servicename, p)] and os.access(service, os.X_OK):
+                cmd = '%s -qs "\(^\|\W\)status)" %s' % (getcmdpath('grep'), service)
+                c = subprocess.Popen(cmd, shell=True)
+                c.wait()
+                if c.returncode == 0:
+                    cmd = ['env', '-i', 'LANG="%s"' % os.environ['LANG'], 'PATH="%s"' % os.environ['PATH'], 'TERM="%s"' % os.environ['TERM'], service, 'status']
+                    c = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+                    c.wait()
+                    if c.returncode == 0 and (c.stdout.read() or c.stderr.read()):
+                        ret_services[servicename] = 'running'
+                    else:
+                        ret_services[servicename] = 'not running'
+                else:
+                    ret_services[servicename] = 'unknown'
         return ret_services
-            
+        
+    def __get_services_systemd(self):
+        ret_services = {}
+        cmd = '%s list-unit-files -t service --no-legend' % getcmdpath('systemctl')
+        self.debug("cmd: %s" % cmd)
+        c = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+        for p in c.stdout:
+            # p are lines like "servicename.service status"
+            v = p.strip().split()
+            ret_services[v[0].split('.')[0]] = v[1]
+        return ret_services
+
+    def get_services(self):
+        cmd = [getcmdpath('ps'), '-ocomm=',  '1']
+        c = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+        self.init = c.stdout.read().strip()
+        if self.init == 'systemd':
+            self.debug("Using systemd to get services status")
+            return self.__get_services_systemd()
+        elif self.init == 'init':
+            self.init = 'sysvinit'
+            self.debug("Using sysvinit to get services status")
+            return self.__get_services_sysvinit()
+        else:
+            raise RuntimeError, "Unknown init system (%s)" % self.init
+        return {}
 
     def get_kthreads(self):
         policies = {'FF':'fifo', 'RR':'rrobin', 'TS':'other', '?':'unknown' }
@@ -434,7 +477,7 @@ class RtEval(object):
         self.xmlreport.taggedvalue('memory_size', "%.3f" % self.memsize[0], {"unit": self.memsize[1]})
         self.xmlreport.closeblock()
 
-        self.xmlreport.openblock('services')
+        self.xmlreport.openblock('services', {'init': self.init})
         for s in self.services:
             self.xmlreport.taggedvalue("service", self.services[s], {"name": s})
         self.xmlreport.closeblock()
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rt-users" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/3] rteval cross-distribution patch
  2012-10-23 15:45 [PATCH 0/3] rteval cross-distribution patch Raphaël Beamonte
                   ` (2 preceding siblings ...)
  2012-10-23 15:45 ` [PATCH 3/3] Rewrite of the get_services method to make it cross-distribution Raphaël Beamonte
@ 2012-10-23 17:26 ` Clark Williams
  3 siblings, 0 replies; 5+ messages in thread
From: Clark Williams @ 2012-10-23 17:26 UTC (permalink / raw)
  To: Raphaël Beamonte; +Cc: linux-rt-users

[-- Attachment #1: Type: text/plain, Size: 386 bytes --]

On Tue, 23 Oct 2012 11:45:02 -0400
Raphaël Beamonte <raphael.beamonte@gmail.com> wrote:

> Hi Clark,
> 
> Here are the patches to make rteval working independently of the used
> distribution.
> 
> Let me know if you have any comments/corrections,
> 
> -- Raphaël
> 
> ---
> 

Raphaël,

Thanks, I've applied your patches and pushed v.36 back to kernel.org.

Clark

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-10-23 17:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-23 15:45 [PATCH 0/3] rteval cross-distribution patch Raphaël Beamonte
2012-10-23 15:45 ` [PATCH 1/3] Rewrite of the get_kthreads method to make it cross-distribution Raphaël Beamonte
2012-10-23 15:45 ` [PATCH 2/3] Adds getcmdpath method to use which to locate the used commands Raphaël Beamonte
2012-10-23 15:45 ` [PATCH 3/3] Rewrite of the get_services method to make it cross-distribution Raphaël Beamonte
2012-10-23 17:26 ` [PATCH 0/3] rteval cross-distribution patch Clark Williams

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.