root/gip/trunk/test/test_gip_common.py

Revision 2676, 3.8 kB (checked in by burt, 11 months ago)

Previous incomplete commit -- python 2.2 fixes

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 import os
4 import sys
5 import gip_sets as sets
6 import unittest
7 import tempfile
8 import ConfigParser
9 from gip_sets import Set
10
11 sys.path.append(os.path.expandvars("$GIP_LOCATION/lib/python"))
12 from gip_common import config, cp_getBoolean, voList
13 from gip_cluster import getOSGVersion, getApplications
14 from gip_testing import runTest, streamHandler
15 import gip_testing
16
17 fermigrid_vos = sets.Set(['osg', 'cdms', 'lqcd', 'auger', 'i2u2', 'cdf', 'des',
18     'dzero', 'nanohub', 'grase', 'cms', 'fermilab', 'astro', 'accelerator',
19     'hypercp', 'ktev', 'miniboone', 'minos', 'nova', 'numi', 'mipp', 'patriot',
20     'sdss', 'theory', 'fermilab-test', 'accelerator', 'cdms', 'LIGO', 'glow',
21     'dosar', 'star', 'geant4', 'mariachi', 'atlas', 'nwicg', 'ops', 'gugrid',
22     'gpn', 'compbiogrid', 'engage', 'pragma', 'nysgrid', 'sbgrid', 'cigi',
23     'mis', 'fmri', 'gridex', 'vo1'])
24
25 class TestGipCommon(unittest.TestCase):
26
27     def test_config(self):
28         """
29         Make sure that the ConfigParser object can load without errors
30         """
31         cp = config()
32
33     def test_gip_conf(self):
34         """
35         Make sure that the $GIP_LOCATION/etc/gip.conf file is read.
36         """
37         old_gip_location = os.environ['GIP_LOCATION']
38         tmpdir = tempfile.mkdtemp()
39         try:
40             os.environ['GIP_LOCATION'] = tmpdir
41             etc_dir = os.path.join(tmpdir, 'etc')
42             try:
43                 os.mkdir(etc_dir)
44                 cp_orig = ConfigParser.ConfigParser()
45                 cp_orig.add_section("gip_test")
46                 cp_orig.set("gip_test", "gip_conf", "True")
47                 gip_conf = os.path.join(etc_dir, 'gip.conf')
48                 fp = open(gip_conf, 'w')
49                 try:
50                     cp_orig.write(fp)
51                     fp.close()
52                     cp = ConfigParser.ConfigParser()
53                     cp.read([gip_conf])
54                     result = cp_getBoolean(cp, "gip_test", "gip_conf", False)
55                     self.failUnless(result, msg="Failed to load $GIP_LOCATION"\
56                         "/etc/gip.conf")
57                 finally:
58                     os.unlink(gip_conf)
59             finally:
60                 os.rmdir(etc_dir)
61         finally:
62             os.rmdir(tmpdir)
63             os.environ['GIP_LOCATION'] = old_gip_location
64
65     def test_voList(self):
66         """
67         Make sure voList does indeed load up the correct VOs.
68         """
69         cp = ConfigParser.ConfigParser()
70         cp.add_section("vo")
71         cp.set("vo", "vo_blacklist", "ilc")
72         cp.set("vo", "vo_whitelist", "vo1")
73         cp.set("vo","user_vo_map", "test_configs/fermigrid-osg-user-vo-map.txt")
74         vos = voList(cp)
75         vos = sets.Set(vos)
76         diff = vos.symmetric_difference(fermigrid_vos)
77         self.failIf(diff, msg="Difference between voList output and desired " \
78             "output: %s." % ', '.join(diff))
79
80     def test_osg_version(self):
81         """
82         Test the osg-version function and test for the contents in the software.
83         """
84         my_version = 'OSG-magic-version'
85         cp = config("test_configs/red.conf")
86         version = getOSGVersion(cp)
87         self.failUnless(version == my_version, msg="Computed OSG version does"\
88             " not match the test case's OSG version.")
89         found_osg = False
90         locations = getApplications(cp)
91         for loc in locations:
92             if loc['locationId'] == my_version:
93                 self.failUnless(loc['locationName'] == my_version)
94                 self.failUnless(loc['version'] == my_version)
95                 found_osg = True
96         if found_osg == False:
97             self.fail(msg="OSG version not in software list!")
98        
99
100 def main():
101     cp = config()
102     stream = streamHandler(cp)
103     runTest(cp, TestGipCommon, stream, per_site=False)
104
105 if __name__ == '__main__':
106     main()
107
Note: See TracBrowser for help on using the browser.