Skip to content

Commit 1fc3880

Browse files
authored
Merge pull request #2 from dmgav/ci-config
CI configuration
2 parents f872ae2 + 3d10365 commit 1fc3880

File tree

10 files changed

+145
-79
lines changed

10 files changed

+145
-79
lines changed

.github/workflows/ci.yml_

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
shell: bash -l {0}
2020

2121
steps:
22-
- name: Checkout the branch
22+
- name: Checkout
2323
uses: actions/checkout@v3
2424

2525
- name: Set up Python

.github/workflows/testing.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Unit Tests
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
12+
fail-fast: false
13+
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
23+
- name: Install dependencies
24+
run: |
25+
pip install .[dev]
26+
pip list
27+
28+
- name: Start save-and-restore service
29+
run: |
30+
pushd container
31+
./start-save-and-restore.sh
32+
popd
33+
34+
- name: Test with pytest
35+
run: |
36+
# pytest -k test_ip_kernel_func -vvv
37+
coverage run -m pytest -vv
38+
coverage report -m

container/create_env_file.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import socket
2+
3+
if __name__ == "__main__":
4+
# Get the local IP address
5+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
6+
s.connect(("8.8.8.8", 80))
7+
ip = s.getsockname()[0]
8+
9+
with open(".env", "w") as f:
10+
f.write(f"HOST_EXTERNAL_IP_ADDRESS={ip}")

container/save-and-restore.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Running elasticsearch in docker
2+
# sudo docker compose -f save-and-restore.yml up -d
3+
# Test:
4+
# curl -X GET "http://localhost:9200/"
5+
6+
# .env file:
7+
#
8+
# HOST_EXTERNAL_IP_ADDRESS=192.168.50.49
9+
10+
services:
11+
saveandrestore:
12+
image: ghcr.io/controlsystemstudio/phoebus/service-save-and-restore:master
13+
ports:
14+
- "8080:8080"
15+
depends_on:
16+
- elasticsearch
17+
environment:
18+
ELASTICSEARCH_NETWORK_HOST: ${HOST_EXTERNAL_IP_ADDRESS}
19+
EPICS_PVA_ADDR_LIST: ${HOST_EXTERNAL_IP_ADDRESS}
20+
EPICS_PVA_AUTO_ADDR_LIST: "NO"
21+
EPICS_PVA_ENABLE_IPV6: "false"
22+
command: >
23+
/bin/bash -c "
24+
until curl --fail --silent http://${HOST_EXTERNAL_IP_ADDRESS}:9200/_cluster/health; do
25+
echo 'Waiting for Elasticsearch'
26+
sleep 1
27+
done
28+
java -DdefaultProtocol=pva -Dauthorization.permitall=false -Dauth.impl=demo -jar /saveandrestore/service-save-and-restore-*.jar"
29+
extra_hosts:
30+
- "host.docker.internal:host-gateway"
31+
32+
elasticsearch:
33+
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.2
34+
ports:
35+
- "9200:9200"
36+
environment:
37+
discovery.type: single-node
38+
bootstrap.memory_lock: "true"
39+
xpack.security.enabled: "false"
40+
volumes:
41+
- saveandrestore-es-data:/usr/share/elasticsearch/data
42+
extra_hosts:
43+
- "host.docker.internal:host-gateway"
44+
45+
volumes:
46+
saveandrestore-es-data:
47+
driver: local
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set -x
2+
3+
python create_env_file.py
4+
sudo docker compose -f save-and-restore.yml up -d
5+
python wait_for_startup.py
6+
7+
# Wait until the service is started.
8+
#sleep 30

container/wait_for_startup.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import time
2+
3+
import httpx
4+
5+
t_wait = 120
6+
BASE_URL = "http://localhost:8080/save-restore"
7+
root_node_uid = "44bef5de-e8e6-4014-af37-b8f6c8a939a2"
8+
9+
if __name__ == "__main__":
10+
t_start = time.time()
11+
url = f"/node/{root_node_uid}"
12+
with httpx.Client(base_url=BASE_URL, timeout=1) as client:
13+
while time.time() - t_start < t_wait:
14+
try:
15+
response = client.request("GET", url)
16+
if response.status_code == 200:
17+
print("Success: save-and-restore server is up")
18+
exit(0)
19+
except Exception:
20+
pass
21+
22+
print(f"TIMEOUT: save-and-restore server failed to start in {t_wait} seconds")
23+
exit(1)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ extend-select = [
110110
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
111111
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up
112112
]
113+
unfixable = ["F401"]
113114
ignore = [
114115
]
115116
isort.required-imports = [

src/save_and_restore_api/tools/upload.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def ROOT_NODE_UID(self):
2929

3030
def open(self):
3131
auth = httpx.BasicAuth(username=self._username, password=self._password)
32-
self._client = httpx.Client(base_url=BASE_URL, timeout=timeout, auth=auth)
32+
self._client = httpx.Client(base_url=self._base_url, timeout=timeout, auth=auth)
3333

3434
def close(self):
3535
self._client.close()

tests/test_package.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,23 @@
33
import importlib.metadata
44

55
import save_and_restore_api as m
6+
from save_and_restore_api.tools.upload import SaveRestoreAPI
67

78

89
def test_version():
910
assert importlib.metadata.version("save_and_restore_api") == m.__version__
11+
12+
13+
def test_import():
14+
from save_and_restore_api.tools.upload import SaveRestoreAPI # noqa: F401
15+
16+
17+
def test_comm():
18+
SR = SaveRestoreAPI(base_url="http://localhost:8080/save-restore", timeout=2)
19+
# SR.set_username_password(username="johndoe", password="1234")
20+
SR.set_username_password(username="user", password="userPass")
21+
# SR.set_username_password(username="admin", password="adminPass")
22+
SR.open()
23+
SR.login()
24+
SR.get_node(SR.ROOT_NODE_UID)
25+
SR.close()

0 commit comments

Comments
 (0)