Best Python code snippet using lisa_python
dockersuite.py
Source:dockersuite.py
...127 string_identifier: str,128 prog_src: str,129 dockerfile: str,130 ) -> None:131 docker_tool = self._verify_and_remove_containers(132 node, docker_image_name, docker_container_name133 )134 if prog_src:135 self._copy_to_node(node, prog_src)136 self._copy_to_node(node, dockerfile)137 self._run_and_verify_results(138 node,139 docker_tool,140 dockerfile,141 docker_image_name,142 docker_container_name,143 string_identifier,144 )145 def _run_and_verify_results(146 self,147 node: Node,148 docker_tool: Docker,149 dockerfile_name: str,150 docker_image_name: str,151 docker_container_name: str,152 string_identifier: str,153 ) -> None:154 docker_run_output_file = "docker_run.log"155 docker_tool.build_image(docker_image_name, dockerfile_name)156 docker_tool.run_container(157 docker_image_name, docker_container_name, docker_run_output_file158 )159 docker_tool.remove_image(docker_image_name)160 docker_tool.remove_container(docker_container_name)161 docker_run_output = node.execute(162 f"cat {docker_run_output_file}",163 sudo=True,164 expected_exit_code=0,165 expected_exit_code_failure_message="Docker run output file not found",166 cwd=node.working_path,167 ).stdout168 assert_that(docker_run_output).described_as(169 "The container didn't output expected result. "170 "There may have been errors when the container was run. "171 f"String Identifier: {string_identifier}. "172 f"Docker Run Output: {docker_run_output}."173 ).is_equal_to(string_identifier)174 def _skip_if_not_supported(self, node: Node) -> None:175 if isinstance(node.os, Redhat) and node.os.information.version < "7.0.0":176 raise SkippedException(177 f"Test not supported for RH/CentOS {node.os.information.release}"178 )179 def _verify_and_remove_containers(180 self, node: Node, docker_image_name: str, docker_container_name: str181 ) -> Docker:182 self._skip_if_not_supported(node)183 docker_tool = node.tools[Docker]184 self._verify_docker_engine(node)185 docker_tool.remove_image(docker_image_name)186 docker_tool.remove_container(docker_container_name)187 return docker_tool188 def _verify_docker_engine(self, node: Node) -> None:189 node.log.debug(f"VerifyDockerEngine on {node.os.information.vendor.lower()}")190 result = node.execute(191 "docker run hello-world",192 expected_exit_code=0,193 expected_exit_code_failure_message="Fail to run docker run hello-world",...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!