Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7693aec
initial commit
noursaidi Aug 17, 2023
4c35bc5
Merge remote-tracking branch 'origin/dev' into test_api
noursaidi Aug 17, 2023
8acf4ea
changes
noursaidi Aug 17, 2023
3f6a736
new report structure
noursaidi Aug 17, 2023
831b777
wip
noursaidi Aug 30, 2023
286f66d
bug fixes, tester3, archive
noursaidi Aug 30, 2023
998d2d2
parralel actions
noursaidi Aug 30, 2023
5d0c60f
try fixing archive results
noursaidi Aug 30, 2023
98586d1
fix tar path
noursaidi Aug 30, 2023
22b62b6
api test
noursaidi Aug 31, 2023
1f5dbcc
add api test
noursaidi Sep 1, 2023
850e907
fix workflow
noursaidi Sep 1, 2023
9c5032e
Merge branch 'dev' into test_api
jboddey Sep 1, 2023
67584d0
Install pytest
jboddey Sep 1, 2023
f68617b
Remove sudo on pytest
jboddey Sep 1, 2023
c232751
improved logging
noursaidi Sep 4, 2023
b862d17
build ui
noursaidi Sep 4, 2023
15ac9b6
pylint
noursaidi Sep 4, 2023
219d656
testing api
noursaidi Sep 4, 2023
64b7bbe
api testing
noursaidi Sep 5, 2023
83a64aa
rename pass to compliant
noursaidi Sep 5, 2023
b7be7ab
x
noursaidi Sep 5, 2023
8cc0a8c
use new test names
noursaidi Sep 5, 2023
fa3963b
more test renaming
noursaidi Sep 5, 2023
2a98ce0
more test renaming
noursaidi Sep 5, 2023
b24a7f3
more test renaming
noursaidi Sep 5, 2023
f6674bf
Update testing.yml
noursaidi Sep 6, 2023
5ad84c4
Update test_api.py
noursaidi Sep 6, 2023
c374aca
Merge branch 'dev' into test_api
noursaidi Sep 6, 2023
170bdee
refactor
noursaidi Sep 8, 2023
dc902a4
fixs
noursaidi Sep 8, 2023
540bd3f
ftimeout
noursaidi Sep 8, 2023
ed44d8b
increase timeout and disable bugs
noursaidi Sep 8, 2023
e4efbac
fix incorrect key
noursaidi Sep 11, 2023
f2db100
increase ready timelimit for baseline test
noursaidi Sep 11, 2023
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
23 changes: 21 additions & 2 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: Testrun test suite

on:
push:
pull_request:
schedule:
- cron: '0 13 * * *'
Expand All @@ -21,14 +20,34 @@ jobs:
testrun_tests:
name: Tests
runs-on: ubuntu-20.04
needs: testrun_baseline
timeout-minutes: 40
steps:
- name: Checkout source
uses: actions/checkout@v2.3.4
- name: Run tests
shell: bash {0}
run: testing/tests/test_tests
- name: Archive runtime results
if: ${{ always() }}
run: sudo tar --exclude-vcs -czf runtime.tgz runtime/
- name: Upload runtime results
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
if-no-files-found: error
name: runtime_${{ github.workflow }}_${{ github.run_id }}
path: runtime.tgz

testrun_api:
name: API
runs-on: ubuntu-20.04
timeout-minutes: 40
steps:
- name: Checkout source
uses: actions/checkout@v2.3.4
- name: Run tests
shell: bash {0}
run: testing/api/test_api

pylint:
name: Pylint
Expand Down
2 changes: 1 addition & 1 deletion bin/testrun
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.

if [[ "$EUID" -ne 0 ]]; then
echo "Must run as root. Use sudo testrun"
echo "Must run as root. Use sudo $0"
exit 1
fi

Expand Down
3 changes: 3 additions & 0 deletions cmd/install
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ pip3 install -r framework/requirements.txt
# required by python package weasyprint
sudo apt-get install libpangocairo-1.0-0

#TODO move into docker build process
(cd modules/ui && npm install && npm run build)

deactivate
15 changes: 10 additions & 5 deletions framework/python/src/common/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,21 @@ def _load_config(self):
if (NETWORK_KEY in config_file_json
and DEVICE_INTF_KEY in config_file_json.get(NETWORK_KEY)
and INTERNET_INTF_KEY in config_file_json.get(NETWORK_KEY)):
self._config[NETWORK_KEY][DEVICE_INTF_KEY] = config_file_json.get(NETWORK_KEY, {}).get(DEVICE_INTF_KEY)
self._config[NETWORK_KEY][INTERNET_INTF_KEY] = config_file_json.get(NETWORK_KEY, {}).get(INTERNET_INTF_KEY)
self._config[NETWORK_KEY][DEVICE_INTF_KEY] = config_file_json.get(
NETWORK_KEY, {}).get(DEVICE_INTF_KEY)
self._config[NETWORK_KEY][INTERNET_INTF_KEY] = config_file_json.get(
NETWORK_KEY, {}).get(INTERNET_INTF_KEY)

if RUNTIME_KEY in config_file_json:
self._config[RUNTIME_KEY] = config_file_json.get(RUNTIME_KEY)

if STARTUP_TIMEOUT_KEY in config_file_json:
self._config[STARTUP_TIMEOUT_KEY] = config_file_json.get(STARTUP_TIMEOUT_KEY)
self._config[STARTUP_TIMEOUT_KEY] = config_file_json.get(
STARTUP_TIMEOUT_KEY)

if MONITOR_PERIOD_KEY in config_file_json:
self._config[MONITOR_PERIOD_KEY] = config_file_json.get(MONITOR_PERIOD_KEY)
self._config[MONITOR_PERIOD_KEY] = config_file_json.get(
MONITOR_PERIOD_KEY)

if LOG_LEVEL_KEY in config_file_json:
self._config[LOG_LEVEL_KEY] = config_file_json.get(LOG_LEVEL_KEY)
Expand All @@ -106,7 +110,8 @@ def _load_config(self):
self._config[API_PORT_KEY] = config_file_json.get(API_PORT_KEY)

if MAX_DEVICE_REPORTS_KEY in config_file_json:
self._config[MAX_DEVICE_REPORTS_KEY] = config_file_json.get(MAX_DEVICE_REPORTS_KEY)
self._config[MAX_DEVICE_REPORTS_KEY] = config_file_json.get(
MAX_DEVICE_REPORTS_KEY)

def _save_config(self):
with open(self._config_file, 'w', encoding='utf-8') as f:
Expand Down
17 changes: 9 additions & 8 deletions framework/python/src/common/testreport.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def to_pdf(self):
pdf_bytes = BytesIO()
HTML(string=report_html).write_pdf(pdf_bytes)
return pdf_bytes

def to_html(self):
json_data = self.to_json()
return f'''
Expand All @@ -118,18 +118,19 @@ def to_html(self):
'''

def generate_test_sections(self,json_data):
results = json_data["tests"]["results"]
sections = ""
results = json_data['tests']['results']
sections = ''
for result in results:
sections += self.generate_test_section(result)
sections += self.generate_test_section(result)
return sections

def generate_test_section(self, result):
section_content = '<section class="test-section">\n'
for key, value in result.items():
if value is not None: # Check if the value is not None
formatted_key = key.replace('_', ' ').title() # Replace underscores and capitalize
section_content += f'<p><strong>{formatted_key}:</strong> {value}</p>\n'
if value is not None: # Check if the value is not None
# Replace underscores and capitalize
formatted_key = key.replace('_', ' ').title()
section_content += f'<p><strong>{formatted_key}:</strong> {value}</p>\n'
section_content += '</section>\n<div style="margin-bottom: 40px;"></div>\n'
return section_content

Expand Down Expand Up @@ -171,4 +172,4 @@ def generate_css(self):
text-decoration: none;
color: #007bff;
}
'''
'''
6 changes: 5 additions & 1 deletion framework/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ weasyprint
fastapi==0.99.1
psutil
uvicorn
pydantic==1.10.11
pydantic==1.10.11

# Requirements for testing
pytest
pytest-timeout
2 changes: 1 addition & 1 deletion modules/network/dhcp-1/dhcp-1.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get install -y wget
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get install -y isc-dhcp-server radvd systemd
RUN apt-get update && apt-get install -y isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf
Expand Down
2 changes: 1 addition & 1 deletion modules/network/dhcp-2/dhcp-2.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ RUN apt-get install -y wget
RUN wget http://standards-oui.ieee.org/oui.txt -P /usr/local/etc/

# Install dhcp server
RUN apt-get install -y isc-dhcp-server radvd systemd
RUN apt-get update && apt-get install -y isc-dhcp-server radvd systemd

# Copy over all configuration files
COPY $MODULE_DIR/conf /testrun/conf
Expand Down
6 changes: 3 additions & 3 deletions modules/test/baseline/python/src/baseline_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ def __init__(self, module):
global LOGGER
LOGGER = self._get_logger()

def _baseline_pass(self):
def _baseline_compliant(self):
LOGGER.info('Running baseline pass test')
LOGGER.info('Baseline pass test finished')
return True, 'Baseline pass test ran successfully'

def _baseline_fail(self):
def _baseline_non_compliant(self):
LOGGER.info('Running baseline fail test')
LOGGER.info('Baseline fail test finished')
return False, 'Baseline fail test ran successfully'

def _baseline_skip(self):
def _baseline_informational(self):
LOGGER.info('Running baseline skip test')
LOGGER.info('Baseline skip test finished')
return None, 'Baseline skip test ran successfully'
46 changes: 46 additions & 0 deletions testing/api/mockito/get_devices.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
[
{
"mac_addr": "00:1e:42:35:73:c4",
"manufacturer": "Teltonika",
"model": "TRB 140",
"test_modules": {
"dns": {
"enabled": false
},
"connection": {
"enabled": true
},
"ntp": {
"enabled": false
},
"baseline": {
"enabled": false
},
"nmap": {
"enabled": false
}
}
},
{
"mac_addr": "aa:bb:cc:dd:ee:ff",
"manufacturer": "Manufacturer X",
"model": "Device X",
"test_modules": {
"dns": {
"enabled": true
},
"connection": {
"enabled": true
},
"ntp": {
"enabled": true
},
"baseline": {
"enabled": false
},
"nmap": {
"enabled": true
}
}
}
]
3 changes: 3 additions & 0 deletions testing/api/mockito/invalid_request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"error": "Invalid request received"
}
26 changes: 26 additions & 0 deletions testing/api/mockito/running_system_status.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"status": "In Progress",
"device": {
"manufacturer": "Delta",
"model": "03-DIN-CPU",
"mac_addr": "01:02:03:04:05:06",
"firmware": "1.2.2"
},
"started": "2023-06-22T09:20:00.123Z",
"finished": null,
"tests": {
"total": 26,
"results": [
{
"name": "dns.network.hostname_resolution",
"description": "The device should resolve hostnames",
"result": "Compliant"
},
{
"name": "dns.network.from_dhcp",
"description": "The device should use the DNS server provided by the DHCP server",
"result": "Non-Compliant"
}
]
}
}
57 changes: 57 additions & 0 deletions testing/api/test_api
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Copyright 2023 Google LLC
#
# 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
#
# https://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.

ifconfig

# Setup requirements
sudo apt-get update
sudo apt-get install openvswitch-common openvswitch-switch tcpdump jq moreutils coreutils isc-dhcp-client

pip3 install pytest

# Setup device network
sudo ip link add dev dummynet type dummy
sudo ip link add dev endev0a type veth peer name endev0b
sudo ip link set dev endev0a up
sudo ip link set dev endev0b up
sudo docker network create -d macvlan -o parent=endev0b endev0

sudo ip link add dev dummynet type dummy

# Start OVS
sudo /usr/share/openvswitch/scripts/ovs-ctl start

# Build Test Container
sudo docker build ./testing/docker/ci_test_device1 -t ci_test_device1 -f ./testing/docker/ci_test_device1/Dockerfile

sudo chown -R $USER local

cat <<EOF >local/system.json
{
"network": {
"device_intf": "endev0a",
"internet_intf": "dummynet"
},
"log_level": "DEBUG"
}
EOF

sudo cmd/install

# Needs to be sudo because this invokes bin/testrun
sudo venv/bin/python -m pytest -v testing/api/test_api.py

exit $?
Loading