def test_publish_create_request(self): """Publish a Request over STOMP and verify it via HTTP.""" stomp_connection = self.create_stomp_connection() request_model = self.create_request("test_publish_create_request") sample_operation_request = Operation( operation_type="REQUEST_CREATE", model=request_model, model_type="Request", target_garden_name="docker", ) listener = MessageListener() stomp_connection.set_listener("", listener) stomp_connection.subscribe( destination="Beer_Garden_Events", id="event_listener", ack="auto", headers={ "subscription-type": "MULTICAST", "durable-subscription-name": "events", }, ) stomp_connection.send( body=SchemaParser.serialize_operation(sample_operation_request, to_string=True), headers={ "model_class": sample_operation_request.__class__.__name__, }, destination="Beer_Garden_Operations", ) time.sleep(10) requests = self.easy_client.find_requests() found_request = False print(len(requests)) for request in requests: print(SchemaParser.serialize_request(request, to_string=True)) if ("generated-by" in request.metadata and request.metadata["generated-by"] == "test_publish_create_request"): found_request = True break assert found_request assert listener.create_event_captured if stomp_connection.is_connected(): stomp_connection.disconnect()
def test_publish_create_request(self): """Published the Request over STOMP and verifies of HTTP""" stomp_connection = self.create_stomp_connection() request_model = self.create_request("test_publish_create_request") sample_operation_request = Operation( operation_type="REQUEST_CREATE", model=request_model, model_type="Request", ) listener = MessageListener() stomp_connection.set_listener('', listener) stomp_connection.subscribe(destination='Beer_Garden_Events', id='event_listener', ack='auto', headers={ 'subscription-type': 'MULTICAST', 'durable-subscription-name': 'events' }) stomp_connection.send( body=SchemaParser.serialize_operation(sample_operation_request, to_string=True), headers={ "model_class": sample_operation_request.__class__.__name__, }, destination="Beer_Garden_Operations", ) time.sleep(10) requests = self.easy_client.find_requests() found_request = False print(len(requests)) for request in requests: print(SchemaParser.serialize_request(request, to_string=True)) if "generated-by" in request.metadata and request.metadata[ "generated-by"] == "test_publish_create_request": found_request = True break assert found_request assert listener.create_event_captured if stomp_connection.is_connected(): stomp_connection.disconnect()
def forward(self, operation, **kwargs): """Forwards an Operation Args: operation: The Operation to be forwarded **kwargs: Keyword arguments to pass to Requests session call Returns: The API response """ return self.client.post_forward( SchemaParser.serialize_operation(operation), **kwargs)
def send(): global conn host_and_ports = [("localhost", 61613)] conn = stomp.Connection(host_and_ports=host_and_ports, heartbeats=(10000, 0)) try: conn.connect("beer_garden", "password", wait=True, headers={"client-id": "beer_garden"}) except: print("Connection attempt failed, attempting TLS connection") key = "./certs/server_key.pem" cert = "./certs/server_certificate.pem" conn.set_ssl(for_hosts=host_and_ports, key_file=key, cert_file=cert) conn.connect("beer_garden", "password", wait=True, headers={"client-id": "beer_garden"}) signal.signal(signal.SIGINT, signal_handler) # Sending a Request request_model = Request( system="echo-sleeper", system_version="1.0.0.dev0", instance_name="default", command="say_sleep", parameters={ "message": "Hello, World!", "loud": False, "amount": 10 }, namespace="default", metadata={"reply-to": "metadataReplyto"}, ) wait_timeout = 0 sample_operation_request = Operation( operation_type="REQUEST_CREATE", model=request_model, model_type="Request", kwargs={"wait_timeout": wait_timeout}, ) count = 0 operation = sample_operation_request while True: count = count + 1 count_str = "request count: " + count.__str__() operation.model.parameters["message"] = count_str while not conn.is_connected(): try: conn.connect( "beer_garden", "password", wait=True, headers={"client-id": "beer_garden"}, ) except: pass conn.send( body=SchemaParser.serialize_operation(operation, to_string=True), headers={ "reply-to": "replyto", "model_class": operation.__class__.__name__, }, destination="Beer_Garden_Events_test", ) with open("count.json", "w") as outfile: json.dump(count.__str__(), outfile) time.sleep(0.01)
def send(): global conn host_and_ports = [("localhost", 61613)] conn = stomp.Connection(host_and_ports=host_and_ports, heartbeats=(10000, 0)) try: conn.connect("beer_garden", "password", wait=True, headers={"client-id": "beer_garden"}) except: print("Connection attempt failed, attempting TLS connection") key = "./certs/server_key.pem" cert = "./certs/server_certificate.pem" conn.set_ssl(for_hosts=host_and_ports, key_file=key, cert_file=cert) conn.connect("beer_garden", "password", wait=True, headers={"client-id": "beer_garden"}) signal.signal(signal.SIGINT, signal_handler) # Sending a Request request_model = Request( system="echo", system_version="1.0.0.dev0", instance_name="default", command="say", parameters={ "message": "Hello, World!", "loud": True }, namespace="default", metadata={"reply-to": "metadataReplyto"}, ) wait_timeout = 0 sample_operation_request = Operation( operation_type="REQUEST_CREATE", model=request_model, model_type="Request", kwargs={"wait_timeout": wait_timeout}, ) # Request all Systems sample_operation_systems = Operation(operation_type="SYSTEM_READ_ALL") sample_operation_read = Operation( operation_type="REQUEST_READ", args={"5f295ceb82f2dbf9740ba41e"}, ) operations = { "1": sample_operation_request, "2": sample_operation_read, "3": sample_operation_systems, "4": "quit", } operation = None while operation != "quit": in_put = input( "1: sample_operation_request, 2: sample_operation_read, " "3: sample_operation_systems, 4: 'quit'\n Enter corresponding number: " ) if in_put in operations: operation = operations[in_put] if in_put == "2": operation.args = {input("Enter request id: ")} if operation != "quit": conn.send( body=SchemaParser.serialize_operation(operation, to_string=True), headers={ "reply-to": "replyto", "model_class": operation.__class__.__name__, }, destination="Beer_Garden_Operations", ) else: print("Error: Input is not valid") if conn.is_connected(): conn.disconnect()