Skip to content

Commit f703068

Browse files
committed
run kafka bin/ scripts for test fixtures
1 parent 39b68eb commit f703068

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

test/fixtures.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ def test_resource(cls, filename):
116116
return path
117117
return os.path.join(cls.project_root, "servers", "resources", "default", filename)
118118

119+
@classmethod
120+
def run_script(cls, script, *args):
121+
result = [os.path.join(cls.kafka_root, 'bin', script)]
122+
result.extend([str(arg) for arg in args])
123+
return result
124+
119125
@classmethod
120126
def kafka_run_class_args(cls, *args):
121127
result = [os.path.join(cls.kafka_root, 'bin', 'kafka-run-class.sh')]
@@ -202,6 +208,7 @@ def open(self):
202208
# Configure Zookeeper child process
203209
template = self.test_resource("zookeeper.properties")
204210
properties = self.tmp_dir.join("zookeeper.properties")
211+
# Consider replacing w/ run_script('zookeper-server-start.sh', ...)
205212
args = self.kafka_run_class_args("org.apache.zookeeper.server.quorum.QuorumPeerMain",
206213
properties.strpath)
207214
env = self.kafka_run_class_env()
@@ -348,8 +355,7 @@ def _jaas_config(self):
348355

349356
def _add_scram_user(self):
350357
self.out("Adding SCRAM credentials for user {} to zookeeper.".format(self.broker_user))
351-
args = self.kafka_run_class_args(
352-
"kafka.admin.ConfigCommand",
358+
args = self.run_script('kafka-configs.sh',
353359
"--zookeeper",
354360
"%s:%d/%s" % (self.zookeeper.host,
355361
self.zookeeper.port,
@@ -390,8 +396,7 @@ def out(self, message):
390396

391397
def _create_zk_chroot(self):
392398
self.out("Creating Zookeeper chroot node...")
393-
args = self.kafka_run_class_args("org.apache.zookeeper.ZooKeeperMain",
394-
"-server",
399+
args = self.run_script('zookeeper-shell.sh',
395400
"%s:%d" % (self.zookeeper.host,
396401
self.zookeeper.port),
397402
"create",
@@ -416,6 +421,7 @@ def start(self):
416421
properties_template = self.test_resource("kafka.properties")
417422
jaas_conf_template = self.test_resource("kafka_server_jaas.conf")
418423

424+
# Consider replacing w/ run_script('kafka-server-start.sh', ...)
419425
args = self.kafka_run_class_args("kafka.Kafka", properties.strpath)
420426
env = self.kafka_run_class_env()
421427
if self.sasl_enabled:
@@ -590,7 +596,7 @@ def _create_topic_via_admin_api(self, topic_name, num_partitions, replication_fa
590596
raise errors.for_code(error_code)
591597

592598
def _create_topic_via_cli(self, topic_name, num_partitions, replication_factor):
593-
args = self.kafka_run_class_args('kafka.admin.TopicCommand',
599+
args = self.run_script('kafka-topics.sh',
594600
'--zookeeper', '%s:%s/%s' % (self.zookeeper.host,
595601
self.zookeeper.port,
596602
self.zk_chroot),
@@ -614,12 +620,12 @@ def _create_topic_via_cli(self, topic_name, num_partitions, replication_factor):
614620
raise RuntimeError("Failed to create topic %s" % (topic_name,))
615621

616622
def get_topic_names(self):
617-
args = self.kafka_run_class_args('kafka.admin.TopicCommand',
623+
args = self.run_script('kafka-topics.sh',
618624
'--zookeeper', '%s:%s/%s' % (self.zookeeper.host,
619625
self.zookeeper.port,
620626
self.zk_chroot),
621627
'--list'
622-
)
628+
)
623629
env = self.kafka_run_class_env()
624630
env.pop('KAFKA_LOG4J_OPTS')
625631
proc = subprocess.Popen(args, env=env, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

0 commit comments

Comments
 (0)