8000 Add ChannelFinder and RecSync (reccaster/recceiver) roles, with Molecule tests by ralphlange · Pull Request #107 · epics-training/training-vm · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .github/workflows/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ jobs:
# Don't let a failure on one architecture hide the result on the other
fail-fast: false
matrix:
# kafka, elasticsearch and phoebus_alarm_logger run in a container
# with systemd (ansible/molecule/systemd) and test the services
# functionally; phoebus_alarm_logger builds Phoebus and covers the
# whole alarm system (Kafka, alarm server, Elasticsearch, logger)
# kafka, elasticsearch, phoebus_alarm_logger, channelfinder and
# recceiver run in a container with systemd (ansible/molecule/systemd)
# and test the services functionally; phoebus_alarm_logger builds
# Phoebus and covers the whole alarm system (Kafka, alarm server,
# Elasticsearch, logger), recceiver covers the whole RecSync stack
# (IOC with reccaster, recceiver, ChannelFinder, Elasticsearch)
role:
- initial_setup
- m_base
- m_iocstats
- m_reccaster
- phoebus
- archiver_appliance
- kafka
- elasticsearch
- phoebus_alarm_logger
- channelfinder
- recceiver
# The molecule platform image (ubuntu:22.04) is multi-arch, so each
# runner exercises the role natively on its own architecture
arch:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/test-roles-phoebus-aa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ on:
- 'ansible/roles/phoebus_alarm_logger/**'
- 'ansible/roles/elasticsearch/**'
- 'ansible/roles/java/**'
- 'ansible/roles/maven/**'
- 'ansible/roles/channelfinder/**'
- 'ansible/roles/recceiver/**'
- 'ansible/roles/archiver_appliance/**'
pull_request:
paths:
Expand All @@ -29,6 +32,9 @@ on:
- 'ansible/roles/phoebus_alarm_logger/**'
- 'ansible/roles/elasticsearch/**'
- 'ansible/roles/java/**'
- 'ansible/roles/maven/**'
- 'ansible/roles/channelfinder/**'
- 'ansible/roles/recceiver/**'
- 'ansible/roles/archiver_appliance/**'
workflow_dispatch:
inputs:
Expand Down
2 changes: 2 additions & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ phoebus_alarm: false
phoebus_alarm_logger: false
kafka: false
elasticsearch: false
channelfinder: false
recceiver: false
oac_tree: false
archiver_appliance: false
bluesky: false
Expand Down
2 changes: 1 addition & 1 deletion ansible/molecule/systemd/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Molecule platform image with systemd as PID 1
#
# Shared by the Molecule scenarios that test services (kafka, elasticsearch,
# phoebus_alarm_logger):
# phoebus_alarm_logger, channelfinder, recceiver):
# with a real systemd the roles run with in_container=false, i.e. exactly as on a VM,
# and the tests can check that the services are actually running and working.
# Needs a privileged container sharing the host's cgroup namespace - see the
Expand Down
20 changes: 20 additions & 0 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@
when: m_iocstats is defined and m_iocstats | bool
tags: m_iocstats

- name: RecSync reccaster
include_role:
name: m_reccaster
when: m_reccaster is defined and m_reccaster | bool
tags: m_reccaster

- name: SScan
include_role:
name: m_sscan
Expand Down Expand Up @@ -185,6 +191,20 @@
when: phoebus_alarm_logger is defined and phoebus_alarm_logger | bool
tags: phoebus_alarm_logger

# Pulls in the elasticsearch role as a dependency
- name: ChannelFinder
include_role:
name: channelfinder
when: channelfinder is defined and channelfinder | bool
tags: channelfinder

# Pulls in the channelfinder role as a dependency
- name: RecSync recceiver
include_role:
name: recceiver
when: recceiver is defined and recceiver | bool
tags: recceiver

- name: OAC Tree
include_role:
name: oac_tree
Expand Down
35 changes: 35 additions & 0 deletions ansible/roles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ The Busy record (a dependency of AreaDetector).
### m_opcua
OPC UA Device Support and the open62541 low-level driver.

### m_reccaster
The reccaster module of [RecSync](https://github.com/ChannelFinder/recsync):
linked into an IOC, it uploads the IOC's records (with their info tags and
some environment variables) to a recceiver (`recceiver` role), which feeds
them into ChannelFinder. The EPICS module is the `client/` directory of the
recsync release (see `subdir` below); the demo IOC is not built.

### m_p4p
Python wrapper for PVAccess (PVXS-based) and PVA Gateway.

