assertSoftware.py 5 KB
Newer Older
1 2 3 4 5
"""
 TODO: Add copyright.
"""


6
import unittest
7
import sys, os, tempfile, stat, subprocess
8 9

def createCleanList(s):
10 11 12
  """
    TODO: Add doc string.
  """
13 14 15
  return sorted([q.strip() for q in s.split() if len(q.strip()) > 0])

class AssertPythonSoftware(unittest.TestCase):
16 17 18 19
  """
    TODO: Add doc string.
  """

20
  def test_python_version(self):
21 22 23 24
   """
    TODO: Add doc string.
   """
   self.assertEqual((2,4), sys.version_info[:2])
25

26
  def test_use_generated_python(self):
27 28 29
    """
      TODO: Add doc string.
    """
30
    fd, name = tempfile.mkstemp()
31 32 33
    try:
      f = os.fdopen(fd, 'w')
      f.write("""\
34 35 36 37
#!%s
import sys
print sys.version_info[:2]
    """ % sys.executable)
38 39 40
      f.close()
      f_stat = os.stat(name)
      os.chmod(name, f_stat.st_mode | stat.S_IXUSR)
41 42
      result = subprocess.Popen([name], stdout=subprocess.PIPE)\
          .communicate()[0].strip()
43
      self.assertEqual('(2, 4)', result)
44 45 46
    finally:
      os.unlink(name)

47 48 49 50
  def test_use_generated_python_as_normal_interpreter(self):
    """
      TODO: Add doc string.
    """
Rafael Monnerat's avatar
Rafael Monnerat committed
51
    stdout, stderr = subprocess.Popen(["bin/python2.4", "-V"],
52
        stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
Rafael Monnerat's avatar
Rafael Monnerat committed
53
    self.assertTrue('Python 2.4' in stderr)
54

55
  def test_required_libraries(self):
56 57 58
    """
      TODO: Add doc string.
    """
59 60 61 62 63 64 65
    required_library_list = createCleanList("""
      ERP5Diff
      MySQLdb
      SOAPpy
      _ssl
      _xmlplus
      bz2
Łukasz Nowak's avatar
Łukasz Nowak committed
66
      cElementTree
67 68 69 70 71 72
      elementtree
      fpconst
      gdbm
      itools
      ldap
      lxml
Łukasz Nowak's avatar
Łukasz Nowak committed
73
      mechanize
74 75
      memcache
      numpy
Łukasz Nowak's avatar
Łukasz Nowak committed
76 77
      paramiko
      ply
78
      pytz
79
      readline
80
      simplejson
Łukasz Nowak's avatar
Łukasz Nowak committed
81
      socks
82
      threadframe
83
      uuid
Łukasz Nowak's avatar
Łukasz Nowak committed
84
      xml
85 86 87 88 89 90 91 92 93 94
      xml.parsers.expat
      zlib
      """)
    failed_library_list = []
    for lib in required_library_list:
      try:
        __import__(lib)
      except ImportError:
        failed_library_list.append(lib)
    self.assertEqual([], failed_library_list,
Łukasz Nowak's avatar
Łukasz Nowak committed
95
        'Python libraries not found:\n'+'\n'.join(failed_library_list))
96 97

class AssertLddLibs(unittest.TestCase):
98 99 100 101
  """
    TODO: Add doc string.
  """

102
  def test_tritonn_senna(self):
103 104 105
    """
      TODO: Add doc string.
    """
106 107 108 109 110
    result = os.system("ldd parts/mysql-tritonn-5.0/libexec/mysqld | grep -q "
        "'parts/senna/lib/libsenna.so.0'")
    self.assertEqual(result, 0)

  def test_MySQLdb(self):
111 112 113
    """
      TODO: Add doc string.
    """
114 115 116 117 118 119
    result = os.system("ldd develop-eggs/MySQL_python-1.2.3c1-py2.4-linux-x86"
       "_64.egg/_mysql.so | grep -q 'parts/mysql-tritonn-5.0/lib/mysql/libmys"
       "qlclient_r.so'")
    self.assertEqual(result, 0)

  def test_memcached_libevent(self):
120 121 122
    """
      TODO: Add doc string.
    """
123 124 125 126
    result = os.system("ldd parts/memcached/bin/memcached | grep -q 'parts/li"
        "bevent/lib/libevent'")

class AssertApache(unittest.TestCase):
127 128 129 130
  """
    TODO: Add doc string.
  """

131
  def test_modules(self):
132 133 134
    """
      TODO: Add doc string.
    """
135
    required_module_list = createCleanList("""
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
      authn_default_module
      log_config_module
      proxy_http_module
      authn_alias_module
      authz_dbm_module
      case_filter_in_module
      imagemap_module
      setenvif_module
      include_module
      charset_lite_module
      info_module
      cache_module
      actions_module
      proxy_connect_module
      auth_digest_module
      unique_id_module
      mime_magic_module
      disk_cache_module
      mime_module
      usertrack_module
      asis_module
      optional_hook_import_module
      negotiation_module
      proxy_module
      authz_default_module
      ext_filter_module
      auth_basic_module
      authz_owner_module
      authn_anon_module
      rewrite_module
      proxy_balancer_module
      substitute_module
      filter_module
      expires_module
      autoindex_module
      status_module
      cgid_module
      version_module
      echo_module
      optional_fn_export_module
      optional_fn_import_module
      ident_module
      cgi_module
      bucketeer_module
      optional_hook_export_module
      vhost_alias_module
      ssl_module
      authz_user_module
      env_module
      logio_module
      proxy_ftp_module
      cern_meta_module
      authz_groupfile_module
      dir_module
      log_forensic_module
      alias_module
      deflate_module
      authn_dbm_module
      case_filter_module
      authz_host_module
      headers_module
      dumpio_module
      speling_module
      authn_file_module
200
    """)
201 202 203 204 205
    parts_path_prefix = os.path.join(os.path.dirname(__file__), '../parts')
    result = os.popen("%s/apache/bin/httpd -M" % parts_path_prefix)
    loaded_module_list = [module_name for module_name in result.read().split() 
                          if module_name.endswith('module')]
    result.close()
206 207
    failed_module_list = []
    for module in required_module_list:
208
      if module not in loaded_module_list:
209 210
        failed_module_list.append(module)
    self.assertEqual([], failed_module_list,
Łukasz Nowak's avatar
Łukasz Nowak committed
211
        'Apache modules not found:\n'+'\n'.join(failed_module_list))
212

213
    
214 215
if __name__ == '__main__':
  unittest.main()