@@ -647,6 +647,40 @@ def _getuid() -> int:
647647 # Windows, hence the type: ignore comment.
648648 return 1000 if sys .platform == 'win32' else os .getuid () # type: ignore
649649
650+ def _omc_port_get (self ) -> str :
651+ port = None
652+
653+ if not isinstance (self ._dockerCid , str ):
654+ raise OMCSessionException (f"Invalid docker container ID: { self ._dockerCid } " )
655+
656+ # See if the omc server is running
657+ attempts = 0
658+ while True :
659+ omc_portfile_path = self ._get_portfile_path ()
660+ if omc_portfile_path is not None :
661+ try :
662+ output = subprocess .check_output (args = ["docker" ,
663+ "exec" , self ._dockerCid ,
664+ "cat" , omc_portfile_path .as_posix ()],
665+ stderr = subprocess .DEVNULL )
666+ port = output .decode ().strip ()
667+ except subprocess .CalledProcessError :
668+ pass
669+
670+ if port is not None :
671+ break
672+
673+ attempts += 1
674+ if attempts == 80.0 :
675+ raise OMCSessionException (f"Docker based OMC Server did not start (timeout={ self ._timeout } ). "
676+ f"Could not open port file { omc_portfile_path } . "
677+ f"Log-file says:\n { self .get_log ()} " )
678+ time .sleep (self ._timeout / 80.0 )
679+
680+ logger .info (f"Docker based OMC Server is up and running at port { port } " )
681+
682+ return port
683+
650684 def get_server_address (self ) -> Optional [str ]:
651685 if self ._dockerNetwork == "separate" and isinstance (self ._dockerCid , str ):
652686 output = subprocess .check_output (["docker" , "inspect" , self ._dockerCid ]).decode ().strip ()
@@ -761,41 +795,6 @@ def _omc_command_docker(
761795
762796 return omc_command
763797
764- def _omc_port_get (self ) -> str :
765- port = None
766-
767- if not isinstance (self ._dockerCid , str ):
768- raise OMCSessionException (f"Invalid docker container ID: { self ._dockerCid } " )
769-
770- # See if the omc server is running
771- attempts = 0
772- while True :
773- omc_portfile_path = self ._get_portfile_path ()
774- if omc_portfile_path is not None :
775- try :
776- output = subprocess .check_output (args = ["docker" ,
777- "exec" , self ._dockerCid ,
778- "cat" , omc_portfile_path .as_posix ()],
779- stderr = subprocess .DEVNULL )
780- port = output .decode ().strip ()
781- except subprocess .CalledProcessError :
782- pass
783-
784- if port is not None :
785- break
786-
787- attempts += 1
788- if attempts == 80.0 :
789- raise OMCSessionException (f"Docker based OMC Server did not start (timeout={ self ._timeout } ). "
790- f"Could not open port file { omc_portfile_path } . "
791- f"Log-file says:\n { self .get_log ()} " )
792- time .sleep (self ._timeout / 80.0 )
793-
794- logger .info (f"OMC Server is up and running at port { port } "
795- f"pid={ self ._omc_process .pid if isinstance (self ._omc_process , subprocess .Popen ) else '?' } " )
796-
797- return port
798-
799798 def _omc_docker_start (self ) -> Tuple [subprocess .Popen , DummyPopen , str ]:
800799 my_env = os .environ .copy ()
801800
@@ -907,40 +906,6 @@ def _omc_command_docker(self, omc_path_and_args_list) -> list:
907906
908907 return omc_command
909908
910- def _omc_port_get (self ) -> str :
911- port = None
912-
913- if not isinstance (self ._dockerCid , str ):
914- raise OMCSessionException (f"Invalid docker container ID: { self ._dockerCid } " )
915-
916- # See if the omc server is running
917- attempts = 0
918- while True :
919- omc_portfile_path = self ._get_portfile_path ()
920- if omc_portfile_path is not None :
921- try :
922- output = subprocess .check_output (args = ["docker" ,
923- "exec" , self ._dockerCid ,
924- "cat" , omc_portfile_path .as_posix ()],
925- stderr = subprocess .DEVNULL )
926- port = output .decode ().strip ()
927- except subprocess .CalledProcessError :
928- pass
929-
930- if port is not None :
931- break
932-
933- attempts += 1
934- if attempts == 80.0 :
935- raise OMCSessionException (f"Docker container based OMC Server did not start (timeout={ self ._timeout } ). "
936- f"Could not open port file { omc_portfile_path } . "
937- f"Log-file says:\n { self .get_log ()} " )
938- time .sleep (self ._timeout / 80.0 )
939-
940- logger .info (f"DockerContainer based OMC Server is up and running at port { port } " )
941-
942- return port
943-
944909 def _omc_docker_start (self ) -> Tuple [subprocess .Popen , DummyPopen ]:
945910 my_env = os .environ .copy ()
946911
0 commit comments