1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2020 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
26 cm= salome.lcc.getContainerManager()
27 rm= salome.lcc.getResourcesManager()
29 class TestResourceManager(unittest.TestCase):
31 Test with CatalogResources.xml:
32 <!DOCTYPE ResourcesCatalog>
34 <machine hostname="m1" />
35 <machine hostname="m2" />
36 <machine hostname="m3" >
37 <modules moduleName="tutu" />
39 <machine hostname="m4" >
40 <component name="sub" moduleName="tata" />
42 <machine hostname="claui2c6" >
43 <modules moduleName="toto" />
44 <component name="add" moduleName="titi" />
53 params=LifeCycleCORBA.ResourceParameters(hostname="m3")
54 machineList=rm.GetFittingResources(params)
55 self.assertEqual(machineList, ["m3"])
59 params=LifeCycleCORBA.ResourceParameters(OS="Linux")
60 self.assertRaises(SALOME.SALOME_Exception,rm.GetFittingResources,params)
63 """component add required.
64 If a resource doesn't have any module or component defined in the catalog,
65 it means that it has every module and component and it fits for any request.
67 params=LifeCycleCORBA.ResourceParameters(componentList=["add"])
68 machineList=rm.GetFittingResources(params)
69 self.assertEqual(machineList, ['claui2c6', 'localhost', 'm1', 'm2'])
72 """component tutu required"""
73 params=LifeCycleCORBA.ResourceParameters(componentList=["tutu"])
74 machineList=rm.GetFittingResources(params)
75 self.assertEqual(machineList, ['localhost', 'm1', 'm2', 'm3'])
78 """component tata required"""
79 params=LifeCycleCORBA.ResourceParameters(componentList=["tata"])
80 machineList=rm.GetFittingResources(params)
81 self.assertEqual(machineList, ['localhost', 'm1', 'm2'])
84 """component titi required"""
85 params=LifeCycleCORBA.ResourceParameters(componentList=["titi"])
86 machineList=rm.GetFittingResources(params)
87 self.assertEqual(machineList, ['localhost', 'm1', 'm2'])
90 """component toto required"""
91 params=LifeCycleCORBA.ResourceParameters(componentList=["toto"])
92 machineList=rm.GetFittingResources(params)
93 self.assertEqual(machineList, ['claui2c6', 'localhost', 'm1', 'm2'])
96 """components add and toto required"""
97 params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
98 machineList=rm.GetFittingResources(params)
99 self.assertEqual(machineList, ['claui2c6', 'localhost', 'm1', 'm2'])
102 """components add and toto required"""
103 machineDef=rm.GetResourceDefinition('claui2c6')
104 self.assertEqual(machineDef.componentList, ['toto', 'add'])
108 params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
109 machineList=rm.GetFittingResources(params)
110 self.assertEqual(rm.Find('altcycl',machineList), "claui2c6")
111 self.assertEqual(rm.Find('altcycl',machineList), "localhost")
112 self.assertEqual(rm.Find('altcycl',machineList), "m1")
113 self.assertEqual(rm.Find('altcycl',machineList), "m2")
114 self.assertEqual(rm.Find('altcycl',machineList), "claui2c6")
115 self.assertEqual(rm.Find('altcycl',machineList), "localhost")
116 self.assertEqual(rm.Find('altcycl',machineList), "m1")
117 self.assertEqual(rm.Find('altcycl',machineList), "m2")
121 params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
122 machineList=rm.GetFittingResources(params)
123 self.assertEqual(rm.Find('cycl',machineList), "claui2c6")
124 self.assertEqual(rm.Find('cycl',machineList), "localhost")
125 self.assertEqual(rm.Find('cycl',machineList), "m1")
126 self.assertEqual(rm.Find('cycl',machineList), "m2")
127 self.assertEqual(rm.Find('cycl',machineList), "claui2c6")
128 self.assertEqual(rm.Find('cycl',machineList), "localhost")
129 self.assertEqual(rm.Find('cycl',machineList), "m1")
130 self.assertEqual(rm.Find('cycl',machineList), "m2")
134 params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
135 machineList=rm.GetFittingResources(params)
136 self.assertEqual(rm.Find('first',machineList), "claui2c6")
137 self.assertEqual(rm.Find('first',machineList), "claui2c6")
141 params=LifeCycleCORBA.ResourceParameters(componentList=["add","toto"])
142 machineList=rm.GetFittingResources(params)
143 self.assertEqual(rm.Find('best',machineList), "claui2c6")
144 self.assertEqual(rm.Find('best',machineList), "localhost")
145 self.assertEqual(rm.Find('best',machineList), "m1")
146 self.assertEqual(rm.Find('best',machineList), "m2")
147 self.assertEqual(rm.Find('best',machineList), "claui2c6")
148 self.assertEqual(rm.Find('best',machineList), "localhost")
149 self.assertEqual(rm.Find('best',machineList), "m1")
150 self.assertEqual(rm.Find('best',machineList), "m2")
152 if __name__ == '__main__':
153 #suite = unittest.TestLoader().loadTestsFromTestCase(TestResourceManager)
154 #unittest.TextTestRunner().run(suite)