Commit c3d7023c authored by julian.gethmann's avatar julian.gethmann

Use environment variable hostname and port

parent 8c1ac400
......@@ -8,6 +8,7 @@ Changelog
------------------
* Add `fillingpattern` PV
* Add `connected` command line tool
* Add environment variable support for `CASSANDRA_HOST` and `CASSANDRA_PORT`
0.7.2 (2018-05-25)
------------------
......
......@@ -21,6 +21,8 @@ from __future__ import with_statement
import datetime
import json
import logging
import os
from collections import namedtuple
from os import path
from sys import version_info
......@@ -104,6 +106,16 @@ class Pvs(object):
"clic_I2": "A:ID-S1:Wig:01:PS2:Current:Readback",
"clic_I3": "A:ID-S1:Wig:01:PS3:Current:Readback",
"clic_I4": "A:ID-S1:Wig:01:PS4:Current:Readback",
"clic_I11p_temp": "A:ID-S1:Wig:01:JB:Temp:08",
"clic_I12p_temp": "A:ID-S1:Wig:01:JB:Temp:10",
"clic_I11m_temp": "A:ID-S1:Wig:01:JB:Temp:09",
"clic_I12m_temp": "A:ID-S1:Wig:01:JB:Temp:11",
"clic_I21p_temp": "A:ID-S1:Wig:01:JB:Temp:04",
"clic_I22p_temp": "A:ID-S1:Wig:01:JB:Temp:06",
"clic_I21m_temp": "A:ID-S1:Wig:01:JB:Temp:05",
"clic_I22m_temp": "A:ID-S1:Wig:01:JB:Temp:07",
"clic_cooler4": "A:ID-S1:Wig:01:JB:Temp:19",
"clic_cooler3": "A:ID-S1:Wig:01:JB:Temp:18",
"clic_he_bar": "A:ID-S1:Wig:01:JB:Pressure:Abs",
"clic_iso_vac_mbar": "A:ID-S1:Wig:01:JB:Pressure:Vac",
"delta_ps1": "A:ID-S1:PS:MCV-01:Current",
......@@ -314,6 +326,10 @@ class Cassandra(object):
Can also be used as a context manager that returns the :func:`get_json_local`.
.. versionchanged:: 0.7.3
If the environment variables `CASSANDRA_HOST` is set that will be used as
the HOSTNAME. Similar for `CASSANDRA_PORT`.
Raises:
URLError: in case the connection times out (e.g. if one has not
connected to the IBPT-LAN)
......@@ -327,8 +343,9 @@ class Cassandra(object):
>>> clic_field
dataset(timestamps=[datetime.datetime(2016, 4, 13, 10, 59, 59, 250177), datetime.datetime(2016, 4, 13, 11, 0, 0, 250285), datetime.datetime(2016, 4, 13, 11, 0, 1, 250484)], values=[0.9991628617721655, 0.9992209719948126, 0.9991912895254449])
"""
HOSTNAME = "ankasr-archiver.anka.kit.edu"
PORT = 9812
HOSTNAME = str(os.environ.get("CASSANDRA_HOST", "ankasr-archiver.anka.kit.edu"))
PORT = int(os.environ.get("CASSANDRA_PORT", 9812))
logging.debug("Hostname: {}:{}".format(HOSTNAME, PORT))
RETRIES = 10
def __init__(
......
......@@ -8,6 +8,7 @@
import datetime
import json
import os
from importlib import reload
import cassandra
import pytest
......@@ -83,6 +84,23 @@ class TestCassandraClass(object):
monkeypatch.setattr(request, "urlopen", request_openurl)
assert cas.check_connection()
@pytest.fixture(scope="function")
def env(self, monkeypatch):
with monkeypatch.context() as m:
m.setenv("CASSANDRA_HOST", "test")
m.setenv("CASSANDRA_PORT", "1234")
reload(cassandra.cassandra)
yield
reload(cassandra.cassandra)
def test_environment(self, setup_, env):
start, end, pv = setup_
cas = cassandra.cassandra.Cassandra(start, end, pv)
assert cas.HOSTNAME == "test"
assert cas.PORT == 1234
def test_download_cassandra_data_online(self, cas, monkeypatch):
with open(
os.path.dirname(os.path.abspath(__file__)) +
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment