Skip to content

Commit

Permalink
Add RT-AX88U / Merlin test data (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaskivskyi committed Nov 19, 2023
1 parent 89bb161 commit 5854af0
Show file tree
Hide file tree
Showing 40 changed files with 3,031 additions and 6 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ jobs:
run: |
pip install -r requirements_test.txt
- name: Run tests
- name: Run unit tests
run: |
pytest --cov=asusrouter --cov-report term-missing
pytest --cov=asusrouter --cov-report=xml:unit-tests-cov.xml -k 'not test_devices'
- name: Run real-data tests
run: |
pytest --cov=asusrouter --cov-report=xml:real-data-tests-cov.xml tests/test_devices.py --log-cli-level=INFO
- name: Upload coverage to Codecov
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: unit-tests-cov.xml,real-data-tests-cov.xml
8 changes: 8 additions & 0 deletions asusrouter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import aiohttp

from asusrouter import AsusRouter, AsusRouterDump, AsusRouterError
from asusrouter.modules.data import AsusData

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -43,6 +44,13 @@ async def _connect_and_dump(args: argparse.Namespace) -> None:

_LOGGER.debug("Connected and identified")

_LOGGER.debug("Checking all known data...")

for datatype in AsusData:
await router.async_get_data(datatype)

_LOGGER.debug("Finished checking all known data")

# Disconnect from the router
await router.async_disconnect()
_LOGGER.debug("Disconnected")
Expand Down
2 changes: 0 additions & 2 deletions asusrouter/asusrouter.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,6 @@ async def _check_flags(self) -> None:
):
flags = state_flags.data

print("FLAGS: ", flags)

if flags.get("reboot", False) is True:
_LOGGER.debug("Reboot flag is set")
await self._async_handle_reboot()
Expand Down
7 changes: 6 additions & 1 deletion asusrouter/modules/endpoint/devicemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import logging
import re
from datetime import datetime, timedelta
from typing import Any, Optional, Tuple
Expand All @@ -18,6 +19,8 @@

from .devicemap_const import DEVICEMAP_BY_INDEX, DEVICEMAP_BY_KEY, DEVICEMAP_CLEAR

_LOGGER = logging.getLogger(__name__)

REQUIRE_HISTORY = True


Expand All @@ -31,8 +34,10 @@ def read(content: str) -> dict[str, Any]:
try:
xml_content: dict[str, Any] = xmltodict.parse(content).get("devicemap", {})
if not xml_content:
_LOGGER.debug("Received empty devicemap XML")
return devicemap
except xmltodict.expat.ExpatError: # type: ignore
except xmltodict.expat.ExpatError as ex: # type: ignore
_LOGGER.debug("Received invalid devicemap XML: %s", ex)
return devicemap

# Go through the data and fill the dict
Expand Down
2 changes: 1 addition & 1 deletion asusrouter/modules/endpoint/ethernet_ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def process(data: dict[str, Any]) -> dict[AsusData, Any]:
"""Process ethernet ports data."""

