testHodRing.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #Licensed to the Apache Software Foundation (ASF) under one
  2. #or more contributor license agreements. See the NOTICE file
  3. #distributed with this work for additional information
  4. #regarding copyright ownership. The ASF licenses this file
  5. #to you under the Apache License, Version 2.0 (the
  6. #"License"); you may not use this file except in compliance
  7. #with the License. You may obtain a copy of the License at
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #Unless required by applicable law or agreed to in writing, software
  10. #distributed under the License is distributed on an "AS IS" BASIS,
  11. #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. #See the License for the specific language governing permissions and
  13. #limitations under the License.
  14. import unittest, os, sys, re, threading, time
  15. myDirectory = os.path.realpath(sys.argv[0])
  16. rootDirectory = re.sub("/testing/.*", "", myDirectory)
  17. sys.path.append(rootDirectory)
  18. from testing.lib import BaseTestSuite
  19. excludes = []
  20. import tempfile, getpass, logging
  21. from xml.dom import minidom
  22. from hodlib.Hod.hadoop import hadoopConfig
  23. from hodlib.HodRing.hodRing import CommandDesc, HadoopCommand
  24. # All test-case classes should have the naming convention test_.*
  25. class test_HadoopCommand(unittest.TestCase):
  26. def setUp(self):
  27. self.rootDir = '/tmp/hod-%s' % getpass.getuser()
  28. self.id = 0
  29. self.desc = None
  30. self.tempDir = os.path.join(self.rootDir,'test_HadoopCommand_tempDir')
  31. self.pkgDir = os.path.join(self.rootDir,'test_HadoopCommand_pkgDir')
  32. self.log = logging.getLogger() # TODO Use MockLogger
  33. self.javaHome = '/usr/java/bin/'
  34. self.mrSysDir = '/user/' + getpass.getuser() + '/mapredsystem'
  35. self.attrs = {}
  36. self.finalAttrs = {
  37. 'fs.default.name': 'nohost.apache.com:56366',
  38. 'mapred.child.java.opts' : '-Xmx1024m',
  39. 'mapred.compress.map.output' : 'false',
  40. }
  41. self.attrs = {
  42. 'mapred.userlog.limit' : '200',
  43. 'mapred.userlog.retain.hours' : '10',
  44. 'mapred.reduce.parallel.copies' : '20',
  45. }
  46. self.desc = CommandDesc(
  47. {
  48. 'name' : 'dummyHadoop',
  49. 'program' : 'bin/hadoop',
  50. 'pkgdirs' : self.pkgDir,
  51. 'final-attrs' : self.finalAttrs,
  52. 'attrs' : self.attrs,
  53. }, self.log
  54. )
  55. # TODO
  56. # 4th arg to HadoopCommand 'tardir' is not used at all. Instead pkgdir is
  57. # specified through HadoopCommand.run(pkgdir). This could be changed so
  58. # that pkgdir is specified at the time of object creation.
  59. # END OF TODO
  60. self.hadoopCommand = HadoopCommand(self.id, self.desc, self.tempDir,
  61. self.pkgDir, (50000, 60000), self.log, self.javaHome,
  62. self.mrSysDir, restart=True)
  63. self.hadoopSite = os.path.join( self.hadoopCommand.confdir,
  64. 'hadoop-site.xml')
  65. pass
  66. def test_createHadoopSiteXml(self):
  67. self.hadoopCommand._createHadoopSiteXml()
  68. xmldoc = minidom.parse(self.hadoopSite)
  69. xmldoc = xmldoc.childNodes[0] # leave out xml spec
  70. properties = xmldoc.childNodes # children of tag configuration
  71. keyvals = {}
  72. for prop in properties:
  73. if not isinstance(prop,minidom.Comment):
  74. # ---------- tag -------------------- -value elem-- data --
  75. name = prop.getElementsByTagName('name')[0].childNodes[0].data
  76. value = prop.getElementsByTagName('value')[0].childNodes[0].data
  77. keyvals[name] = value
  78. # fs.default.name should start with hdfs://
  79. assert(keyvals['fs.default.name'].startswith('hdfs://'))
  80. # TODO other tests
  81. pass
  82. def tearDown(self):
  83. pass
  84. class HodRingTestSuite(BaseTestSuite):
  85. def __init__(self):
  86. # suite setup
  87. BaseTestSuite.__init__(self, __name__, excludes)
  88. pass
  89. def cleanUp(self):
  90. # suite tearDown
  91. pass
  92. def RunHodRingTests():
  93. # modulename_suite
  94. suite = HodRingTestSuite()
  95. testResult = suite.runTests()
  96. suite.cleanUp()
  97. return testResult
  98. if __name__ == "__main__":
  99. RunHodRingTests()