def test_example_preload(self): print 'preloading...' self.preload_example1() data_product_ids, _ = self.container.resource_registry.find_resources_ext(alt_id='DPROD102', alt_id_ns='PRE') data_product_id = data_product_ids[0] dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(data_product_id) with DirectCoverageAccess() as dca: dca.upload_calibration_coefficients(dataset_id, 'test_data/sbe16coeffs.csv', 'test_data/sbe16coeffs.yml') ph = ParameterHelper(self.dataset_management, self.addCleanup) rdt = ph.rdt_for_data_product(data_product_id) rdt['time'] = [time.time() + 2208988800] rdt['temperature'] = [248471] rdt['pressure'] = [528418] rdt['conductivity'] = [1673175] rdt['thermistor_temperature']=[24303] dataset_monitor = DatasetMonitor(dataset_id) self.addCleanup(dataset_monitor.stop) ph.publish_rdt_to_data_product(data_product_id, rdt) dataset_monitor.event.wait(10) g = self.data_retriever.retrieve(dataset_id) rdt = RecordDictionaryTool.load_from_granule(g) breakpoint(locals())
def test_example2_preload(self): print 'preloading...' self.preload_example2() data_product_ids, _ = self.container.resource_registry.find_resources_ext(alt_id='DPROD104', alt_id_ns='PRE') data_product_id = data_product_ids[0] dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(data_product_id) with DirectCoverageAccess() as dca: dca.upload_calibration_coefficients(dataset_id, 'test_data/vel3d_coeff.csv', 'test_data/vel3d_coeff.yml') from ion_functions.data.test.test_vel_functions import TS, VE, VN, VU rdt = ParameterHelper.rdt_for_data_product(data_product_id) rdt['time'] = [time.time() + 2208988800] rdt['velocity_east'] = [VE[0]] rdt['velocity_north'] = [VN[0]] rdt['velocity_up'] = [VU[0]] dataset_monitor = DatasetMonitor(dataset_id) self.addCleanup(dataset_monitor.stop) ParameterHelper.publish_rdt_to_data_product(data_product_id, rdt) dataset_monitor.event.wait(10) g = self.data_retriever.retrieve(dataset_id) rdt = RecordDictionaryTool.load_from_granule(g) breakpoint(locals())
def test_tmpsf_arrays(self): self.preload_tmpsf() pdict_id = self.dataset_management.read_parameter_dictionary_by_name('tmpsf_sample', id_only=True) stream_def_id = self.create_stream_definition('tmpsf', parameter_dictionary_id=pdict_id) data_product_id = self.create_data_product('tmpsf', stream_def_id=stream_def_id) self.activate_data_product(data_product_id) rdt = ParameterHelper.rdt_for_data_product(data_product_id) tomato = {'quality_flag': 'ok', 'preferred_timestamp': 'port_timestamp', 'internal_timestamp': 3223662780.0, 'stream_name': 'tmpsf_sample', 'values': [{'value_id': 'timestamp', 'value': 3223662780.0}, {'value_id': 'temperature', 'value': [21.4548, 21.0132, 20.9255, 21.1266, 21.1341, 21.5606, 21.2156, 21.4749, 21.3044, 21.132, 21.1798, 21.2352, 21.3488, 21.1214, 21.6426, 21.1479, 21.0069, 21.5426, 21.3204, 21.2402, 21.3968, 21.4371, 21.0411, 21.4361]}, {'value_id': 'battery_voltage', 'value': 11.5916}, {'value_id': 'serial_number', 'value': '021964'}], 'port_timestamp': 1378230448.439269, 'driver_timestamp': 3587219248.444593, 'pkt_format_id': 'JSON_Data', 'pkt_version': 1} from ion.agents.populate_rdt import populate_rdt rdt = populate_rdt(rdt, [tomato]) ParameterHelper.publish_rdt_to_data_product(data_product_id, rdt) dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(data_product_id) breakpoint(locals())
def test_create_dataset(self): ph = ParameterHelper(self.dataset_management, self.addCleanup) pdict_id = ph.create_extended_parsed() stream_def_id = self.pubsub_management.create_stream_definition('example', parameter_dictionary_id=pdict_id) self.addCleanup(self.pubsub_management.delete_stream_definition, stream_def_id) dp = DataProduct(name='example') data_product_id = self.data_product_management.create_data_product(dp, stream_def_id) self.addCleanup(self.data_product_management.delete_data_product, data_product_id) self.data_product_management.activate_data_product_persistence(data_product_id) self.addCleanup(self.data_product_management.suspend_data_product_persistence, data_product_id) dataset_id = self.resource_registry.find_objects(data_product_id, PRED.hasDataset, id_only=True)[0][0] monitor = DatasetMonitor(dataset_id) self.addCleanup(monitor.stop) rdt = ph.get_rdt(stream_def_id) ph.fill_rdt(rdt, 100) ph.publish_rdt_to_data_product(data_product_id, rdt) self.assertTrue(monitor.event.wait(10)) # Yield to other greenlets, had an issue with connectivity gevent.sleep(1) log.debug("--------------------------------") log.debug(dataset_id) coverage_path = DatasetManagementService()._get_coverage_path(dataset_id) log.debug(coverage_path) log.debug("--------------------------------") breakpoint(locals(), globals())
def test_lctest_preload(self): self.preload_lctest() pdict_id = self.dataset_management.read_parameter_dictionary_by_name('sparse_dict', id_only=True) stream_def_id = self.create_stream_definition('sparse_example', parameter_dictionary_id=pdict_id) data_product_id = self.create_data_product('sparse_example', stream_def_id=stream_def_id) self.activate_data_product(data_product_id) dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(data_product_id) rdt = ParameterHelper.rdt_for_data_product(data_product_id) rdt['time'] = [time.time() + 2208988800] rdt['sparse_float'] = [3.14159265358979323] rdt['sparse_double'] = [2.7182818284590452353602874713526624977572470936999595] rdt['sparse_int'] = [131071] # 6th mersenne prime dataset_monitor = DatasetMonitor(dataset_id) self.addCleanup(dataset_monitor.stop) ParameterHelper.publish_rdt_to_data_product(data_product_id, rdt) dataset_monitor.event.wait(10) for i in xrange(10): dataset_monitor.event.clear() rdt = ParameterHelper.rdt_for_data_product(data_product_id) rdt['time'] = [time.time() + 2208988800] ParameterHelper.publish_rdt_to_data_product(data_product_id, rdt) dataset_monitor.event.wait(10) g = self.data_retriever.retrieve(dataset_id) rdt = RecordDictionaryTool.load_from_granule(g) breakpoint(locals())
def test_hydrophone_simulator(self): ph = ParameterHelper(self.dataset_management, self.addCleanup) pdict_id = ph.crete_simple_array_pdict() stream_def_id = self.create_stream_definition('ctd parsed', parameter_dictionary_id=pdict_id) data_product_id = self.create_data_product('ctd hydrophone', stream_def_id=stream_def_id) self.activate_data_product(data_product_id) s = HydrophoneSimulator(data_product_id, interval=4) breakpoint(locals()) s.stop()
def test_out_of_order(self): pdict_id = self.dataset_management.read_parameter_dictionary_by_name('ctd_parsed_param_dict') stream_def_id = self.create_stream_definition('ctd', parameter_dictionary_id=pdict_id) data_product_id = self.create_data_product('ctd', stream_def_id=stream_def_id) self.activate_data_product(data_product_id) dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(data_product_id) s = BadSimulator(data_product_id) breakpoint(locals()) s.stop()
def test_sequences(self): s = SequenceType('s') i = BaseType('i', data=np.arange(10), type='i') c = BaseType('c', data=['hi'] * 10, type='S') f = BaseType('f', data=np.arange(20,30), type='f') d = BaseType('d', data=np.arange(30,40), type='d') b = BaseType('b', data=np.arange(40,50), type='B') s['i'] = i s['c'] = c s['f'] = f s['d'] = d s['b'] = b breakpoint(locals(), globals())
def test_sequences(self): s = SequenceType('s') i = BaseType('i', data=np.arange(10), type='i') c = BaseType('c', data=['hi'] * 10, type='S') f = BaseType('f', data=np.arange(20, 30), type='f') d = BaseType('d', data=np.arange(30, 40), type='d') b = BaseType('b', data=np.arange(40, 50), type='B') s['i'] = i s['c'] = c s['f'] = f s['d'] = d s['b'] = b breakpoint(locals(), globals())
def test_ui_functionality(self): ''' Tests the service implementations and UI compliance through the service gateway ''' # Get some initial dpds # There's one specifically for converting from C to F self.preload_units() # User clicks create data process # User is presented with a dropdown of data process definitions dpds, _ = self.resource_registry.find_resources(restype=RT.DataProcessDefinition) # User selects the c_to_f data process definition relevant = filter(lambda x: 'c_to_f' in x.name, dpds) breakpoint(locals(), globals())
def test_ui_functionality(self): ''' Tests the service implementations and UI compliance through the service gateway ''' # Get some initial dpds # There's one specifically for converting from C to F self.preload_units() # User clicks create data process # User is presented with a dropdown of data process definitions dpds, _ = self.resource_registry.find_resources( restype=RT.DataProcessDefinition) # User selects the c_to_f data process definition relevant = filter(lambda x: 'c_to_f' in x.name, dpds) breakpoint(locals(), globals())
def test_dm_realtime_visualization(self): self.preload_beta() # Create the google_dt workflow definition since there is no preload for the test workflow_def_id = self.create_google_dt_workflow_def() #Create the input data product pdict_id = self.dataset_management.read_parameter_dictionary_by_name('ctd_simulator', id_only=True) stream_def_id = self.create_stream_definition('ctd sim L2', parameter_dictionary_id=pdict_id) data_product_id = self.create_data_product('ctd simulator', stream_def_id=stream_def_id) self.activate_data_product(data_product_id) #viz_token = self.visualization.initiate_realtime_visualization_data(data_product_id=data_product_id) streamer = Streamer(data_product_id) self.addCleanup(streamer.stop) breakpoint(locals())
def test_create_dataset(self): ph = ParameterHelper(self.dataset_management, self.addCleanup) pdict_id = ph.create_extended_parsed() stream_def_id = self.pubsub_management.create_stream_definition( 'example', parameter_dictionary_id=pdict_id) self.addCleanup(self.pubsub_management.delete_stream_definition, stream_def_id) dp = DataProduct(name='example') data_product_id = self.data_product_management.create_data_product( dp, stream_def_id) self.addCleanup(self.data_product_management.delete_data_product, data_product_id) self.data_product_management.activate_data_product_persistence( data_product_id) self.addCleanup( self.data_product_management.suspend_data_product_persistence, data_product_id) dataset_id = self.resource_registry.find_objects(data_product_id, PRED.hasDataset, id_only=True)[0][0] monitor = DatasetMonitor(dataset_id) self.addCleanup(monitor.stop) rdt = ph.get_rdt(stream_def_id) ph.fill_rdt(rdt, 100) ph.publish_rdt_to_data_product(data_product_id, rdt) self.assertTrue(monitor.event.wait(10)) # Yield to other greenlets, had an issue with connectivity gevent.sleep(1) log.debug("--------------------------------") log.debug(dataset_id) coverage_path = DatasetManagementService()._get_coverage_path( dataset_id) log.debug(coverage_path) log.debug("--------------------------------") breakpoint(locals(), globals())
def test_creation_args(self): pdict_id = self.dataset_management.read_parameter_dictionary_by_name('ctd_parsed_param_dict') stream_def_id = self.create_stream_definition('ctd', parameter_dictionary_id=pdict_id) data_product_id = self.create_data_product('ctd', stream_def_id=stream_def_id) self.activate_data_product(data_product_id) dataset_id = self.RR2.find_dataset_id_of_data_product_using_has_dataset(data_product_id) breakpoint(locals()) rdt = self.ph.get_rdt(stream_def_id) rdt['time'] = np.arange(20) rdt['temp'] = np.arange(20) dataset_monitor = DatasetMonitor(dataset_id) self.addCleanup(dataset_monitor.stop) self.ph.publish_rdt_to_data_product(data_product_id,rdt) dataset_monitor.event.wait(10) breakpoint(locals()) granule = self.data_retriever.retrieve(dataset_id) breakpoint(locals())
def main(uri): # pragma: no cover oms_event_listener = launch_listener() print '\nconnecting to %r ...' % uri proxy = xmlrpclib.ServerProxy(uri, allow_none=True) print 'connection established.' pp = pprint.PrettyPrinter() def show_listeners(): from datetime import datetime from ion.agents.platform.util import ntp_2_ion_ts event_listeners = proxy.event.get_registered_event_listeners() print("Event listeners (%d):" % len(event_listeners)) for a, b in sorted(event_listeners.iteritems(), lambda a, b: int(a[1] - b[1])): time = datetime.fromtimestamp(float(ntp_2_ion_ts(b)) / 1000) print(" %s %s" % (time, a)) print def format_val(value): prefix = "\t\t" print "\n%s%s" % (prefix, pp.pformat(value).replace("\n", "\n" + prefix)) def format_err(msg): prefix = "\t\t" print "\n%s%s" % (prefix, msg.replace("\n", "\n" + prefix)) def get_method(handler_name, method_name): """ Gets the method from the proxy. @param handler_name Name of the handler; can be None to indicate get method directly from proxy. @param method_name Method's name @return callable; None if any error getting the method """ # get method: if handler_name: # get handler: try: handler = getattr(proxy, handler_name) except Exception as e: print "error getting handler %s: %s: %s" % (handler_name, type(e), str(e)) return None try: method = getattr(handler, method_name) return method except Exception as e: print "error method %s.%s: %s: %s" % (handler_name, method_name, type(e), str(e)) return None else: try: method = getattr(proxy, method_name) return method except Exception as e: print "error getting proxy's method %s: %s: %s" % (method_name, type(e), str(e)) return None def run(full_method_name, *args): """ Runs a method against the proxy. @param full_method_name @param args """ global tried tried[full_method_name] = "" handler_name, method_name = full_method_name.split(".") # get the method method = get_method(handler_name, method_name) if method is None: tried[full_method_name] = "could not get handler or method" return sargs = ", ".join(["%r" % a for a in args]) sys.stdout.write("\n%s(%s) -> " % (full_method_name, sargs)) sys.stdout.flush() # run method retval, reterr = None, None try: retval = method(*args) tried[full_method_name] = "OK" # print "%r" % retval format_val(retval) except xmlrpclib.Fault as e: if e.faultCode == 8001: reterr = "-- NOT FOUND (fault %s)" % e.faultCode else: reterr = "-- Fault %d: %s" % (e.faultCode, e.faultString) # raise # print "Exception: %s: %s" % (type(e), str(e)) # tried[full_method_name] = str(e) tried[full_method_name] = reterr format_err(reterr) return retval, reterr def verify_entry_in_dict(retval, reterr, entry): if reterr is not None: return retval, reterr if not isinstance(retval, dict): reterr = "-- expecting a dict with entry %r" % entry elif entry not in retval: reterr = "-- expecting a dict with entry %r" % entry else: retval = retval[entry] print("full_method_name = %s" % full_method_name) if reterr: tried[full_method_name] = reterr format_err(reterr) return retval, reterr def verify_test_event_notified(retval, reterr, event): print("waiting for a max of %d secs for test event to be notified..." % max_wait) import time wait_until = time.time() + max_wait got_it = False while not got_it and time.time() <= wait_until: time.sleep(1) for evt in oms_event_listener.notifications: if event['message'] == evt['message']: got_it = True break # print("Received external events: %s" % oms_event_listener.notifications) if not got_it: reterr = "error: didn't get expected test event notification within %d " \ "secs. (Got %d event notifications.)" % ( max_wait, len(oms_event_listener.notifications)) print("full_method_name = %s" % full_method_name) if reterr: tried[full_method_name] = reterr format_err(reterr) return retval, reterr show_listeners() if launch_breakpoint: breakpoint(locals()) print "Basic verification of the operations:\n" #---------------------------------------------------------------------- full_method_name = "hello.ping" retval, reterr = run(full_method_name) if retval and retval.lower() != "pong": error = "expecting 'pong'" tried[full_method_name] = error format_err(error) #---------------------------------------------------------------------- full_method_name = "config.get_platform_types" retval, reterr = run(full_method_name) if retval and not isinstance(retval, dict): error = "expecting a dict" tried[full_method_name] = error format_err(error) platform_id = "dummy_platform_id" #---------------------------------------------------------------------- full_method_name = "config.get_platform_map" retval, reterr = run(full_method_name) if retval is not None: if isinstance(retval, list): if len(retval): if isinstance(retval[0], (tuple, list)): platform_id = retval[0][0] else: reterr = "expecting a list of tuples or lists" else: reterr = "expecting a non-empty list" else: reterr = "expecting a list" if reterr: tried[full_method_name] = reterr format_err(reterr) #---------------------------------------------------------------------- full_method_name = "config.get_platform_metadata" retval, reterr = run(full_method_name, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) #---------------------------------------------------------------------- full_method_name = "attr.get_platform_attributes" retval, reterr = run(full_method_name, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) #---------------------------------------------------------------------- full_method_name = "attr.get_platform_attribute_values" retval, reterr = run(full_method_name, platform_id, []) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) #---------------------------------------------------------------------- full_method_name = "attr.set_platform_attribute_values" retval, reterr = run(full_method_name, platform_id, {}) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) port_id = "dummy_port_id" #---------------------------------------------------------------------- full_method_name = "port.get_platform_ports" retval, reterr = run(full_method_name, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) if retval is not None: if isinstance(retval, dict): if len(retval): port_id = retval.keys()[0] else: reterr = "empty dict of ports for platform %r" % platform_id else: reterr = "expecting a dict {%r: ...}. got: %s" % (platform_id, type(retval)) if reterr: tried[full_method_name] = reterr format_err(reterr) instrument_id = "dummy_instrument_id" if reterr is None: full_method_name = "port.get_platform_ports" retval, reterr = run(full_method_name, "dummy_platform_id") orig_retval = retval retval, reterr = verify_entry_in_dict(retval, reterr, "dummy_platform_id") if retval != INVALID_PLATFORM_ID: reterr = "expecting dict {%r: %r}. got: %r" % ( "dummy_platform_id", INVALID_PLATFORM_ID, orig_retval) tried[full_method_name] = reterr format_err(reterr) instrument_id = "dummy_instrument_id" #---------------------------------------------------------------------- full_method_name = "instr.connect_instrument" retval, reterr = run(full_method_name, platform_id, port_id, instrument_id, {}) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, port_id) retval, reterr = verify_entry_in_dict(retval, reterr, instrument_id) connect_instrument_error = reterr #---------------------------------------------------------------------- full_method_name = "instr.get_connected_instruments" retval, reterr = run(full_method_name, platform_id, port_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, port_id) # note, in case of error in instr.connect_instrument, don't expect the # instrument_id to be reported: if connect_instrument_error is None: retval, reterr = verify_entry_in_dict(retval, reterr, instrument_id) #---------------------------------------------------------------------- full_method_name = "instr.disconnect_instrument" retval, reterr = run(full_method_name, platform_id, port_id, instrument_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, port_id) retval, reterr = verify_entry_in_dict(retval, reterr, instrument_id) #---------------------------------------------------------------------- full_method_name = "port.turn_on_platform_port" retval, reterr = run(full_method_name, platform_id, port_id) #---------------------------------------------------------------------- full_method_name = "port.turn_off_platform_port" retval, reterr = run(full_method_name, platform_id, port_id) #---------------------------------------------------------------------- url = EVENT_LISTENER_URL #---------------------------------------------------------------------- full_method_name = "event.register_event_listener" retval, reterr = run(full_method_name, url) retval, reterr = verify_entry_in_dict(retval, reterr, url) #---------------------------------------------------------------------- full_method_name = "event.get_registered_event_listeners" retval, reterr = run(full_method_name) urls = retval retval, reterr = verify_entry_in_dict(retval, reterr, url) #---------------------------------------------------------------------- full_method_name = "event.unregister_event_listener" if isinstance(urls, dict): # this part just as a convenience to unregister listeners that were # left registered by some error in a prior interaction. prefix = "http://127.0.0.1:" # or some other needed prefix for url2 in urls: if url2.find(prefix) >= 0: retval, reterr = run(full_method_name, url2) retval, reterr = verify_entry_in_dict(retval, reterr, url2) if reterr is not None: break if reterr is None: retval, reterr = run(full_method_name, url) retval, reterr = verify_entry_in_dict(retval, reterr, url) #---------------------------------------------------------------------- full_method_name = "config.get_checksum" retval, reterr = run(full_method_name, platform_id) # the following to specifically verify reception of test event if max_wait: full_method_name = "event.register_event_listener" retval, reterr = run(full_method_name, EVENT_LISTENER_URL) retval, reterr = verify_entry_in_dict(retval, reterr, EVENT_LISTENER_URL) full_method_name = "event.generate_test_event" event = { 'message' : "fake event triggered from CI using OMS' generate_test_event", 'platform_id' : "fake_platform_id", 'severity' : "3", 'group ' : "power", } retval, reterr = run(full_method_name, event) if max_wait: verify_test_event_notified(retval, reterr, event) full_method_name = "event.unregister_event_listener" retval, reterr = run(full_method_name, EVENT_LISTENER_URL) retval, reterr = verify_entry_in_dict(retval, reterr, EVENT_LISTENER_URL) elif not reterr: ok_but = "OK (but verification of event reception was not performed)" tried[full_method_name] = ok_but format_err(ok_but) show_listeners() ####################################################################### print("\nSummary of basic verification:") okeys = 0 for full_method_name, result in sorted(tried.iteritems()): print("%20s %-40s: %s" % ("", full_method_name, result)) if result.startswith("OK"): okeys += 1 print("OK methods %d out of %s" % (okeys, len(tried)))
def main(uri): # pragma: no cover oms_event_listener = launch_listener() print '\nconnecting to %r ...' % uri proxy = xmlrpclib.ServerProxy(uri, allow_none=True) print 'connection established.' pp = pprint.PrettyPrinter() def show_listeners(): from datetime import datetime from ion.agents.platform.util import ntp_2_ion_ts event_listeners = proxy.event.get_registered_event_listeners() print("Event listeners (%d):" % len(event_listeners)) for a, b in sorted(event_listeners.iteritems(), lambda a, b: int(a[1] - b[1])): time = datetime.fromtimestamp(float(ntp_2_ion_ts(b)) / 1000) print(" %s %s" % (time, a)) print def format_val(value): prefix = "\t\t" print "\n%s%s" % (prefix, pp.pformat(value).replace( "\n", "\n" + prefix)) def format_err(msg): prefix = "\t\t" print "\n%s%s" % (prefix, msg.replace("\n", "\n" + prefix)) def get_method(handler_name, method_name): """ Gets the method from the proxy. @param handler_name Name of the handler; can be None to indicate get method directly from proxy. @param method_name Method's name @return callable; None if any error getting the method """ # get method: if handler_name: # get handler: try: handler = getattr(proxy, handler_name) except Exception as e: print "error getting handler %s: %s: %s" % (handler_name, type(e), str(e)) return None try: method = getattr(handler, method_name) return method except Exception as e: print "error method %s.%s: %s: %s" % ( handler_name, method_name, type(e), str(e)) return None else: try: method = getattr(proxy, method_name) return method except Exception as e: print "error getting proxy's method %s: %s: %s" % ( method_name, type(e), str(e)) return None def run(full_method_name, *args): """ Runs a method against the proxy. @param full_method_name @param args """ global tried tried[full_method_name] = "" handler_name, method_name = full_method_name.split(".") # get the method method = get_method(handler_name, method_name) if method is None: tried[full_method_name] = "could not get handler or method" return sargs = ", ".join(["%r" % a for a in args]) sys.stdout.write("\n%s(%s) -> " % (full_method_name, sargs)) sys.stdout.flush() # run method retval, reterr = None, None try: retval = method(*args) tried[full_method_name] = "OK" # print "%r" % retval format_val(retval) except xmlrpclib.Fault as e: if e.faultCode == 8001: reterr = "-- NOT FOUND (fault %s)" % e.faultCode else: reterr = "-- Fault %d: %s" % (e.faultCode, e.faultString) # raise # print "Exception: %s: %s" % (type(e), str(e)) # tried[full_method_name] = str(e) tried[full_method_name] = reterr format_err(reterr) return retval, reterr def verify_entry_in_dict(retval, reterr, entry): if reterr is not None: return retval, reterr if not isinstance(retval, dict): reterr = "-- expecting a dict with entry %r" % entry elif entry not in retval: reterr = "-- expecting a dict with entry %r" % entry else: retval = retval[entry] print("full_method_name = %s" % full_method_name) if reterr: tried[full_method_name] = reterr format_err(reterr) return retval, reterr def verify_test_event_notified(retval, reterr, event): print("waiting for a max of %d secs for test event to be notified..." % max_wait) import time wait_until = time.time() + max_wait got_it = False while not got_it and time.time() <= wait_until: time.sleep(1) for evt in oms_event_listener.notifications: if event['message'] == evt['message']: got_it = True break # print("Received external events: %s" % oms_event_listener.notifications) if not got_it: reterr = "error: didn't get expected test event notification within %d " \ "secs. (Got %d event notifications.)" % ( max_wait, len(oms_event_listener.notifications)) print("full_method_name = %s" % full_method_name) if reterr: tried[full_method_name] = reterr format_err(reterr) return retval, reterr show_listeners() if launch_breakpoint: breakpoint(locals()) print "Basic verification of the operations:\n" #---------------------------------------------------------------------- full_method_name = "hello.ping" retval, reterr = run(full_method_name) if retval and retval.lower() != "pong": error = "expecting 'pong'" tried[full_method_name] = error format_err(error) #---------------------------------------------------------------------- full_method_name = "config.get_platform_types" retval, reterr = run(full_method_name) if retval and not isinstance(retval, dict): error = "expecting a dict" tried[full_method_name] = error format_err(error) platform_id = "dummy_platform_id" #---------------------------------------------------------------------- full_method_name = "config.get_platform_map" retval, reterr = run(full_method_name) if retval is not None: if isinstance(retval, list): if len(retval): if isinstance(retval[0], (tuple, list)): platform_id = retval[0][0] else: reterr = "expecting a list of tuples or lists" else: reterr = "expecting a non-empty list" else: reterr = "expecting a list" if reterr: tried[full_method_name] = reterr format_err(reterr) #---------------------------------------------------------------------- full_method_name = "config.get_platform_metadata" retval, reterr = run(full_method_name, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) #---------------------------------------------------------------------- full_method_name = "attr.get_platform_attributes" retval, reterr = run(full_method_name, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) #---------------------------------------------------------------------- full_method_name = "attr.get_platform_attribute_values" retval, reterr = run(full_method_name, platform_id, []) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) #---------------------------------------------------------------------- full_method_name = "attr.set_platform_attribute_values" retval, reterr = run(full_method_name, platform_id, {}) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) port_id = "dummy_port_id" #---------------------------------------------------------------------- full_method_name = "port.get_platform_ports" retval, reterr = run(full_method_name, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) if retval is not None: if isinstance(retval, dict): if len(retval): port_id = retval.keys()[0] else: reterr = "empty dict of ports for platform %r" % platform_id else: reterr = "expecting a dict {%r: ...}. got: %s" % (platform_id, type(retval)) if reterr: tried[full_method_name] = reterr format_err(reterr) instrument_id = "dummy_instrument_id" if reterr is None: full_method_name = "port.get_platform_ports" retval, reterr = run(full_method_name, "dummy_platform_id") orig_retval = retval retval, reterr = verify_entry_in_dict(retval, reterr, "dummy_platform_id") if retval != INVALID_PLATFORM_ID: reterr = "expecting dict {%r: %r}. got: %r" % ( "dummy_platform_id", INVALID_PLATFORM_ID, orig_retval) tried[full_method_name] = reterr format_err(reterr) instrument_id = "dummy_instrument_id" #---------------------------------------------------------------------- full_method_name = "instr.connect_instrument" retval, reterr = run(full_method_name, platform_id, port_id, instrument_id, {}) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, port_id) retval, reterr = verify_entry_in_dict(retval, reterr, instrument_id) connect_instrument_error = reterr #---------------------------------------------------------------------- full_method_name = "instr.get_connected_instruments" retval, reterr = run(full_method_name, platform_id, port_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, port_id) # note, in case of error in instr.connect_instrument, don't expect the # instrument_id to be reported: if connect_instrument_error is None: retval, reterr = verify_entry_in_dict(retval, reterr, instrument_id) #---------------------------------------------------------------------- full_method_name = "instr.disconnect_instrument" retval, reterr = run(full_method_name, platform_id, port_id, instrument_id) retval, reterr = verify_entry_in_dict(retval, reterr, platform_id) retval, reterr = verify_entry_in_dict(retval, reterr, port_id) retval, reterr = verify_entry_in_dict(retval, reterr, instrument_id) #---------------------------------------------------------------------- full_method_name = "port.turn_on_platform_port" retval, reterr = run(full_method_name, platform_id, port_id) #---------------------------------------------------------------------- full_method_name = "port.turn_off_platform_port" retval, reterr = run(full_method_name, platform_id, port_id) #---------------------------------------------------------------------- url = EVENT_LISTENER_URL #---------------------------------------------------------------------- full_method_name = "event.register_event_listener" retval, reterr = run(full_method_name, url) retval, reterr = verify_entry_in_dict(retval, reterr, url) #---------------------------------------------------------------------- full_method_name = "event.get_registered_event_listeners" retval, reterr = run(full_method_name) urls = retval retval, reterr = verify_entry_in_dict(retval, reterr, url) #---------------------------------------------------------------------- full_method_name = "event.unregister_event_listener" if isinstance(urls, dict): # this part just as a convenience to unregister listeners that were # left registered by some error in a prior interaction. prefix = "http://127.0.0.1:" # or some other needed prefix for url2 in urls: if url2.find(prefix) >= 0: retval, reterr = run(full_method_name, url2) retval, reterr = verify_entry_in_dict(retval, reterr, url2) if reterr is not None: break if reterr is None: retval, reterr = run(full_method_name, url) retval, reterr = verify_entry_in_dict(retval, reterr, url) #---------------------------------------------------------------------- full_method_name = "config.get_checksum" retval, reterr = run(full_method_name, platform_id) # the following to specifically verify reception of test event if max_wait: full_method_name = "event.register_event_listener" retval, reterr = run(full_method_name, EVENT_LISTENER_URL) retval, reterr = verify_entry_in_dict(retval, reterr, EVENT_LISTENER_URL) full_method_name = "event.generate_test_event" event = { 'message': "fake event triggered from CI using OMS' generate_test_event", 'platform_id': "fake_platform_id", 'severity': "3", 'group ': "power", } retval, reterr = run(full_method_name, event) if max_wait: verify_test_event_notified(retval, reterr, event) full_method_name = "event.unregister_event_listener" retval, reterr = run(full_method_name, EVENT_LISTENER_URL) retval, reterr = verify_entry_in_dict(retval, reterr, EVENT_LISTENER_URL) elif not reterr: ok_but = "OK (but verification of event reception was not performed)" tried[full_method_name] = ok_but format_err(ok_but) show_listeners() ####################################################################### print("\nSummary of basic verification:") okeys = 0 for full_method_name, result in sorted(tried.iteritems()): print("%20s %-40s: %s" % ("", full_method_name, result)) if result.startswith("OK"): okeys += 1 print("OK methods %d out of %s" % (okeys, len(tried)))
def _breakpoint(self, scope=None, global_scope=None): from pyon.util.breakpoint import breakpoint breakpoint(scope=scope, global_scope=global_scope)
def test_ctdpf(self): print 'preloading' self.preload_ctdpf() breakpoint(locals())