Skip to content

Commit

Permalink
Refactor mock service for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
erikbosch committed Mar 5, 2024
1 parent b225773 commit 103a354
Show file tree
Hide file tree
Showing 54 changed files with 250 additions and 196 deletions.
5 changes: 5 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"image": "mcr.microsoft.com/devcontainers/python:3.11",
"runArgs": ["--network=host"]

}
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max_line_length = 120
33 changes: 33 additions & 0 deletions .github/workflows/check_license.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
41 changes: 41 additions & 0 deletions .github/workflows/dash.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,24 @@
# * SPDX-License-Identifier: Apache-2.0
# ********************************************************************************/

name: mock-service
name: mock-provider

on:
push:
branches:
- main
pull_request:
paths:
- ".github/workflows/mock_service.yml"
- "mock_service/**"
- "proto/**"
workflow_call:
workflow_dispatch:

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true

# Needed as default_workflow_permissions is "read"
permissions:
packages: write

jobs:

check_ghcr_push:
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
with:
# list of Docker images to use as base name for tags
images: |
ghcr.io/eclipse/kuksa.val.services/mock_service
ghcr.io/eclipse-kuksa/kuksa-mock-provider/mock-provider
# generate Docker tags based on the following events/attributes
tags: |
type=ref,event=branch
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -141,7 +141,7 @@ jobs:

- name: (Re-) Build Pydoc Markdown
shell: bash
working-directory: mock_service
working-directory: .
run: |
./update-api-docs.sh
Expand Down Expand Up @@ -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
24 changes: 24 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
with:
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }}
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[FORMAT]
max-line-length=120
8 changes: 1 addition & 7 deletions mock_service/Dockerfile → Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
61 changes: 50 additions & 11 deletions mock_service/README.md → README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,7 +26,19 @@ flowchart LR
ValIF <--> id3
```

# Running mockservice
## Running Mock Provider

The Kuksa Mock Provider will try to connect to a KUKSA Databroker.
Before starting the Mock Provider you must start a compatible version of the
[KUKSA Databroker](https://github.com/eclipse/kuksa.val/tree/master/kuksa_databroker).
If the Databroker is not reachable on `127.0.0.1:55555` you must specify IP and Port when starting
the Mock provider.
The Mock provider does not have support for TLS and Token authorization,
so you cannot connect to a Databroker requiring TLS or Authorization.

The [default mock](mock/mock.py) contains VSS signals that must exist in the VSS catalog loaded
by the Databroker. As of today VSS 3.0 onwards shall match the default mock in this repository.


Firstly, you will need to install all necessary Python dependencies by issuing the following command in your favorite terminal:

Expand All @@ -35,22 +49,47 @@ 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.
### Running with Docker

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.
As an alternative, you can build and execute the container from the [Dockerfile](./Dockerfile).

```bash
$ docker build -f Dockerfile -t mock-provider:latest .
$ docker run --net=host mock-provider:latest
INFO:mock_service:Initialization ...
INFO:mock_service:Connecting to Data Broker [127.0.0.1:55555]
INFO:kuksa_client.grpc:No Root CA present, it will not be possible to use a secure connection!
...
```

### Running with Devcontainer

A decontainer is provided. To run you must first install dependencies.

```bash
vscode ➜ /workspaces/kuksa-mock-provider $ python3 -m pip install -r ./requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Processing /workspaces/kuksa-mock-provider
...
vscode ➜ /workspaces/kuksa-mock-provider $ python3 mockprovider.py
INFO:mock_service:Initialization ...
INFO:mock_service:Connecting to Data Broker [127.0.0.1:55555]
INFO:kuksa_client.grpc:No Root CA present, it will not be possible to use a secure connection!
...
```

## 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:<br>`"127.0.0.1:$DAPR_GRPC_PORT"` <br>else:<br> `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
Expand All @@ -74,7 +113,7 @@ If the mocked datapoints are not enough, the `mock.py` in this repository can be

The full Python mocking DSL is available [here](./doc/pydoc/mocking-dsl.md)

# Running showcase GUI
# Running showcase GUI

Firstly, you will need to install all necessary Python dependencies by using the following command in your favorite terminal:

Expand All @@ -83,7 +122,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
Expand Down
8 changes: 4 additions & 4 deletions mock_service/doc/concept.md → doc/concept.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
|:---|:-------:|:-----------|
Expand Down Expand Up @@ -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()
}
Expand Down
Binary file added doc/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 103a354

Please sign in to comment.