def __init__(self, metadata, log_file = None, launch_data_moniotor = False):
        """
        @brief Constructor
        @param metadata IDK Metadata object
        @param log_file File to store test results.  If none specified log to STDOUT
        """
        repo_dir = Config().get("working_repo")
        if(not repo_dir):
            raise IDKConfigMissing()
        
        # Ion scripts need to be run from the base os the repo dir so it has access
        # to resources using relative pathing.  So we just do 
        os.chdir(repo_dir)
        
        self.metadata = metadata
        if(not self.metadata.driver_name):
            raise DriverNotStarted()

        if( log_file ):
            self.log_fh = open(log_file, "w")
        else:
            self.log_fh = sys.stdout
            
        config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_file(config_path)
        if(not self.comm_config):
            raise CommConfigReadFail(msg=config_path)

        self.test_runner = nose.core.TextTestRunner(stream=self.log_fh)
    def fetch_comm_config(self):
        """
        @brief collect connection information for the logger from the user
        """

        config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_console(config_path)
        self.comm_config.display_config()
        #self.comm_config.get_from_console()
        self.ip_address = self.comm_config.device_addr
        self.data_port = self.comm_config.data_port
        self.command_port = self.comm_config.command_port
        
        if not (self.ip_address):
            self.ip_address = prompt.text( 'Instrument IP Address', self.ip_address )
            
        if not (self.data_port):
            continuing = True
            while continuing:
                sport = prompt.text( 'Instrument Port', self.data_port )
                try:
                    self.data_port = int(sport)
                    continuing = False
                except ValueError as e:
                    print "Error converting port to number: " + str(e)
                    print "Please enter a valid port number.\n"
