Skip to content

Commit

Permalink
code for testing
Browse files Browse the repository at this point in the history
Uses docker to up two recceivers and channelfinder
  • Loading branch information
jacomago committed Apr 17, 2024
1 parent 1f73833 commit 80abf12
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 11 deletions.
22 changes: 22 additions & 0 deletions server/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM python:3.8 as build

WORKDIR /home/recceiver

COPY . ./server

RUN python -m venv venv && \
venv/bin/pip install \
--no-cache-dir \
-i https://artifactory.esss.lu.se/artifactory/api/pypi/pypi-virtual/simple \
-r server/requirements.txt

RUN venv/bin/python -m pip install ./server

FROM python:3.8-slim

WORKDIR /home/recceiver

COPY --from=build /home/recceiver/venv venv

CMD venv/bin/twistd --pidfile= --nodaemon recceiver --config cf.conf

4 changes: 3 additions & 1 deletion server/README → server/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
Server testing
# Recceiver

## Server testing

Setup

Expand Down
60 changes: 60 additions & 0 deletions server/cf1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# run with
#twistd -n recceiver -f <thisfile>.conf

[recceiver]

# list of broadcast addresses.
# default
#addrlist = 255.255.255.255:5049
# for local testing w/ firewall
#addrlist = 127.255.255.255:5049

# Listen for TCP connections on this interface and port.
# Port also used as source for UDP broadcasts.
# Default uses wildcard address and a random port.
#bind = 0.0.0.0:0

# Processing chain
procs = cf

# Time interval for sending recceiver advertisments
#announceInterval = 15.0

# Idle Timeout for TCP connections.
#tcptimeout = 15.0

# Time to wait before commiting updates
# Doesn't effect IOC clients
#commitInterval = 5.0

# Maximum concurrent "active" clients
# to allow.
#maxActive = 20

# The channelFinder client is configuration information is
# stored in /etc/channelfinderapi.conf as described in the client

[cf]
# a space-separated list of infotags to set as CF Properties
#infotags = archive foo bar blah
# List environment variables that should be written as channel finder properties
#
# Comma-separated list of VARIABLE:PropertyName,
# specifying which environment VARIABLEs to pass on to the channel finder
# and defining the corresponding PropertyName
#environment_vars=ENGINEER:Engineer,EPICS_BASE:EpicsVersion,PWD:WorkingDirectory
# Turn on optional alias and recordType properties
#alias = on
#recordType = on
#recordDesc = on

# Mark all channels as 'Inactive' when processor is stopped (default: True)
cleanOnStop = True
# Mark all channels as 'Inactive' when processor is started (default: True)
#cleanOnStart = True

recceiverID = recc1
[DEFAULT]
BaseURL = http://cf:8080/ChannelFinder
username = admin
password = password
61 changes: 61 additions & 0 deletions server/cf2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# run with
#twistd -n recceiver -f <thisfile>.conf

[recceiver]

# list of broadcast addresses.
# default
#addrlist = 255.255.255.255:5049
# for local testing w/ firewall
#addrlist = 127.255.255.255:5049

# Listen for TCP connections on this interface and port.
# Port also used as source for UDP broadcasts.
# Default uses wildcard address and a random port.
#bind = 0.0.0.0:0

# Processing chain
procs = cf

# Time interval for sending recceiver advertisments
#announceInterval = 15.0

# Idle Timeout for TCP connections.
#tcptimeout = 15.0

# Time to wait before commiting updates
# Doesn't effect IOC clients
#commitInterval = 5.0

# Maximum concurrent "active" clients
# to allow.
#maxActive = 20

# The channelFinder client is configuration information is
# stored in /etc/channelfinderapi.conf as described in the client

[cf]
# a space-separated list of infotags to set as CF Properties
#infotags = archive foo bar blah
# List environment variables that should be written as channel finder properties
#
# Comma-separated list of VARIABLE:PropertyName,
# specifying which environment VARIABLEs to pass on to the channel finder
# and defining the corresponding PropertyName
#environment_vars=ENGINEER:Engineer,EPICS_BASE:EpicsVersion,PWD:WorkingDirectory
# Turn on optional alias and recordType properties
#alias = on
#recordType = on
#recordDesc = on

