Skip to content

Commit

Permalink
Merge pull request #2911 from jarhodes314/enable-bridge-2
Browse files Browse the repository at this point in the history
test: built-in bridge system test compatibility
  • Loading branch information
reubenmiller committed Jul 31, 2024
2 parents 2a9eed4 + 224c182 commit e4fdb00
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
14 changes: 14 additions & 0 deletions tests/RobotFramework/libraries/ThinEdgeIO/ThinEdgeIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,20 @@ def configure_ssh(self, user: str = "root", device: str = None) -> str:
)
return str(key)

@keyword("Get Bridge Service Name")
def get_bridge_service_name(self, cloud: str) -> str:
"""Get the name of the bridge service.
The service name will depend if the built-in bridge
has been activated or not (on the device).
"""
output = self.execute_command("tedge config get mqtt.bridge.built_in", strip=True, ignore_exit_code=True)
if output == "true":
return f"tedge-mapper-bridge-{cloud}"

# Legacy mosquitto bridge
return f"mosquitto-{cloud}-bridge"


def to_date(value: relativetime_) -> datetime:
if isinstance(value, datetime):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ Test if all c8y services are up
c8y-firmware-plugin

Test bridge service status up
External Identity Should Exist ${DEVICE_SN}:device:main:service:mosquitto-c8y-bridge show_info=False
${SERVICE_NAME}= Get Bridge Service Name cloud=c8y
External Identity Should Exist ${DEVICE_SN}:device:main:service:${SERVICE_NAME} show_info=False
Cumulocity.Managed Object Should Have Fragment Values status\=up timeout=${TIMEOUT}

Test mosquitto bridge service status mapping
Expand Down
32 changes: 32 additions & 0 deletions tests/images/debian-systemd/files/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ FLAGS
--connect/--no-connect Connect the mapper. Provide the type of mapper via '--mapper <name>'. Default True
--mapper <name> Name of the mapper to use when connecting (if user has specified the --connect option).
Defaults to 'c8y'. Currently only c8y works.
--bridge-type <mosquitto|builtin> Which bridge type to use. mosquitto or builtin
DEVICE FLAGS
--device-id <name> Use a specific device-id. A prefix will be added to the device id
Expand Down Expand Up @@ -116,6 +117,7 @@ INSTALL_METHOD="${INSTALL_METHOD:-}"
INSTALL_SOURCEDIR=${INSTALL_SOURCEDIR:-.}
MAX_CONNECT_ATTEMPTS=${MAX_CONNECT_ATTEMPTS:-2}
TEDGE_MAPPER=${TEDGE_MAPPER:-c8y}
BRIDGE_TYPE=${BRIDGE_TYPE:-mosquitto}
ARCH=${ARCH:-}
USE_RANDOM_ID=${USE_RANDOM_ID:-0}
SHOULD_PROMPT=${SHOULD_PROMPT:-1}
Expand Down Expand Up @@ -302,6 +304,12 @@ do
TEDGE_MAPPER="$2"
shift
;;

# Which bridge type to use. mosquitto or builtin
--bridge-type)
BRIDGE_TYPE="$2"
shift
;;

# Cumulocity settings
--c8y-user)
Expand Down Expand Up @@ -896,6 +904,30 @@ connect_mappers() {
# retry connection attempts
sudo tedge disconnect "$TEDGE_MAPPER" || true

# Only set the bridge type setting if it is supported (as it is a relatively new setting)
if tedge config get mqtt.bridge.built_in >/dev/null 2>&1; then
current_built_in_value=$(tedge config get mqtt.bridge.built_in)
desired_built_in_value=

case "$BRIDGE_TYPE" in
builtin|built_in)
desired_built_in_value=true
;;
mosquitto)
desired_built_in_value=false
;;
*)
echo "FAIL: Invalid bridge-type setting. got=$BRIDGE_TYPE, expected one of [builtin, mosquitto]"
exit 1
;;
esac

if [ -n "$desired_built_in_value" ] && [ "$current_built_in_value" != "$desired_built_in_value" ]; then
echo "Setting mqtt.bridge.built_in to $desired_built_in_value"
sudo tedge config set mqtt.bridge.built_in "$desired_built_in_value"
fi
fi

CONNECT_ATTEMPT=0
while true; do
CONNECT_ATTEMPT=$((CONNECT_ATTEMPT + 1))
Expand Down

0 comments on commit e4fdb00

Please sign in to comment.