def test_read_config_bad_field(self):
     """test reading from config file with bad section"""
     with self.assertRaises(ArchiveInterfaceError) as context:
         read_config_value('hms_sideband', 'bad_field')
     self.assertTrue(
         'Error reading config file, no field: bad_field in section: hms_sideband',
         context.exception)
 def __init__(self, prefix):
     super(HmsSidebandBackendArchive, self).__init__(prefix)
     self._prefix = prefix
     self._file = None
     self._fpath = None
     #since the database prefix may be different then the system the file is mounted on
     self._sam_qfs_prefix = read_config_value('hms_sideband',
                                              'sam_qfs_prefix')
 def __init__(self, prefix):
     super(HpssBackendArchive, self).__init__(prefix)
     self._prefix = prefix
     self._user = read_config_value('hpss', 'user')
     self._auth = read_config_value('hpss', 'auth')
     self._file = None
     self._filepath = None
     self._hpsslib = None
     self._latency = 5  #number not significant
     #need to load  the hpss libraries/ extensions
     try:
         self._hpsslib = cdll.LoadLibrary(HPSS_LIBRARY_PATH)
     except Exception as ex:
         err_str = "Can't load hpss libraries with error: " + str(ex)
         raise ArchiveInterfaceError(err_str)
     #need to authenticate with hpss
     try:
         self.authenticate()
     except Exception as ex:
         err_str = "Can't authenticate with hpss, error: " + str(ex)
         raise ArchiveInterfaceError(err_str)
Пример #4
0
"""ORM for the sideband database """
#disabling some pylint checks due to this being a database model
#things like too few methods and invalid class attributes like id
# pylint: disable=too-few-public-methods
# pylint: disable=invalid-name

from peewee import MySQLDatabase, CharField
from peewee import IntegerField, BigIntegerField
from peewee import Model, CompositeKey, FloatField
from archiveinterface.archive_utils import read_config_value

MYSQL_ADDR = read_config_value('hms_sideband', 'host')
MYSQL_PORT = read_config_value('hms_sideband', 'port')
MYSQL_USER = read_config_value('hms_sideband', 'user')
MYSQL_PASS = read_config_value('hms_sideband', 'password')
MYSQL_SCHEMA = read_config_value('hms_sideband', 'schema')

DB = MySQLDatabase(MYSQL_SCHEMA,
                   host=MYSQL_ADDR,
                   port=int(MYSQL_PORT),
                   user=MYSQL_USER,
                   passwd=MYSQL_PASS)


class BaseModel(Model):
    """Base class models inherit from.  Has Connection pieces"""
    @classmethod
    def database_connect(cls):
        """Makes sure database is connected.  Dont reopen connection"""
        # pylint: disable=no-member
        if cls._meta.database.is_closed():
 def test_read_config_bad_section(self):
     """test reading from config file with bad section"""
     with self.assertRaises(ArchiveInterfaceError) as context:
         read_config_value('bad_section', 'port')
     self.assertTrue('Error reading config file, no section: bad_section',
                     context.exception)
 def test_read_config_file(self):
     """test reading from config file"""
     port = read_config_value('hms_sideband', 'port')
     self.assertEqual(port, '3306')