Expand Down Expand Up @@ -49,6 +56,28 @@ them to the Phoebus "Alarm Log" table through its REST API
`phoebus` role's client preferences like the alarm server's settings).
Built by the `phoebus` role and pulls in `phoebus_alarm` (alarm server, Kafka).

### channelfinder
[ChannelFinder](https://github.com/ChannelFinder/ChannelFinderService)
directory service as a systemd service, built from its source release with
Maven (`maven` role), storing its directory in Elasticsearch
(`elasticsearch` role, a dependency).
REST API and admin web page on `channelfinder_url` (default
`http://localhost:8080/ChannelFinder`, shared with the `phoebus` role's
client preferences), HTTPS on port 8443; demo accounts `admin`/`adminPass`
and `user`/`userPass`. When the `archiver_appliance` role is enabled,
channels with an `archive` property are added to the archiver.
The service also runs an EPICS PVA RPC server (`cfService:query`).

### recceiver
[RecSync](https://github.com/ChannelFinder/recsync) recceiver (the
Python/Twisted server of the same recsync release as `m_reccaster`) as a
systemd service, in a virtualenv under `/opt/epics-tools/services/recceiver`.
It announces itself to the IOCs on the VM (`recceiver_addrlist`, default
`127.255.255.255:5049`, the loopback broadcast address), collects the
records of the IOCs built with reccaster and pushes them, with properties
like `iocName`, `recordType`, `pvStatus` and the `archive` info tag, into
ChannelFinder (`channelfinder` role, a dependency).

### archiver_appliance
Minimal install of the EPICS Archiver Appliance.

Expand Down Expand Up @@ -107,6 +136,9 @@ One-off role called at the first run in a freshly provisioned VM.
### java
Java SDK needed for Phoebus and Services.

### maven
Apache Maven to build Phoebus and the ChannelFinder service.

# Writing architecture-independent roles

The playbook supports both `x86_64` and `aarch64` (ARM64) targets.
Expand Down Expand Up @@ -161,6 +193,9 @@ Each dictionary in `epics_modules_to_build` should have the following keys:
- `post_hook`: (Optional) Name of task file to run after the build. Must be in `/tasks/` directory.
- `args`: (Optional) Additional arguments to pass to `make`.
- `exclude`: (Optional) List of patterns to exclude when extracting the tarball.
- `subdir`: (Optional) Subdirectory of the unpacked source tree that is the
module's EPICS top (where it is configured and built, and what `RELEASE.local`
points to), e.g. `client` for recsync's reccaster module.

## Usage Example

Expand Down
39 changes: 39 additions & 0 deletions ansible/roles/channelfinder/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
# ChannelFinder directory service
# (after phoebus_services_cf of ControlSystemStudio/ansible-phoebus)
#
# channelfinder_url is shared with the phoebus role (client preferences)
# and used by the recceiver role.

# 5.x builds and runs with JDK 25 and the Elasticsearch 8 client
channelfinder_version: "5.1.0"
# Source release (there are no binary releases)
channelfinder_download_url: "https://github.com/ChannelFinder/ChannelFinderService/\
archive/refs/tags/ChannelFinder-{{ channelfinder_version }}.tar.gz"
channelfinder_src_dir: "/opt/epics-tools/lib/channelfinder-{{ channelfinder_version }}"

channelfinder_account: channelfinder
channelfinder_root: "/opt/epics-tools/services/channelfinder"
channelfinder_jar: "{{ channelfinder_root }}/ChannelFinder-{{ channelfinder_version }}.jar"
channelfinder_java_heap_opts: "-Xms128m -Xmx512m"

# REST API (plain HTTP), as the Phoebus client expects it
channelfinder_url: "http://localhost:8080/ChannelFinder"
channelfinder_http_port: "{{ channelfinder_url | urlsplit('port') }}"
# HTTPS, with the self-signed certificate bundled with the service
channelfinder_https_port: 8443

# Demo authentication (the service's default accounts)
channelfinder_admin_user: admin
channelfinder_admin_password: adminPass
channelfinder_user: user
channelfinder_user_password: userPass

channelfinder_es_url: "http://{{ elasticsearch_network_host }}:{{ elasticsearch_http_port }}"

# Add channels with an 'archive' property to the Archiver Appliance
channelfinder_aa_enabled: "{{ archiver_appliance | default(false) | bool }}"
channelfinder_aa_url: "http://localhost:17665"

