[120] | 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 | |
---|
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
| 10 | |
---|
| 11 | #Unless required by applicable law or agreed to in writing, software |
---|
| 12 | #distributed under the License is distributed on an "AS IS" BASIS, |
---|
| 13 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
| 14 | #See the License for the specific language governing permissions and |
---|
| 15 | #limitations under the License. |
---|
| 16 | import unittest, os, sys, re, threading, time |
---|
| 17 | |
---|
| 18 | import logging |
---|
| 19 | |
---|
| 20 | myDirectory = os.path.realpath(sys.argv[0]) |
---|
| 21 | rootDirectory = re.sub("/testing/.*", "", myDirectory) |
---|
| 22 | |
---|
| 23 | sys.path.append(rootDirectory) |
---|
| 24 | |
---|
| 25 | from testing.lib import BaseTestSuite |
---|
| 26 | |
---|
| 27 | excludes = ['test_MINITEST1', 'test_MINITEST2'] |
---|
| 28 | |
---|
| 29 | from hodlib.GridServices import * |
---|
| 30 | from hodlib.Common.desc import ServiceDesc |
---|
| 31 | from hodlib.RingMaster.ringMaster import _LogMasterSources |
---|
| 32 | |
---|
| 33 | configuration = { |
---|
| 34 | 'hod': {}, |
---|
| 35 | 'resource_manager': { |
---|
| 36 | 'id': 'torque', |
---|
| 37 | 'batch-home': '/home/y/' |
---|
| 38 | }, |
---|
| 39 | 'ringmaster': { |
---|
| 40 | 'max-connect' : 2, |
---|
| 41 | 'max-master-failures' : 5 |
---|
| 42 | }, |
---|
| 43 | 'hodring': { |
---|
| 44 | }, |
---|
| 45 | 'gridservice-mapred': { |
---|
| 46 | 'id': 'mapred' |
---|
| 47 | } , |
---|
| 48 | 'gridservice-hdfs': { |
---|
| 49 | 'id': 'hdfs' |
---|
| 50 | }, |
---|
| 51 | 'servicedesc' : {} , |
---|
| 52 | 'nodepooldesc': {} , |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | # All test-case classes should have the naming convention test_.* |
---|
| 56 | class test_MINITEST1(unittest.TestCase): |
---|
| 57 | def setUp(self): |
---|
| 58 | pass |
---|
| 59 | |
---|
| 60 | # All testMethods have to have their names start with 'test' |
---|
| 61 | def testSuccess(self): |
---|
| 62 | pass |
---|
| 63 | |
---|
| 64 | def testFailure(self): |
---|
| 65 | pass |
---|
| 66 | |
---|
| 67 | def tearDown(self): |
---|
| 68 | pass |
---|
| 69 | |
---|
| 70 | class test_Multiple_Workers(unittest.TestCase): |
---|
| 71 | def setUp(self): |
---|
| 72 | self.config = configuration |
---|
| 73 | self.config['ringmaster']['workers_per_ring'] = 2 |
---|
| 74 | |
---|
| 75 | hdfsDesc = self.config['servicedesc']['hdfs'] = ServiceDesc(self.config['gridservice-hdfs']) |
---|
| 76 | mrDesc = self.config['servicedesc']['mapred'] = ServiceDesc(self.config['gridservice-mapred']) |
---|
| 77 | |
---|
| 78 | self.hdfs = Hdfs(hdfsDesc, [], 0, 19, workers_per_ring = \ |
---|
| 79 | self.config['ringmaster']['workers_per_ring']) |
---|
| 80 | self.mr = MapReduce(mrDesc, [],1, 19, workers_per_ring = \ |
---|
| 81 | self.config['ringmaster']['workers_per_ring']) |
---|
| 82 | |
---|
| 83 | self.log = logging.getLogger() |
---|
| 84 | pass |
---|
| 85 | |
---|
| 86 | # All testMethods have to have their names start with 'test' |
---|
| 87 | def testWorkersCount(self): |
---|
| 88 | self.serviceDict = {} |
---|
| 89 | self.serviceDict[self.hdfs.getName()] = self.hdfs |
---|
| 90 | self.serviceDict[self.mr.getName()] = self.mr |
---|
| 91 | self.rpcSet = _LogMasterSources(self.serviceDict, self.config, None, self.log, None) |
---|
| 92 | |
---|
| 93 | cmdList = self.rpcSet.getCommand('host1') |
---|
| 94 | self.assertEquals(len(cmdList), 2) |
---|
| 95 | self.assertEquals(cmdList[0].dict['argv'][0], 'namenode') |
---|
| 96 | self.assertEquals(cmdList[1].dict['argv'][0], 'namenode') |
---|
| 97 | addParams = ['fs.default.name=host1:51234', 'dfs.http.address=host1:5125' ] |
---|
| 98 | self.rpcSet.addMasterParams('host1', addParams) |
---|
| 99 | # print "NN is launched" |
---|
| 100 | |
---|
| 101 | cmdList = self.rpcSet.getCommand('host2') |
---|
| 102 | self.assertEquals(len(cmdList), 1) |
---|
| 103 | self.assertEquals(cmdList[0].dict['argv'][0], 'jobtracker') |
---|
| 104 | addParams = ['mapred.job.tracker=host2:51236', |
---|
| 105 | 'mapred.job.tracker.http.address=host2:51237'] |
---|
| 106 | self.rpcSet.addMasterParams('host2', addParams) |
---|
| 107 | # print "JT is launched" |
---|
| 108 | |
---|
| 109 | cmdList = self.rpcSet.getCommand('host3') |
---|
| 110 | # Verify the workers count per ring : TTs + DNs |
---|
| 111 | self.assertEquals(len(cmdList), |
---|
| 112 | self.config['ringmaster']['workers_per_ring'] * 2) |
---|
| 113 | pass |
---|
| 114 | |
---|
| 115 | def testFailure(self): |
---|
| 116 | pass |
---|
| 117 | |
---|
| 118 | def tearDown(self): |
---|
| 119 | pass |
---|
| 120 | |
---|
| 121 | class test_GetCommand(unittest.TestCase): |
---|
| 122 | def setUp(self): |
---|
| 123 | self.config = configuration |
---|
| 124 | |
---|
| 125 | hdfsDesc = self.config['servicedesc']['hdfs'] = ServiceDesc(self.config['gridservice-hdfs']) |
---|
| 126 | mrDesc = self.config['servicedesc']['mapred'] = ServiceDesc(self.config['gridservice-mapred']) |
---|
| 127 | |
---|
| 128 | # API : serviceObj = service(desc, workDirs, reqNodes, version) |
---|
| 129 | self.hdfs = Hdfs(hdfsDesc, [], 0, 17) |
---|
| 130 | self.hdfsExternal = HdfsExternal(hdfsDesc, [], 17) |
---|
| 131 | self.mr = MapReduce(mrDesc, [],1, 17) |
---|
| 132 | self.mrExternal = MapReduceExternal(mrDesc, [], 17) |
---|
| 133 | |
---|
| 134 | self.log = logging.getLogger() |
---|
| 135 | pass |
---|
| 136 | |
---|
| 137 | # All testMethods have to have their names start with 'test' |
---|
| 138 | def testBothInternal(self): |
---|
| 139 | self.serviceDict = {} |
---|
| 140 | self.serviceDict[self.hdfs.getName()] = self.hdfs |
---|
| 141 | self.serviceDict[self.mr.getName()] = self.mr |
---|
| 142 | self.rpcSet = _LogMasterSources(self.serviceDict, self.config, None, self.log, None) |
---|
| 143 | |
---|
| 144 | cmdList = self.rpcSet.getCommand('localhost') |
---|
| 145 | self.assertEquals(cmdList.__len__(), 2) |
---|
| 146 | self.assertEquals(cmdList[0].dict['argv'][0], 'namenode') |
---|
| 147 | self.assertEquals(cmdList[1].dict['argv'][0], 'namenode') |
---|
| 148 | pass |
---|
| 149 | |
---|
| 150 | def tearDown(self): |
---|
| 151 | pass |
---|
| 152 | |
---|
| 153 | class RingmasterRPCsTestSuite(BaseTestSuite): |
---|
| 154 | def __init__(self): |
---|
| 155 | # suite setup |
---|
| 156 | BaseTestSuite.__init__(self, __name__, excludes) |
---|
| 157 | pass |
---|
| 158 | |
---|
| 159 | def cleanUp(self): |
---|
| 160 | # suite tearDown |
---|
| 161 | pass |
---|
| 162 | |
---|
| 163 | def RunRingmasterRPCsTests(): |
---|
| 164 | # modulename_suite |
---|
| 165 | suite = RingmasterRPCsTestSuite() |
---|
| 166 | testResult = suite.runTests() |
---|
| 167 | suite.cleanUp() |
---|
| 168 | return testResult |
---|
| 169 | |
---|
| 170 | if __name__ == "__main__": |
---|
| 171 | RunRingmasterRPCsTests() |
---|