Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move plug type parameter to config #64

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Robot-Framework/config/variables.robot
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Set Variables
Set Global Variable ${SERIAL_PORT} ${config['addresses']['${DEVICE}']['serial_port']}
Set Global Variable ${DEVICE_IP_ADDRESS} ${config['addresses']['${DEVICE}']['device_ip_address']}
Set Global Variable ${SOCKET_IP_ADDRESS} ${config['addresses']['${DEVICE}']['socket_ip_address']}
Set Global Variable ${PLUG_TYPE} ${config['addresses']['${DEVICE}']['plug_type']}
Set Global Variable ${THREADS_NUMBER} ${config['addresses']['${DEVICE}']['threads']}
Set Global Variable ${NETVM_NAME} net-vm
Set Global Variable ${NETVM_SERVICE} microvm@${NETVM_NAME}.service
Expand Down
29 changes: 5 additions & 24 deletions Robot-Framework/lib/PlugLibrary/PlugLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,52 +8,33 @@
from robot.libraries.BuiltIn import BuiltIn


# PlugLibrary Usage:
# * Tapo Plug:
# -v PLUG_TYPE:TAPOP100 (default, needs SOCKET_IP_ADDRESS, PLUG_USERNAME and
# PLUG_PASSWORD)
# * Kasa Plug:
# -v PLUG_TYPE:KASAPLUG (needs only SOCKET_IP_ADDRESS)
#
# * Tapo Plug Hardware Version 2.0:
# -v PLUG_TYPE:TAPOP100v2 (needs only SOCKET_IP_ADDRESS)
#
class PlugLibrary:
def __init__(self, *args, **kwargs):
def __init__(self, plug_type, *args, **kwargs):
self._plug = None
self._plug_type = "TAPOP100"
self._plug_type = plug_type

def _get_plug(self):
if not self._plug:
# Setting self._plug for the first time
self._plug_type = self._get_plug_type()
if self._plug_type == "TAPOP100":
self._plug = TapoP100()
elif self._plug_type == "KASAPLUG":
self._plug = KasaPlug()
elif self._plug_type == "TAPOP100v2":
self._plug = TapoP100v2()
else:
raise Exception('Unknown plug type or there is no plug for this device')
print(f"plug type: {self._plug_type}")
return self._plug

# Return TAPOP100 if PLUG_TYPE is not known
def _get_plug_type(self):
allowed_types = ["TAPOP100", "KASAPLUG", "TAPOP100v2"]
raw = BuiltIn().get_variable_value("${PLUG_TYPE}")
if raw in allowed_types:
return raw
else:
# By default use TAPOP100
return allowed_types[0]

def turn_plug_on(self):
if self._plug_type == "TAPOP100v2":
asyncio.run(self._get_plug().turn_plug_on())
else:
self._get_plug().turn_plug_on()

def turn_plug_off(self):
if self._get_plug_type() == "TAPOP100v2":
if self._plug_type == "TAPOP100v2":
asyncio.run(self._get_plug().turn_plug_off())
else:
self._get_plug().turn_plug_off()
18 changes: 18 additions & 0 deletions Robot-Framework/test-suites/__init__.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2022-2023 Technology Innovation Institute (TII)
# SPDX-License-Identifier: Apache-2.0

*** Settings ***
Documentation To be executed for all tests
Resource ../resources/ssh_keywords.resource
Resource ../config/variables.robot
Suite Setup Common Setup
Suite Teardown Common Teardown


*** Keywords ***

Common Setup
Set Variables ${DEVICE}

Common Teardown
Close All Connections
9 changes: 3 additions & 6 deletions Robot-Framework/test-suites/bat-tests/__init__.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
# SPDX-License-Identifier: Apache-2.0

*** Settings ***
#Documentation
#Force Tags
Documentation To be executed only for BAT tests
Resource ../../resources/ssh_keywords.resource
Resource ../../config/variables.robot
Suite Setup Common Setup
Suite Teardown Common Teardown


*** Keywords ***

Common Setup
Set Variables ${DEVICE}
Connect
Log versions
Run journalctl recording
Expand All @@ -35,6 +32,6 @@ Log journctl

Log versions
${ghaf_version} Execute Command ghaf-version
Log Ghaf version: ${ghaf_version}
Log to console Ghaf version: ${ghaf_version}
${nixos_version} Execute Command nixos-version
Log Nixos version: ${nixos_version}
Log to console Nixos version: ${nixos_version}
12 changes: 3 additions & 9 deletions Robot-Framework/test-suites/boot_test.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@
*** Settings ***
Documentation Testing target device booting up.
Force Tags ssh_boot_test
# PlugLibrary Usage:
# * Tapo Plug:
# -v PLUG_TYPE:TAPOP100 (default, needs SOCKET_IP_ADDRESS, PLUG_USERNAME and
# PLUG_PASSWORD)
# * Kasa Plug:
# -v PLUG_TYPE:KASAPLUG (needs only SOCKET_IP_ADDRESS)
#
Library ../lib/PlugLibrary/PlugLibrary.py
Library ../lib/PlugLibrary/PlugLibrary.py ${PLUG_TYPE}
Resource ../resources/serial_keywords.resource
Resource ../resources/ssh_keywords.resource
Resource ../config/variables.robot
Suite Setup Set Variables ${DEVICE}


*** Variables ***
${CONNECTION_TYPE} ssh
${IS_AVAILABLE} False


*** Test Cases ***

Verify booting after restart by power
Expand Down