def test_subscribe_with_existing_sensor(): # create an unrelated sensor pico child_name = "test-existing" root_eci = "XQZfq3v86HdaNE3PXHxeow" url = picos.event_url(root_eci, "existing_sensor", "wrangler", "child_creation") ok, r = picos.post(url, data={ "name": child_name, "rids": [ "xandroxygen.temperature_store", "xandroxygen.wovyn_base", "xandroxygen.sensor_profile", "io.picolabs.subscription" ] }) assert ok == True # get the eci and name of the newly created sensor pico_details = r.content["directives"][0]["options"]["pico"] child_eci = pico_details["eci"] assert child_name == pico_details["name"] # wait for everything to finish sleep(2) url = picos.event_url(manager_eci, "existing_sensor", "sensor", "existing_sensor") ok, r = picos.post(url, data={"name": child_name, "eci": child_eci}) assert ok == True # check that the subscription was created sleep(2) assert len(subscriptions()) > 0
def run_pico_based_systems_test(manager_eci, reset=True): if reset: # Undo the last test reset_pico_based_systems_test(manager_eci) # Create 5 picos, generating a series of random heartbeats for each print("Generating 5 picos...") add_url = picos.event_url(manager_eci, "add-sensor", "sensor", "new_sensor") for i in range(1, 6): ok, r = picos.post(add_url, data={"sensor_id": i}) if not ok: print(r) return False eci = r.content["directives"][0]["options"]["pico"]["eci"] if eci is None: return False print("Populating %d with heartbeat data" % i) heartbeat_url = picos.event_url(eci, "mock-heartbeat", "wovyn", "heartbeat") for temp in range(10): ok, r = picos.post(heartbeat_url, data=mock_heartbeat(random.uniform(1.0, 70.0))) if not ok: print(r) return False if i == 1: print("Sending threshold violating heartbeat data to %d" % i) ok, r = picos.post(heartbeat_url, data=mock_heartbeat(100.0)) if not ok: print(r) return False # Wait for a bit print("Check results!") time.sleep(10) # Delete a sensor pico #print("Deleting sensor pico randomly...") #remove_url = picos.event_url(manager_eci, "remove-sensor", "sensor", "unneeded_sensor") #ok, r = picos.post(remove_url, data={"sensor_id": random.randint(1,5)}) #if not ok: # print(r) # return False # Wait for a bit #print("Check results!") #time.sleep(10) # Get the temperature values for all sensors with the sensor manager temperature_url = picos.api_url(manager_eci, "manage_sensors", "temperatures") ok, r = picos.get(temperature_url) print(r)
def delete_existing_subscription(child_eci, root_eci, child_name): # delete subscription url = picos.event_url(child_eci, "delete", "wrangler", "subscription_cancelled") ok, r = picos.post(url) # delete extra sensor pico url = picos.event_url(root_eci, "delete", "wrangler", "child_deletion") ok, r = picos.post(url, data={"name": child_name}) assert ok == True
def cleanup(): sleep(0.5) sensors = sensor_names() # delete subscriptions delete_subscriptions() # delete sensors sleep(0.5) url = picos.event_url(manager_eci, "unneeded_sensor", "sensor", "unneeded_sensor") for name in sensors: picos.post(url, data={"name": name})
def delete_subscriptions(): url = picos.event_url(manager_eci, "delete", "sensor", "delete_subscriptions") ok, r = picos.post(url) if not ok: raise Exception("Call to `delete subscriptions` failed.") return r.content
def request_temp_report(): report_url = picos.event_url(manager_eci, "report", "sensor", "temperature_report") ok, r = picos.post(report_url) if not ok: raise Exception("Call to `temperature_report` failed.") return r.content["directives"][0]["options"]["correlation_id"]
def reset_pico_based_systems_test(manager_eci): print("Cleaning up from last test...") url = picos.event_url(manager_eci, "remove-sensor", "sensor", "unneeded_sensor") for i in range(1,6): print("Removing pico sensor %d" % i) ok, r = picos.post(url, data={"sensor_id": i}) if not ok: print(r) return True
def add_temp_reading(eci, temp=float(format(random.uniform(10.0, 18.0), '.2f'))): heartbeat_url = picos.event_url(eci, "temp-reading", "wovyn", "new_temperature_reading") return picos.post(heartbeat_url, data={ "temperature": temp, "timestamp": "now/test" })
def gossip_resume(eci): url = picos.event_url(eci, "stop", "gossip", "process") return picos.post(url, data={"status": "on"})
def gossip_init(eci): url = picos.event_url(eci, "init", "gossip", "init") return picos.post(url)
def create_child(name="test"): url = picos.event_url(manager_eci, "new_sensor", "sensor", "new_sensor") return picos.post(url, data={"name": name})