# Mark all channels as 'Inactive' when processor is stopped (default: True)
#cleanOnStop = True
# Mark all channels as 'Inactive' when processor is started (default: True)
cleanOnStart = True

recceiverID = recc2

[DEFAULT]
BaseURL = http://cf:8080/ChannelFinder
username = admin
password = password
95 changes: 95 additions & 0 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: '3'

services:
cf:
image: ghcr.io/channelfinder/channelfinderservice:master
hostname: cf
networks:
- net-cf
ports:
- "8080:8080"
- "8443:8443"
depends_on:
elasticsearch:
condition: service_healthy
restart: true
environment:
ELASTICSEARCH_NETWORK_HOST: elasticsearch-cf
elasticsearch.query.size: 10
demo_auth.enabled: true
demo_auth.users: admin
demo_auth.pwds: password
demo_auth.roles: ADMIN
EPICS_PVAS_INTF_ADDR_LIST: "0.0.0.0"
healthcheck:
test: curl -s -f http://cf:8080/ChannelFinder
interval: 10s
timeout: 60s
retries: 5

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.4
hostname: elasticsearch-cf
networks:
- net-cf
environment:
cluster.name: channelfinder
discovery.type: single-node
bootstrap.memory_lock: "true"
xpack.security.enabled: "false"
healthcheck:
test: curl -s -f http://localhost:9200/_cluster/health
interval: 10s
timeout: 60s
retries: 5
volumes:
- channelfinder-es-data:/usr/share/elasticsearch/data

recc1:
build: .
networks:
- net-recc-1
- net-cf
depends_on:
cf:
condition: service_healthy
restart: true
volumes:
- type: bind
source: cf1.conf
target: /home/recceiver/cf.conf
read_only: true
- type: bind
source: cf1.conf
target: /home/recceiver/channelfinderapi.conf
read_only: true
recc2:
build: .
networks:
- net-recc-2
- net-cf
depends_on:
cf:
condition: service_healthy
restart: true
volumes:
- type: bind
source: cf2.conf
target: /home/recceiver/cf.conf
read_only: true
- type: bind
source: cf2.conf
target: /home/recceiver/channelfinderapi.conf
read_only: true

volumes:
channelfinder-es-data:
driver: local

networks:
net-cf:
driver: bridge
net-recc-1:
driver: bridge
net-recc-2:
driver: bridge
11 changes: 6 additions & 5 deletions server/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
Expand All @@ -9,11 +9,12 @@ authors = [
]
description="resync server"
version="1.5"
readme = "README.rst"
readme = "README.md"
requires-python = ">=3.6"
dependencies = [
# "requests",
"twisted",
"twisted",
"requests",
"channelfinder"
]

[project.urls]
Expand All @@ -24,4 +25,4 @@ packages = ["recceiver", "twisted.plugins"]
include-package-data = true

[tool.setuptools.package-data]
twisted = ["plugins/recceiver_plugin.py"]
twisted = ["plugins/recceiver_plugin.py"]
3 changes: 3 additions & 0 deletions server/recceiver/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
from zope.interface import implementer

from twisted import plugin
from twisted.internet import pollreactor
pollreactor.install()

from twisted.python import usage, log
from twisted.internet import reactor, defer
from twisted.internet.error import CannotListenError
Expand Down
3 changes: 3 additions & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channelfinder==3.0.0.post2
twisted==22.8.0
requests==2.28.1
5 changes: 0 additions & 5 deletions server/setup.py

This file was deleted.

35 changes: 35 additions & 0 deletions server/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import json

import urllib3

def insert_fake_data(recc:str, cf: str, ch: str):
http = urllib3.PoolManager()
headers = urllib3.make_headers(basic_auth='admin:password')
headers.update({'Content-Type':
'application/json'})
req = http.request('PUT', cf +"/ChannelFinder/resources/channels",
headers=headers,
body=json.dumps([
{
"name": ch,
"owner": recc,
"properties": [
{
"name": "recceiverID",
"owner": recc,
"value": recc
},
{
"name":"pvStatus",
"owner": recc,
"value": "Active"
}
]
}
]))


cf = "http://localhost:8080"
for i in range(1, 20):
insert_fake_data("recc1", cf, "ch" + str(i))
insert_fake_data("recc2", cf, "ch" + str(i))

0 comments on commit 80abf12

Please sign in to comment.