Skip to content

Commit

Permalink
Add a fake device connector for testing purposes (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
plars authored Apr 18, 2024
1 parent 2e1177a commit cb4e184
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions device-connectors/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ testing on other types of devices.

- cm3 - Raspberry PI CM3 with a sidecar device and tools to support putting it in otg mode to flash an image
- dragonboard - dragonboard with a stable image on usb and test images are flashed to a wiped sd with a dual boot process
- fake_connector - fake device connector that can be used for testing
- maas2 - Metal as a Service (MaaS) systems, which support additional features such as disk layouts. Images provisioned must be imported first!
- multi - multi-device connector used for provisioning jobs that span multiple devices at once
- muxpi - muxpi/sdwire provisioned devices that utilize a device that can write to an sd the boot it on the DUT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"cm3",
"dell_oemscript",
"dragonboard",
"fake_connector",
"hp_oemscript",
"lenovo_oemscript",
"maas2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright (C) 2024 Canonical
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
This is a fake device connector that can be used for testing
It will not actually provision anything, but it will otherwise act like a
normal device connector for the other phases, such as running the test_cmds
"""

import json
import logging

from testflinger_device_connectors.devices import (
DefaultDevice,
RecoveryError,
catch,
)


logger = logging.getLogger(__name__)


class DeviceConnector(DefaultDevice):
"""Fake device connector."""

@catch(RecoveryError, 46)
def provision(self, args):
"""dummy provision"""
with open(args.job_data) as json_file:
job_data = json.load(json_file)
provision_data = job_data.get("provision_data", {})

logger.info("BEGIN provision")
print("*" * 40)
print(
"This is a fake device connector!\n"
"No provisioning will actually happen, but here are the values "
"from the provision_data:"
)
print(json.dumps(provision_data, indent=4))
print("*" * 40)
logger.info("END provision")
7 changes: 7 additions & 0 deletions docs/reference/device-connector-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ The ``dragonboard`` device connector supports the following ``provision_data`` k
the ``zstd`` tool is supported) and
flashed to the SD card, which will be used to boot up the DUT.

.. _fake_connector:

fake_connector
--------------

The ``fake_connector`` device connector doesn't actually provision any devices, but is useful for testing the Testflinger without needing to have any real devices connected.

.. _maas2:

maas2
Expand Down

0 comments on commit cb4e184

Please sign in to comment.