def __init__(self, config=None, param_dict=None, instrument=None):
        logger.info('--> building class SpiacsDispatcher instrument: %s config: %s', instrument, config)

        self.param_dict = param_dict

        
        config = DataServerConf(data_server_url=instrument.data_server_conf_dict['data_server_url'],
                                dummy_cache=instrument.data_server_conf_dict['dummy_cache'])

        logger.info('--> config passed to init %s', config)

        if config is not None:
            pass

        elif instrument is not None and hasattr(instrument, 'data_server_conf_dict'):

            logger.info('--> from data_server_conf_dict')
            try:
                # config = DataServerConf(data_server_url=instrument.data_server_conf_dict['data_server_url'],
                #                        data_server_port=instrument.data_server_conf_dict['data_server_port'])

                config = DataServerConf(data_server_url=instrument.data_server_conf_dict['data_server_url'],
                                        data_server_port=instrument.data_server_conf_dict['data_server_port'])
                # data_server_remote_cache=instrument.data_server_conf_dict['data_server_cache'],
                # dispatcher_mnt_point=instrument.data_server_conf_dict['dispatcher_mnt_point'],
                # s dummy_cache=instrument.data_server_conf_dict['dummy_cache'])

                logger.info('config %s', config)
                for v in vars(config):
                    logger.info('attr: %s = %s', v, getattr(config, v))

            except Exception as e:
                raise RuntimeError(f"failed to use config {e}")

        elif instrument is not None:
            try:
                print('--> plugin_conf_file', plugin_conf_file)
                config = instrument.from_conf_file(plugin_conf_file)

            except Exception as e:
                raise RuntimeError(f"failed to use config {e}")

        else:

            raise SpiacsException(message='instrument cannot be None',
                                  debug_message='instrument se to None in SpiacsDispatcher __init__')

        try:
            _data_server_url = config.data_server_url
            _data_server_port = config.data_server_port

        except Exception as e:
            #    #print(e)

            print("ERROR->")
            raise RuntimeError(f"failed to use config {e}")

        self.config(_data_server_url, _data_server_port)

        logger.info("data_server_url: %s", self.data_server_url)
def test_dsconf_pass_keys():
    conf_dict = {
        'data_server_url': 'https://data-server:5000',
        'dummy_cache': 'dummy_cache',
        'required_key': 'required_value',
        'extra_key': 'extra_value'
    }
    required_keys = ['data_server_url', 'dummy_cache', 'required_key']
    allowed_keys = required_keys + ['extra_key']
    conf = DataServerConf.from_conf_dict(conf_dict, required_keys,
                                         allowed_keys)

    conf_dict['spam'] = 'eggs'
    with pytest.raises(KeyError):
        conf = DataServerConf.from_conf_dict(conf_dict, required_keys,
                                             allowed_keys)
def test_dsconf_allowed_key():
    conf_dict = {
        'data_server_url': 'https://data-server:5000',
        'dummy_cache': 'dummy_cache',
        'data_server_cache': 'reduced/ddcache'
    }
    conf = DataServerConf.from_conf_dict(conf_dict)
def test_dsconf_required_warning(caplog, dispatcher_debug):
    conf_dict = {
        'data_server_url': 'https://data-server:5000',
        'dummy_cache': None
    }
    conf = DataServerConf.from_conf_dict(conf_dict)
    assert "required configuration" in caplog.text
Beispiel #5
0
    def get_dummy_products(self, instrument, config, out_dir='./',prod_prefix='polar',api=False):
        config = DataServerConf(data_server_url=instrument.data_server_conf_dict['data_server_url'],
                                data_server_port=instrument.data_server_conf_dict['data_server_port'],
                                data_server_remote_cache=instrument.data_server_conf_dict['data_server_cache'],
                                dispatcher_mnt_point=instrument.data_server_conf_dict['dispatcher_mnt_point'],
                                dummy_cache=instrument.data_server_conf_dict['dummy_cache'])
        #print('config',config)
        meta_data = {'product': 'light_curve', 'instrument': 'isgri', 'src_name': ''}
        meta_data['query_parameters'] = self.get_parameters_list_as_json()

        dummy_cache = config.dummy_cache

        res = DummyPolarRes()
        res.__setattr__('dummy_src', 'dummy_src')
        res.__setattr__('dummy_lc', '%s/polar_query_lc.fits' % dummy_cache)
        res.__setattr__('dummy_root', '%s/polar_query_lc.root' % dummy_cache)
        res.__setattr__('extracted_sources', [('dummy_src', 'dummy_lc')])

        prod_list=PolarLigthtCurve.build_from_res(res,
                                        src_name='lc',
                                        prod_prefix=prod_prefix,
                                        out_dir=out_dir,
                                        skip_root=True)



        prod_list = QueryProductList(prod_list=prod_list)
        #
        return prod_list
def test_dsconf_bad_key():
    conf_dict = {
        'data_server_url': 'https://data-server:5000',
        'dummy_cache': 'dummy_cache',
        'spam': 'eggs'
    }
    with pytest.raises(KeyError):
        conf = DataServerConf.from_conf_dict(conf_dict)