# true: install and configure the service, but don't start it
in_container: false
10 changes: 10 additions & 0 deletions ansible/roles/channelfinder/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
# Handlers for ChannelFinder

- name: Restart channelfinder
become: true
when: not in_container
ansible.builtin.systemd_service:
name: channelfinder
state: restarted
daemon_reload: true
13 changes: 13 additions & 0 deletions ansible/roles/channelfinder/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
# galaxy_info is required by Molecule's prerun (role name check)
galaxy_info:
role_name: channelfinder
namespace: epics
author: Ralph Lange
description: ChannelFinder directory service
license: EPICS open license
min_ansible_version: "2.15"
dependencies:
- role: java
- role: maven
- role: elasticsearch
34 changes: 34 additions & 0 deletions ansible/roles/channelfinder/molecule/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Molecule tests for the channelfinder role

Functional tests: the `default` scenario builds ChannelFinder and sets it up
with Elasticsearch (role `channelfinder`, which pulls in `java`, `maven` and
`elasticsearch`) in an `ubuntu:22.04` container, then runs the testinfra
tests in `resources/tests/test_channelfinder.py`.
The container runs systemd as PID 1 (privileged, host cgroup namespace;
image definition shared in `ansible/molecule/systemd/Dockerfile.j2`), so the
role runs with `in_container: false`, exactly as on a VM, and the services
really start.

| Test | Checks |
|---|---|
| `test_service_is_running_and_enabled` | `elasticsearch` and `channelfinder` are running and enabled |
| `test_runs_as_unprivileged_user` | ChannelFinder runs as the `channelfinder` user |
| `test_configuration_is_not_world_readable` | `application.properties` (with the account passwords) is only readable by root and the service |
| `test_service_info_reports_elasticsearch_connected` | the service info (`/ChannelFinder`) reports version 5.1.0 and Elasticsearch as connected |
| `test_indices_are_created_in_elasticsearch` | the `channelfinder`, `cf_properties` and `cf_tags` indices exist |
| `test_https_connector_answers` | the HTTPS connector (port 8443, self-signed certificate) answers |
| `test_web_admin_page_is_served` | the admin web page (`/index.html`) is served |
| `test_anonymous_writes_are_refused` | creating a tag without credentials is refused (401) |
| `test_find_channels_by_name` | channels created through the REST API (as `admin`, with a property and a tag) are found by name pattern |
| `test_find_channels_by_property_value` | ... by property value |
| `test_find_channels_by_tag` | ... by tag |
| `test_channel_carries_its_property_and_tag` | a single channel is returned with its property value and tag |

Building ChannelFinder with Maven takes a few minutes.
CI runs the scenario on x86_64 and aarch64 (`.github/workflows/molecule.yml`).
To run it locally (needs Docker):

```bash
cd ansible/roles/channelfinder
molecule test
```
42 changes: 42 additions & 0 deletions ansible/roles/channelfinder/molecule/default/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
dependency:
name: galaxy
lint: |
set -e
yamllint .
ansible-lint
flake8
provisioner:
name: ansible
playbooks:
converge: ../resources/converge.yml
inventory:
host_vars:
channelfinder-systemd:
# Real systemd in the container: run the services as on a VM
in_container: false
group_vars:
all:

scenario:
name: default
verifier:
name: testinfra
directory: ../resources/tests/
driver:
name: docker
# Container with systemd as PID 1 (shared image definition in ansible/molecule/systemd)
platforms:
- name: channelfinder-systemd
image: ubuntu:22.04
# relative to the scenario directory
dockerfile: ../../../../molecule/systemd/Dockerfile.j2
pre_build_image: false
command: /lib/systemd/systemd
privileged: true
cgroupns_mode: host
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
tmpfs:
- /run
- /run/lock
22 changes: 22 additions & 0 deletions ansible/roles/channelfinder/molecule/resources/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: Converge
hosts: all
become: true

# Molecule runs the roles directly, bypassing playbook.yml, so the
# architecture variables (the arch dict, e.g. for the JDK and Elasticsearch
# downloads) have to be loaded here too - same first-found logic as
# playbook.yml's pre_tasks. Everything else comes from the roles' own
# defaults.
pre_tasks:
- name: Load architecture-specific variables with fallback
ansible.builtin.include_vars: "{{ item }}"
with_first_found:
- files:
- "{{ ansible_facts['architecture'] }}.yml"
- "default.yml"
paths:
- "{{ playbook_dir }}/../../../../vars/arch"

roles:
- role: channelfinder
Loading
0