anmolnar commented on code in PR #8517:
URL: https://github.com/apache/hbase/pull/8517#discussion_r3724030945


##########
dev-support/integration-test/read-replica/python/src/hbase_docker_client.py:
##########
@@ -0,0 +1,529 @@
+#!/usr/bin/env python3
+import ast
+import logging
+import re
+import requests
+import subprocess
+import time
+import xml.etree.ElementTree as ET
+
+from .logger_config import get_logger
+
+logger = get_logger(__name__)
+
+
+class DockerExecCommandError(Exception):
+    pass
+
+
+class HBaseShellCommandError(DockerExecCommandError):
+    pass
+
+
+class DockerExecCommandTimeoutError(DockerExecCommandError):
+    pass
+
+
+class HBaseDockerClient:
+    def __init__(self, container_name: str, local_conf: str, hbase_ui_port: 
int = 16010,
+                 cluster_name: str = "HBase Cluster", max_retries: int = 12, 
sleep_time: int = 5) -> None:
+        self._container_name = container_name
+        self._local_conf = local_conf
+        self._hbase_ui_port = hbase_ui_port
+        self._cluster_name = cluster_name
+        self._max_retries = max_retries
+        self._sleep_time = sleep_time
+
+    @property
+    def name(self) -> str:
+        return self._cluster_name
+
+    def run_docker_exec_command(self, bash_cmd: str, timeout: int | None = 
None) -> str:
+        """
+        Uses 'docker exec' to run the provided Bash command in the object's 
Docker container.
+        The command looks like: docker exec <container> bash -c <bash_cmd>
+        Note: In the Terminal, we usually put double quotes around everything 
after "-c",
+        but doing that with subprocess.run() results in a failure.
+        """
+        cmd = ["docker", "exec", self._container_name, "bash", "-c", 
f'''{bash_cmd}''']

Review Comment:
   Could it be easier to use `docker` python module to execute commands inside 
the container instead of subprocessing the docker command?
   
   ```
   exec_run(cmd, stdout=True, stderr=True, stdin=False, tty=False, 
privileged=False, user='', detach=False, stream=False, socket=False, 
environment=None, workdir=None, demux=False)
   
   Run a command inside this container. Similar to docker exec.
   ```
   
   https://docker-py.readthedocs.io/en/stable/containers.html



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to