Back to index

salome-kernel  6.5.0
testresourcemanager.py
Go to the documentation of this file.
00001 #  -*- coding: iso-8859-1 -*-
00002 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00003 #
00004 # This library is free software; you can redistribute it and/or
00005 # modify it under the terms of the GNU Lesser General Public
00006 # License as published by the Free Software Foundation; either
00007 # version 2.1 of the License.
00008 #
00009 # This library is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 # Lesser General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU Lesser General Public
00015 # License along with this library; if not, write to the Free Software
00016 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00017 #
00018 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00019 #
00020 
00021 import unittest
00022 import salome
00023 import LifeCycleCORBA
00024 import SALOME
00025 salome.salome_init()
00026 cm= salome.lcc.getContainerManager()
00027 rm= salome.lcc.getResourcesManager()
00028 
00029 class TestResourceManager(unittest.TestCase):
00030   """
00031 Test with CatalogResources.xml:
00032 <!DOCTYPE ResourcesCatalog>
00033 <resources>
00034    <machine hostname="m1" />
00035    <machine hostname="m2" />
00036    <machine hostname="m3" >
00037      <modules moduleName="tutu" />
00038    </machine>
00039    <machine hostname="m4" >
00040      <component name="sub" moduleName="tata" />
00041    </machine>
00042    <machine hostname="claui2c6" >
00043      <modules moduleName="toto" />
00044      <component name="add" moduleName="titi" />
00045    </machine>
00046 </resources>
00047 """
00048   def setUp(self):
00049     pass
00050 
00051   def test0(self):
00052     """host required"""
00053     params=LifeCycleCORBA.ResourceParameters(hostname="m3")
00054     machineList=rm.GetFittingResources(params)
00055     self.assertEqual(machineList, ["m3"])
00056 
00057   def test1(self):
00058     """OS required"""
00059     params=LifeCycleCORBA.ResourceParameters(OS="Linux")
00060     self.assertRaises(SALOME.SALOME_Exception,rm.GetFittingResources,params)
00061 
00062   def test2(self):
00063     """component add required"""
00064     params=LifeCycleCORBA.ResourceParameters(componentList=["add"])
00065     machineList=rm.GetFittingResources(params)
00066     self.assertEqual(machineList, ['claui2c6', 'm1', 'm2'])
00067 
00068   def test3(self):
00069     """component tutu required"""
00070     params=LifeCycleCORBA.ResourceParameters(componentList=["tutu"])
00071     machineList=rm.GetFittingResources(params)
00072     self.assertEqual(machineList, ['m1', 'm2', 'm3'])
00073 
00074   def test4(self):
00075     """component tata required"""
00076     params=LifeCycleCORBA.ResourceParameters(componentList=["tata"])
00077     machineList=rm.GetFittingResources(params)
00078     self.assertEqual(machineList, ['m1', 'm2'])
00079 
00080   def test5(self):
00081     """component titi required"""
00082     params=LifeCycleCORBA.ResourceParameters(componentList=["titi"])
00083     machineList=rm.GetFittingResources(params)
00084     self.assertEqual(machineList, ['m1', 'm2'])
00085 
00086   def test6(self):
00087     """component toto required"""
00088     params=LifeCycleCORBA.ResourceParameters(componentList=["toto"])
00089     machineList=rm.GetFittingResources(params)
00090     self.assertEqual(machineList, ['claui2c6', 'm1', 'm2'])
00091 
00092   def test7(self):
00093     """components add and toto required"""
00094     params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
00095     machineList=rm.GetFittingResources(params)
00096     self.assertEqual(machineList, ['claui2c6', 'm1', 'm2'])
00097 
00098   def test8(self):
00099     """components add and toto required"""
00100     machineDef=rm.GetResourceDefinition('claui2c6')
00101     self.assertEqual(machineDef.componentList, ['toto', 'add'])
00102 
00103   def test10(self):
00104     """policy altcycl"""
00105     params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
00106     machineList=rm.GetFittingResources(params)
00107     self.assertEqual(rm.Find('altcycl',machineList), "claui2c6")
00108     self.assertEqual(rm.Find('altcycl',machineList), "m1")
00109     self.assertEqual(rm.Find('altcycl',machineList), "m2")
00110     self.assertEqual(rm.Find('altcycl',machineList), "claui2c6")
00111     self.assertEqual(rm.Find('altcycl',machineList), "m1")
00112     self.assertEqual(rm.Find('altcycl',machineList), "m2")
00113 
00114   def test11(self):
00115     """policy cycl"""
00116     params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
00117     machineList=rm.GetFittingResources(params)
00118     self.assertEqual(rm.Find('cycl',machineList), "claui2c6")
00119     self.assertEqual(rm.Find('cycl',machineList), "m1")
00120     self.assertEqual(rm.Find('cycl',machineList), "m2")
00121     self.assertEqual(rm.Find('cycl',machineList), "claui2c6")
00122     self.assertEqual(rm.Find('cycl',machineList), "m1")
00123     self.assertEqual(rm.Find('cycl',machineList), "m2")
00124 
00125   def test12(self):
00126     """policy first"""
00127     params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
00128     machineList=rm.GetFittingResources(params)
00129     self.assertEqual(rm.Find('first',machineList), "claui2c6")
00130     self.assertEqual(rm.Find('first',machineList), "claui2c6")
00131 
00132   def test13(self):
00133     """policy best"""
00134     params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
00135     machineList=rm.GetFittingResources(params)
00136     self.assertEqual(rm.Find('best',machineList), "claui2c6")
00137     self.assertEqual(rm.Find('best',machineList), "m1")
00138     self.assertEqual(rm.Find('best',machineList), "m2")
00139     self.assertEqual(rm.Find('best',machineList), "claui2c6")
00140     self.assertEqual(rm.Find('best',machineList), "m1")
00141     self.assertEqual(rm.Find('best',machineList), "m2")
00142 
00143 if __name__ == '__main__':
00144   suite = unittest.TestLoader().loadTestsFromTestCase(TestResourceManager)
00145   unittest.TextTestRunner().run(suite)
00146