Skip to content
Merged
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
109 changes: 109 additions & 0 deletions .github/workflows/dt4acc-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,112 @@ jobs:
with:
name: dt4acc-twin-log
path: ${{ runner.temp }}/dt4acc-twin.log

epics-smoke:
runs-on: ubuntu-24.04
timeout-minutes: 30

defaults:
run:
shell: bash -el {0}

env:
DT4ACC_IMAGE_URI: ${{ inputs.dt4acc_image_uri || 'oras://registry.synchrotron-soleil.fr/software_control_system_public/dt4acc-soleil-twin:latest' }}
DT4ACC_REGISTRY_USER: ${{ secrets.DT4ACC_REGISTRY_USER }}
DT4ACC_REGISTRY_PASSWORD: ${{ secrets.DT4ACC_REGISTRY_PASSWORD }}
PYAML_DT4ACC_EPICS_PREFIX: pyaml-it
EPICS_CA_AUTO_ADDR_LIST: "NO"
EPICS_CA_ADDR_LIST: 127.0.0.1
EPICS_PVA_AUTO_ADDR_LIST: "NO"
EPICS_PVA_ADDR_LIST: 127.0.0.1

steps:
- uses: actions/checkout@v4
with:
repository: ${{ github.event.pull_request.head.repo.full_name || github.repository }}
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}

- name: Set up Apptainer
uses: eWaterCycle/setup-apptainer@v2

- name: Set up Python environment
uses: mamba-org/setup-micromamba@v2
with:
environment-name: pyaml-dt4acc-integration
create-args: >-
-c conda-forge
python=3.12
pip
pytest
pytango
cache-environment: true

- name: Install pyAML and the EPICS control-system backend
run: |
python -m pip install --upgrade pip
python -m pip install -e ".[test]"
python -m pip install "ophyd-async[ca, pva]<0.21"
python -m pip install --no-deps pyaml-cs-oa
python -c "import aioca; import pyaml_cs_oa"

- name: Log in to GitLab registry
if: ${{ env.DT4ACC_REGISTRY_USER != '' && env.DT4ACC_REGISTRY_PASSWORD != '' }}
run: |
printf '%s' "${DT4ACC_REGISTRY_PASSWORD}" |
apptainer registry login \
--username "${DT4ACC_REGISTRY_USER}" \
--password-stdin \
oras://gitlab-registry.synchrotron-soleil.fr

- name: Pull dt4acc twin image
run: |
mkdir -p "${RUNNER_TEMP}/apptainer"
apptainer pull --force --disable-cache \
"${RUNNER_TEMP}/apptainer/dt4acc-soleil-twin.sif" \
"${DT4ACC_IMAGE_URI}"

- name: Start dt4acc EPICS twin
run: |
LOG_FILE="${RUNNER_TEMP}/dt4acc-epics-twin.log"
PID_FILE="${RUNNER_TEMP}/dt4acc-epics-twin.pid"

ACCEL_SETUP_FILE=$(python -c "from pyaml_test_lattice import configurations; print(configurations['dt4acc/fodo_1gev_6d_dt4acc_epics.json'])")
LATTICE_FILE=$(python -c "from pyaml_test_lattice import lattices; print(lattices['fodo_1gev_6d.json'])")

bash tests/integration/start_dt4acc_twin.sh \
--mode epics \
--accelerator-setup-file "${ACCEL_SETUP_FILE}" \
--lattice-file "${LATTICE_FILE}" \
--prefix "${PYAML_DT4ACC_EPICS_PREFIX}" \
--sif "${RUNNER_TEMP}/apptainer/dt4acc-soleil-twin.sif" \
--log-file "${LOG_FILE}" \
--pid-file "${PID_FILE}" \
--timeout 900 \
--detach

- name: Run pyAML dt4acc EPICS smoke test
env:
PYAML_DT4ACC_INTEGRATION: "1"
run: |
python -m pytest -v tests/integration/test_dt4acc_epics_twin_smoke.py

- name: Stop dt4acc EPICS twin
if: always()
run: |
PID_FILE="${RUNNER_TEMP}/dt4acc-epics-twin.pid"
if [ -f "${PID_FILE}" ]; then
TWIN_PID="$(cat "${PID_FILE}")"
kill -- "-${TWIN_PID}" 2>/dev/null || kill "${TWIN_PID}" 2>/dev/null || true
sleep 5
kill -KILL -- "-${TWIN_PID}" 2>/dev/null || kill -KILL "${TWIN_PID}" 2>/dev/null || true
fi
if [ -f "${RUNNER_TEMP}/dt4acc-epics-twin.log" ]; then
tail -n 200 "${RUNNER_TEMP}/dt4acc-epics-twin.log" || true
fi

