| 
									
										
										
										
											2012-08-30 02:07:58 +08:00
										 |  |  | # Licensed to the Apache Software Foundation (ASF) under one | 
					
						
							|  |  |  | # or more contributor license agreements.  See the NOTICE file | 
					
						
							|  |  |  | # distributed with this work for additional information | 
					
						
							|  |  |  | # regarding copyright ownership.  The ASF licenses this file | 
					
						
							|  |  |  | # to you under the Apache License, Version 2.0 (the | 
					
						
							|  |  |  | # "License"); you may not use this file except in compliance | 
					
						
							|  |  |  | # with the License.  You may obtain a copy of the License at | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | #   http://www.apache.org/licenses/LICENSE-2.0 | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # Unless required by applicable law or agreed to in writing, | 
					
						
							|  |  |  | # software distributed under the License is distributed on an | 
					
						
							|  |  |  | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
					
						
							|  |  |  | # KIND, either express or implied.  See the License for the | 
					
						
							|  |  |  | # specific language governing permissions and limitations | 
					
						
							|  |  |  | # under the License. | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  | #!/usr/bin/env python | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # =================================== | 
					
						
							|  |  |  | # testcase_env.py | 
					
						
							|  |  |  | # =================================== | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import json | 
					
						
							|  |  |  | import os | 
					
						
							|  |  |  | import sys | 
					
						
							| 
									
										
										
										
											2012-09-15 01:20:04 +08:00
										 |  |  | import thread | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  | import system_test_utils | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  | class TestcaseEnv(): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # ================================ | 
					
						
							|  |  |  |     # Generic testcase environment | 
					
						
							|  |  |  |     # ================================ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  |     # dictionary of entity_id to ppid for Zookeeper entities | 
					
						
							|  |  |  |     # key: entity_id | 
					
						
							|  |  |  |     # val: ppid of Zookeeper associated to that entity_id | 
					
						
							|  |  |  |     # { 0: 12345, 1: 12389, ... } | 
					
						
							|  |  |  |     entityZkParentPidDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # dictionary of entity_id to ppid for broker entities | 
					
						
							| 
									
										
										
										
											2012-08-31 07:47:55 +08:00
										 |  |  |     # key: entity_id | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  |     # val: ppid of broker associated to that entity_id | 
					
						
							| 
									
										
										
										
											2012-08-31 07:47:55 +08:00
										 |  |  |     # { 0: 12345, 1: 12389, ... } | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  |     entityBrokerParentPidDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # dictionary of entity_id to ppid for mirror-maker entities | 
					
						
							|  |  |  |     # key: entity_id | 
					
						
							|  |  |  |     # val: ppid of broker associated to that entity_id | 
					
						
							|  |  |  |     # { 0: 12345, 1: 12389, ... } | 
					
						
							|  |  |  |     entityMirrorMakerParentPidDict = {} | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-10 06:58:23 +08:00
										 |  |  |     # dictionary of entity_id to ppid for migration tool entities | 
					
						
							|  |  |  |     # key: entity_id | 
					
						
							|  |  |  |     # val: ppid of broker associated to that entity_id | 
					
						
							|  |  |  |     # { 0: 12345, 1: 12389, ... } | 
					
						
							|  |  |  |     entityMigrationToolParentPidDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-31 07:47:55 +08:00
										 |  |  |     # dictionary of entity_id to list of JMX ppid | 
					
						
							|  |  |  |     # key: entity_id | 
					
						
							|  |  |  |     # val: list of JMX ppid associated to that entity_id | 
					
						
							|  |  |  |     # { 1: [1234, 1235, 1236], 2: [2234, 2235, 2236], ... } | 
					
						
							|  |  |  |     entityJmxParentPidDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # dictionary of hostname-topic-ppid for consumer | 
					
						
							|  |  |  |     # key: hostname | 
					
						
							|  |  |  |     # val: dict of topic-ppid | 
					
						
							|  |  |  |     # { host1: { test1 : 12345 }, host1: { test2 : 12389 }, ... } | 
					
						
							|  |  |  |     consumerHostParentPidDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # dictionary of hostname-topic-ppid for producer | 
					
						
							|  |  |  |     # key: hostname | 
					
						
							|  |  |  |     # val: dict of topic-ppid | 
					
						
							|  |  |  |     # { host1: { test1 : 12345 }, host1: { test2 : 12389 }, ... } | 
					
						
							|  |  |  |     producerHostParentPidDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  |     # list of testcase configs | 
					
						
							|  |  |  |     testcaseConfigsList = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # dictionary to keep track of testcase arguments such as replica_factor, num_partition | 
					
						
							|  |  |  |     testcaseArgumentsDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, systemTestEnv, classInstance): | 
					
						
							|  |  |  |         self.systemTestEnv    = systemTestEnv | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # gather the test case related info and add to an SystemTestEnv object | 
					
						
							|  |  |  |         self.testcaseResultsDict = {} | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  |         self.testcaseResultsDict["_test_class_name"] = classInstance.__class__.__name__ | 
					
						
							|  |  |  |         self.testcaseResultsDict["_test_case_name"]  = "" | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  |         self.validationStatusDict                      = {} | 
					
						
							|  |  |  |         self.testcaseResultsDict["validation_status"]  = self.validationStatusDict | 
					
						
							|  |  |  |         self.systemTestEnv.systemTestResultsList.append(self.testcaseResultsDict) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # FIXME: in a distributed environement, kafkaBaseDir could be different in individual host | 
					
						
							|  |  |  |         #        => TBD | 
					
						
							|  |  |  |         self.kafkaBaseDir      = "" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         self.systemTestBaseDir = systemTestEnv.SYSTEM_TEST_BASE_DIR | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # to be initialized in the Test Module | 
					
						
							| 
									
										
										
										
											2012-08-30 02:07:58 +08:00
										 |  |  |         self.testSuiteBaseDir      = "" | 
					
						
							|  |  |  |         self.testCaseBaseDir       = "" | 
					
						
							|  |  |  |         self.testCaseLogsDir       = "" | 
					
						
							|  |  |  |         self.testCaseDashboardsDir = "" | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  |         self.testcasePropJsonPathName = "" | 
					
						
							|  |  |  |         self.testcaseNonEntityDataDict = {} | 
					
						
							| 
									
										
										
										
											2012-09-15 01:20:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-23 01:16:26 +08:00
										 |  |  |         # ================================ | 
					
						
							|  |  |  |         # dictionary to keep track of | 
					
						
							|  |  |  |         # user-defined environment variables | 
					
						
							|  |  |  |         # ================================ | 
					
						
							|  |  |  |         # LEADER_ELECTION_COMPLETED_MSG = "completed the leader state transition" | 
					
						
							|  |  |  |         # REGX_LEADER_ELECTION_PATTERN  = "\[(.*?)\] .* Broker (.*?) " + \ | 
					
						
							|  |  |  |         #                            LEADER_ELECTION_COMPLETED_MSG + \ | 
					
						
							|  |  |  |         #                            " for topic (.*?) partition (.*?) \(.*" | 
					
						
							|  |  |  |         # zkConnectStr = "" | 
					
						
							|  |  |  |         # consumerLogPathName    = "" | 
					
						
							|  |  |  |         # consumerConfigPathName = "" | 
					
						
							|  |  |  |         # producerLogPathName    = "" | 
					
						
							|  |  |  |         # producerConfigPathName = "" | 
					
						
							|  |  |  |         self.userDefinedEnvVarDict = {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 01:20:04 +08:00
										 |  |  |         # Lock object for producer threads synchronization | 
					
						
							|  |  |  |         self.lock = thread.allocate_lock() | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-11 00:56:57 +08:00
										 |  |  |         self.numProducerThreadsRunning = 0 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def initWithKnownTestCasePathName(self, testCasePathName): | 
					
						
							|  |  |  |         testcaseDirName = os.path.basename(testCasePathName) | 
					
						
							|  |  |  |         self.testcaseResultsDict["_test_case_name"] = testcaseDirName | 
					
						
							|  |  |  |         self.testCaseBaseDir = testCasePathName | 
					
						
							|  |  |  |         self.testCaseLogsDir = self.testCaseBaseDir + "/logs" | 
					
						
							|  |  |  |         self.testCaseDashboardsDir = self.testCaseBaseDir + "/dashboards" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # find testcase properties json file | 
					
						
							|  |  |  |         self.testcasePropJsonPathName = system_test_utils.get_testcase_prop_json_pathname(testCasePathName) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         # get the dictionary that contains the testcase arguments and description | 
					
						
							|  |  |  |         self.testcaseNonEntityDataDict = system_test_utils.get_json_dict_data(self.testcasePropJsonPathName) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def printTestCaseDescription(self, testcaseDirName): | 
					
						
							|  |  |  |         testcaseDescription = "" | 
					
						
							|  |  |  |         for k,v in self.testcaseNonEntityDataDict.items(): | 
					
						
							|  |  |  |             if ( k == "description" ): | 
					
						
							|  |  |  |                 testcaseDescription = v | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         print "\n" | 
					
						
							|  |  |  |         print "=======================================================================================" | 
					
						
							|  |  |  |         print "Test Case Name :", testcaseDirName | 
					
						
							|  |  |  |         print "=======================================================================================" | 
					
						
							|  |  |  |         print "Description    :" | 
					
						
							|  |  |  |         for step in sorted(testcaseDescription.iterkeys()): | 
					
						
							|  |  |  |             print "   ", step, ":", testcaseDescription[step] | 
					
						
							|  |  |  |         print "=======================================================================================" | 
					
						
							|  |  |  |         print "Test Case Args :" | 
					
						
							|  |  |  |         for k,v in self.testcaseArgumentsDict.items(): | 
					
						
							|  |  |  |             print "   ", k, " : ", v | 
					
						
							|  |  |  |             self.testcaseResultsDict["arg : " + k] = v | 
					
						
							|  |  |  |         print "=======================================================================================" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-15 01:20:04 +08:00
										 |  |  | 
 |