Package: gazoo-device
Gazoo Device Manager (GDM)gazoo_deviceis a python package for interacting with smart devices.It contains Gazoo Device Manager (GDM), which defines a common device interface.
The common device interface standardizes device interactions and allows test
writers to share tests across devices despite the underlying differences in
communication types, OSes, and logic.GDM is available as a Python package for use in tests and comes with its own CLI
for quick device interactions.GDM is the open-source architecture which enables device-agnostic interations.
Device controllers used by GDM are contained in separate Python packages and can
be registered with the GDM architecture.GDM runs on the test host and communicates with the physical devices via one or
more device transports (such as SSH, ADB, HTTPS, UART). GDM does not require any
additional support from the device firmware.GDM is used in most end-to-end device tests at Google Nest.Table of contentsInstallUninstallQuick startDevice controllers in GDMConfig filesLogsDetecting devicesUsing the CLIExploring device capabilities without a physical deviceExploring device capabilities with a physical deviceBasic CLI usageUsing the gazoo_device python packageHow to use GDM with test frameworksGDM with MoblyGDM with UnittestContributor documentationLicenseDisclaimerInstallSupported host operating systems:Debian;Ubuntu;MacOS.Windows is not supported.Note: Raspberry Pi 4 on 64-bit Ubuntu 20.04 LTS is also supported as a host (see
the relevantdevice setup section).MacOS prerequisites:Install Xcode Command Line Tools:xcode-select--installInstall Brew (MacOS package manager):https://brew.sh/Verify your systempython3executable.Check that Python 3 is available:whichpython3Check that your Python 3 version is at least 3.9:python3 -VCheck that yourpython3executable haspipmodule:python3 -m pip --versionInstallation steps:Download the GDM installer archive:curl-OLhttps://github.com/google/gazoo-device/releases/latest/download/gdm-install.shRun the installer:bashgdm-install.shYou should see the following message at the end of the installation:Install done (exit 0)Addgdmto your$PATH:Add the following line to~/.bash_profileor~/.bashrc:exportPATH="${PATH}:${HOME}/gazoo/bin"[Optional] Install optional dependenciesSome of GDM's dependencies are optional and are not installed by the
installer automatically due to licensing restrictions.To enable flashing NRF52840 DK and EFR32 dev boards through GDM, install the
J-Link SDK:https://www.segger.com/downloads/jlink/#J-LinkSoftwareAndDocumentationPack.Additional note to Apple M1 users:
Make sure to download "64-bit Apple M1 Installer" under macOS.To determine whether your Mac is using an M1 chip, runarchin terminal. If you seearm64, then your Mac is using M1.To enable flashing ESP32 dev boards through GDM, installesptool:~/gazoo/gdm/virtual_env/bin/pipinstallesptool==4.1GDM installation creates a virtual environment for the CLI at~/gazoo/gdm/virtual_env.gdmCLI commands run in this virtual environment.Run a few GDM CLI commands to verify GDM works:gdm-v
gdmdevices
gdmgdm -vdisplays versions of the GDM launcher and of the python package:Gazoo Device Manager launcher 1.0
Gazoo Device Manager 1.0.0Typical output ofgdm devices:Device          Alias           Type         Model                Connected
--------------- --------------- -----------  ----------------     ------------

Other Devices   Alias           Type         Model                Available
--------------- --------------- -----------  ----------------     ------------

