Skip to content

Commit 801637b

Browse files
committed
[OMCProcessDocker*] reworked inheritance chain - move _omc_port_get() to OMCProcessDockerHelper
1 parent 18c24b8 commit 801637b

1 file changed

Lines changed: 34 additions & 69 deletions

File tree

OMPython/OMCSession.py

Lines changed: 34 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,40 @@ def _omc_process_docker(self) -> Optional[DummyPopen]:
636636

637637
return docker_process
638638

639+
def _omc_port_get(self) -> str:
640+
port = None
641+
642+
if not isinstance(self._dockerCid, str):
643+
raise OMCSessionException(f"Invalid docker container ID: {self._dockerCid}")
644+
645+
# See if the omc server is running
646+
attempts = 0
647+
while True:
648+
omc_portfile_path = self._get_portfile_path()
649+
if omc_portfile_path is not None:
650+
try:
651+
output = subprocess.check_output(args=["docker",
652+
"exec", self._dockerCid,
653+
"cat", omc_portfile_path.as_posix()],
654+
stderr=subprocess.DEVNULL)
655+
port = output.decode().strip()
656+
except subprocess.CalledProcessError:
657+
pass
658+
659+
if port is not None:
660+
break
661+
662+
attempts += 1
663+
if attempts == 80.0:
664+
raise OMCSessionException(f"Docker based OMC Server did not start (timeout={self._timeout}). "
665+
f"Could not open port file {omc_portfile_path}. "
666+
f"Log-file says:\n{self.get_log()}")
667+
time.sleep(self._timeout / 80.0)
668+
669+
logger.info(f"Docker based OMC Server is up and running at port {port}")
670+
671+
return port
672+
639673
def get_server_address(self) -> Optional[str]:
640674
if self._dockerNetwork == "separate" and isinstance(self._dockerCid, str):
641675
output = subprocess.check_output(["docker", "inspect", self._dockerCid]).decode().strip()
@@ -749,41 +783,6 @@ def _omc_command_docker(
749783

750784
return omc_command
751785

752-
def _omc_port_get(self) -> str:
753-
port = None
754-
755-
if not isinstance(self._dockerCid, str):
756-
raise OMCSessionException(f"Invalid docker container ID: {self._dockerCid}")
757-
758-
# See if the omc server is running
759-
attempts = 0
760-
while True:
761-
omc_portfile_path = self._get_portfile_path()
762-
if omc_portfile_path is not None:
763-
try:
764-
output = subprocess.check_output(args=["docker",
765-
"exec", self._dockerCid,
766-
"cat", omc_portfile_path.as_posix()],
767-
stderr=subprocess.DEVNULL)
768-
port = output.decode().strip()
769-
except subprocess.CalledProcessError:
770-
pass
771-
772-
if port is not None:
773-
break
774-
775-
attempts += 1
776-
if attempts == 80.0:
777-
raise OMCSessionException(f"Docker based OMC Server did not start (timeout={self._timeout}). "
778-
f"Could not open port file {omc_portfile_path}. "
779-
f"Log-file says:\n{self.get_log()}")
780-
time.sleep(self._timeout / 80.0)
781-
782-
logger.info(f"OMC Server is up and running at port {port} "
783-
f"pid={self._omc_process.pid if isinstance(self._omc_process, subprocess.Popen) else '?'}")
784-
785-
return port
786-
787786
def _omc_docker_start(self) -> Tuple[subprocess.Popen, DummyPopen, str]:
788787
my_env = os.environ.copy()
789788

@@ -892,40 +891,6 @@ def _omc_command_docker(self, omc_path_and_args_list) -> list:
892891

893892
return omc_command
894893

895-
def _omc_port_get(self) -> str:
896-
port = None
897-
898-
if not isinstance(self._dockerCid, str):
899-
raise OMCSessionException(f"Invalid docker container ID: {self._dockerCid}")
900-
901-
# See if the omc server is running
902-
attempts = 0
903-
while True:
904-
omc_portfile_path = self._get_portfile_path()
905-
if omc_portfile_path is not None:
906-
try:
907-
output = subprocess.check_output(args=["docker",
908-
"exec", self._dockerCid,
909-
"cat", omc_portfile_path.as_posix()],
910-
stderr=subprocess.DEVNULL)
911-
port = output.decode().strip()
912-
except subprocess.CalledProcessError:
913-
pass
914-
915-
if port is not None:
916-
break
917-
918-
attempts += 1
919-
if attempts == 80.0:
920-
raise OMCSessionException(f"Docker container based OMC Server did not start (timeout={self._timeout}). "
921-
f"Could not open port file {omc_portfile_path}. "
922-
f"Log-file says:\n{self.get_log()}")
923-
time.sleep(self._timeout / 80.0)
924-
925-
logger.info(f"DockerContainer based OMC Server is up and running at port {port}")
926-
927-
return port
928-
929894
def _omc_docker_start(self) -> Tuple[subprocess.Popen, DummyPopen]:
930895
my_env = os.environ.copy()
931896

0 commit comments

Comments
 (0)