def request_service(self, app_name, port, expected_output=None): """Make request on service of app. If there is connection error function return False. :param app_name: str, name of the app :param expected_output: str, If not None method will check output returned from request and try to find matching string. :param port: str or int, port of the service :return: bool, True if connection was established False if there was connection error """ # get ip of service ip = [service.get_ip() for service in self.list_services(namespace=self.project) if service.name == app_name][0] # make http request to obtain output if expected_output is not None: try: output = self.http_request(host=ip, port=port) if expected_output not in output.text: raise ConuException( "Connection to service established, but didn't match expected output") else: logger.info("Connection to service established and return expected output!") return True except ConnectionError as e: logger.info("Connection to service failed %s!", e) return False elif check_port(port, host=ip): # check if port is open return True return False
def is_port_open(self, port, timeout=2): """ check if given port is open and receiving connections on container ip_address :param port: int, container port :param timeout: int, how many seconds to wait for connection; defaults to 2 :return: True if the connection has been established inside timeout, False otherwise """ addresses = self.get_IPv4s() if not addresses: return False return check_port(port, host=addresses[0], timeout=timeout)