0 total Gazoo device(s) available.gdmdisplays a help menu.To update GDM to the latest version:gdm update-gdmTo update (or downgrade) GDM to a specific version:gdm update-gdm <version>  # Example: gdm update-gdm 1.0.0To install GDM in a virtual environment:/path_to_virtual_env/bin/pip install gazoo-deviceUninstallTo uninstall GDM:curl -OL https://github.com/google/gazoo-device/releases/latest/download/gdm-cleanup.sh
bash gdm-cleanup.shQuick startThis is the quickest way to get your hands dirty with GDM. You will need a
Raspberry Pi.Install GDM on the host.Set up your Raspberry Pi as an auxiliary device in GDM and try out the CLI.Run the example on-device test with a test framework of your choice.Device controllers in GDMTo interact with devices, GDM creates one Python device controller object for
each physical device. The lifecycle of GDM device controllers is as follows:a new device is connected to the host and is detected by GDM (one-time setup
step), which makes the device known to GDM:gdm detecta device controller instance is created at the beginning of a test or a CLI
device interaction;one or more device commands are issued through the device controller
instance;the device controller instance is closed when the test is finished or the
CLI interaction completes;if the device is permanently disconnected from the host, it is removed from
the list of devices known to GDM (also a one-time step) throughgdm delete device-1234Note that the term "device" is ambiguous in the context of GDM: it can refer to
either the device controller or the physical device. Device controllers can also
be referred to as device classes.Config filesGDM device configs are found in~/gazoo/gdm/conf.You should not modify them directly. Instead, useset-propandget-propcommands:To set an optional device property:gdm set-prop device-1234 property-name property-valueTo retrieve a device property:gdm get-prop device-1234 property-nameTo set a Manager property:gdm set-prop manager property-name property-valueTo retrieve a Manager property:gdm get-prop manager property-nameLogsBy default all GDM logs go to~/gazoo/gdm/log/. Log verbosity, output
directory, and standard output behavior can be configured via arguments toManager.__init__(seegazoo_device/manager.py).GDM creates three types of log files.Thegdm.txtlogAll GDM logs go here. Device logs arenotcaptured in this file. This log
file persists across GDM invocations. It provides the best history, but it can
be difficult to pinpoint the logs for a particular device interaction.Device log files, such aslinuxexample-1eb2-20201113-123538.txtThese capture all communications between GDM and the device. Each log line is
prefixed withGDM-<letter_or_digit>, such asGDM-M,GDM-0, orGDM-1.GDM-Mare logs written by GDM. These include the commands that GDM wrote, the
regular expressions GDM expects to find after writing a command and the maximum
time window for the response, and the result of the expect (which regular
expression matched, if any).GDM-0,GDM-1, and otherGDM-<digit>logs come from device transports. The
digit corresponds to the index of the transport (as defined byget_transport_list()methods of communication types ingazoo_device/switchboard/communication_types.py).For some communication types, such as SSH and ADB, logs and command responses
come from different transports. In that case device responses come fromGDM-0and device logs come fromGDM-1.For other communication types, there may only be a single transport, in which
case both device responses and logs come fromGDM-0.The names of device log files are logged during every CLI interaction. For
example:linuxexample-1eb2 logging to file /Users/artorl/gdm/log/linuxexample-1eb2-20201113-123548.txtDevice log event files, such aslinuxexample-1eb2-20201113-123548-events.txtThese contain device log events. The log events to be captured are defined by
log event filters ingazoo_device/filters/.A log filtering process receives all device logs in real time and captures lines
which match any of the device log filters into the device log event file.The name of the log event file is constructed as<name_of_log_file>-events.txt. For example,linuxexample-1eb2-20201113-123548-events.txtis the log event file for thelinuxexample-1eb2-20201113-123548.txtdevice log file.Detecting devicesTo detect all devices attached to your host, rungdm detecton the host. This
is a one-time step that is required when GDM is installed on the host or when a
new device is connected to the host. Devices typically require a special setup
before being usable with GDM. This can include a special cable connection
configuration, renaming serial cables, updating device firmware to a specific
version, setting up the device on a static IP address, or setting up
passwordless SSH access to the device. Refer todocs/device_setup/for instructions.Device detection populates device configs:persistent properties are stored in~/gazoo/gdm/conf/devices.json;optional (settable) properties are stored in~/gazoo/gdm/conf/device_options.json.To view all devices currently known to GDM, rungdm devices.Sample detection output (cambrionix-kljowas detected):$ gdm detect

##### Step 1/3: Detecting potential new communication addresses. #####

        detecting potential AdbComms communication addresses
        detecting potential DockerComms communication addresses
'docker' is not installed. Cannot get Docker devices.
        detecting potential JlinkSerialComms communication addresses
        detecting potential PtyProcessComms communication addresses
        detecting potential SshComms communication addresses
        detecting potential SerialComms communication addresses
        detecting potential YepkitComms communication addresses
'ykushcmd' is not installed. Cannot get Yepkit serials.
        detecting potential PigweedSerialComms communication addresses
Found 1 possible serialcomms connections:
        /dev/tty.usbserial-DM01KLJO

##### Step 2/3 Identify Device Type of Connections. #####

Identifying serialcomms devices..
        /dev/tty.usbserial-DM01KLJO is a cambrionix.
        serialcomms device_type detection complete.

##### Step 3/3: Extract Persistent Info from Detected Devices. #####

Getting info from communication port /dev/tty.usbserial-DM01KLJO for cambrionix
        cambrionix_detect checking device readiness: attempt 1 of 1
        cambrionix_detect starting AuxiliaryDevice.check_device_ready
        cambrionix_detect health check 1/2 succeeded: Check device connected.
        cambrionix_detect health check 2/2 succeeded: Check clear flags.
        cambrionix_detect AuxiliaryDevice.check_device_ready successful. It took 0s.
        cambrionix_detect starting Cambrionix.get_detection_info
        cambrionix_detect Cambrionix.get_detection_info successful. It took 0s.

