Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable CI tests for discovery node #1047

Merged
merged 32 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
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
48 changes: 45 additions & 3 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
tags:
- '**'
branches:
- '**'
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -148,13 +150,53 @@ jobs:
env:
IMAGE_NAME: ${{ github.repository }}
REF_NAME: ${{ github.ref_name }}
DEVICE_ID: ${{'AHU-1'}}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No ${{

steps:
- name: Execute discovery node
- name: Setup Environment
run: |
sudo apt-get install moreutils
git clone https://github.com/faucetsdn/udmi_site_model.git
ln -s udmi_site_model/ site_model
(cd site_model; git log -n 1)
jq ".device_id = \"$DEVICE_ID\"" site_model/cloud_iot_config.json | sponge site_model/cloud_iot_config.json
jq . site_model/cloud_iot_config.json
docker network create udminet --subnet 192.168.99.0/24
- name: Start UDMIS container
run: |
export IMAGE_TAG=ghcr.io/$IMAGE_NAME:udmis-$REF_NAME
docker run $IMAGE_TAG cat bin/actualize > /tmp/actualize.sh
cat /tmp/actualize.sh && bash /tmp/actualize.sh
- name: Generate keys
run: |
docker run --net udminet --name keygen -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:validator-$REF_NAME bin/keygen CERT site_model/devices/$DEVICE_ID
- name: Registrar run
run: |
docker run --net udminet --name registrar -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:validator-$REF_NAME bin/registrar site_model/cloud_iot_config.json
- name: Start discoverynode
run: |
export IMAGE_TAG=ghcr.io/$IMAGE_NAME:misc-$REF_NAME
# This currently fails (no config), but just check that it actually runs.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment

docker run $IMAGE_TAG discoverynode/bin/run | fgrep "Loading config"

docker run -d \
--net udminet \
-v $(realpath site_model):/var/site_model \
--name discoverynode \
$IMAGE_TAG \
bin/run /var/site_model //mqtt/udmis AHU-1 vendor.range=0x65,28179023,20231,,,,,,,,,,,,,,,,
- name: Sequencer run
run: |
docker run --net udminet --name sequencer -v $(realpath site_model):/root/site_model \
ghcr.io/$IMAGE_NAME:validator-$REF_NAME bin/sequencer site_model/cloud_iot_config.json \
scan_single_future
- name: Sequencer results
run: |
cat site_model/out/devices/$DEVICE_ID/results.md
[[ $(cat site_model/out/devices/$DEVICE_ID/results.md | grep -Ec ".*discovery.* pass") == 1 ]]
- name: Discoverynode logs
if: ${{ !cancelled() }}
run: docker logs discoverynode

udmif:
name: UDMIF unit tests
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -394,4 +394,4 @@ jobs:
done
ls -l var/tmp/pod_ready.txt 2>&1
- name: Run Tests
run: misc/discoverynode/testing/e2e/test_local site_model || true
run: misc/discoverynode/testing/e2e/test_local site_model
9 changes: 4 additions & 5 deletions misc/Dockerfile.misc
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM debian:12-slim

WORKDIR /root
COPY discoverynode/ /root/discoverynode/
WORKDIR /root/discoverynode

RUN apt-get update && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev sudo && \
apt-get install --no-install-suggests --no-install-recommends --yes python3-venv gcc libpython3-dev sudo jq moreutils && \
python3 -m venv venv && \
venv/bin/pip install --upgrade pip setuptools wheel

ADD discoverynode/src/requirements.txt /tmp/
RUN venv/bin/pip install --disable-pip-version-check -r /tmp/requirements.txt
ADD discoverynode/ discoverynode/
RUN venv/bin/pip install --disable-pip-version-check -r src/requirements.txt
17 changes: 10 additions & 7 deletions misc/discoverynode/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ ROOT_DIR=$(realpath $(dirname $0)/..)
BASE_CONFIG=$(realpath $ROOT_DIR/etc/base_config.json)
TMP_CONFIG="/tmp/discoverynode_config.json"

if [[ $# -ne 3 ]]; then
error Usage: $0 SITE_MODEL TARGET DEVICE_ID
if (( $# -le 4 )); then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be -le 2 since the [OPTIONS] bit is optional? Or -lt 3?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's three required options:

  • site model
  • target
  • device ID

error Usage: $0 SITE_MODEL TARGET DEVICE_ID [OPTIONS]
fi

site_model=$1
Expand Down Expand Up @@ -65,12 +65,8 @@ EOF
)

elif [[ $provider == mqtt ]]; then
if [[ $project != localhost ]]; then
error only localhost supported
fi

substitutions=$(cat <<EOF
.mqtt.host|="localhost" |
.mqtt.host|="$project" |
.mqtt.port|=8883 |
.mqtt.region|="$region" |
.mqtt.project_id|="$project" |
Expand All @@ -88,6 +84,13 @@ else
exit
fi

shift 3

cat $TMP_CONFIG | jq -r "$substitutions" | sponge $TMP_CONFIG

for option in "$@"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

convention is to have "; do" at the end, rather than "do" on a new line

do
cat $TMP_CONFIG | jq -r ".${option/=/|=\"}\"" | sponge $TMP_CONFIG
done

$ROOT_DIR/venv/bin/python3 $ROOT_DIR/src/main.py --config_file=$TMP_CONFIG
Empty file modified misc/discoverynode/bin/setup
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion misc/discoverynode/src/udmi/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def enable_discovery(self,*,bacnet=True,vendor=True,ipv4=True,ether=True):

if vendor:
number_discovery = udmi.discovery.numbers.NumberDiscovery(
self.state, self.publish_discovery
self.state, self.publish_discovery, range=self.config.get("vendor", {}).get("range"),
)

self.add_config_route(
Expand Down
19 changes: 13 additions & 6 deletions misc/discoverynode/src/udmi/discovery/numbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class NumberDiscovery(discovery.DiscoveryController):

scan_family = "vendor"

def __init__(self, state, publisher):
def __init__(self, state, publisher, *, range):
self.cancelled = None
self.task_thread = None
self.range = range
super().__init__(state, publisher)

def start_discovery(self):
Expand All @@ -26,13 +27,19 @@ def start_discovery(self):
@discovery.catch_exceptions_to_state
@discovery.main_task
def discoverer(self):
for i in itertools.count(1):
if self.range:
iterator = self.range.split(",")
else:
iterator = itertools.count(1)

for i in iterator:
if self.cancelled:
return
result = DiscoveryEvent(
generation=self.generation, scan_family=self.scan_family, scan_addr=str(i)
)
self.publish(result)
if i:
result = DiscoveryEvent(
generation=self.generation, scan_family=self.scan_family, scan_addr=str(i)
)
self.publish(result)
time.sleep(1)

def stop_discovery(self):
Expand Down
12 changes: 8 additions & 4 deletions misc/discoverynode/testing/e2e/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def run(cmd: str) -> subprocess.CompletedProcess:
execution_time_seconds = time.monotonic() - start
info("completed with result code %s in %s seconds", str(result.returncode), str(execution_time_seconds))
# print not log, so they are captured when there is a failure
print(result.stdout.decode("utf-8"))
# print(result.stdout.decode("utf-8"))
return result


Expand All @@ -134,7 +134,9 @@ def _docker_devices(*, devices):
)

yield _docker_devices

result = run("docker logs discoverynode-test-device1")
print("discovery node logs")
print(result.stdout.decode("utf-8"))
run(
"docker ps -a | grep 'discoverynode-test-device' | awk '{print $1}' |"
Expand Down Expand Up @@ -278,17 +280,19 @@ def test_sequencer(new_site_model, docker_devices, discovery_node):

run(f"bin/registrar {SITE_PATH} {TARGET}")

# Note: Start after running registrar preferably
# Note: Start after running registrar preferably.
discovery_node(
device_id="GAT-1",
site_path=SITE_PATH
)

result = run(
f"bin/sequencer -v {SITE_PATH} {TARGET} GAT-1 single_scan_future"
f"bin/sequencer -v {SITE_PATH} {TARGET} GAT-1 scan_single_future"
)

assert "RESULT pass discovery.scan single_scan_future" in str(result.stdout), "result is pass (note this test can be flakey)"
print("sequencer output")
print(result.stdout.decode("utf8"))
assert "RESULT pass discovery.scan scan_single_future" in str(result.stdout), "result is pass (note this test can be flakey)"


@pytest.fixture
Expand Down
Loading