From a4d156744ca30ed8577ec69cc04ee34871107862 Mon Sep 17 00:00:00 2001 From: Stanislaw Cabala Date: Tue, 18 Feb 2020 13:25:43 +0100 Subject: [PATCH 1/6] Add Dockerfile for docker image build (dependencies) --- .dockerignore | 5 +++++ Dockerfile | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..921722e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +.gitignore +.git/ +LICENSE.txt +README.md +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..adfa7fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3 + +# TODO: determine and pin versions +RUN apk update \ + && apk add --no-cache py3-zmq \ + && pip3 install -U --no-cache \ + aiozmq==0.7.1 \ + && adduser -D runner + +USER runner From 922f4f52950101b238a3e0578ab9f1072fae4657 Mon Sep 17 00:00:00 2001 From: Stanislaw Cabala Date: Tue, 18 Feb 2020 13:25:58 +0100 Subject: [PATCH 2/6] Add testing environment using docker-compose --- docker-compose.yml | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fb3996a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,90 @@ +version: "3" + +networks: + net-int: + driver: bridge + net-ext: + driver: bridge + +services: + + database: + image: tangocs/mysql:latest + environment: + - MYSQL_ALLOW_EMPTY_PASSWORD=1 + networks: + - net-int + + control-system: + image: tangocs/tango-cs:latest + environment: + - ORB_PORT=10000 + - TANGO_HOST=127.0.0.1:10000 + - MYSQL_HOST=database:3306 + - MYSQL_USER=tango + - MYSQL_PASSWORD=tango + - MYSQL_DATABASE=tango + networks: + - net-int + + tango-test: + image: tangocs/tango-test:latest + environment: + - TANGO_HOST=control-system:10000 + depends_on: + - control-system + networks: + - net-int + command: ["test", "-v4"] + + jive: + image: tangocs/tango-jive + networks: + - net-int + depends_on: + - control-system + environment: + TANGO_HOST: control-system:10000 + DISPLAY: :0 + _JAVA_OPTIONS: '-Dawt.useSystemAAFontSettings=lcd' + volumes: + - /tmp/.X11-unix:/tmp/.X11-unix + + pytango-in : + image: tangocs/tango-pytango + networks: + - net-int + depends_on: + - control-system + environment: + TANGO_HOST: control-system:10000 + command: ["sleep", "3600"] + + pytango-ext : + image: tangocs/tango-pytango + networks: + - net-ext + depends_on: + - gateway + environment: + TANGO_HOST: gateway:10000 + command: ["sleep", "3600"] + + gateway: + build: + context: . + hostname: gateway + networks: + - net-int + - net-ext + restart: on-failure + depends_on: + - control-system + working_dir: /mnt + environment: + TANGO_GATEWAY_BIND: 0.0.0.0 + TANGO_GATEWAY_PORT: 1000 + TANGO_GATEWAY_HOST: control-system:10000 + command: ["python3", "-m", "tangogateway", "--verbose"] + volumes: + - ./tangogateway:/mnt/tangogateway From 9916459006d2e71be7296d84dfbac2d8e22d5ec8 Mon Sep 17 00:00:00 2001 From: Stanislaw Cabala Date: Tue, 18 Feb 2020 13:28:03 +0100 Subject: [PATCH 3/6] Fix port number --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index fb3996a..3bc0477 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -83,7 +83,7 @@ services: working_dir: /mnt environment: TANGO_GATEWAY_BIND: 0.0.0.0 - TANGO_GATEWAY_PORT: 1000 + TANGO_GATEWAY_PORT: 10000 TANGO_GATEWAY_HOST: control-system:10000 command: ["python3", "-m", "tangogateway", "--verbose"] volumes: From a1eb063ad83880915d7c601ef3de9ff4f6a82773 Mon Sep 17 00:00:00 2001 From: Stanislaw Cabala Date: Tue, 18 Feb 2020 13:49:31 +0100 Subject: [PATCH 4/6] Add documentation section --- README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/README.md b/README.md index 69195b7..fa61f4b 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,25 @@ optional arguments: Tango host (default is given by PyTango) ``` +Local testing +------------- + +Developer can test this project locally by using minimal control system set up with ``docker-compose`` + +Requirements: + +- docker +- docker-compose + +To set up testing environment, run `docker-compose up -d` in project root directory. + +To see logs from Tango Gateway in real time, run `docker-compose logs -f gateway`. + +Test environment is separated in two netwroks: `net-int` and `net-ext`. `net-int` is internal network for Tango Control System. +It consists of all services needed by Tango Control System like DatabaseDs, Jive, etc. +Other network, `net-ext`, is separated from control system. Only joint point is `gateway` container. It has access to both networks. +There are to client services, `pytango-in` and `pytango-ext`, both placed in different networks. They can be used for +connectivity tests. Contact ------- From 6310d189fc8d991b4438a27e179da8f8ca9532ba Mon Sep 17 00:00:00 2001 From: Stanislaw Cabala Date: Wed, 10 Jun 2020 17:39:10 +0200 Subject: [PATCH 5/6] Add script for testing event subscription --- sub/sub.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 sub/sub.py diff --git a/sub/sub.py b/sub/sub.py new file mode 100644 index 0000000..151c684 --- /dev/null +++ b/sub/sub.py @@ -0,0 +1,91 @@ +#!/usr/bin/env python3 + +import tango +import datetime +import argparse +import time + + +EVENT_TYPES = {"periodic": tango.EventType.PERIODIC_EVENT, + "change": tango.EventType.CHANGE_EVENT, + "archive": tango.EventType.ARCHIVE_EVENT, + "data_ready": tango.EventType.DATA_READY_EVENT} + +# PIPE_EVENT +# ATTR_CONF_EVENT +# QUALITY_EVENT +# USER_EVENT +# INTERFACE_CHANGE_EVENT + + +def echo(event): + """ + Event subscribtion callabck, print all relevant info + :param event: + :return: + """ + + print(datetime.datetime.now()) + print(event) + print("To exit use Ctrl+C!") + + +def sub_pull(attr, evt_type, sleep): + ap = tango.AttributeProxy(attr) + + evt_id = ap.subscribe_event(EVENT_TYPES[evt_type], 1) + + try: + while True: + if not ap.is_event_queue_empty(evt_id): + print("Extracting event") + print("Processing event: " + str(datetime.datetime.now())) + print("Event time: " + str(ap.get_last_event_date(evt_id))) + events = ap.get_events(event_id=evt_id) + print(events[0].attr_value.value) + else: + print("No event") + print(datetime.datetime.now()) + time.sleep(sleep) + + except KeyboardInterrupt: + ap.unsubscribe_event(evt_id) + print("Unbsubscribing for %s event on attribute %s" % (evt_type, attr)) + + +def sub_push(attr, evt_type): + ap = tango.AttributeProxy(attr) + + evt_id = ap.subscribe_event(EVENT_TYPES[evt_type], echo) + + try: + while True: + pass + + except KeyboardInterrupt: + ap.unsubscribe_event(evt_id) + print("Unbsubscribing for %s event on attribute %s" % (evt_type, attr)) + + +def main(attr, evt_type, push, pull): + try: + if push: + sub_push(attr, evt_type) + else: + sub_pull(attr, evt_type, pull) + + except TypeError: + print("Error with parsing attribute!") + + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Simple script for testing Tango events") + parser.add_argument('attribute', help='device attribute name to test') + parser.add_argument('event_type', choices=['periodic', 'change', 'archive'], help='type of event') + group = parser.add_mutually_exclusive_group(required=True) + group.add_argument("--push", action="store_true", help="Subscribe in push mode") + group.add_argument("--pull", type=float, help="Subscribe in pull mode. Provide value of loop time") + + args = parser.parse_args() + main(args.attribute, args.event_type, args.push, args.pull) + From 4ef45367ea2409546467988b0f9ff69b0115f2c6 Mon Sep 17 00:00:00 2001 From: Stanislaw Cabala Date: Wed, 10 Jun 2020 17:46:47 +0200 Subject: [PATCH 6/6] Make test environment work --- docker-compose.yml | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3bc0477..a4070b9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,7 +58,10 @@ services: - control-system environment: TANGO_HOST: control-system:10000 - command: ["sleep", "3600"] + command: ["sleep", "infinity"] + working_dir: /mnt + volumes: + - ./sub:/mnt/ pytango-ext : image: tangocs/tango-pytango @@ -67,16 +70,19 @@ services: depends_on: - gateway environment: - TANGO_HOST: gateway:10000 - command: ["sleep", "3600"] + TANGO_HOST: tango-gateway_gateway_1.tango-gateway_net-ext:10000 # if you change docker-compose project name (i.e. change parent folder name) you have to modify it accordingly + command: ["sleep", "infinity"] + working_dir: /mnt + volumes: + - ./sub:/mnt/ gateway: build: context: . hostname: gateway networks: - - net-int - - net-ext + net-ext: + priority: 1000 # this makes this interface first - make CORBA working restart: on-failure depends_on: - control-system @@ -84,7 +90,7 @@ services: environment: TANGO_GATEWAY_BIND: 0.0.0.0 TANGO_GATEWAY_PORT: 10000 - TANGO_GATEWAY_HOST: control-system:10000 + TANGO_GATEWAY_HOST: tango-gateway_control-system_1.tango-gateway_net-in:10000 # if you change docker-compose project name (i.e. change parent folder name) you have to modify it accordingly command: ["python3", "-m", "tangogateway", "--verbose"] volumes: - ./tangogateway:/mnt/tangogateway