Exemple #3
0
    def fetch_comm_config(self):
        """
        @brief collect connection information for the logger from the user
        """

        config_path = "%s/%s" % (self.metadata.driver_dir(),
                                 CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_console(config_path)
        self.comm_config.display_config()
        #self.comm_config.get_from_console()
        self.ip_address = self.comm_config.device_addr
        self.data_port = self.comm_config.data_port
        self.command_port = self.comm_config.command_port

        if not (self.ip_address):
            self.ip_address = prompt.text('Instrument IP Address',
                                          self.ip_address)

        if not (self.data_port):
            continuing = True
            while continuing:
                sport = prompt.text('Instrument Port', self.data_port)
                try:
                    self.data_port = int(sport)
                    continuing = False
                except ValueError as e:
                    print "Error converting port to number: " + str(e)
                    print "Please enter a valid port number.\n"
Exemple #4
0
 def fetch_comm_config(self):
     """
     @brief collect connection information for the logger from the user
     """
     config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
     self.comm_config = CommConfig.get_config_from_console(config_path)
     self.comm_config.get_from_console()
Exemple #5
0
 def overwrite(self):
     """
     @brief Overwrite the current files with what is stored in the current metadata file.
     """
     self.metadata = Metadata()
     config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
     self.comm_config = CommConfig.get_config_from_file(config_path)
     self.generate_code(force = True)
 def test_8_config_read_multi(self):
     # create an ethernet config
     self.test_4_config_write_ethernet()
     ethernet_config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
     # stuff it into a multi-comm config
     config = { 'comm': {'method': 'multi', 'configs': {'test': {'comm': ethernet_config.dict()}}}}
     # dump the new config to a file
     open(self.config_file(), 'wb').write(yaml.dump(config))
     # load the config from file, verify the embedded config matches the original ethernet config
     multi_config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.MULTI)
     self.assertEqual(multi_config.configs['test'].dict(), ethernet_config.dict())
    def _init_test(self, metadata):
        """
        initialize the test with driver metadata
        """
        self.metadata = metadata
        if(not self.metadata.driver_name):
            raise DriverNotStarted()

        config_path = "%s/%s" % (self.metadata.driver_dir(), CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_file(config_path)
        if(not self.comm_config):
            raise CommConfigReadFail(msg=config_path)

        self._inspect_driver_module(self._driver_test_module())
Exemple #8
0
    def _init_test(self, metadata):
        """
        initialize the test with driver metadata
        """
        self.metadata = metadata
        if (not self.metadata.driver_name):
            raise DriverNotStarted()

        config_path = "%s/%s" % (self.metadata.driver_dir(),
                                 CommConfig.config_filename())
        self.comm_config = CommConfig.get_config_from_file(config_path)
        if (not self.comm_config):
            raise CommConfigReadFail(msg=config_path)

        self._inspect_driver_module(self._driver_test_module())
 def test_3_comm_config_type_list(self):
     types = CommConfig.valid_type_list()
     log.debug( "types: %s" % types)
     
     known_types = [ConfigTypes.ETHERNET, ConfigTypes.SERIAL, ConfigTypes.BOTPT]
     
     self.assertEqual(sorted(types), sorted(known_types))
    def test_4_config_write_ethernet(self):
        log.debug("Config File: %s" % self.config_file())
        if exists(self.config_file()):
            log.debug(" -- remove %s" % self.config_file())
            remove(self.config_file())

        self.assertFalse(exists(self.config_file()))

        config = CommConfig.get_config_from_type(self.config_file(),
                                                 ConfigTypes.ETHERNET)
        config.device_addr = INSTRUMENT_ADDR
        config.device_port = INSTRUMENT_PORT
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT

        log.debug("CONFIG: %s" % config.serialize())

        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(
            sorted(
                string.replace(self.config_ethernet_content(), "\n",
                               '').split('  ')),
            sorted(string.replace(self.read_config(), "\n", '').split('  ')))
    def test_6_config_write_serial(self):
        log.debug("Config File: %s" % self.config_file())
        if exists(self.config_file()):
            log.debug(" -- remove %s" % self.config_file())
            remove(self.config_file())

        self.assertFalse(exists(self.config_file()))

        config = CommConfig.get_config_from_type(self.config_file(),
                                                 ConfigTypes.SERIAL)
        config.device_os_port = DEVICE_OS_PORT
        config.device_baud = DEVICE_BAUD
        config.device_data_bits = DEVICE_DATA_BITS
        config.device_parity = DEVICE_PARITY
        config.device_stop_bits = DEVICE_STOP_BITS
        config.device_flow_control = DEVICE_FLOW_CONTROL
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT

        log.debug("CONFIG: %s" % config.serialize())

        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(
            sorted(
                string.replace(self.config_serial_content(), "\n",
                               '').split('  ')),
            sorted(string.replace(self.read_config(), "\n", '').split('  ')))
 def test_config_read_ethernet(self):
     config = CommConfig.get_config_from_type(self.config_file(), "ethernet")
     
     self.assertEqual(config.device_addr, 'localhost')
     self.assertEqual(config.device_port, 1000)
     self.assertEqual(config.server_addr, 'localhost')
     self.assertEqual(config.server_port, 2000)
 def test_5_config_read_ethernet(self):
     config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
     
     self.assertEqual(config.device_addr, INSTRUMENT_ADDR)
     self.assertEqual(config.device_port, INSTRUMENT_PORT)
     self.assertEqual(config.data_port, DATA_PORT)
     self.assertEqual(config.command_port, COMMAND_PORT)
    def test_6_config_write_serial(self):
        log.debug("Config File: %s" % self.config_file())
        if exists(self.config_file()):
            log.debug(" -- remove %s" % self.config_file())
            remove(self.config_file())

        self.assertFalse(exists(self.config_file()))

        config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.SERIAL)
        config.device_os_port = DEVICE_OS_PORT
        config.device_baud = DEVICE_BAUD
        config.device_data_bits = DEVICE_DATA_BITS
        config.device_parity = DEVICE_PARITY
        config.device_stop_bits = DEVICE_STOP_BITS
        config.device_flow_control = DEVICE_FLOW_CONTROL
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT

        log.debug("CONFIG: %s" % config.serialize())

        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(sorted(string.replace(self.config_serial_content(), "\n", '').split('  ')),
                         sorted(string.replace(self.read_config(), "\n", '').split('  ')))
 def test_5_config_read_ethernet(self):
     config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
     
     self.assertEqual(config.device_addr, INSTRUMENT_ADDR)
     self.assertEqual(config.device_port, INSTRUMENT_PORT)
     self.assertEqual(config.data_port, DATA_PORT)
     self.assertEqual(config.command_port, COMMAND_PORT)
 def test_3_comm_config_type_list(self):
     types = CommConfig.valid_type_list()
     log.debug( "types: %s" % types)
     
     known_types = [ConfigTypes.ETHERNET, ConfigTypes.RSN, ConfigTypes.SERIAL, ConfigTypes.BOTPT, ConfigTypes.MULTI]
     
     self.assertEqual(sorted(types), sorted(known_types))
 def test_comm_config_type_list(self):
     types = CommConfig.valid_type_list()
     log.debug( "types: %s" % types)
     
     known_types = ['ethernet']
     
     self.assertEqual(sorted(types), sorted(known_types))
 def test_2_exceptions(self):
     """
     Test exceptions raised by the CommConfig object
     """
     ## No exception thrown if file doesn't exist
     error = None
     try:
         config = CommConfig("this_file_does_not_exist.foo")
     except CommConfigReadFail, e:
         error = e
    def test_7_config_read_serial(self):
        config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.SERIAL)

        self.assertEqual(config.device_os_port, DEVICE_OS_PORT)
        self.assertEqual(config.device_baud, DEVICE_BAUD)
        self.assertEqual(config.device_data_bits, DEVICE_DATA_BITS)
        self.assertEqual(config.device_parity, DEVICE_PARITY)
        self.assertEqual(config.device_stop_bits, DEVICE_STOP_BITS)
        self.assertEqual(config.device_flow_control, DEVICE_FLOW_CONTROL)
        self.assertEqual(config.data_port, DATA_PORT)
        self.assertEqual(config.command_port, COMMAND_PORT)
    def test_7_config_read_serial(self):
        config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.SERIAL)

        self.assertEqual(config.device_os_port, DEVICE_OS_PORT)
        self.assertEqual(config.device_baud, DEVICE_BAUD)
        self.assertEqual(config.device_data_bits, DEVICE_DATA_BITS)
        self.assertEqual(config.device_parity, DEVICE_PARITY)
        self.assertEqual(config.device_stop_bits, DEVICE_STOP_BITS)
        self.assertEqual(config.device_flow_control, DEVICE_FLOW_CONTROL)
        self.assertEqual(config.data_port, DATA_PORT)
        self.assertEqual(config.command_port, COMMAND_PORT)
 def get_comm_config(cls):
     """
     @brief Create the comm config object by reading the comm_config.yml file.
     """
     log.info("get comm config")
     config_file = cls.comm_config_file()
     
     log.debug( " -- reading comm config from: %s" % config_file )
     if not os.path.exists(config_file):
         raise TestNoCommConfig(msg="Missing comm config.  Try running start_driver or switch_driver")
     
     return CommConfig.get_config_from_file(config_file)
def _get_file():
    """
    build the data file name.  Then loop until the file can be open successfully
    @return: file pointer to the data file
    """
    metadata = Metadata()
    config_path = "%s/%s" % (metadata.driver_dir(), CommConfig.config_filename())
    comm_config = CommConfig.get_config_from_file(config_path)
    date = time.strftime("%Y%m%d")

    filename = "%s/port_agent_%d.%s.data" % (DATADIR, comm_config.command_port, date)

    file = None
    while(not file):
        try:
            file = open(filename)
        except Exception as e:
            sys.stderr.write("file open failed: %s\n" % e)
            time.sleep(SLEEP)

    return file
    def init_comm_config(self):
        """
        @brief Create the comm config object by reading the comm_config.yml file.
        """
        log.info("Initialize comm config")
        config_file = self.comm_config_file()

        log.debug( " -- reading comm config from: %s" % config_file )
        if not os.path.exists(config_file):
            raise TestNoCommConfig(msg="Missing comm config.  Try running start_driver or switch_driver")

        self.comm_config = CommConfig.get_config_from_file(config_file)
def _get_file():
    """
    build the data file name.  Then loop until the file can be open successfully
    @return: file pointer to the data file
    """
    metadata = Metadata()
    config_path = "%s/%s" % (metadata.driver_dir(), CommConfig.config_filename())
    comm_config = CommConfig.get_config_from_file(config_path)
    date = time.strftime("%Y%m%d")

    filename = "%s/port_agent_%d.%s.data" % (DATADIR, comm_config.command_port, date)

    file = None
    while(not file):
        try:
            file = open(filename)
        except Exception as e:
            sys.stderr.write("file open failed: %s\n" % e)
            time.sleep(SLEEP)

    return file
 def comm_config_file(cls):
     """
     @brief Return the path the the driver comm config yaml file.
     @return if comm_config.yml exists return the full path
     """
     repo_dir = Config().get('working_repo')
     driver_path = cls.test_config.driver_module
     p = re.compile('\.')
     driver_path = p.sub('/', driver_path)
     abs_path = "%s/%s/%s" % (repo_dir, os.path.dirname(driver_path), CommConfig.config_filename())
     
     log.debug(abs_path)
     return abs_path
 def test_8_config_read_multi(self):
     # create an ethernet config
     self.test_4_config_write_ethernet()
     ethernet_config = CommConfig.get_config_from_type(
         self.config_file(), ConfigTypes.ETHERNET)
     # stuff it into a multi-comm config
     config = {
         'comm': {
             'method': 'multi',
             'configs': {
                 'test': {
                     'comm': ethernet_config.dict()
                 }
             }
         }
     }
     # dump the new config to a file
     open(self.config_file(), 'wb').write(yaml.dump(config))
     # load the config from file, verify the embedded config matches the original ethernet config
     multi_config = CommConfig.get_config_from_type(self.config_file(),
                                                    ConfigTypes.MULTI)
     self.assertEqual(multi_config.configs['test'].dict(),
                      ethernet_config.dict())
 def test_config_write_ethernet(self):
     log.debug("Config File: %s" % self.config_file())
     if exists(self.config_file()):
         log.debug(" -- remove %s" % self.config_file())
         remove(self.config_file())
         
     self.assertFalse(exists(self.config_file()))
     
     config = CommConfig.get_config_from_type(self.config_file(), "ethernet")
     config.device_addr = INSTRUMENT_ADDR
     config.device_port = INSTRUMENT_PORT
     config.data_port = DATA_PORT
     config.command_port = COMMAND_PORT
     
     log.debug("CONFIG: %s" % config.serialize())
     
     config.store_to_file()
     
     self.assertEqual(self.config_content(), self.read_config())
 def test_config_write_ethernet(self):
     log.debug("Config File: %s" % self.config_file())
     if exists(self.config_file()):
         log.debug(" -- remove %s" % self.config_file())
         remove(self.config_file())
         
     self.assertFalse(exists(self.config_file()))
     
     config = CommConfig.get_config_from_type(self.config_file(), "ethernet")
     config.device_addr = 'localhost'
     config.device_port = 1000
     config.server_addr = 'localhost'
     config.server_port = 2000
     
     log.debug("CONFIG: %s" % config.serialize())
     
     config.store_to_file()
     
     self.assertEqual(self.config_content(), self.read_config())
    def test_4_config_write_ethernet(self):
        log.debug("Config File: %s" % self.config_file())
        if exists(self.config_file()):
            log.debug(" -- remove %s" % self.config_file())
            remove(self.config_file())
            
        self.assertFalse(exists(self.config_file()))
        
        config = CommConfig.get_config_from_type(self.config_file(), ConfigTypes.ETHERNET)
        config.device_addr = INSTRUMENT_ADDR
        config.device_port = INSTRUMENT_PORT
        config.data_port = DATA_PORT
        config.command_port = COMMAND_PORT
        
        log.debug("CONFIG: %s" % config.serialize())
        
        config.store_to_file()

        # order isnt the same, so lets turn it into an array of label: value's then sort and compare.
        self.assertEqual(sorted(string.replace(self.config_ethernet_content(), "\n", '').split('  ')),
                         sorted(string.replace(self.read_config(), "\n", '').split('  ')))
        except CommConfigReadFail, e:
            error = e
        self.assertFalse(error)

        error = None
        try:
            config = CommConfig()
            config.read_from_file("/tmp")
        except CommConfigReadFail, e:
            log.debug("caught error %s" % e)
            error = e
        self.assertTrue(error)

        error = None
        try:
            config = CommConfig()
            config.store_to_file()
        except NoConfigFileSpecified, e:
            log.debug("caught error %s" % e)
            error = e
        self.assertTrue(error)

        error = None
        try:
            config = CommConfig.get_config_from_type(self.config_file(), "foo")
        except InvalidCommType, e:
            log.debug("caught error %s" % e)
            error = e
        self.assertTrue(error)

    def test_3_comm_config_type_list(self):
 def test_1_constructor(self):
     """
     Test object creation
     """
     config = CommConfig()
     self.assertTrue(config)
     except CommConfigReadFail, e:
         error = e
     self.assertFalse(error)
     
     error = None
     try:
         config = CommConfig()
         config.read_from_file("/tmp");
     except CommConfigReadFail, e:
         log.debug("caught error %s" % e)
         error = e
     self.assertTrue(error)
     
     error = None
     try:
         config = CommConfig()
         config.store_to_file();
     except NoConfigFileSpecified, e:
         log.debug("caught error %s" % e)
         error = e
     self.assertTrue(error)
     
     error = None
     try:
         config = CommConfig.get_config_from_type(self.config_file(), "foo")
     except InvalidCommType, e:
         log.debug("caught error %s" % e)
         error = e
     self.assertTrue(error)
 
 def test_comm_config_type_list(self):
class TestCommConfig(MiUnitTest):
    """
    Test the comm config object.  
    """
    def setUp(self):
        """
        Setup the test case
        """
        if not exists(ROOTDIR):
            makedirs(ROOTDIR)

        #self.write_config()

    def config_file(self):
        return "%s/comm_config.yml" % ROOTDIR

    def config_ethernet_content(self):
        return "comm:\n" +\
               "  command_port: %d\n" % (COMMAND_PORT) + \
               "  data_port: %d\n" % (DATA_PORT) + \
               "  device_addr: %s\n" % (INSTRUMENT_ADDR) + \
               "  device_port: %d\n" % (INSTRUMENT_PORT) + \
               "  host: %s\n" % (HOST) + \
               "  sniffer_port: %d\n" % (SNIFFER_PORT) + \
               "  method: ethernet\n"

    def config_serial_content(self):
        return "comm:\n" +\
               "  command_port: %d\n" % (COMMAND_PORT) +\
               "  data_port: %d\n" % (DATA_PORT) +\
               "  device_os_port: %s\n" % (DEVICE_OS_PORT) + \
               "  device_baud: %d\n" % (DEVICE_BAUD) + \
               "  device_data_bits: %d\n" % (DEVICE_DATA_BITS) + \
               "  device_parity: %d\n" % (DEVICE_PARITY) + \
               "  device_stop_bits: %d\n" % (DEVICE_STOP_BITS) + \
               "  device_flow_control: %d\n" % (DEVICE_FLOW_CONTROL) + \
               "  host: %s\n" % (HOST) + \
               "  sniffer_port: %d\n" % (SNIFFER_PORT) + \
               "  method: serial\n"

    def write_ethernet_config(self):
        ofile = open(self.config_file(), "w")
        ofile.write(self.config_ethernet_content())
        ofile.close()

    def write_serial_config(self):
        ofile = open(self.config_file(), "w")
        ofile.write(self.config_serial_content())
        ofile.close()

    def read_config(self):
        infile = open(self.config_file(), "r")
        result = infile.read()
        infile.close()
        return result

    def test_1_constructor(self):
        """
        Test object creation
        """
        config = CommConfig()
        self.assertTrue(config)

    def test_2_exceptions(self):
        """
        Test exceptions raised by the CommConfig object
        """
        ## No exception thrown if file doesn't exist
        error = None
        try:
            config = CommConfig("this_file_does_not_exist.foo")
        except CommConfigReadFail, e:
            error = e
        self.assertFalse(error)

        error = None
        try:
            config = CommConfig()
            config.read_from_file("/tmp")
        except CommConfigReadFail, e:
            log.debug("caught error %s" % e)
            error = e