def test_dsconf_obsolete_warning(caplog):
    conf_dict = {
        'data_server_url': 'https://data-server:5000',
        'dummy_cache': 'dummy_cache',
        'data_server_port': '5000'
    }
    conf = DataServerConf.from_conf_dict(conf_dict)
    assert "disregarded" in caplog.text
def test_dsconf_legacy_plugin_keys(caplog):
    conf = DataServerConf(data_server_url="eggs",
                          data_server_port="bacon",
                          data_server_remote_cache=None,
                          dispatcher_mnt_point=None,
                          dummy_cache="spam")

    assert conf.data_server_port is None
    assert conf.data_server_host is None
    assert 'attempting to access obsolete key data_server_port, returning None' in caplog.text
    assert 'attempting to access obsolete key data_server_host, returning None' in caplog.text

    with pytest.raises(AttributeError):
        conf.data_server_spam
def test_dsconf_integral_osa(tmpdir):
    conf_dict = {
        'data_server_url': 'https://data-server:5000',
        'dispatcher_mnt_point': 'data',
        'data_server_remote_cache': 'reduced/ddcache',
        'dummy_cache': 'data/dummy_prods',
    }
    os.chdir(tmpdir)
    conf = DataServerConf.from_conf_dict(conf_dict)
    assert conf.dummy_cache == conf_dict['dummy_cache']
    assert conf.data_server_url == conf_dict['data_server_url']
    assert conf.data_server_remote_path == conf_dict[
        'data_server_remote_cache']
    assert os.path.isdir(conf_dict['dispatcher_mnt_point'])
def test_dsconf_required_error(caplog, dispatcher_nodebug):
    conf_dict = {'data_server_url': 'https://data-server:5000'}
    with pytest.raises(KeyError):
        conf = DataServerConf.from_conf_dict(conf_dict)
def test_dsconf_lost_url():
    conf_dict = {
        'dummy_cache': 'dumme_cache',
    }
    with pytest.raises(KeyError):
        DataServerConf.from_conf_dict(conf_dict)
Beispiel #12
0
    def __init__(self,
                 config=None,
                 use_dicosverer=False,
                 target=None,
                 modules=[],
                 assume=[],
                 inject=[],
                 instrument=None):

        self.target = target
        self.modules = modules
        self.assume = assume
        self.inject = inject

        self._test_products_with_astroquery = True

        config = None

        if instrument is not None and hasattr(instrument,
                                              'data_server_conf_dict'):
            try:
                config = DataServerConf(
                    data_server_url=instrument.
                    data_server_conf_dict['data_server_url'],
                    data_server_remote_cache=instrument.
                    data_server_conf_dict['data_server_cache'],
                    dispatcher_mnt_point=instrument.
                    data_server_conf_dict['dispatcher_mnt_point'],
                    dummy_cache=instrument.
                    data_server_conf_dict['dummy_cache'],
                    allowed_keys=[
                        "data_server_remote_cache", "dispatcher_mnt_point"
                    ],
                )

                logger.info(
                    "built config from instrument.data_server_conf_dict: %s, config: %s",
                    instrument.data_server_conf_dict, config)

            except Exception as e:
                logger.error("problem building config with DataServerConf: %s",
                             e)
                raise

        elif instrument is not None:
            try:
                config = instrument.from_conf_file(plugin_conf_file)
                logger.info(
                    "succeeded to instrument.from_conf_file from {plugin_conf_file}: {config}"
                )
            except Exception as e:
                raise RuntimeError(
                    f"failed to instrument.from_conf_file from {plugin_conf_file}: {e}"
                )

        else:
            raise RequestNotUnderstood(
                message='instrument cannot be None',
                debug_message='instrument set to None in OsaDispatcher __init__'
            )

        try:
            _data_server_url = config.data_server_url
            _data_server_cache = config.data_server_cache

            if _data_server_url is None or _data_server_cache is None:
                raise Exception(
                    f"some config values are not set, loading from {config}")

        except Exception as e:
            logger.error("problem loading config with %s: %s", config, e)
            raise

        self.config(_data_server_url, _data_server_cache)