- name: Upload dt4acc EPICS logs
if: always()
uses: actions/upload-artifact@v4
with:
name: dt4acc-epics-twin-log
path: ${{ runner.temp }}/dt4acc-epics-twin.log
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ cs-oa-tango = [
test = [
"pytest>=7.4",
"pytest-cov>=3.0",
"pyaml-test-lattice>=0.2.0",
"pyaml-test-lattice>=0.4.0",
"jsonschema>=4.18",
]
doc = [
Expand Down
41 changes: 41 additions & 0 deletions tests/integration/fodo_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Build pyAML accelerators from the pyaml-test-lattice FODO 1 GeV 6D fixtures."""

from pathlib import Path

from pyaml_test_lattice import configurations, lattices

from pyaml.accelerator import Accelerator
from pyaml.configuration import ConfigurationManager

FODO_LATTICE_KEY = "fodo_1gev_6d.json"


def load_fodo_fragment(config_key: str, control_overrides: dict | None = None) -> dict:
"""Load one pyaml-test-lattice FODO config fragment as a plain dict.

The ``lattice`` reference is overridden since it lives in a different
package subtree (``data/lattice``) than the config fragment
(``data/configuration``).

``control_overrides`` entries are merged into every control system of the
fragment, for instance an EPICS PV ``prefix``.
"""
config_path = Path(configurations[config_key])
manager = ConfigurationManager()
manager.add(config_path)
fragment = manager.to_dict()

fragment["simulators"][0]["lattice"] = str(Path(lattices[FODO_LATTICE_KEY]))

for control in fragment.get("controls", []):
control.update(control_overrides or {})

return fragment


def build_fodo_accelerator(config_key: str, control_overrides: dict | None = None) -> Accelerator:
"""Build an Accelerator from one pyaml-test-lattice FODO config fragment."""
configuration_manager = ConfigurationManager()
configuration_manager.add(load_fodo_fragment(config_key, control_overrides))

return Accelerator.from_dict(configuration_manager.to_dict())
104 changes: 84 additions & 20 deletions tests/integration/start_dt4acc_twin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
set -Eeuo pipefail

DEFAULT_IMAGE_URI="oras://registry.synchrotron-soleil.fr/software_control_system_public/dt4acc-soleil-twin:latest"
READY_PATTERN="Calculation heartbeat: simulator/ringsimulator/ringsimulator reachable"
TANGO_READY_PATTERN="Calculation heartbeat: simulator/ringsimulator/ringsimulator reachable"
EPICS_READY_PATTERN="EPICS IOC ready:"

usage() {
cat <<'EOF'
Expand All @@ -15,8 +16,13 @@ Required simulator input data:
--lattice-file FILE Lattice file passed to the twin.

Options:
--tango-host HOST Tango database host. Default: localhost.
--tango-port PORT Tango database port. If omitted, the twin may choose it.
--mode tango|epics Twin flavour. Default: tango.
tango: Tango twin with an embedded Tango database.
epics: EPICS soft-IOC twin, no database.
--tango-host HOST Tango mode only. Tango database host. Default: localhost.
--tango-port PORT Tango mode only. Tango database port. If omitted, the twin may choose it.
--prefix PREFIX EPICS mode only. PV prefix. If omitted, the twin uses
DT4ACC_PREFIX, then the current user name.
--image-uri URI Apptainer image URI. Default: dt4acc latest ORAS image.
--sif FILE Use a local SIF file instead of --image-uri.
--log-file FILE Log file path. Default: mktemp under /tmp.
Expand All @@ -25,17 +31,22 @@ Options:
--detach Exit after readiness and leave the twin running.
-h, --help Show this help.

The script prints "Ready to use" when the twin reaches the same heartbeat used by
the dt4acc-integration CI workflow. Keep this process running; press Ctrl-C to
The script prints "Ready to use" when the twin reaches the readiness log line used by
the dt4acc-integration CI workflow (the calculation heartbeat in Tango mode, the
"EPICS IOC ready" line in EPICS mode). Keep this process running; press Ctrl-C to
stop the twin. With --detach, the script exits after readiness; use --pid-file
so a later step can stop the twin.
EOF
}

accelerator_setup_file=""
lattice_file=""
mode="tango"
tango_host="localhost"
tango_port=""
tango_option_given="0"
prefix=""
prefix_given="0"
image_uri="${DEFAULT_IMAGE_URI}"
sif_file=""
log_file=""
Expand All @@ -54,12 +65,23 @@ while (($#)); do
lattice_file="${2:-}"
shift 2
;;
--mode)
mode="${2:-}"
shift 2
;;
--tango-host)
tango_host="${2:-}"
tango_option_given="1"
shift 2
;;
--tango-port)
tango_port="${2:-}"
tango_option_given="1"
shift 2
;;
--prefix)
prefix="${2:-}"
prefix_given="1"
shift 2
;;
--image-uri)
Expand Down Expand Up @@ -129,6 +151,27 @@ if [[ -z "${accelerator_setup_file}" || -z "${lattice_file}" ]]; then
exit 2
fi

case "${mode}" in
tango)
if [[ "${prefix_given}" == "1" ]]; then
echo "--prefix is only valid with --mode epics." >&2
exit 2
fi
ready_pattern="${TANGO_READY_PATTERN}"
;;
epics)
if [[ "${tango_option_given}" == "1" ]]; then
echo "--tango-host and --tango-port are only valid with --mode tango." >&2
exit 2
fi
ready_pattern="${EPICS_READY_PATTERN}"
;;
*)
echo "--mode must be 'tango' or 'epics', got '${mode}'." >&2
exit 2
;;
esac

if ! command -v apptainer >/dev/null 2>&1; then
echo "apptainer is required but was not found in PATH." >&2
exit 127
Expand Down Expand Up @@ -253,11 +296,16 @@ detect_tango_port() {
}

echo "Starting dt4acc twin"
echo " mode: ${mode}"
echo " accelerator setup: ${accelerator_setup_file}"
echo " lattice file: ${lattice_file}"
echo " tango host: ${tango_host}"
echo " tango port: ${tango_port:-auto}"
echo " requested TANGO_HOST: ${requested_tango_host}"
if [[ "${mode}" == "tango" ]]; then
echo " tango host: ${tango_host}"
echo " tango port: ${tango_port:-auto}"
echo " requested TANGO_HOST: ${requested_tango_host}"
else
echo " PV prefix: ${prefix:-twin default}"
fi
echo " image: ${image_ref}"
echo " log file: ${log_file}"
if [[ -n "${pid_file}" ]]; then
Expand All @@ -266,15 +314,31 @@ fi

trap cleanup INT TERM EXIT

setsid env TANGO_HOST="${requested_tango_host}" apptainer run \
"${bind_args[@]}" \
"${image_ref}" \
tango-db-embedded \
--force-kill-db \
--tango-host "${requested_tango_host}" \
--accelerator-setup-file "${accelerator_setup_container}" \
--lattice-file "${lattice_container}" \
>"${log_file}" 2>&1 &
if [[ "${mode}" == "tango" ]]; then
setsid env TANGO_HOST="${requested_tango_host}" apptainer run \
"${bind_args[@]}" \
"${image_ref}" \
tango-db-embedded \
--force-kill-db \
--tango-host "${requested_tango_host}" \
--accelerator-setup-file "${accelerator_setup_container}" \
--lattice-file "${lattice_container}" \
>"${log_file}" 2>&1 &
else
epics_args=(
--accelerator-setup-file "${accelerator_setup_container}"
--lattice-file "${lattice_container}"
)
if [[ -n "${prefix}" ]]; then
epics_args+=(--prefix "${prefix}")
fi
setsid apptainer run \
"${bind_args[@]}" \
"${image_ref}" \
epics-embedded \
"${epics_args[@]}" \
>"${log_file}" 2>&1 &
fi

twin_pid="$!"
if [[ -n "${pid_file}" ]]; then
Expand All @@ -289,7 +353,7 @@ while true; do
exit 1
fi

if [[ -z "${detected_tango_port}" ]]; then
if [[ "${mode}" == "tango" && -z "${detected_tango_port}" ]]; then
if detected_tango_port="$(detect_tango_port)"; then
echo "Detected Tango database port: ${detected_tango_port}"
echo "Effective TANGO_HOST: ${tango_host}:${detected_tango_port}"
Expand All @@ -298,8 +362,8 @@ while true; do
fi
fi

if grep -q "${READY_PATTERN}" "${log_file}"; then
if [[ -z "${detected_tango_port}" ]]; then
if grep -q "${ready_pattern}" "${log_file}"; then
if [[ "${mode}" == "tango" && -z "${detected_tango_port}" ]]; then
if detected_tango_port="$(detect_tango_port)"; then
echo "Detected Tango database port: ${detected_tango_port}"
echo "Effective TANGO_HOST: ${tango_host}:${detected_tango_port}"
Expand Down
Loading
Loading