def testFilesystemCopyObject2(self):
        from comoonics import ComSystem
        _xml = """
 <copyset type="filesystem" name="save-tmp">
    <source type="filesystem">
      <device id="sourcerootfs" name="/dev/vg_vmware_cluster_sr/lv_sharedroot" options="skipmount">
        <filesystem type="gfs"/>
        <mountpoint name="/">
          <option value="lock_nolock" name="lockproto"/>
          <option value="hdfhgg" name="locktable"/>
        </mountpoint>
      </device>
    </source>
    <destination type="filesystem">
      <device id="destrootfs" name="/dev/vg_vmware_cluster_srC/lv_sharedroot">
        <filesystem clustername="vmware_cluster" type="gfs"/>
        <mountpoint name="/var/lib/com-ec/dest">
          <option value="lock_nolock" name="lockproto"/>
          <option value="jhdshf" name="locktable"/>
        </mountpoint>
      </device>
    </destination>
 </copyset>
        """
        oldexecmode = ComSystem.getExecMode()
        ComSystem.setExecMode(ComSystem.SIMULATE)
        self.__testCopyset(_xml)
        ComSystem.setExecMode(oldexecmode)
 def testsplitLVPath(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     for device in self.devicenames.keys():
         print("device=" + device)
         expresult = self.devicenames[device][0]
         try:
             result = list(LogicalVolume.splitLVPath(device))
             if expresult != LogicalVolume.LVMInvalidLVPathException:
                 result.sort()
                 expresult.sort()
                 print "Found: vgname: %s, lvname: %s" % (result[0],
                                                          result[1])
                 self.assertEquals(
                     result, expresult,
                     "vgname: %s lvname: %s but returned vgname %s, lvname %s"
                     % (result[0], result[1], expresult[0], expresult[1]))
             else:
                 self.fail("We would expect a %s but got a %s" %
                           (expresult, result))
         except LogicalVolume.LVMInvalidLVPathException, e:
             print e.value
             self.assertEquals(
                 e.__class__, expresult,
                 "Expected exception %s but got %s" %
                 (expresult, e.__class__))
示例#3
0
 def testLVMCopyObject(self):
     import comoonics.XmlTools
     from comoonics.enterprisecopy.ComCopyObject import CopyObject
     from comoonics import ComSystem
     sourcexml = """
     <source type="lvm">
        <volumegroup name='centos' free='32' numlvs='2' attrs='wz--n-' numpvs='1' serial='0' size='3456'>
           <physicalvolume attr='a-' size='3456' name='/dev/sdf2' free='32' format='lvm2'/>
           <logicalvolume origin='' size='512' name='swap' attrs='-wi-a-'/>
           <logicalvolume origin='' size='2912' name='system' attrs='-wi-a-'/>
        </volumegroup>
    </source>
     """
     destxml = """
     <destination type="lvm">
         <volumegroup name="centos_new">
             <physicalvolume name="/dev/sde"/>
         </volumegroup>
     </destination>
     """
     ComSystem.setExecMode(ComSystem.SIMULATE)
     sourcedoc = comoonics.XmlTools.parseXMLString(sourcexml)
     destdoc = comoonics.XmlTools.parseXMLString(destxml)
     try:
         source = CopyObject(sourcedoc.documentElement, sourcedoc)
         dest = CopyObject(destdoc.documentElement, destdoc)
         dest.updateMetaData(source.getMetaData())
     except Exception, e:
         self.assert_(
             "Could not execute copyobject %s => %s. Exception %s." %
             (source, dest, e))
 def testLVMCopyObject(self):
     import comoonics.XmlTools
     from comoonics.enterprisecopy.ComCopyObject import CopyObject
     from comoonics import ComSystem
     sourcexml="""
     <source type="lvm">
        <volumegroup name='centos' free='32' numlvs='2' attrs='wz--n-' numpvs='1' serial='0' size='3456'>
           <physicalvolume attr='a-' size='3456' name='/dev/sdf2' free='32' format='lvm2'/>
           <logicalvolume origin='' size='512' name='swap' attrs='-wi-a-'/>
           <logicalvolume origin='' size='2912' name='system' attrs='-wi-a-'/>
        </volumegroup>
    </source>
     """
     destxml="""
     <destination type="lvm">
         <volumegroup name="centos_new">
             <physicalvolume name="/dev/sde"/>
         </volumegroup>
     </destination>
     """
     ComSystem.setExecMode(ComSystem.SIMULATE)
     sourcedoc=comoonics.XmlTools.parseXMLString(sourcexml)
     destdoc=comoonics.XmlTools.parseXMLString(destxml)
     try:
         source=CopyObject(sourcedoc.documentElement, sourcedoc)
         dest=CopyObject(destdoc.documentElement, destdoc)
         dest.updateMetaData(source.getMetaData())
     except Exception, e:
         self.assert_("Could not execute copyobject %s => %s. Exception %s." %(source, dest, e))
def setSimulation(flag):
    if flag:
        try:
            from comoonics import ComSystem
            ComSystem.setExecMode(ComSystem.SIMULATE)
        except ImportError:
            pass
def setSimulation(flag):
    if flag:
        try:
            from comoonics import ComSystem
            ComSystem.setExecMode(ComSystem.SIMULATE)
        except ImportError:
            pass
    def testFilesystemCopyObject2(self):
        from comoonics import ComSystem
        _xml="""
 <copyset type="filesystem" name="save-tmp">
    <source type="filesystem">
      <device id="sourcerootfs" name="/dev/vg_vmware_cluster_sr/lv_sharedroot" options="skipmount">
        <filesystem type="gfs"/>
        <mountpoint name="/">
          <option value="lock_nolock" name="lockproto"/>
          <option value="hdfhgg" name="locktable"/>
        </mountpoint>
      </device>
    </source>
    <destination type="filesystem">
      <device id="destrootfs" name="/dev/vg_vmware_cluster_srC/lv_sharedroot">
        <filesystem clustername="vmware_cluster" type="gfs"/>
        <mountpoint name="/var/lib/com-ec/dest">
          <option value="lock_nolock" name="lockproto"/>
          <option value="jhdshf" name="locktable"/>
        </mountpoint>
      </device>
    </destination>
 </copyset>
        """          
        oldexecmode=ComSystem.getExecMode()
        ComSystem.setExecMode(ComSystem.SIMULATE)
        self.__testCopyset(_xml)
        ComSystem.setExecMode(oldexecmode)
 def _testMethod(self, method, execmode, *params):
     oldmode=ComSystem.getExecMode()
     ComSystem.clearSimCommands()
     ComSystem.setExecMode(execmode)
     try:
         method(*params)
     except Exception, e:
         import traceback
         traceback.print_exc()
         self.fail("Could not execute %s method on with parameters %s, Error: %s" %(method, params, e))
    def init(self):
        import os.path
        ComSystem.setExecMode(ComSystem.SIMULATE)
        super(test_ClusterNodeNic, self).init()
        #create comclusterRepository Object
        self.clusterRepository = getClusterRepository(os.path.join(self._testpath, "cluster2.conf"))

        #create comclusterinfo object
        self.clusterInfo = getClusterInfo(self.clusterRepository)  

        # setup the cashes for clustat for redhat cluster
        self.clusterInfo.helper.setSimOutput()
示例#10
0
 def _testMethod(self, method, execmode, *params):
     oldmode = ComSystem.getExecMode()
     ComSystem.clearSimCommands()
     ComSystem.setExecMode(execmode)
     try:
         method(*params)
     except Exception, e:
         import traceback
         traceback.print_exc()
         self.fail(
             "Could not execute %s method on with parameters %s, Error: %s"
             % (method, params, e))
示例#11
0
 def setUp(self):
     from comoonics import ComSystem
     ComSystem.setExecMode(ComSystem.SIMULATE)
     from comoonics import ComLog
     import logging
     import inspect
     import os.path
     ComLog.setLevel(logging.DEBUG)
     self.helper=RedHatClusterHelper()
     path=os.path.dirname(inspect.getfile(self.__class__))
     f=open(os.path.join(path, self.OUTPUT_TEST_FILE))
     import StringIO
     buf=StringIO.StringIO()
     for line in f:
         buf.write(line)
     self.TEST_OUTPUT=buf.getvalue()
 def setUp(self):
     from comoonics import ComSystem
     ComSystem.setExecMode(ComSystem.SIMULATE)
     from comoonics import ComLog
     import logging
     import inspect
     import os.path
     ComLog.setLevel(logging.DEBUG)
     self.helper=getClusterHelper()
     path=os.path.dirname(inspect.getfile(self.__class__))
     f=open(os.path.join(path, self.OUTPUT_TEST_FILE))
     import StringIO
     buf=StringIO.StringIO()
     for line in f:
         buf.write(line)
     self.TEST_OUTPUT=buf.getvalue()
    def init(self):
        import os.path
        ComSystem.setExecMode(ComSystem.SIMULATE)
        super(test_ClusterNode, self).init()
        #create comclusterRepository Object
        self.clusterRepository = getClusterRepository(os.path.join(self._testpath, "cluster2.conf"))

        #create comclusterinfo object
        self.clusterInfo = getClusterInfo(self.clusterRepository)  

        # setup the cashes for clustat for redhat cluster
        self.clusterInfo.helper.setSimOutput()
        self.nics=list()
        for node in self.clusterInfo.getNodes():
            node.helper.output=self.clusterInfo.helper.output
            for nic in node.getNics():
                self.nics.append(nic)
 def testsplitLVPath(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     for device in self.devicenames.keys():
         print("device="+device)
         expresult=self.devicenames[device][0]
         try:
             result=list(LogicalVolume.splitLVPath(device))
             if expresult != LogicalVolume.LVMInvalidLVPathException:
                 result.sort()
                 expresult.sort()
                 print "Found: vgname: %s, lvname: %s" %(result[0], result[1])
                 self.assertEquals(result, expresult, "vgname: %s lvname: %s but returned vgname %s, lvname %s" %(result[0], result[1], expresult[0], expresult[1]))
             else:
                 self.fail("We would expect a %s but got a %s" %(expresult, result))
         except LogicalVolume.LVMInvalidLVPathException, e:
             print e.value
             self.assertEquals(e.__class__, expresult, "Expected exception %s but got %s" %(expresult, e.__class__))
示例#15
0
    def init(self):
        import os.path
        from comoonics.cluster.ComClusterRepository import ClusterRepository
        from comoonics.cluster.ComClusterInfo import ClusterInfo
        from comoonics import ComSystem
        ComSystem.setExecMode(ComSystem.SIMULATE)
        super(test_ClusterNode, self).init()
        #create comclusterRepository Object
        self.clusterRepository = ClusterRepository(
            os.path.join(self._testpath, "cluster2.conf"))

        #create comclusterinfo object
        self.clusterInfo = ClusterInfo(self.clusterRepository)

        # setup the cashes for clustat for redhat cluster
        self.clusterInfo.helper.setSimOutput()
        self.nics = list()
        for node in self.clusterInfo.getNodes():
            node.helper.output = self.clusterInfo.helper.output
            for nic in node.getNics():
                self.nics.append(nic)
    def init(self):
        import os.path
        from comoonics.cluster.ComClusterRepository import ClusterRepository
        from comoonics.cluster.ComClusterInfo import ClusterInfo
        import logging
        from comoonics import ComSystem
        ComSystem.setExecMode(ComSystem.SIMULATE)
        super(test_ClusterInfo, self).init()
        #create comclusterRepository Object
        self.clusterRepository = ClusterRepository(os.path.join(self._testpath, "cluster2.conf"))

        #create comclusterinfo object
        self.clusterInfo = ClusterInfo(self.clusterRepository)  

        # setup the cashes for clustat for redhat cluster
        ComLog.setLevel(logging.DEBUG)
        self.clusterInfo.helper.setSimOutput()
        self.nics=list()
        for node in self.clusterInfo.getNodes():
            node.helper.output=self.clusterInfo.helper.output
            for nic in node.getNics():
                self.nics.append(nic)
 def testExecLocalGetResultSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalGetResult(self.cmd1, False, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[2])
 def testExecLocalOutputAsStringSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[0])
 def testExecLocalFalse(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocal("/bin/false", "output of /bin/false, execLocal")
     self.assertEquals(result, 256)
 def testExecMethodErrSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execMethod(ComSystem.execLocalGetResult, self.cmd1,
                                   True)
     self.assertEquals(result, True)
 def testExecLocalStatusOutput(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalStatusOutput(self.cmd1, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[4])
 def testExecMethodErrSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execMethod(ComSystem.execLocalGetResult, self.cmd1, True)
     self.assertEquals(result, True)
 def testExecLocalOutputAsStringSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[0])
 def testExecLocalGetResultErrSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalGetResult(self.cmd1, True, self.cmd1_simout, self.cmd1_simerr)
     self.assertEquals(result, self.cmd1_sim_result[3])
import sys
import os

sys.path.append("../lib")

from comoonics import ComScsi
from comoonics import ComSystem


ComSystem.setExecMode("ask")
#print os.listdir("/sys/class")

scsi=ComScsi.SCSI()
scsi.rescan("-", "-", "-", "-")
scsi.rescan("-", "0", "1", "2")
scsi.rescan("-", "x", "-", "-")
示例#26
0
class BaseTestFileSystem(unittest.TestCase):
    xml = None
    filesystem = None
    device = None
    mountpoint = None
    commands = None
    simmethods = None
    name = ""
    label = "mylabel"

    def setUp(self):
        from comoonics import XmlTools
        import StringIO
        from comoonics.storage.ComDevice import Device
        from comoonics.storage.ComMountpoint import MountPoint
        from comoonics.storage.ComFileSystem import getFileSystem

        xmlfp = StringIO.StringIO(self.xml)
        doc = XmlTools.parseXMLFP(xmlfp)
        __device = doc.documentElement

        self.device = Device(__device, doc)
        __fs = __device.getElementsByTagName("filesystem")[0]
        self.filesystem = getFileSystem(__fs, doc)
        __mp = __device.getElementsByTagName("mountpoint")[0]
        self.mountpoint = MountPoint(__mp, doc)

    def _testMethod(self, method, execmode, *params):
        oldmode = ComSystem.getExecMode()
        ComSystem.clearSimCommands()
        ComSystem.setExecMode(execmode)
        try:
            method(*params)
        except Exception, e:
            import traceback
            traceback.print_exc()
            self.fail(
                "Could not execute %s method on with parameters %s, Error: %s"
                % (method, params, e))
        if self.simmethods and ComSystem.isSimulate():
            errormethods = list()
            for simmethod in ComSystem.getSimCommands():
                matched = False
                for simmethod2 in self.simmethods:
                    if not matched and isinstance(simmethod2, basestring):
                        matched = simmethod == simmethod2
                    elif not matched:
                        # Must be re
                        matched = simmethod2.match(simmethod)
                if matched == False:
                    errormethods.append(simmethod)
            if len(errormethods) > 0:
                bufsimmethods = list()
                for simmethod in self.simmethods:
                    if isinstance(simmethod, basestring):
                        bufsimmethods.append(simmethod)
                    else:
                        bufsimmethods.append(simmethod.pattern)
                self.fail(
                    """The commands being executed are not to be found in the commands that must have been executed.
Commands that could not be matched are:
%s
Executed commands are: 
%s
Expected commands are:
%s
""" % ("\n".join(errormethods), "\n".join(
                        ComSystem.getSimCommands()), "\n".join(bufsimmethods)))
        ComSystem.setExecMode(oldmode)
示例#27
0
 def setUp(self):
     from comoonics import ComSystem
     ComSystem.setExecMode(ComSystem.SIMULATE)
     from comoonics.enterprisecopy.ComPathCopyObject import PathCopyObject
     from comoonics.enterprisecopy.ComCopyObject import registerCopyObject
     registerCopyObject("path", PathCopyObject)
 def testExecLocalGetResultErrSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalGetResult(self.cmd1, True,
                                           self.cmd1_simout,
                                           self.cmd1_simerr)
     self.assertEquals(result, self.cmd1_sim_result[3])
 def testExecLocalGetResultSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalGetResult(self.cmd1, False,
                                           self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[2])
 def testExecLocalStatusOutputSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalStatusOutput(self.cmd1, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[4])
 def testExecLocalFalse(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocal("/bin/false",
                                  "output of /bin/false, execLocal")
     self.assertEquals(result, 256)
 def testExecLocalStatusOutputFalse(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalStatusOutput(
         "/bin/false", "output of /bin/false, execLocalStatusOutput")
     self.assertEquals(result, (256, ""))
 def testExecLocalGetResultErr(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalGetResult(self.cmd1, True,
                                           self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[3])
 def testExecMethodErr(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execMethod(ComSystem.execLocalGetResult, self.cmd1,
                                   True)
     self.assertEquals(result, self.cmd1_result[3])
 def testExecLocalGetResultErr(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalGetResult(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[3])
 def testExecLocalStatusOutput(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalStatusOutput(self.cmd1, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[4])
 def testExecMethodErr(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execMethod(ComSystem.execLocalGetResult, self.cmd1, True)
     self.assertEquals(result, self.cmd1_result[3])
'''
Created on Feb 26, 2010

@author: marc
'''
from comoonics import ComLog
from comoonics import ComSystem
from comoonics.storage.ComLVM import LogicalVolume, LinuxVolumeManager, PhysicalVolume, VolumeGroup
import logging
logging.basicConfig()
ComLog.setLevel(logging.DEBUG)
import unittest
ComSystem.setExecMode(ComSystem.SIMULATE)

class Test(unittest.TestCase):
    devicenames={"/dev/sda": [ LogicalVolume.LVMInvalidLVPathException ], 
                 "/dev/cciss/c0d0p1": [ [ "cciss", "c0d0p1" ] ], 
                 "/dev/mapper/abc-def": [ [ "abc", "def" ] ], 
                 "/dev/abc/def" : [ [ "abc", "def" ] ], 
                 "/dev/mapper/abc_def" : [ LogicalVolume.LVMInvalidLVPathException, None ],
                 "/dev/abc/def/geh" :  [ LogicalVolume.LVMInvalidLVPathException, None ]}

    def testsplitLVPath(self):
        ComSystem.setExecMode(ComSystem.SIMULATE)
        for device in self.devicenames.keys():
            print("device="+device)
            expresult=self.devicenames[device][0]
            try:
                result=list(LogicalVolume.splitLVPath(device))
                if expresult != LogicalVolume.LVMInvalidLVPathException:
                    result.sort()
 def testExecLocalStatusOutputFalse(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalStatusOutput("/bin/false", "output of /bin/false, execLocalStatusOutput")
     self.assertEquals(result, (256, ""))
'''
Created on Feb 26, 2010

@author: marc
'''
from comoonics import ComLog
from comoonics import ComSystem
from comoonics.storage.ComLVM import LogicalVolume, LinuxVolumeManager, PhysicalVolume, VolumeGroup
import logging
logging.basicConfig()
ComLog.setLevel(logging.DEBUG)
import unittest
ComSystem.setExecMode(ComSystem.SIMULATE)


class Test(unittest.TestCase):
    devicenames = {
        "/dev/sda": [LogicalVolume.LVMInvalidLVPathException],
        "/dev/cciss/c0d0p1": [["cciss", "c0d0p1"]],
        "/dev/mapper/abc-def": [["abc", "def"]],
        "/dev/abc/def": [["abc", "def"]],
        "/dev/mapper/abc_def": [LogicalVolume.LVMInvalidLVPathException, None],
        "/dev/abc/def/geh": [LogicalVolume.LVMInvalidLVPathException, None]
    }

    def testsplitLVPath(self):
        ComSystem.setExecMode(ComSystem.SIMULATE)
        for device in self.devicenames.keys():
            print("device=" + device)
            expresult = self.devicenames[device][0]
            try:
 def testExecLocalStatusOutputSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execLocalStatusOutput(self.cmd1, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_sim_result[4])
 def testExecLocalOutputAsString(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[0])
 def testExecLocalOutputAsString(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execLocalOutput(self.cmd1, True, self.cmd1_simout)
     self.assertEquals(result, self.cmd1_result[0])