Beispiel #13
0
    def __init__(self, config=None, param_dict=None, instrument=None):
        print('--> building class SpiacsDispatcher', instrument, config)

        simple_logger.log()
        simple_logger.logger.setLevel(logging.ERROR)

        self.param_dict = param_dict

        #resp = urlopen("http://isdc.unige.ch/~savchenk/spiacs-online/spiacs.pl",
        #           urlencode({"requeststring": utc, 'submit': "Submit", 'generate': 'ipnlc'})).read()

        config = DataServerConf(
            data_server_url=instrument.
            data_server_conf_dict['data_server_url'],
            data_server_port=instrument.
            data_server_conf_dict['data_server_port'],
            data_server_remote_cache=instrument.
            data_server_conf_dict['data_server_cache'],
            dispatcher_mnt_point=instrument.
            data_server_conf_dict['dispatcher_mnt_point'],
            dummy_cache=instrument.data_server_conf_dict['dummy_cache'])
        #for v in vars(config):
        #   print('attr:', v, getattr(config, v))

        print('--> config passed to init', config)

        if config is not None:

            pass

        elif instrument is not None and hasattr(instrument,
                                                'data_server_conf_dict'):

            print('--> from data_server_conf_dict')
            try:
                #config = DataServerConf(data_server_url=instrument.data_server_conf_dict['data_server_url'],
                #                        data_server_port=instrument.data_server_conf_dict['data_server_port'])

                config = DataServerConf(
                    data_server_url=instrument.
                    data_server_conf_dict['data_server_url'],
                    data_server_port=instrument.
                    data_server_conf_dict['data_server_port'])
                # data_server_remote_cache=instrument.data_server_conf_dict['data_server_cache'],
                # dispatcher_mnt_point=instrument.data_server_conf_dict['dispatcher_mnt_point'],
                #s dummy_cache=instrument.data_server_conf_dict['dummy_cache'])

                print('config', config)
                for v in vars(config):
                    print('attr:', v, getattr(config, v))

            except Exception as e:
                #    #print(e)

                print("ERROR->")
                raise RuntimeError("failed to use config ", e)

        elif instrument is not None:
            try:
                print('--> plugin_conf_file', plugin_conf_file)
                config = instrument.from_conf_file(plugin_conf_file)

            except Exception as e:
                #    #print(e)

                print("ERROR->")
                raise RuntimeError("failed to use config ", e)

        else:

            raise SpiacsException(
                message='instrument cannot be None',
                debug_message=
                'instrument se to None in SpiacsDispatcher __init__')

        try:
            _data_server_url = config.data_server_url
            _data_server_port = config.data_server_port

        except Exception as e:
            #    #print(e)

            print("ERROR->")
            raise RuntimeError("failed to use config ", e)

        self.config(_data_server_url, _data_server_port)

        print("data_server_url:", self.data_server_url)
        #print("dataserver_cache:", self.dataserver_cache)
        print("dataserver_port:", self.data_server_port)
        print('--> done')
Beispiel #14
0
    def __init__(self,
                 config=None,
                 task=None,
                 param_dict=None,
                 instrument=None):
        print('--> building class PolarDispatcher', instrument, config)

        simple_logger.log()
        simple_logger.logger.setLevel(logging.ERROR)

        self.task = task

        self.param_dict = param_dict

        #print ('TEST')
        #for k in instrument.data_server_conf_dict.keys():
        #   print ('dict:',k,instrument.data_server_conf_dict[k ])

        config = DataServerConf(
            data_server_url=instrument.
            data_server_conf_dict['data_server_url'],
            data_server_port=instrument.
            data_server_conf_dict['data_server_port'],
            data_server_remote_cache=instrument.
            data_server_conf_dict['data_server_cache'],
            dispatcher_mnt_point=instrument.
            data_server_conf_dict['dispatcher_mnt_point'],
            dummy_cache=instrument.data_server_conf_dict['dummy_cache'])
        #for v in vars(config):
        #   print('attr:', v, getattr(config, v))

        print('--> config passed to init', config)

        if config is not None:

            pass

        elif instrument is not None and hasattr(instrument,
                                                'data_server_conf_dict'):

            print('--> from data_server_conf_dict')
            try:
                #config = DataServerConf(data_server_url=instrument.data_server_conf_dict['data_server_url'],
                #                        data_server_port=instrument.data_server_conf_dict['data_server_port'])

                config = DataServerConf(
                    data_server_url=instrument.
                    data_server_conf_dict['data_server_url'],
                    data_server_port=instrument.
                    data_server_conf_dict['data_server_port'])
                # data_server_remote_cache=instrument.data_server_conf_dict['data_server_cache'],
                # dispatcher_mnt_point=instrument.data_server_conf_dict['dispatcher_mnt_point'],
                #s dummy_cache=instrument.data_server_conf_dict['dummy_cache'])

                print('config', config)
                for v in vars(config):
                    print('attr:', v, getattr(config, v))

            except Exception as e:
                #    #print(e)

                print("ERROR->")
                raise RuntimeError("failed to use config ", e)

        elif instrument is not None:
            try:
                print('--> plugin_conf_file', plugin_conf_file)
                config = instrument.from_conf_file(plugin_conf_file)

            except Exception as e:
                #    #print(e)

                print("ERROR->")
                raise RuntimeError("failed to use config ", e)

        else:

            raise PolarException(
                message='instrument cannot be None',
                debug_message=
                'instrument se to None in PolarDispatcher __init__')

        try:
            _data_server_url = config.data_server_url
            _data_server_port = config.data_server_port

        except Exception as e:
            #    #print(e)

            print("ERROR->")
            raise RuntimeError("failed to use config ", e)

        self.config(_data_server_url, _data_server_port)

        print("data_server_url:", self.data_server_url)
        #print("dataserver_cache:", self.dataserver_cache)
        print("dataserver_port:", self.data_server_port)
        print('--> done')