##### Detection Summary #####

        1 new devices detected:
                cambrionix-kljo
Device                     Alias           Type                 Model                Connected
-------------------------- --------------- -------------------- -------------------- ----------

Other Devices              Alias           Type                 Model                Available
-------------------------- --------------- -------------------- -------------------- ----------
cambrionix-kljo            <undefined>     cambrionix           PP15S                available

0 total Gazoo device(s) available.Device names are created asdevicetype-1234, where the device type is provided
by the device controller, and the digits are the last 4 digits of the device's
serial number.Detection only detectsnewdevices. It does not re-detect already known
devices.To delete a known device:gdm delete device-1234To redetect a device:gdm redetect device-1234Using the CLIExploring device capabilities without a physical deviceGDM comes equipped with auto-generated documentation. To access it, you do not
need a device.To see all commands available through the Manager class, run:gdmTo start exploring device documentation, run:gdm manIt will list all supported devices and provide commands to run if you are
interested in exploring capabilities of a specific device.To see what is supported by a device type:gdm man device_typeFor example:gdm man raspberrypiTo explore a device method, property, or capability, issue:gdm man device_type attribute_nameFor example:gdm man raspberrypi firmware_version
gdm man raspberrypi reboot
gdm man raspberrypi file_transferTo explore a capability method or property, issue:gdm man device_type capability_name method_or_property_nameFor example:gdm man cambrionix switch_power off
gdm man raspberrypi file_transfer send_file_to_deviceYou can also explore GDM functionality via the dynamic Fire CLI. For example:gdm -- --help
gdm create_device -- --helpExploring device capabilities with a physical deviceIf you have a physical device, you can use the dynamic Fire CLI to get help
about any attribute of the device. There are no limitations to this
documentation, and it is more detailed and more accurate, but the drawback is
that it requires a physical device. For example, assuming araspberrypi-kljois attached:gdm issue raspberrypi-kljo -- --help
gdm issue raspberrypi-kljo - reboot -- --helpBasic CLI usageLet us assume you have araspberrypi-kljoconnected.Here are a few commonly used CLI commands:list all known devices:gdm devicesdetect new devices:gdm detectorgdm detect --static_ips=10.20.30.40,50.60.70.80Note: detection does not remove devices which are already known to GDM.set a device property (such as an alias):gdm set-prop raspberrypi-kljo alias rpicheck GDM version:gdm -vrun health checks on a device:gdm health-check raspberrypi-kljoif you set the alias above, the following will also work:gdm health-check rpirun health checks, then issue a device command or retrieve a property:gdm issue raspberrypi-kljo - rebootissue a device command or retrieve a propertywithoutrunning health
checks:gdm exec raspberrypi-kljo - rebootuse a device capability:gdm issue raspberrypi-kljo - file_transfer - recv_file_from_device --src="/tmp/foo" --dest="/tmp/bar"(or usegdm execto skip health checks).Sometimes passing the arguments to the Fire CLI gets a bit tricky. Refer to thePython Fire documentationand
definitely review theargument parsing section.The most commonly used device method isshell. It runs a shell command on the
device. It is required for primary devices, but is optional for auxiliary
devices. The only auxiliary device included with GDM that implementsshell()is Raspberry Pi. If you have a Raspberry Pi connected, you can try it out:gdm issue raspberrypi-1234 - shell "echo 'foo'"Using the gazoo_device python packageLaunch Python from a virtual environment with gazoo_device installed.You can use the GDM CLI virtual environment:~/gazoo/gdm/virtual_env/bin/python.from gazoo_device import Manager
manager = Manager()
rpi = manager.create_device('raspberrypi-962c')
rpi.reboot()Note that the device you are creating should be shown as "available" in the
output ofgdm devices.How to use GDM with test frameworksGDM is framework-agnostic and can be used with any Python test framework.Seeexamples/device_tests/README.mdfor GDM + unittest and GDM + Mobly examples.Contributor documentationIf you are interested in adding support for your device(s) to GDM, refer toCONTRIBUTING.md.LicenseGazoo Device Manager is licensed under theApache 2.0License.Dependency license complianceGazoo Device Manager contains a dependency onpyudev, which is licensed underLGPL 2.1.pyudevsource code can be found here:https://github.com/pyudev/pyudev.DisclaimerThis is not an official Google product.