Author: gnichols
Date: 2010-06-15 17:28:18 +0000 (Tue, 15 Jun 2010)
New Revision: 549
Added:
trunk/v7/daemon.py
Log:
568518 - FEAT: add a BMC fencing testing
Added: trunk/v7/daemon.py
===================================================================
--- trunk/v7/daemon.py (rev 0)
+++ trunk/v7/daemon.py 2010-06-15 17:28:18 UTC (rev 549)
@@ -0,0 +1,118 @@
+# Copyright (c) 2006 Red Hat, Inc. All rights reserved. This copyrighted material
+# is made available to anyone wishing to use, modify, copy, or
+# redistribute it subject to the terms and conditions of the GNU General
+# Public License v.2.
+#
+# 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.
+#
+# Author: Greg Nichols
+#
+
+import os, time, subprocess, sys
+
+from v7.controller import Controller
+from v7.tags import Tags, Attributes, Constants
+from v7.environment import Environment
+from v7.command import Command, V7CommandException
+from v7.test import Test
+from v7.planner import Planner
+
+
+class V7Daemon(Controller):
+
+
+ def __init__(self, environment, options):
+ Controller.__init__(self)
+ self.options = options
+ self.environment = environment
+ self.planner = Planner(self.options, virtualization=None)
+ self.planner.analyse(self.environment.getSourceDirectory())
+
+ def __clearPipes(self):
+ try:
+ os.remove(self.environment.getTaskFilePath()+ ".in")
+ except OSError, e:
+ if self.options.debug != Constants.off:
+ print "Warning: "
+ print e
+ pass # ignore
+ try:
+ os.remove(self.environment.getTaskFilePath()+ ".out")
+ except OSError, e:
+ if self.options.debug != Constants.off:
+ print "Warning: "
+ print e
+ pass # ignore
+ mask = os.umask(0111)
+ os.mkfifo(self.environment.getTaskFilePath()+ ".in", 0666)
+ os.mkfifo(self.environment.getTaskFilePath()+ ".out", 0666)
+ os.umask(mask)
+
+
+ def run(self):
+ self.__clearPipes()
+ while True:
+ if self.options.debug != Constants.off:
+ print "checking for tasks"
+ sys.stdout.flush()
+ taskInFile = open(self.environment.getTaskFilePath()+ ".in", 'r')
+ line = taskInFile.readline()
+ taskInFile.close()
+ if len(line.strip()) is 0:
+ continue
+ else:
+ print "\"" + line.strip() + "\""
+
+ if line.strip() == "shutdown":
+ print "v7 daemon shutdown"
+ # delete the lines from the file
+ taskOutFile = open(self.environment.getTaskFilePath()+ ".out", 'w')
+ taskOutFile.write("v7 shutdown")
+ taskOutFile.close()
+ return 0
+ # otherwise
+ # only run v7 - nothing else
+ words = line.split()
+ if len(words) > 0 and words[0] == "v7" and ";" not in line:
+ if words[1] == "daemon" and words[2] =="run":
+ self.serverTest(line)
+ else: # run local vi subprocess
+ print "Running: " + line
+ taskOutFile = open(self.environment.getTaskFilePath()+ ".out", 'w')
+ pipe = subprocess.Popen(line, shell=True,
+ stdin=subprocess.PIPE,
+ stdout=taskOutFile,
+ stderr=taskOutFile,)
+ (output, errors) = pipe.communicate()
+ taskOutFile.close()
+ else:
+ print "unsupported command: " + line
+
+ def serverTest(self, line):
+ """ run server-side test code per client/SUT request """
+ args = dict()
+ word=line.split()[3:]
+ i = 0
+ while i+1 < len(word):
+ args[word[i][2:]] = word[i+1]
+ i += 1
+
+ taskOutFile = open(self.environment.getTaskFilePath()+ ".out", 'w')
+ taskOutFile.write("Running test " + args["test"] + "\n")
+ result = True
+ try:
+ test = self.planner.getTest(args["test"])
+ test.runOnServer(args, taskOutFile)
+ except KeyError:
+ print "Error: test not found"
+ result = False
+ taskOutFile.close()
+ return result
+
+
\ No newline at end of file