diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..dc207f7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,64 @@ +name: sysrepo-plugin-snabb CI + +on: + push: + branches: ["devel"] + pull_request: + branches: ["devel"] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + submodules: 'recursive' + - name: deps-libyang + shell: bash + run: | + git clone https://github.com/cesnet/libyang + cd libyang + CC=gcc cmake -B build + cmake --build build + sudo cmake --install build + sudo ldconfig + cd .. + + - name: Deps-sysrepo + shell: bash + run: | + git clone https://github.com/sysrepo/sysrepo + cd sysrepo + CC=gcc cmake -B build + cmake --build build + sudo cmake --install build + sudo ldconfig + cd .. + + - name: Deps-snabb + shell: bash + run: | + git clone https://github.com/SnabbCo/snabb + cd snabb + make -j4 && sudo make install + sudo ldconfig + cd .. + + - name: Snabb-plugin + shell: bash + working-directory: ${{github.workspace}} + run: | + cmake -B build -DCMAKE_BUILD_TYPE:String="Release" \ + -DPLUGIN:BOOL=ON -DSR_PLUGINS_DIR=/usr/local/lib/ \ + -DYANG_MODEL:String="snabb-softwire-v3" + cd build + make -j4 + sudo make install + sudo ldconfig + cd .. + + - name: Install-yang-model + shell: bash + working-directory: ${{github.workspace}} + run: | + sudo sysrepoctl -i snabb/src/lib/yang/snabb-softwire-v3.yang diff --git a/tests/robot-tests/README.md b/tests/robot-tests/README.md new file mode 100644 index 0000000..dd9285c --- /dev/null +++ b/tests/robot-tests/README.md @@ -0,0 +1,26 @@ +# Integration tests for sysrepo-snabb-plugin + +# Requirements +* Sysrepo +* Snabb +* Libyang +* Python packages inside of "requirements.txt" +* Robot framework + +# Running +Before running the tests for the first time run the as ```setup.sh``` script +as root, also make sure that you have built the the plugin and have snabb installed. +The script will fetch the configuration file for the tests and +create the virtual interfaces needed for execution of the tests. +It will also create a python virtual environment with the needed +python packages. + +Activate virtual python environment with +``` +source ./test-venv/bin/activate +``` + +After you have done all that, you may run the tests with +``` +robot ./src/Main.robot +``` diff --git a/tests/robot-tests/requirements.txt b/tests/robot-tests/requirements.txt new file mode 100644 index 0000000..55d3d51 --- /dev/null +++ b/tests/robot-tests/requirements.txt @@ -0,0 +1,10 @@ +build +cffi +libyang +packaging +pycparser +pyproject_hooks +robotframework +robotframework-sysrepolibrary +sysrepo +xmltodict diff --git a/tests/robot-tests/setup.sh b/tests/robot-tests/setup.sh new file mode 100755 index 0000000..a4c4d0f --- /dev/null +++ b/tests/robot-tests/setup.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Requirements +# Before running this script make sure these requirements are satisfied +# Compile the sysrepo-snabb-plugin in the root directory of this project +# Install snabb on your system + +set -e + +# Get the bare minimum config and veth setup script +if [ ! -e lwaftr-veth-env.sh ]; then + curl 'https://raw.githubusercontent.com/snabbco/snabb/master/src/program/lwaftr/doc/tutorial/lwaftr-veth-env.sh' \ + > lwaftr-veth-env.sh +fi + +if [ ! -e ./config/lwaftr-start.conf ]; then + mkdir config + curl 'https://raw.githubusercontent.com/snabbco/snabb/master/src/program/lwaftr/doc/tutorial/lwaftr-start.conf' \ + > ./config/lwaftr-start.conf +fi + + +# create venv with dependencies +if [ ! -d test-venv ];then + python -m test-venv && pip install -r requirements.txt +fi + +# Run the veth setup script +sh lwaftr-veth-env.sh create diff --git a/tests/robot-tests/src/Main.robot b/tests/robot-tests/src/Main.robot new file mode 100644 index 0000000..7f4f0a6 --- /dev/null +++ b/tests/robot-tests/src/Main.robot @@ -0,0 +1,49 @@ +*** Settings *** +Library Collections +Library OperatingSystem +Library String +Library Process +Library BuiltIn +Library SysrepoLibrary +Library XML + +Resource PluginInit.resource + +Test Setup Startup +Test Teardown Cleanup + +*** Test Cases *** +Test Get External Interface Name + [Documentation] Check if it's possible to get data values from the snabb config + ${Interface Name}= Get Datastore Data ${Connection} + ... ${Session Running} /softwire-config/instance/external-device xml + Element Text Should Be ${Interface Name} aftrv4 xpath=*/external-device + +Test Add softwire + [Documentation] Creates a new softwire entry to the datastore and check if it has been added to the snabb lwaftr config + ${New softwire}= catenate SEPARATOR= + ... + ... 0.0.0.0 + ... 1 + ... 0 + ... 1e:1:1:1:1:1:1:af + ... 127:24:35:46:57:68:79:128 + ... + ... 16 + ... 0 + ... + ... + + ${New softwire entry}= catenate SEPARATOR= + ... + ... + ... ${New softwire} + ... + ... + Edit Datastore Config ${Connection} ${Session Running} ${New softwire entry} xml + ${Datastore state}= Get Datastore Data ${Connection} ${Session Running} + ... * xml + ${Softwire Elements}= Get Elements ${Datastore state} xpath=*/softwire + ${tmp}= Element to String ${Softwire Elements}[1] + Elements Should Be Equal ${New softwire} ${Softwire Elements}[1] + diff --git a/tests/robot-tests/src/PluginInit.resource b/tests/robot-tests/src/PluginInit.resource new file mode 100644 index 0000000..d4cd0b2 --- /dev/null +++ b/tests/robot-tests/src/PluginInit.resource @@ -0,0 +1,42 @@ +** Settings *** +Library OperatingSystem +Library SysrepoLibrary + + +*** Variables *** +${CONFIG_FILE_PATH} config/lwaftr-start.conf +${SNABB_LWAFTR_INSTANCE_NAME} sysrepo-snabb-plugin-test + +*** Keywords *** + +Start Plugin + ${Plugin}= Start Process sysrepo-snabb-plugin + Set Global Variable ${Plugin} + Wait For Process ${Plugin} timeout=0.5s on_timeout=continue + +Stop Plugin + Terminate Process ${Plugin} + +Connect To Softwire + ${Connection}= Open Sysrepo Connection + Set Global Variable ${Connection} + ${Session Running}= Open Datastore Session ${Connection} running + Set Global Variable ${Session Running} + +Start Snabb + ${Snabb}= Start Process snabb lwaftr run --config ${CONFIG_FILE_PATH} --name ${SNABB_LWAFTR_INSTANCE_NAME} + Set Global Variable ${Snabb} + Wait For Process ${Plugin} timeout=0.5s on_timeout=continue + +Stop Snabb + Terminate Process ${Snabb} + +Startup + Start Plugin + Start Snabb + Set Global Variable ${SNABB_LWAFTR_INSTANCE_NAME} + Connect To Softwire + +Cleanup + Stop Plugin + Stop Snabb