def test_04_get_egg(self): """ Test _get_egg should return a path to a local egg for existing eggs, and exception for non-existing in the repo. """ launcher = ZMQEggDriverProcess("DUMMY_VAL") got_exception = False try: self.assertEqual(launcher._get_egg("NOT_FOUND_EGG"), None) except DriverLaunchException: got_exception = True self.assertTrue(got_exception)
def load_egg(): # Dynamically load the egg into the test path dvr_config = make_config() dvr_egg = dvr_config['dvr_egg'] dvr_sha = CFG.device.sbe37.dvr_sha launcher = ZMQEggDriverProcess(dvr_config) egg = launcher._get_egg(dvr_egg) from hashlib import sha1 with open(egg,'r') as f: doc = f.read() sha = sha1(doc).hexdigest() if sha != dvr_sha: raise ImportError('Failed to load driver %s: incorrect checksum. (%s!=%s)' % (dvr_egg, dvr_sha, sha)) if not egg in sys.path: sys.path.insert(0, egg) dvr_config['process_type'] = (DriverProcessType.EGG,) return dvr_config
def load_egg(dvr_config=None): # Dynamically load the egg into the test path if dvr_config is None: dvr_config = make_config() dvr_egg = dvr_config['dvr_egg'] #dvr_sha = CFG.device.sbe37.dvr_sha launcher = ZMQEggDriverProcess(dvr_config) egg = launcher._get_egg(dvr_egg) #from hashlib import sha1 with open(egg, 'r') as f: doc = f.read() #This does not work uniformly #sha = sha1(doc).hexdigest() #if sha != dvr_sha: # raise ImportError('Failed to load driver %s: incorrect checksum. (%s!=%s)' % (dvr_egg, dvr_sha, sha)) if not egg in sys.path: sys.path.insert(0, egg) dvr_config['process_type'] = (DriverProcessType.EGG, ) return dvr_config
# DVR_CONFIG['comms_config']['port'] is set by the setup. DVR_CONFIG = { 'dvr_egg': DRV_URI, 'dvr_mod': DRV_MOD, 'dvr_cls': DRV_CLS, 'workdir': WORK_DIR, 'process_type': None } # Launch from egg or a local MI repo. LAUNCH_FROM_EGG = True if LAUNCH_FROM_EGG: # Dynamically load the egg into the test path launcher = ZMQEggDriverProcess(DVR_CONFIG) egg = launcher._get_egg(DRV_URI) from hashlib import sha1 with open(egg, 'r') as f: doc = f.read() sha = sha1(doc).hexdigest() if not egg in sys.path: sys.path.insert(0, egg) DVR_CONFIG['process_type'] = (DriverProcessType.EGG, ) else: mi_repo = os.getcwd() + os.sep + 'extern' + os.sep + 'mi_repo' if not mi_repo in sys.path: sys.path.insert(0, mi_repo) DVR_CONFIG['process_type'] = (DriverProcessType.PYTHON_MODULE, ) DVR_CONFIG['mi_repo'] = mi_repo # Load MI modules from the egg
DRV_MOD = 'mi.instrument.seabird.sbe37smb.ooicore.driver' DRV_CLS = 'SBE37Driver' # Driver config. # DVR_CONFIG['comms_config']['port'] is set by the setup. DVR_CONFIG = { 'dvr_egg' : DRV_URI, 'dvr_mod' : DRV_MOD, 'dvr_cls' : DRV_CLS, 'workdir' : WORK_DIR, 'process_type' : (DriverProcessType.EGG,) } # Dynamically load the egg into the test path launcher = ZMQEggDriverProcess(DVR_CONFIG) egg = launcher._get_egg(DRV_URI) from hashlib import sha1 with open(egg,'r') as f: doc = f.read() sha = sha1(doc).hexdigest() if sha != DRV_SHA: raise ImportError('Failed to load driver %s: incorrect checksum. (%s!=%s)' % (DRV_URI, DRV_SHA, sha)) if not egg in sys.path: sys.path.insert(0, egg) # Load MI modules from the egg from mi.core.instrument.instrument_driver import DriverProtocolState from mi.core.instrument.instrument_driver import DriverConnectionState from mi.core.exceptions import InstrumentParameterException from mi.instrument.seabird.sbe37smb.ooicore.driver import SBE37ProtocolEvent from mi.instrument.seabird.sbe37smb.ooicore.driver import SBE37Parameter
def _set_up_pre_environment_for_instrument(self, instr_info): """ Based on test_instrument_agent.py Basically, this method launches a port agent and then completes the instrument driver configuration used to properly set up a particular instrument agent. @param instr_info A value in instruments_dict @return instrument_driver_config """ import sys from ion.agents.instrument.driver_process import DriverProcessType from ion.agents.instrument.driver_process import ZMQEggDriverProcess # A seabird driver. DRV_URI = SBE37_EGG DRV_MOD = 'mi.instrument.seabird.sbe37smb.ooicore.driver' DRV_CLS = 'SBE37Driver' WORK_DIR = '/tmp/' DELIM = ['<<', '>>'] instrument_driver_config = { 'dvr_egg' : DRV_URI, 'dvr_mod' : DRV_MOD, 'dvr_cls' : DRV_CLS, 'workdir' : WORK_DIR, 'process_type' : None } # Launch from egg or a local MI repo. LAUNCH_FROM_EGG=True if LAUNCH_FROM_EGG: # Dynamically load the egg into the test path launcher = ZMQEggDriverProcess(instrument_driver_config) egg = launcher._get_egg(DRV_URI) if not egg in sys.path: sys.path.insert(0, egg) instrument_driver_config['process_type'] = (DriverProcessType.EGG,) else: mi_repo = os.getcwd() + os.sep + 'extern' + os.sep + 'mi_repo' if not mi_repo in sys.path: sys.path.insert(0, mi_repo) instrument_driver_config['process_type'] = (DriverProcessType.PYTHON_MODULE,) instrument_driver_config['mi_repo'] = mi_repo DEV_ADDR = instr_info['DEV_ADDR'] DEV_PORT = instr_info['DEV_PORT'] DATA_PORT = instr_info['DATA_PORT'] CMD_PORT = instr_info['CMD_PORT'] PA_BINARY = instr_info['PA_BINARY'] support = DriverIntegrationTestSupport(None, None, DEV_ADDR, DEV_PORT, DATA_PORT, CMD_PORT, PA_BINARY, DELIM, WORK_DIR) # Start port agent, add stop to cleanup. port = support.start_pagent() log.info('Port agent started at port %i', port) self.addCleanup(support.stop_pagent) # Configure instrument driver to use port agent port number. instrument_driver_config['comms_config'] = { 'addr': 'localhost', 'port': port, 'cmd_port': CMD_PORT } return instrument_driver_config
def _set_up_pre_environment_for_instrument(self): """ From test_instrument_agent.py Basically, this method launches the port agent and the completes the instrument driver configuration used to properly set up the instrument agent. @return instrument_driver_config """ import sys from ion.agents.instrument.driver_process import DriverProcessType from ion.agents.instrument.driver_process import ZMQEggDriverProcess # A seabird driver. DRV_URI = 'http://sddevrepo.oceanobservatories.org/releases/seabird_sbe37smb_ooicore-0.0.7-py2.7.egg' DRV_MOD = 'mi.instrument.seabird.sbe37smb.ooicore.driver' DRV_CLS = 'SBE37Driver' WORK_DIR = '/tmp/' DELIM = ['<<', '>>'] instrument_driver_config = { 'dvr_egg' : DRV_URI, 'dvr_mod' : DRV_MOD, 'dvr_cls' : DRV_CLS, 'workdir' : WORK_DIR, 'process_type' : None } # Launch from egg or a local MI repo. LAUNCH_FROM_EGG=True if LAUNCH_FROM_EGG: # Dynamically load the egg into the test path launcher = ZMQEggDriverProcess(instrument_driver_config) egg = launcher._get_egg(DRV_URI) if not egg in sys.path: sys.path.insert(0, egg) instrument_driver_config['process_type'] = (DriverProcessType.EGG,) else: mi_repo = os.getcwd() + os.sep + 'extern' + os.sep + 'mi_repo' if not mi_repo in sys.path: sys.path.insert(0, mi_repo) instrument_driver_config['process_type'] = (DriverProcessType.PYTHON_MODULE,) instrument_driver_config['mi_repo'] = mi_repo DEV_ADDR = CFG.device.sbe37.host DEV_PORT = CFG.device.sbe37.port DATA_PORT = CFG.device.sbe37.port_agent_data_port CMD_PORT = CFG.device.sbe37.port_agent_cmd_port PA_BINARY = CFG.device.sbe37.port_agent_binary self._support = DriverIntegrationTestSupport(None, None, DEV_ADDR, DEV_PORT, DATA_PORT, CMD_PORT, PA_BINARY, DELIM, WORK_DIR) # Start port agent, add stop to cleanup. port = self._support.start_pagent() log.info('Port agent started at port %i', port) self.addCleanup(self._support.stop_pagent) # Configure instrument driver to use port agent port number. instrument_driver_config['comms_config'] = { 'addr': 'localhost', 'port': port, 'cmd_port': CMD_PORT } return instrument_driver_config
DRV_MOD = 'mi.instrument.seabird.sbe37smb.ooicore.driver' DRV_CLS = 'SBE37Driver' WORK_DIR = '/tmp/' DVR_CONFIG = { 'dvr_egg' : DRV_URI_GOOD, 'dvr_mod' : DRV_MOD, 'dvr_cls' : DRV_CLS, 'workdir' : WORK_DIR, 'process_type' : None } # Dynamically load the egg into the test path launcher = ZMQEggDriverProcess(DVR_CONFIG) egg = launcher._get_egg(DRV_URI_GOOD) if not egg in sys.path: sys.path.insert(0, egg) # now we can import SBE37ProtocolEvent from mi.instrument.seabird.sbe37smb.ooicore.driver import SBE37ProtocolEvent # ------------------------------------------------------------------------ @patch.dict(CFG, {'endpoint': {'receive': {'timeout': 180}}}) class TestPlatformInstrument(BaseIntTestPlatform): # def setUp(self): # # Start container # super(TestPlatformInstrument, self).setUp()