diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
new file mode 100644
index 0000000..4415689
--- /dev/null
+++ b/.devcontainer/Dockerfile
@@ -0,0 +1,31 @@
+# /********************************************************************************
+# * Copyright (c) 2023 Contributors to the Eclipse Foundation
+# *
+# * See the NOTICE file(s) distributed with this work for additional
+# * information regarding copyright ownership.
+# *
+# * This program and the accompanying materials are made available under the
+# * terms of the Apache License 2.0 which is available at
+# * http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * SPDX-License-Identifier: Apache-2.0
+# ********************************************************************************/
+
+FROM python:3.11
+
+
+COPY . /tmp
+
+WORKDIR /tmp
+
+RUN python3 -m pip install --no-cache-dir -r requirements.txt
+
+# useful dumps about feeding values
+ENV LOG_LEVEL="info,databroker=debug,mock_service=debug"
+
+# Vehicle Data Broker host:port
+#ENV VDB_ADDRESS="localhost:55555"
+
+ENV PYTHONUNBUFFERED=yes
+
+# ENTRYPOINT ["./mockservice.py"]
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
new file mode 100644
index 0000000..a075c04
--- /dev/null
+++ b/.devcontainer/devcontainer.json
@@ -0,0 +1,8 @@
+{
+ "build": {
+ "dockerfile": "Dockerfile",
+ "context": ".."
+ },
+ "runArgs": ["--network=host"]
+
+}
\ No newline at end of file
diff --git a/.flake8 b/.flake8
new file mode 100644
index 0000000..dcc8dce
--- /dev/null
+++ b/.flake8
@@ -0,0 +1,2 @@
+[flake8]
+max_line_length = 120
diff --git a/.github/workflows/check_license.yml b/.github/workflows/check_license.yml
new file mode 100755
index 0000000..df728a0
--- /dev/null
+++ b/.github/workflows/check_license.yml
@@ -0,0 +1,33 @@
+name: spdx
+
+on:
+ pull_request
+
+concurrency:
+ group: ${{ github.ref }}-${{ github.workflow }}
+ cancel-in-progress: true
+
+jobs:
+ check-spdx-headers:
+ runs-on: ubuntu-latest
+
+ steps:
+
+ - name: Checkout code
+ uses: actions/checkout@v4
+ with:
+ # required to grab the history of the PR
+ fetch-depth: 0
+
+ - name: Get changed files
+ run: |
+ echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | tr '\n' ',')" >> $GITHUB_ENV
+
+ - name: Set license
+ run: |
+ echo "licenses=Apache-2.0" >> $GITHUB_ENV
+
+ - uses: eclipse-kuksa/kuksa-actions/spdx@2
+ with:
+ files: "${{ env.files }}"
+ licenses: "${{ env.licenses }}"
diff --git a/.github/workflows/dash.yml b/.github/workflows/dash.yml
new file mode 100644
index 0000000..de63713
--- /dev/null
+++ b/.github/workflows/dash.yml
@@ -0,0 +1,41 @@
+name: dash
+
+on:
+ pull_request:
+ push:
+ branches:
+ - main
+
+jobs:
+ check-dash:
+ runs-on: ubuntu-latest
+ steps:
+
+ - name: Checkout code
+ uses: actions/checkout@v4
+
+ # taken from here: https://github.com/eclipse/dash-licenses#example-python
+ - name: Create Dash Dependency Report
+ run: |
+ python3 -m venv ./.venv/kuksa-can-provider
+ source ./.venv/kuksa-can-provider/bin/activate
+
+ pip install --upgrade pip
+ pip install -r requirements.txt
+
+ deactivate
+
+ python3 -m venv ./.venv/pipdeptree
+ source ./.venv/pipdeptree/bin/activate
+
+ pip install --upgrade pip
+ pip install pipdeptree
+ pipdeptree -a -f --python ./.venv/kuksa-can-provider/bin/python \
+ | sed -E -e 's|([^= ]+)==([^= ]+)|pypi/pypi/-/\1/\2|' -e 's| ||g' \
+ | sort | uniq \
+ > dependencies.txt
+
+ - name: Dash license check
+ uses: eclipse-kuksa/kuksa-actions/check-dash@2
+ with:
+ dashinput: ${{github.workspace}}/dependencies.txt
diff --git a/.github/workflows/mock_service.yml b/.github/workflows/mock_service.yml
index 06fa046..3cb0b55 100644
--- a/.github/workflows/mock_service.yml
+++ b/.github/workflows/mock_service.yml
@@ -18,10 +18,6 @@ on:
branches:
- main
pull_request:
- paths:
- - ".github/workflows/mock_service.yml"
- - "mock_service/**"
- - "proto/**"
workflow_call:
workflow_dispatch:
@@ -29,6 +25,10 @@ concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
+# Needed as default_workflow_permissions is "read"
+permissions:
+ packages: write
+
jobs:
check_ghcr_push:
@@ -100,12 +100,12 @@ jobs:
platforms: |
linux/amd64
linux/arm64
- file: ./mock_service/Dockerfile
- context: ./mock_service
+ file: ./Dockerfile
+ context: .
push: true
tags: |
${{ steps.meta.outputs.tags }}
- ttl.sh/kuksa.val.services/mock_service-${{github.sha}}
+ ttl.sh/eclipse-kuksa/kuksa-mock-provider/mock-provider-${{github.sha}}
labels: ${{ steps.meta.outputs.labels }}
- name: Build container and push to ttl.sh
@@ -116,16 +116,16 @@ jobs:
platforms: |
linux/amd64
linux/arm64
- file: ./mock_service/Dockerfile
- context: ./mock_service
+ file: ./Dockerfile
+ context: .
push: true
- tags: "ttl.sh/kuksa.val.services/mock_service-${{github.sha}}"
+ tags: "ttl.sh/eclipse-kuksa/kuksa-mock-provider/mock-provider-${{github.sha}}"
labels: ${{ steps.meta.outputs.labels }}
- name: Posting message
uses: eclipse-kuksa/kuksa-actions/post-container-location@2
with:
- image: ttl.sh/kuksa.val.services/mock_service-${{github.sha}}
+ image: ttl.sh/eclipse-kuksa/kuksa-mock-provider/mock-provider-${{github.sha}}
ensure-docs-up2date:
name: Ensure docs are up2date
@@ -141,7 +141,7 @@ jobs:
- name: (Re-) Build Pydoc Markdown
shell: bash
- working-directory: mock_service
+ working-directory: .
run: |
./update-api-docs.sh
@@ -174,13 +174,13 @@ jobs:
- name: Install dependencies
shell: bash
- working-directory: mock_service
+ working-directory: .
run: |
python3 -m pip install --pre -r ./requirements.txt
python3 -m pip install -r ./requirements-dev.txt
- name: Run tests
shell: bash
- working-directory: mock_service
+ working-directory: .
run: |
python3 -m pytest
diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml
new file mode 100644
index 0000000..e00578d
--- /dev/null
+++ b/.github/workflows/pre-commit.yml
@@ -0,0 +1,24 @@
+name: pre-commit
+
+on: [pull_request]
+
+concurrency:
+ group: ${{ github.ref }}-${{ github.workflow }}
+ cancel-in-progress: true
+
+
+jobs:
+ pre-commit:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v4
+ with:
+ # required to grab the history of the PR
+ fetch-depth: 0
+ - uses: actions/setup-python@v5
+ with:
+ python-version: '3.10'
+ - uses: pre-commit/action@v3.0.0
+ with:
+ extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
diff --git a/mock_service/.gitignore b/.gitignore
similarity index 100%
rename from mock_service/.gitignore
rename to .gitignore
diff --git a/mock_service/.pre-commit-config.yaml b/.pre-commit-config.yaml
similarity index 100%
rename from mock_service/.pre-commit-config.yaml
rename to .pre-commit-config.yaml
diff --git a/.pylintrc b/.pylintrc
new file mode 100644
index 0000000..7615b86
--- /dev/null
+++ b/.pylintrc
@@ -0,0 +1,2 @@
+[FORMAT]
+max-line-length=120
diff --git a/mock_service/Dockerfile b/Dockerfile
similarity index 77%
rename from mock_service/Dockerfile
rename to Dockerfile
index 0289250..00359e5 100644
--- a/mock_service/Dockerfile
+++ b/Dockerfile
@@ -23,13 +23,7 @@ ENV LOG_LEVEL="info,databroker=debug,mock_service=debug"
# Vehicle Data Broker host:port
#ENV VDB_ADDRESS="localhost:55555"
-# Override VDB_ADDRESS port if set
-#ENV DAPR_GRPC_PORT="55555"
-# VDB DAPR APP ID
-ENV VEHICLEDATABROKER_DAPR_APP_ID=vehicledatabroker
ENV PYTHONUNBUFFERED=yes
-LABEL org.opencontainers.image.source="https://github.com/eclipse/kuksa.val.services"
-
-CMD ["python3", "/mock/mockservice.py"]
+ENTRYPOINT ["./mockprovider.py"]
diff --git a/mock_service/README.md b/README.md
similarity index 79%
rename from mock_service/README.md
rename to README.md
index 6d33f36..cefdc92 100644
--- a/mock_service/README.md
+++ b/README.md
@@ -1,8 +1,10 @@
-# Vehicle Mock Service
+# KUKSA Mock Provider
+
+![KUKSA Logo](./doc/img/logo.png)
## About
-The vehicle mock service is a service dummy allowing to control all specified actuator- and sensor-signals via a configuration file. These configuration files are expressed in a Python-based [domain-specific language (DSL)](./doc/pydoc/mocking-dsl.md).
+The KUKSA Mock Provider is a service dummy allowing to control all specified actuator- and sensor-signals via a configuration file. These configuration files are expressed in a Python-based [domain-specific language (DSL)](./doc/pydoc/mocking-dsl.md).
## Why
@@ -24,7 +26,7 @@ flowchart LR
ValIF <--> id3
```
-# Running mockservice
+# Running Mock Provider
Firstly, you will need to install all necessary Python dependencies by issuing the following command in your favorite terminal:
@@ -35,22 +37,21 @@ python3 -m pip install -r ./requirements.txt
You can then run the vehicle mock service with
```bash
-python3 mockservice.py
+python3 mockprovider.py
```
-As an alternative, you can build and execute the container from the [Dockerfile](./Dockerfile) or through the [docker-build.sh](./docker-build.sh) script.
+As an alternative, you can build and execute the container from the [Dockerfile](./Dockerfile).
-Another option, when using VS Code, is to use the [provided VSCode task](../.vscode/tasks.json) `run-mockservice` which will set up all necessary environment variables and parameters for the service to start up properly.
## Configuration
-### Vehicle Mock Service
+### KUKSA Mock Provider
| parameter | default value | Environment variable | description |
|----------------|-----------------------|----------------------------------------------------------------------------------|---------------------------------|
| listen address | `"127.0.0.1:50053"` | `MOCK_ADDR` | Listen for rpc calls |
-| broker address | `"127.0.0.1:55555"` | if DAPR_GRPC_PORT is set:
`"127.0.0.1:$DAPR_GRPC_PORT"`
else:
`VDB_ADDRESS`| The address of the KUKSA.val databroker to connect to |
-| broker app id | `"vehicledatabroker"` | `VEHICLEDATABROKER_DAPR_APP_ID` | When using DAPR, this allows to configure the id of the KUKSA.val databroker to connect to. |
+| broker address | `"127.0.0.1:55555"` | `VDB_ADDRESS`| The address of the KUKSA.val databroker to connect to |
+
Configuration options have the following priority (highest at top):
1. environment variable
@@ -83,7 +84,7 @@ Firstly, you will need to install all necessary Python dependencies by using the
python3 -m pip install -r ./requirements.txt
```
-To run the GUI do the following in your favourtie terminal:
+To run the GUI do the following in your favorite terminal:
```bash
python3 showcase_gui/GUI.py
diff --git a/mock_service/doc/concept.md b/doc/concept.md
similarity index 95%
rename from mock_service/doc/concept.md
rename to doc/concept.md
index e42a729..692b316 100644
--- a/mock_service/doc/concept.md
+++ b/doc/concept.md
@@ -44,10 +44,10 @@ The scope of the Vehicle Mock is a CLI application without a GUI and without phy
| #F10.2.1 | post-MVP | non-looping
| #F10.2.2 | post-MVP | reset after play, play again
| #F10.2.3 | post-MVP | ping-pong (reverse play)
-| #F11 | MVP | Values in behavior conditions and target values shall support liteals to indicate the use of dynamic values: `$requested_value` for the requested value of an `actuator_target` event, `$Vehicle.Speed` for dynamic evaluation of the Vehicle's current speed. All VSS sensors and actuators shall be supported in the evaluation of dynamic values.
+| #F11 | MVP | Values in behavior conditions and target values shall support literals to indicate the use of dynamic values: `$requested_value` for the requested value of an `actuator_target` event, `$Vehicle.Speed` for dynamic evaluation of the Vehicle's current speed. All VSS sensors and actuators shall be supported in the evaluation of dynamic values.
| #F12 | post-MVP | It shall be possible to re-load the configuration file at runtime via external trigger
-## Non-funtional requirements
+## Non-functional requirements
| id | version | description |
|:---|:-------:|:-----------|
@@ -149,14 +149,14 @@ mock_datapoints:
```
-### Class Diagarm
+### Class Diagram
```mermaid
classDiagram
class BaseService {
Basic service responsible for
establishing connection to
- Dapr sidecar and VDB.
+ KUKSA Databroker.
+ connectToDatabroker()
}
diff --git a/doc/img/logo.png b/doc/img/logo.png
new file mode 100644
index 0000000..522d23e
Binary files /dev/null and b/doc/img/logo.png differ
diff --git a/mock_service/doc/pydoc/action.md b/doc/pydoc/action.md
similarity index 100%
rename from mock_service/doc/pydoc/action.md
rename to doc/pydoc/action.md
diff --git a/mock_service/doc/pydoc/animator.md b/doc/pydoc/animator.md
similarity index 100%
rename from mock_service/doc/pydoc/animator.md
rename to doc/pydoc/animator.md
diff --git a/mock_service/doc/pydoc/behavior.md b/doc/pydoc/behavior.md
similarity index 100%
rename from mock_service/doc/pydoc/behavior.md
rename to doc/pydoc/behavior.md
diff --git a/mock_service/doc/pydoc/datapoint.md b/doc/pydoc/datapoint.md
similarity index 100%
rename from mock_service/doc/pydoc/datapoint.md
rename to doc/pydoc/datapoint.md
diff --git a/mock_service/doc/pydoc/loader.md b/doc/pydoc/loader.md
similarity index 100%
rename from mock_service/doc/pydoc/loader.md
rename to doc/pydoc/loader.md
diff --git a/mock_service/doc/pydoc/mocking-dsl.md b/doc/pydoc/mocking-dsl.md
similarity index 100%
rename from mock_service/doc/pydoc/mocking-dsl.md
rename to doc/pydoc/mocking-dsl.md
diff --git a/mock_service/doc/pydoc/trigger.md b/doc/pydoc/trigger.md
similarity index 100%
rename from mock_service/doc/pydoc/trigger.md
rename to doc/pydoc/trigger.md
diff --git a/mock_service/doc/pydoc/types.md b/doc/pydoc/types.md
similarity index 100%
rename from mock_service/doc/pydoc/types.md
rename to doc/pydoc/types.md
diff --git a/mock_service/examples/README.md b/examples/README.md
similarity index 100%
rename from mock_service/examples/README.md
rename to examples/README.md
diff --git a/mock_service/examples/mock.py b/examples/mock.py
similarity index 100%
rename from mock_service/examples/mock.py
rename to examples/mock.py
diff --git a/mock_service/examples/seat_mock.py b/examples/seat_mock.py
similarity index 100%
rename from mock_service/examples/seat_mock.py
rename to examples/seat_mock.py
diff --git a/mock_service/examples/threaded_mock.py b/examples/threaded_mock.py
similarity index 100%
rename from mock_service/examples/threaded_mock.py
rename to examples/threaded_mock.py
diff --git a/mock_service/lib/__init__.py b/lib/__init__.py
similarity index 100%
rename from mock_service/lib/__init__.py
rename to lib/__init__.py
diff --git a/mock_service/lib/action.py b/lib/action.py
similarity index 100%
rename from mock_service/lib/action.py
rename to lib/action.py
diff --git a/mock_service/lib/animator.py b/lib/animator.py
similarity index 100%
rename from mock_service/lib/animator.py
rename to lib/animator.py
diff --git a/mock_service/lib/baseservice.py b/lib/baseservice.py
similarity index 79%
rename from mock_service/lib/baseservice.py
rename to lib/baseservice.py
index 829ac26..20c77e0 100644
--- a/mock_service/lib/baseservice.py
+++ b/lib/baseservice.py
@@ -23,7 +23,6 @@
log = logging.getLogger("mock_service")
-# VehicleDataBroker address, overridden if "DAPR_GRPC_PORT" is set in environment
VDB_ADDRESS = os.getenv("VDB_ADDRESS", "127.0.0.1:55555")
@@ -47,11 +46,7 @@ class BaseService(ABC):
def __init__(self, service_address: str, service_name: str, databroker_address: str = VDB_ADDRESS):
super().__init__()
- if os.getenv("DAPR_GRPC_PORT") is not None:
- grpc_port = os.getenv("DAPR_GRPC_PORT")
- self._vdb_address = f"127.0.0.1:{grpc_port}"
- else:
- self._vdb_address = databroker_address
+ self._vdb_address = databroker_address
self._address = service_address
self._service_name = service_name
self._connected = False
@@ -66,14 +61,7 @@ def __init__(self, service_address: str, service_name: str, databroker_address:
def _connect_to_databroker(self) -> None:
log.info("Connecting to Data Broker [%s]", self._vdb_address)
- if os.getenv("VEHICLEDATABROKER_DAPR_APP_ID") is not None:
- self._metadata = (
- ("dapr-app-id", os.getenv("VEHICLEDATABROKER_DAPR_APP_ID")),
- )
- # give some time for dapr sidecar startup...
- time.sleep(2)
- else:
- self._metadata = None
+ self._metadata = None
self._client.connect()
self._connected = True
self.on_databroker_connected()
@@ -86,7 +74,6 @@ def _run(self):
time.sleep(0.2)
continue
else:
- # TODO: check if dapr grpc proxy has active connection(e.g. send last temp value)
time.sleep(1)
@abstractmethod
diff --git a/mock_service/lib/behavior.py b/lib/behavior.py
similarity index 100%
rename from mock_service/lib/behavior.py
rename to lib/behavior.py
diff --git a/mock_service/lib/behaviorexecutor.py b/lib/behaviorexecutor.py
similarity index 100%
rename from mock_service/lib/behaviorexecutor.py
rename to lib/behaviorexecutor.py
diff --git a/mock_service/lib/datapoint.py b/lib/datapoint.py
similarity index 100%
rename from mock_service/lib/datapoint.py
rename to lib/datapoint.py
diff --git a/mock_service/lib/dsl.py b/lib/dsl.py
similarity index 100%
rename from mock_service/lib/dsl.py
rename to lib/dsl.py
diff --git a/mock_service/lib/loader.py b/lib/loader.py
similarity index 100%
rename from mock_service/lib/loader.py
rename to lib/loader.py
diff --git a/mock_service/lib/mockeddatapoint.py b/lib/mockeddatapoint.py
similarity index 100%
rename from mock_service/lib/mockeddatapoint.py
rename to lib/mockeddatapoint.py
diff --git a/mock_service/lib/trigger.py b/lib/trigger.py
similarity index 100%
rename from mock_service/lib/trigger.py
rename to lib/trigger.py
diff --git a/mock_service/lib/types.py b/lib/types.py
similarity index 100%
rename from mock_service/lib/types.py
rename to lib/types.py
diff --git a/mock_service/mock/__init__.py b/mock/__init__.py
similarity index 100%
rename from mock_service/mock/__init__.py
rename to mock/__init__.py
diff --git a/mock_service/mock/mock.py b/mock/mock.py
similarity index 100%
rename from mock_service/mock/mock.py
rename to mock/mock.py
diff --git a/mock_service/mock/mockservice.py b/mock/mockservice.py
old mode 100644
new mode 100755
similarity index 91%
rename from mock_service/mock/mockservice.py
rename to mock/mockservice.py
index fb853ad..d477325
--- a/mock_service/mock/mockservice.py
+++ b/mock/mockservice.py
@@ -30,11 +30,13 @@
from lib.types import Event
from lib.action import AnimationAction
from lib.dsl import _mocked_datapoints, _required_datapoint_paths
+# Import mock points that have been defined in mock.py
+from mock import mock # noqa # pylint: disable=unused-import
SERVICE_NAME = "mock_service"
log = logging.getLogger(SERVICE_NAME)
-log.setLevel("INFO")
+log.setLevel(logging.INFO)
# Create a file handler and set the log file name
file_handler = logging.FileHandler("mock_service.log")
@@ -49,25 +51,19 @@
event = threading.Event()
# Set the log level to suppress log messages because we call connect/disconnect of client quite often
-logging.getLogger("kuksa_client").setLevel(logging.WARNING)
-
-# Mock Service bind "host:port"
-MOCK_ADDRESS = os.getenv("MOCK_ADDR", "0.0.0.0:50053")
-VDB_ADDRESS = os.getenv("VDB_ADDRESS", "127.0.0.1:55555")
+logging.getLogger("kuksa_client").setLevel(logging.INFO)
# Data point events from VDB
EVENT_KEY_ACTUATOR_TARGET = "actuator_target"
EVENT_KEY_VALUE = "value"
-log.info(_mocked_datapoints)
-
class MockService(BaseService):
"""Service implementation which reads custom mocking configuration
from mock.py and then simulated the programmed behavior of the mocked
datapoints."""
- def __init__(self, service_address: str, databroker_address: str = VDB_ADDRESS):
+ def __init__(self, service_address: str, databroker_address: str):
log.info("Initialization ...")
super().__init__(service_address, SERVICE_NAME, databroker_address)
self._ids: Dict[str, Any] = dict()
@@ -115,6 +111,7 @@ def main_loop(self):
# wait for datapoints to be registered
while not self._registered:
time.sleep(1)
+
try:
while True:
self.check_for_new_mocks()
@@ -167,7 +164,10 @@ def _mock_update_request_handler(
def _subscribe_to_mocked_datapoints(self):
"""Subscribe to mocked datapoints."""
- log.info("Subscribing to mocked datapoints...")
+ nbr_datapoints = len(_mocked_datapoints)
+ log.info("Subscribing to %d mocked datapoints...", nbr_datapoints)
+ log.debug(_mocked_datapoints)
+
if self._mocked_datapoints:
response_iter_target = self._client.subscribe_target_values(self._mocked_datapoints)
response_iter_current = self._client.subscribe_current_values(self._mocked_datapoints)
@@ -193,18 +193,3 @@ def _set_datapoint(self, path: str, value: Any):
log.warning("Feeding %s failed", path, exc_info=True)
self._connected = is_grpc_fatal_error(err)
raise err
-
-
-async def main():
- """Main function"""
- mock_service = MockService(MOCK_ADDRESS)
- mock_service.main_loop()
-
-
-if __name__ == "__main__":
- logging.basicConfig(level=logging.INFO)
- log.setLevel(logging.DEBUG)
- LOOP = asyncio.get_event_loop()
- LOOP.add_signal_handler(signal.SIGTERM, LOOP.stop)
- LOOP.run_until_complete(main())
- LOOP.close()
diff --git a/mock_service/mock/test_new_mock.py b/mock/test_new_mock.py
similarity index 100%
rename from mock_service/mock/test_new_mock.py
rename to mock/test_new_mock.py
diff --git a/mock_service/docker-build.sh b/mock_service/docker-build.sh
deleted file mode 100755
index b542f9c..0000000
--- a/mock_service/docker-build.sh
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-#********************************************************************************
-# Copyright (c) 2022 Contributors to the Eclipse Foundation
-#
-# See the NOTICE file(s) distributed with this work for additional
-# information regarding copyright ownership.
-#
-# This program and the accompanying materials are made available under the
-# terms of the Apache License 2.0 which is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# SPDX-License-Identifier: Apache-2.0
-#*******************************************************************************/
-# shellcheck disable=SC2181
-# shellcheck disable=SC2086
-# shellcheck disable=SC2230
-
-SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
-CONTEXT_DIR="$SCRIPT_DIR"
-# name of docker image: ${DOCKER_ARCH)/${DOCKER_IMAGE}
-DOCKER_IMAGE="mock_service"
-
-print_usage() {
- echo "USAGE: $0 [OPTIONS] TARGETS"
- echo
- echo "Standalone build helper for $DOCKER_IMAGE docker image."
- echo
- echo "OPTIONS:"
- echo " -l, --local local docker import (does not export tar)"
- echo " -v, --verbose enable plain docker output and disable cache"
- echo " --help show help"
- echo
- echo "TARGETS:"
- echo " x86_64|amd64, aarch64|amd64 Target arch to build for, if not set - defaults to multiarch"
- echo
-}
-
-LOCAL=0
-VERBOSE=0
-while [ $# -gt 0 ]; do
- if [ "$1" = "--local" ] || [ "$1" = "-l" ]; then
- LOCAL=1
- elif [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then
- VERBOSE=1
- elif [ "$1" = "--help" ]; then
- print_usage
- exit 0
- else
- TARGET="$1"
- fi
- shift
-done
-
-target_arch() {
- local target="$1"
- case "$target" in
- "x86_64" | "amd64")
- echo "amd64"
- ;;
- "arm64" | "aarch64")
- echo "arm64"
- ;;
- "armv6" | "arm")
- echo "arm/v6"
- ;;
- "multiarch" | "")
- echo "multiarch"
- ;;
- *)
- return 1
- ;;
- esac
- return 0
-}
-
-if [ -z "$TARGET" ] && [ $LOCAL -eq 1 ]; then
- echo "Multiarch archives are not supported for local builds, removing --local flag ..."
- LOCAL=0
-fi
-
-DOCKER_ARCH=$(target_arch "$TARGET")
-DOCKER_EXPORT="./${DOCKER_ARCH//\//_}-${DOCKER_IMAGE}.tar"
-
-if [ "$DOCKER_ARCH" = "multiarch" ]; then
- DOCKER_ARGS="--platform linux/amd64,linux/arm64 -t $DOCKER_ARCH/$DOCKER_IMAGE --output type=oci,dest=$DOCKER_EXPORT"
-else
- if [ $LOCAL -eq 1 ]; then
- DOCKER_ARGS="--load -t $DOCKER_ARCH/$DOCKER_IMAGE"
- DOCKER_EXPORT="($DOCKER_ARCH/$DOCKER_IMAGE ghcr.io/eclipse/kuksa.val.services/$DOCKER_IMAGE:prerelease)"
- else
- DOCKER_ARGS="--platform linux/$DOCKER_ARCH -t $DOCKER_ARCH/$DOCKER_IMAGE --output type=oci,dest=$DOCKER_EXPORT"
- fi
-fi
-
-if [ "$VERBOSE" = "1" ]; then
- DOCKER_ARGS="--no-cache --progress=plain $DOCKER_ARGS"
-fi
-
-cd "$CONTEXT_DIR" || exit 1
-echo "# docker buildx build $DOCKER_ARGS -f Dockerfile $CONTEXT_DIR"
-DOCKER_BUILDKIT=1 docker buildx build $DOCKER_ARGS -f Dockerfile "$CONTEXT_DIR" $DOCKER_EXT
-
-if [ $? -eq 0 ]; then
- echo "docker image tag $DOCKER_ARCH/$DOCKER_IMAGE ghcr.io/eclipse/kuksa.val.services/$DOCKER_IMAGE:prerelease"
- docker image tag $DOCKER_ARCH/$DOCKER_IMAGE ghcr.io/eclipse/kuksa.val.services/$DOCKER_IMAGE:prerelease
- echo "# Exported $DOCKER_ARCH/$DOCKER_IMAGE in $DOCKER_EXPORT"
- docker image ls | grep "/$DOCKER_IMAGE"
-fi
diff --git a/mock_service/requirements-dev.txt b/mock_service/requirements-dev.txt
deleted file mode 100644
index 79a9eec..0000000
--- a/mock_service/requirements-dev.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-grpcio>=1.44.0
-protobuf>=3.19.4
-types-protobuf
-grpcio-tools
-pytest
diff --git a/mockprovider.py b/mockprovider.py
new file mode 100755
index 0000000..6743f23
--- /dev/null
+++ b/mockprovider.py
@@ -0,0 +1,49 @@
+#! /usr/bin/env python3
+# /********************************************************************************
+# * Copyright (c) 2023 Contributors to the Eclipse Foundation
+# *
+# * See the NOTICE file(s) distributed with this work for additional
+# * information regarding copyright ownership.
+# *
+# * This program and the accompanying materials are made available under the
+# * terms of the Apache License 2.0 which is available at
+# * http://www.apache.org/licenses/LICENSE-2.0
+# *
+# * SPDX-License-Identifier: Apache-2.0
+# ********************************************************************************/
+
+import asyncio
+import logging
+import os
+import signal
+import threading
+from mock.mockservice import MockService
+
+SERVICE_NAME = "mock_provider"
+
+log = logging.getLogger(SERVICE_NAME)
+log.setLevel(logging.INFO)
+
+event = threading.Event()
+
+# Set the log level to suppress log messages because we call connect/disconnect of client quite often
+logging.getLogger("kuksa_client").setLevel(logging.INFO)
+
+# Mock Service bind "host:port"
+MOCK_ADDRESS = os.getenv("MOCK_ADDR", "0.0.0.0:50053")
+VDB_ADDRESS = os.getenv("VDB_ADDRESS", "127.0.0.1:55555")
+
+
+async def main():
+ """Main function"""
+ mock_service = MockService(MOCK_ADDRESS, VDB_ADDRESS)
+ mock_service.main_loop()
+
+
+if __name__ == "__main__":
+ logging.basicConfig(level=logging.INFO)
+ log.setLevel(logging.DEBUG)
+ LOOP = asyncio.get_event_loop()
+ LOOP.add_signal_handler(signal.SIGTERM, LOOP.stop)
+ LOOP.run_until_complete(main())
+ LOOP.close()
diff --git a/mock_service/pydoc-markdown.yml b/pydoc-markdown.yml
similarity index 100%
rename from mock_service/pydoc-markdown.yml
rename to pydoc-markdown.yml
diff --git a/requirements-dev.txt b/requirements-dev.txt
new file mode 100644
index 0000000..e079f8a
--- /dev/null
+++ b/requirements-dev.txt
@@ -0,0 +1 @@
+pytest
diff --git a/mock_service/requirements.txt b/requirements.txt
similarity index 100%
rename from mock_service/requirements.txt
rename to requirements.txt
diff --git a/mock_service/setup.py b/setup.py
similarity index 96%
rename from mock_service/setup.py
rename to setup.py
index 7714ebe..8c5ce33 100644
--- a/mock_service/setup.py
+++ b/setup.py
@@ -18,7 +18,7 @@
pkg_packages = find_packages()
setup(
- name="mock_service",
+ name="mock_provider",
packages=pkg_packages,
version=PKG_VERSION,
classifiers=["License :: OSI Approved :: Apache Software License"],
diff --git a/mock_service/showcase_gui/GUI.py b/showcase_gui/GUI.py
old mode 100644
new mode 100755
similarity index 98%
rename from mock_service/showcase_gui/GUI.py
rename to showcase_gui/GUI.py
index 2149176..a6f3fc3
--- a/mock_service/showcase_gui/GUI.py
+++ b/showcase_gui/GUI.py
@@ -1,3 +1,4 @@
+#! /usr/bin/env python3
# /********************************************************************************
# * Copyright (c) 2022 Contributors to the Eclipse Foundation
# *
@@ -14,6 +15,7 @@
import argparse
import threading
+import os
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
@@ -25,14 +27,15 @@
from kuksa_client.grpc import EntryType
from mock.mockservice import MockService
+from mock import mock
from lib.dsl import (
create_animation_action,
create_behavior,
create_set_action,
get_datapoint_value,
mock_datapoint,
- create_event_trigger
-)
+ create_event_trigger,
+ _mocked_datapoints)
from lib.trigger import ClockTrigger, EventType
from lib.animator import RepeatMode
from lib.behavior import Behavior
@@ -547,13 +550,15 @@ def update_elements(self):
print("Something wrong!")
def mainloop(self):
- mock = MockService("127.0.0.1:50053")
+ VDB_ADDRESS = os.getenv("VDB_ADDRESS", "127.0.0.1:55555")
+ mock2 = MockService("127.0.0.1:50053", VDB_ADDRESS)
+ print("Loaded " + str(len(_mocked_datapoints)) + " mocked datapoints")
# GUI elements to add dynamically
button = ttk.Button(root, text="Add Element", command=app.show_popup)
app.elements.append(button)
app.update_layout()
- Mock = threading.Thread(target=mock.main_loop)
+ Mock = threading.Thread(target=mock2.main_loop)
Mock.start()
print("Mock started ...")
while True:
diff --git a/mock_service/showcase_gui/README.md b/showcase_gui/README.md
similarity index 100%
rename from mock_service/showcase_gui/README.md
rename to showcase_gui/README.md
diff --git a/mock_service/test/__init__.py b/test/__init__.py
similarity index 100%
rename from mock_service/test/__init__.py
rename to test/__init__.py
diff --git a/mock_service/test/test_animator.py b/test/test_animator.py
similarity index 100%
rename from mock_service/test/test_animator.py
rename to test/test_animator.py
diff --git a/mock_service/test/test_behavior.py b/test/test_behavior.py
similarity index 100%
rename from mock_service/test/test_behavior.py
rename to test/test_behavior.py
diff --git a/mock_service/update-api-docs.sh b/update-api-docs.sh
similarity index 100%
rename from mock_service/update-api-docs.sh
rename to update-api-docs.sh