# Ports info
ports = {
ports: dict[PortType, dict] = {
PortType.LAN: {},
PortType.WAN: {},
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_data/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test data for AsusRouter."""
1 change: 1 addition & 0 deletions tests/test_data/rt_ax88u_merlin_388/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test data for RT-AX88U / Merlin 388."""
86 changes: 86 additions & 0 deletions tests/test_data/rt_ax88u_merlin_388/devicemap_001.content
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version="1.0" ?>
<devicemap> <wan>2</wan>
<wan>0</wan>
<wan>0</wan>

<wan>monoClient=</wan>
<wan>wlc_state=0</wan>
<wan>wlc_sbstate=0</wan>
<wan>psta:wlc_state=0;wlc_state_auth=0;</wan>
<wan>wifi_hw_switch=1</wan>
<wan>ddnsRet=</wan>
<wan>ddnsUpdate=</wan>
<wan>wan_line_state=</wan>
<wan>wlan0_radio_flag=1</wan>
<wan>wlan1_radio_flag=1</wan>
<wan>wlan2_radio_flag=</wan>
<wan>data_rate_info_2g="72 Mbps"</wan>
<wan>data_rate_info_5g="1921.5 Mbps"</wan>
<wan>data_rate_info_5g_2="0 Mbps"</wan>
<wan>wan_diag_state=</wan>
<wan>active_wan_unit=0</wan>
<wan>wan0_enable=1</wan>
<wan>wan1_enable=1</wan>
<wan>wan0_realip_state=2</wan>
<wan>wan1_realip_state=0</wan>
<wan>wan0_ipaddr=111.222.111.222</wan>
<wan>wan1_ipaddr=0.0.0.0</wan>
<wan>wan0_realip_ip=111.222.111.222</wan>
<wan>wan1_realip_ip=</wan>
<vpn>vpnc_proto=disable</vpn>
<vpn>vpnc_state_t=0</vpn>
<vpn>vpnc_sbstate_t=0</vpn>
<vpn>vpn_client1_state=0</vpn>
<vpn>vpn_client2_state=</vpn>
<vpn>vpn_client3_state=0</vpn>
<vpn>vpn_client4_state=-1</vpn>
<vpn>vpn_client5_state=</vpn>
<vpn>vpnd_state=0</vpn>
<vpn>vpn_client1_errno=0</vpn>
<vpn>vpn_client2_errno=</vpn>
<vpn>vpn_client3_errno=0</vpn>
<vpn>vpn_client4_errno=8</vpn>
<vpn>vpn_client5_errno=</vpn>
<vpn>vpn_server1_state=2</vpn>
<vpn>vpn_server2_state=</vpn>
<sys>uptimeStr=Sun, 19 Nov 2023 15:51:06 +0100(509356 secs since boot)</sys>
<qtn>qtn_state=</qtn>
<usb>'[]'</usb>
<usb>modem_enable=1</usb>
<first_wan>2</first_wan>
<first_wan>0</first_wan>
<first_wan>0</first_wan>
<second_wan>0</second_wan>
<second_wan>0</second_wan>
<second_wan>0</second_wan>

<sim>sim_state=</sim>
<sim>sim_signal=</sim>
<sim>sim_operation=</sim>
<sim>sim_isp=</sim>
<sim>roaming=0</sim>
<sim>roaming_imsi=</sim>
<sim>sim_imsi=</sim>
<sim>g3err_pin=</sim>
<sim>pin_remaining_count=</sim>
<sim>modem_act_provider=</sim>
<sim>rx_bytes=</sim>
<sim>tx_bytes=</sim>
<sim>modem_sim_order=</sim>
<dhcp>dnsqmode=</dhcp>
<wan>wlc0_state=</wan>
<wan>wlc1_state=</wan>
<wan>rssi_2g=</wan>
<wan>rssi_5g=</wan>
<wan>rssi_5g_2=</wan>
<wan>link_internet=2</wan>
<diag>diag_dblog_enable=0</diag>
<diag>diag_dblog_remaining=0</diag>
<wan>wlc2_state=</wan>
<wan>le_restart_httpd=</wan>
<wanbonding>wan_bonding_speed="0"</wanbonding>
<wanbonding>wan_bonding_p1_status="0"</wanbonding>
<wanbonding>wan_bonding_p2_status="2"</wanbonding>
<wanbonding>lacp_wan=0</wanbonding>
</devicemap>

114 changes: 114 additions & 0 deletions tests/test_data/rt_ax88u_merlin_388/devicemap_001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
"""Result of processing devicemap_001.content."""

from datetime import datetime

from dateutil.tz import tzoffset

from asusrouter import AsusData
from asusrouter.modules.openvpn import AsusOVPNClient, AsusOVPNServer

expected_result = {
AsusData.DEVICEMAP: {
"wan": {
"status": "2",
"sbstatus": "0",
"auxstatus": "0",
"monoClient": None,
"wlc_state": "0",
"wlc_sbstate": "0",
"wifi_hw_switch": "1",
"ddnsRet": None,
"ddnsUpdate": None,
"line_state": None,
"wlan0_radio_flag": "1",
"wlan1_radio_flag": "1",
"wlan2_radio_flag": None,
"data_rate_info_2g": "72 Mbps",
"data_rate_info_5g": "1921.5 Mbps",
"data_rate_info_5g_2": "0 Mbps",
"diag_state": None,
"active_wan_unit": "0",
"wlc0_state": None,
"wlc1_state": None,
"rssi_2g": None,
"rssi_5g": None,
"rssi_5g_2": None,
"link_internet": "2",
"wlc2_state": None,
"le_restart_httpd": None,
},
"wan0": {
"status": "2",
"sbstatus": "0",
"auxstatus": "0",
"enable": "1",
"realip_state": "2",
"ipaddr": "111.222.111.222",
"realip_ip": "111.222.111.222",
},
"wan1": {
"status": "0",
"sbstatus": "0",
"auxstatus": "0",
"enable": "1",
"realip_state": "0",
"ipaddr": "0.0.0.0",
"realip_ip": None,
},
"usb": {"status": "'[]'", "modem_enable": "1"},
"vpn": {
"vpnc_proto": "disable",
"vpnc_state_t": "0",
"vpnc_sbstate_t": "0",
"client1_state": "0",
"client2_state": None,
"client3_state": "0",
"client4_state": "-1",
"client5_state": None,
"vpnd_state": "0",
"client1_errno": "0",
"client2_errno": None,
"client3_errno": "0",
"client4_errno": "8",
"client5_errno": None,
"server1_state": "2",
"server2_state": None,
},
"sys": {"uptimeStr": "Sun, 19 Nov 2023 15:51:06 +0100(509356 secs since boot)"},
"qtn": {"state": None},
"sim": {
"state": None,
"signal": None,
"operation": None,
"isp": None,
"roaming": "0",
"roaming_imsi": None,
"imsi": None,
"g3err_pin": None,
"pin_remaining_count": None,
"modem_act_provider": None,
"rx_bytes": None,
"tx_bytes": None,
"modem_sim_order": None,
},
"dhcp": {"dnsqmode": None},
"diag": {"dblog_enable": "0", "dblog_remaining": "0"},
},
AsusData.BOOTTIME: {
"datetime": datetime(2023, 11, 13, 18, 21, 50, tzinfo=tzoffset(None, 3600))
},
AsusData.OPENVPN: {
"client": {
1: {"state": AsusOVPNClient.DISCONNECTED, "errno": 0},
2: {"state": AsusOVPNClient.DISCONNECTED, "errno": None},
3: {"state": AsusOVPNClient.DISCONNECTED, "errno": 0},
4: {"state": AsusOVPNClient.ERROR, "errno": 8},
5: {"state": AsusOVPNClient.DISCONNECTED, "errno": None},
},
"server": {
1: {"state": AsusOVPNServer.CONNECTED},
2: {"state": AsusOVPNServer.DISCONNECTED},
},
},
AsusData.FLAGS: {},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
get_wan_lan_status = { "portSpeed": { "WAN 0": "G", "LAN 1": "G", "LAN 2": "G", "LAN 3": "G", "LAN 4": "X", "LAN 5": "X", "LAN 6": "X", "LAN 7": "X", "LAN 8": "G" }, "portCount": { "wanCount": 1, "lanCount": 8 } };

49 changes: 49 additions & 0 deletions tests/test_data/rt_ax88u_merlin_388/ethernet_ports_001.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""Result of processing ethernet_ports_001.content."""

from asusrouter import AsusData
from asusrouter.modules.ports import PortSpeed, PortType

expected_result = {
AsusData.PORTS: {
PortType.LAN: {
1: {
"link_rate": PortSpeed.LINK_1000,
"state": True,
},
2: {
"link_rate": PortSpeed.LINK_1000,
"state": True,
},
3: {
"link_rate": PortSpeed.LINK_1000,
"state": True,
},
4: {
"link_rate": PortSpeed.LINK_DOWN,
"state": False,
},
5: {
"link_rate": PortSpeed.LINK_DOWN,
"state": False,
},
6: {
"link_rate": PortSpeed.LINK_DOWN,
"state": False,
},
7: {
"link_rate": PortSpeed.LINK_DOWN,
"state": False,
},
8: {
"link_rate": PortSpeed.LINK_1000,
"state": True,
},
},
PortType.WAN: {
0: {
"link_rate": PortSpeed.LINK_1000,
"state": True,
},
},
}
}
25 changes: 25 additions & 0 deletions tests/test_data/rt_ax88u_merlin_388/firmware_001.content
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
webs_state_update = '1';
webs_state_error = '0';
webs_state_info = '3004_388_4_0';
webs_state_info_beta = '';
webs_state_REQinfo = '';
webs_state_flag = '0';
webs_state_upgrade = '';
webs_state_level = '0';
sig_state_flag = '1';
sig_state_update = '0';
sig_state_upgrade = '1';
sig_state_error = '0';
sig_ver = '2.380';
if(cfg_sync_support){
cfg_check = '';
cfg_upgrade = '';
}
if(pipefw_support || urlfw_support){
hndwr_status = '99';
}
if(rbkfw_support){
_rollback_info = JSON.parse('');
rbk_count = Object.keys(_rollback_info).length;
}

Loading

0 comments on commit 5854af0

Please sign in to comment.