Commit 2d2a7f17 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Merge branch 'develop' of https://gitlab.com/teraflow-h2020/controller into...

Merge branch 'develop' of https://gitlab.com/teraflow-h2020/controller into feat/ecoc22-dc-interconnect-disjoint
parents f0626c36 80a8951e
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ coverage.xml
.pytest_cache/
.benchmarks/
cover/
*_report.xml

# Translations
*.mo
+1 −0
Original line number Diff line number Diff line
@@ -190,6 +190,7 @@ message DeviceList {
message DeviceEvent {
  Event event = 1;
  DeviceId device_id = 2;
  DeviceConfig device_config = 3;
}


run_tests_docker.sh

0 → 100755
+59 −0
Original line number Diff line number Diff line
#!/bin/bash

########################################################################################################################
# Define your deployment settings here
########################################################################################################################

# Set the URL of your local Docker registry where the images will be uploaded to. Leave it blank if you do not want to
# use any Docker registry.
REGISTRY_IMAGE=""
#REGISTRY_IMAGE="http://my-container-registry.local/"

# Set the list of components you want to build images for, and deploy.
COMPONENTS="context device automation policy service compute monitoring centralizedattackdetector"

# Set the tag you want to use for your images.
IMAGE_TAG="tf-dev"

# Constants
TMP_FOLDER="./tmp"

TMP_LOGS_FOLDER="$TMP_FOLDER/logs"
mkdir -p $TMP_LOGS_FOLDER

for COMPONENT in $COMPONENTS; do
    echo "Processing '$COMPONENT' component..."
    IMAGE_NAME="$COMPONENT:$IMAGE_TAG"
    IMAGE_URL="$REGISTRY_IMAGE/$IMAGE_NAME"

    echo "  Building Docker image..."
    BUILD_LOG="$TMP_LOGS_FOLDER/build_${COMPONENT}.log"

    if [ "$COMPONENT" == "automation" ] || [ "$COMPONENT" == "policy" ]; then
        docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/"$COMPONENT"/ > "$BUILD_LOG"
    else 
        docker build -t "$IMAGE_NAME" -f ./src/"$COMPONENT"/Dockerfile ./src/ > "$BUILD_LOG"
    fi

    if [ -n "$REGISTRY_IMAGE" ]; then
        echo "Pushing Docker image to '$REGISTRY_IMAGE'..."

        TAG_LOG="$TMP_LOGS_FOLDER/tag_${COMPONENT}.log"
        docker tag "$IMAGE_NAME" "$IMAGE_URL" > "$TAG_LOG"

        PUSH_LOG="$TMP_LOGS_FOLDER/push_${COMPONENT}.log"
        docker push "$IMAGE_URL" > "$PUSH_LOG"
    fi
done

echo "Preparing for running the tests..."

if docker network list | grep teraflowbridge; then echo "teraflowbridge is already created"; else docker network create -d bridge teraflowbridge; fi  

for COMPONENT in $COMPONENTS; do
    IMAGE_NAME="$COMPONENT:$IMAGE_TAG"
    echo "  Running tests for $COMPONENT:"
    docker run -it -d --name $COMPONENT $IMAGE_NAME --network=teraflowbridge
    docker exec -it $COMPONENT bash -c "pytest --log-level=DEBUG --verbose $COMPONENT/tests/test_unitary.py"
    docker stop $COMPONENT
done
+57 −0
Original line number Diff line number Diff line
#!/bin/bash
# Copyright 2021-2023 H2020 TeraFlow (https://www.teraflow-h2020.eu/)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

die () {
    echo >&2 "$@"
    exit 1
}

[ "$#" -eq 1 ] || die "component name required but not provided"

COMPONENT_NAME=$1 # parameter
IMAGE_NAME="${COMPONENT_NAME}-local"
IMAGE_TAG="latest"

if docker ps | grep $IMAGE_NAME
then
    docker stop $IMAGE_NAME
fi

if docker network list | grep teraflowbridge
then
    echo "teraflowbridge is already created"
else
    docker network create -d bridge teraflowbridge
fi

docker build -t "$IMAGE_NAME:$IMAGE_TAG" -f ./src/$COMPONENT_NAME/Dockerfile .

docker run --name $IMAGE_NAME -d -v "${PWD}/src/${COMPONENT_NAME}/tests:/home/${COMPONENT_NAME}/results" --network=teraflowbridge --rm $IMAGE_NAME:$IMAGE_TAG

docker exec -i $IMAGE_NAME bash -c "coverage run -m pytest --log-level=INFO --verbose $COMPONENT_NAME/tests/ --junitxml=/home/${COMPONENT_NAME}/results/${COMPONENT_NAME}_report.xml"

PROJECTDIR=`pwd`

cd $PROJECTDIR/src
RCFILE=$PROJECTDIR/coverage/.coveragerc

echo
echo "Coverage report:"
echo "----------------"
docker exec -i $IMAGE_NAME bash -c "coverage report --include='${COMPONENT_NAME}/*' --show-missing"

# docker stop $IMAGE_NAME
docker rm -f $IMAGE_NAME
docker network rm teraflowbridge
+50 −15
Original line number Diff line number Diff line
# Automation TeraFlow OS service 
# TeraFlowSDN Automation service

The Automation service, also known as Zero-Touch Provisioning (ZTP), is tested on Ubuntu 20.04. Follow the instructions below to build, test, and run this service on your local environment.
This repository hosts the TeraFlowSDN Automation service, also known as Zero-Touch Provisioning (ZTP) service.
Follow the instructions below to build, test, and run this service on your local environment.

## Automation Teraflow OS service architecture
## TeraFlowSDN Automation service architecture

| The Automation Teraflow OS service architecture consists of six (6) interfaces listed below:                                                                                                                                                 | 
The TeraFlowSDN Automation architecture consists of six (6) interfaces listed below:

Interfaces |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1. The `AutomationGateway` interface that implements all the rpc functions that are described in `automation.proto` file.                                                                                                                    | 
| 2. The `ContextGateway` interface that communicates with a `Context` Service gRPC client and implements all the rpc functions that are described in `context.proto` file.                                                                    |
| 3. The `DeviceGateway` interface that communicates with a `Device` Service gRPC client and implements all the rpc functions that are described in `device.proto` file.                                                                       |
| 4. The `AutomationService` interface that implements the `addDevice()` method by communicating with a `Context` gRPC client & a `Device` gRPC client through the use of `ContextService` interface & `DeviceService` interface respectively. |
| 5. The `ContextService` interface that implements the `getDevice()` & `getDeviceEvents()` methods by communicating with a `Context` gRPC client through the use of `ContextGateway` interface.                                               |
| 6. The `DeviceService` interface that implements the `getInitialConfiguration()` & `configureDevice()` methods by communicating with a `Device` gRPC client through the use of `DeviceGateway` interface.                                    |
| 1. The `AutomationGateway` interface that implements all the RPC functions that are described in `automation.proto` file. |
| 2. The `ContextGateway` interface that communicates with a `Context` Service gRPC client to invoke key RPC functions described in `context.proto` file. |
| 3. The `DeviceGateway` interface that communicates with a `Device` Service gRPC client to invoke key RPC functions described in `device.proto` file. |
| 4. The `AutomationService` interface that implements the `addDevice()`, `updateDevice()`, and `deleteDevice()` methods by communicating with a `Context` gRPC client and a `Device` gRPC client through the use of `ContextService` interface and `DeviceService` interface respectively. |
| 5. The `ContextService` interface that implements the `getDevice()` and `getDeviceEvents()` methods by communicating with a `Context` gRPC client through the use of `ContextGateway` interface. |
| 6. The `DeviceService` interface that implements the `getInitialConfiguration()`, `configureDevice()`, and `deleteDevice()` methods by communicating with a `Device` gRPC client through the use of `DeviceGateway` interface. |


## Prerequisites

The Automation service is currently tested against Ubuntu 20.04 and Java 11.

To quickly install Java 11 on a Debian-based Linux distro do:

```bash
sudo apt-get install openjdk-11-jdk -y
```

Feel free to try more recent Java versions.

## Compile

```bash
./mvnw compile
```

## Run with dev profile
## Run tests

```bash
./mvnw clean quarkus:dev
./mvnw test
```

## Running tests
## Run service

```bash
./mvnw quarkus:dev
````

## Clean

Run unit and functional tests `./mvnw clean test`
```bash
./mvnw clean
```

## Deploying on a Kubernetes cluster

@@ -37,3 +66,9 @@ To deploy the application in a K8s cluster run
```bash
kubectl apply -f "manifests/automationservice.yaml"
```

## Maintainers

This TeraFlowSDN service is implemented by [UBITECH](https://www.ubitech.eu).

Feel free to contact Georgios Katsikas (gkatsikas at ubitech dot eu) in case you have questions.
Loading