Esempio n. 1
0
 def test_S_wrong_file02(self, tmpdir: py.path.local) -> None:
     "A serverconfig file with missing keywords should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = dict(VERSION=99)
     yamlutil.writeyamlfile(dd, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(fname)
Esempio n. 2
0
 def test_S_wrong_file01(self, tmpdir: py.path.local) -> None:
     "A serverconfig file containing an unknown keyword should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = dict(FUNNY=99)
     yamlutil.writeyamlfile(dd, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(fname)
Esempio n. 3
0
 def test_S_wrong_file03(self, tmpdir: py.path.local) -> None:
     "A serverconfig file containing a list should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = dict(a=1, b=2, gg=77)
     data = [1, 2, 3, 4, dd]
     yamlutil.writeyamlfile(data, fname)
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(fname)
Esempio n. 4
0
 def test_S_wrong_values01(self, tmpdir: py.path.local) -> None:
     "A serverconfig file with the wrong values should raise an error."
     fname = str(tmpdir.join('/bla.yaml'))
     dd = serverconfig.read_server_config(
         get_testfilename('test02.OK.yaml'))
     # remove keys that are not meant to be on file...
     dnew = dict(
         [tt for tt in dd.items() if tt[0] in serverconfig.known_set])
     for k, brokenval in [('VERSION', serverconfig.VERSION_FLT + 0.1),
                          ('RFID_REGION_CODE', 'blaa'), ('TIME_ZONE', '?'),
                          ('TIME_ZONE', 'moon')]:
         # with mock.patch.dict(dnew, values={k: brokenval}):
         with mock.patch.dict(dnew, {k: brokenval}):
             yamlutil.writeyamlfile(dnew, fname)
             with pytest.raises(RuntimeError):
                 serverconfig.read_server_config(fname)
Esempio n. 5
0
 def test_S_should_work(self) -> None:
     "Should be able to read a correct serverconfig file."
     retdct = serverconfig.read_server_config(
         get_testfilename('test02.OK.yaml'))
     assert isinstance(retdct, dict), "dict expected"
     got_set = set(retdct.keys())
     assert got_set == serverconfig.valid_keys, "unexpected keys"
Esempio n. 6
0
    def __init__(self, logger: logging.Logger, cfgname: str) -> None:
        """

        Args:
           logger: a logging instance
           cfgname: the name of the server configuration file (a YAML file)

        This class pull all of the data streams together and passes data
        between the actors. When first instantiated, this class performs
        the following.
          - a configuration file is read in
          - a message queue is instantiated
          - a connection to the RFID reader \
            (via a commlink instance passed to a TLSReader) is established.
          - a way of calling to the QAI API is established.
          - a local database of chemical stocks is opened.

        """
        print("Begin CommonStockyServer")
        super().__init__(logger, "Johnny")
        self.logger.info(
            "serverclass: reading config file '{}'".format(cfgname))
        try:
            self.cfg_dct = serverconfig.read_server_config(cfgname)
        except RuntimeError as err:
            self.logger.error(
                "Error reading server config file: {}".format(err))
            raise
        self.cfg_dct['logger'] = self.logger
        self.logger.debug("serverclass: config file read...{}".format(
            self.cfg_dct))
        timelib.set_local_timezone(self.cfg_dct['TZINFO'])

        # create a timer tick for use in radar mode
        self.logger.info("Instantiating Tickgenerator")
        self.timer_tm = Taskmeister.TickGenerator(self.msgQ, self.logger, 1,
                                                  'radartick')
        self.timer_tm.set_active(False)
        self.logger.info("End of serverclass.__init__")

        self.comm_link: typing.Optional[commlink.BaseCommLink] = None
        self.tls: typing.Optional[TLSAscii.TLSReader] = None
        print("Begin CommonStockyServer")
Esempio n. 7
0
def main():
    p = argparse.ArgumentParser(description=desc_str, epilog=epilog_str)
    p.add_argument("-s", "--qaiurl", help="The URL of the QAI server to poll")
    p.add_argument("-u", "--username", help="The QAI user name")
    p.add_argument("-p", "--passwd", help="The QAI user password")
    args = p.parse_args()
    lverb = True
    cfgname = 'serverconfig.yaml'
    cfg_dct = serverconfig.read_server_config(cfgname)
    print("args: {}".format(args))
    if args.qaiurl is None or args.username is None or args.passwd is None:
        raise RuntimeError('missing arguments')

    qai_sess = qai_helper.QAISession(args.qaiurl)
    qai_sess.login(args.username, args.passwd)

    locdbname = cfg_dct['LOCAL_STOCK_DB_FILE']
    print("dumping to local SQL file: {}".format(locdbname))
    csdb = ChemStock.ChemStockDB(locdbname, qai_sess, 'America/Vancouver')
    if lverb:
        print("downloading from QAI...")
    csdb.update_from_QAI()
    if lverb:
        print("OK")
Esempio n. 8
0
 def test_S_old_version(self) -> None:
     "A serverconfig file with an out-dated version should raise a runtime error"
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(
             get_testfilename('test02.old_version.yaml'))
Esempio n. 9
0
 def test_S_missing_KW(self) -> None:
     "A missing keyword in a serverconfig file should raise a runtime error"
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(
             get_testfilename('test01.fail.yaml'))
Esempio n. 10
0
 def test_S_missing_file(self) -> None:
     "A missing serverconfig file should raise an error"
     with pytest.raises(RuntimeError):
         serverconfig.read_server_config(
             get_testfilename('test0.not_there.yaml'))