Skip to content
Snippets Groups Projects
Commit 408d24aa authored by Taya Snijder's avatar Taya Snijder
Browse files

merged master

parents 776d8a66 d38353a7
No related branches found
No related tags found
1 merge request!26Resolve #2021 "04 16 branched from master snmp device"
Showing with 1897 additions and 101 deletions
from threading import Thread
import socket
import time
import numpy
import opcua
from opcua import Client
from tango import DevState
class CommClient(Thread):
"""
......@@ -52,7 +44,6 @@ class CommClient(Thread):
# keep trying to connect
if not self.connected:
if self.connect():
# self.standby_func()
pass
else:
# we retry only once, to catch exotic network issues. if the infra or hardware is down,
......@@ -75,7 +66,7 @@ class CommClient(Thread):
self.fault_func()
def ping(self):
pass
return
def stop(self):
"""
......
......@@ -16,14 +16,14 @@ from tango.server import Device, command
from tango import DevState, DebugIt
# Additional import
from src.attribute_wrapper import *
from util.attribute_wrapper import attribute_wrapper
from util.lofar_logging import log_exceptions
__all__ = ["hardware_device"]
from src.wrappers import only_in_states
from util.wrappers import only_in_states, fault_on_error
#@log_exceptions()
class hardware_device(Device):
"""
......@@ -74,6 +74,8 @@ class hardware_device(Device):
@command()
@only_in_states([DevState.FAULT, DevState.OFF])
@DebugIt()
@fault_on_error()
@log_exceptions()
def Initialise(self):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
......@@ -87,20 +89,11 @@ class hardware_device(Device):
self.set_state(DevState.STANDBY)
# @only_in_states([DevState.INIT])
# def Standby(self):
# """
# Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
#
# :return:None
# """
#
# self.standby()
# self.set_state(DevState.STANDBY)
@command()
@only_in_states([DevState.STANDBY])
@DebugIt()
@fault_on_error()
@log_exceptions()
def On(self):
"""
Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
......@@ -112,6 +105,7 @@ class hardware_device(Device):
@command()
@DebugIt()
@log_exceptions()
def Off(self):
"""
Command to ask for shutdown of this device.
......@@ -133,6 +127,7 @@ class hardware_device(Device):
@command()
@only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY])
@DebugIt()
@log_exceptions()
def Fault(self):
"""
FAULT state is used to indicate our connection with the OPC-UA server is down.
......@@ -154,8 +149,6 @@ class hardware_device(Device):
pass
def on(self):
pass
def standby(self):
pass
def initialise(self):
pass
......
File moved
File moved
File moved
......@@ -22,12 +22,13 @@ def only_in_states(allowed_states):
return wrapper
def only_when_on(func):
def only_when_on():
"""
Wrapper to call and return the wrapped function if the device is
in the ON state. Otherwise None is returned and nothing
will be called.
"""
def inner(func):
@wraps(func)
def when_on_wrapper(self, *args, **kwargs):
if self.get_state() == DevState.ON:
......@@ -37,10 +38,13 @@ def only_when_on(func):
return when_on_wrapper
def fault_on_error(func):
return inner
def fault_on_error():
"""
Wrapper to catch exceptions. Sets the device in a FAULT state if any occurs.
"""
def inner(func):
@wraps(func)
def error_wrapper(self, *args, **kwargs):
try:
......@@ -51,3 +55,5 @@ def fault_on_error(func):
return None
return error_wrapper
return inner
This diff is collapsed.
version: '2'
services:
maria-db:
archiver-maria-db:
image: ${DOCKER_REGISTRY_HOST}/${DOCKER_REGISTRY_USER}/mariadb_hdbpp:latest
container_name: archiver-maria-db
network_mode: ${NETWORK_MODE}
......@@ -23,7 +23,7 @@ services:
depends_on:
- databaseds
- dsconfig
- maria-db
- archiver-maria-db
environment:
- TANGO_HOST=${TANGO_HOST}
- HdbManager=archiving/hdbpp/confmanager01
......@@ -40,7 +40,7 @@ services:
depends_on:
- databaseds
- dsconfig
- maria-db
- archiver-maria-db
environment:
- TANGO_HOST=${TANGO_HOST}
- HdbManager=archiving/hdbpp/confmanager01
......
......@@ -21,7 +21,6 @@ services:
- ${TANGO_LOFAR_CONTAINER_MOUNT}
environment:
- TANGO_HOST=${TANGO_HOST}
user: ${CONTAINER_EXECUTION_UID}
entrypoint:
- /usr/local/bin/wait-for-it.sh
- ${TANGO_HOST}
......
......@@ -21,7 +21,6 @@ services:
- ${TANGO_LOFAR_CONTAINER_MOUNT}
environment:
- TANGO_HOST=${TANGO_HOST}
user: ${CONTAINER_EXECUTION_UID}
entrypoint:
- /usr/local/bin/wait-for-it.sh
- ${TANGO_HOST}
......
......@@ -16,7 +16,7 @@ services:
depends_on:
- databaseds
- dsconfig
- maria-db
- archiver-maria-db
- hdbpp-es
- hdbpp-cm
volumes:
......
......@@ -28,7 +28,6 @@ services:
- TANGO_HOST=${TANGO_HOST}
- XAUTHORITY=${XAUTHORITY}
- DISPLAY=${DISPLAY}
user: ${CONTAINER_EXECUTION_UID}
stdin_open: true
tty: true
entrypoint:
......
......@@ -25,3 +25,7 @@ ENV TINI_VERSION v0.6.0
ENV JUPYTER_RUNTIME_DIR=/tmp
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN sudo chmod +x /usr/bin/tini
# Make sure Jupyter can write to the home directory
ENV HOME=/home/tango
RUN chmod a+rwx /home/tango
#! /usr/bin/env python3
import logging
def configure_logging():
# Always also log the hostname because it makes the origin of the log clear.
import socket
hostname = socket.gethostname()
# Set up logging in a way that it can be understood by a human reader, be
# easily grep'ed, be parsed with a couple of shell commands and
# easily fed into an Kibana/Elastic search system.
logging.basicConfig(format = '%(asctime)s.%(msecs)d %(levelname)s - HOST="{}" PID="%(process)d" TNAME="%(threadName)s" TID="%(thread)d" FILE="%(pathname)s" LINE="%(lineno)d" FUNC="%(funcName)s" MSG="%(message)s"'.format(hostname), datefmt = '%Y-%m-%dT%H:%M:%S', level = logging.INFO, Force = True)
#! /usr/bin/env python3
def startup(device: str, force_restart: bool):
'''
Start a LOFAR Tango device:
pcc = startup(device = 'LTS/PCC/1', force_restart = False)
'''
import tango
proxy = tango.DeviceProxy(device)
state = proxy.state()
if force_restart is True:
print("Forcing device {} restart.".format(device))
proxy.off()
state = proxy.state()
if state is not tango._tango.DevState.OFF:
print("Device {} cannot perform off although restart has been enforced, state = {}. Please investigate.".format(device, state))
return proxy
if state is not tango._tango.DevState.OFF:
print("Device {} is not in OFF state, cannot start it. state = {}".format(device, state))
return proxy
print("Device {} is in OFF, performing initialisation.".format(device))
proxy.initialise()
state = proxy.state()
if state is not tango._tango.DevState.STANDBY:
print("Device {} cannot perform initialise, state = {}. Please investigate.".format(device, state))
return proxy
print("Device {} is in STANDBY, performing on.".format(device))
proxy.on()
state = proxy.state()
if state is not tango._tango.DevState.ON:
print("Device {} cannot perform on, state = {}. Please investigate.".format(device, state))
else:
print("Device {} has successfully reached ON state.".format(device))
return proxy
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment