Exemple #1
0
 def run(self, comp: Composition, workflow: Workflow) -> None:
     ui.progress(
         f"waiting for {self._host}:{self._port}",
         "C",
     )
     for remaining in ui.timeout_loop(self._timeout_secs):
         cmd = f"docker run --rm -t --network {comp.name}_default ubuntu:bionic-20200403".split(
         )
         cmd.extend([
             "timeout",
             str(self._timeout_secs),
             "bash",
             "-c",
             f"cat < /dev/null > /dev/tcp/{self._host}/{self._port}",
         ])
         try:
             spawn.capture(cmd, unicode=True, stderr_too=True)
         except subprocess.CalledProcessError as e:
             ui.log_in_automation(
                 "wait-for-tcp ({}:{}): error running {}: {}, stdout:\n{}\nstderr:\n{}"
                 .format(
                     self._host,
                     self._port,
                     ui.shell_quote(cmd),
                     e,
                     e.stdout,
                     e.stderr,
                 ))
             ui.progress(" {}".format(int(remaining)))
         else:
             ui.progress(" success!", finish=True)
             return
     raise Failed(f"Unable to connect to {self._host}:{self._port}")
 def docker_inspect(self, format: str, container_id: str) -> str:
     try:
         cmd = f"docker inspect -f '{format}' {container_id}".split()
         output = spawn.capture(cmd, unicode=True,
                                stderr_too=True).splitlines()[0]
     except subprocess.CalledProcessError as e:
         ui.log_in_automation(
             "docker inspect ({}): error running {}: {}, stdout:\n{}\nstderr:\n{}"
             .format(container_id, ui.shell_quote(cmd), e, e.stdout,
                     e.stderr))
         raise errors.Failed(f"failed to inspect Docker container: {e}")
     else:
         return output
Exemple #3
0
 def run(self, workflow: Workflow) -> None:
     say(f"dropping kafka topics {self._topic_pattern} from {self._container}")
     try:
         spawn.runv(
             [
                 "docker",
                 "exec",
                 "-t",
                 self._container,
                 "kafka-topics",
                 "--delete",
                 "--bootstrap-server",
                 "localhost:9092",
                 "--topic",
                 self._topic_pattern,
             ],
             capture_output=True,
         )
     except subprocess.CalledProcessError as e:
         # generally this is fine, it just means that the topics already don't exist
         ui.log_in_automation(f"DEBUG: error purging topics: {e}: {e.output}")
def _check_tcp(cmd: List[str],
               host: str,
               port: int,
               timeout_secs: int,
               kind: str = "") -> List[str]:
    cmd.extend([
        "timeout",
        str(timeout_secs),
        "bash",
        "-c",
        f"until [ cat < /dev/null > /dev/tcp/{host}/{port} ] ; do sleep 0.1 ; done",
    ])
    try:
        spawn.capture(cmd, stderr=subprocess.STDOUT)
    except subprocess.CalledProcessError as e:
        ui.log_in_automation(
            "wait-for-tcp ({}{}:{}): error running {}: {}, stdout:\n{}\nstderr:\n{}"
            .format(kind, host, port, ui.shell_quote(cmd), e, e.stdout,
                    e.stderr))
        raise
    return cmd