Ejemplo n.º 1
0
 def test_download_key(self):
   """Tests the download_key function."""
   mock_key_info = data_types.KeyInfo(
       "my_ssh_key", data_types.KeyType.SSH, "gazoo_device_controllers")
   regex = r"GDM doesn't come with built-in SSH key.*my_ssh_key"
   with self.assertRaisesRegex(RuntimeError, regex):
     gazoo_device_controllers.download_key(
         mock_key_info, self.artifacts_directory)
Ejemplo n.º 2
0
    def test_007_detection_works(
        self,
        mock_access,
        mock_sshable,
        mock_ping,
        mock_yepkit,
        mock_adb,
        mock_docker,
        mock_pty,
    ):

        # detection with warnings
        with mock.patch.object(host_utils,
                               "verify_key",
                               side_effect=ValueError):
            a_dict = communication_types.detect_connections(STATIC_IPS)

        # detection with missing keys
        mock_key = data_types.KeyInfo("test_key",
                                      type=data_types.KeyType.SSH,
                                      package="test_package")
        download_key_error = errors.DownloadKeyError(
            mock_key, [RuntimeError("Something failed")])
        with mock.patch.object(host_utils,
                               "verify_key",
                               side_effect=download_key_error):
            a_dict = communication_types.detect_connections(STATIC_IPS)

        a_dict = communication_types.detect_connections(STATIC_IPS)
        self.assertEqual(set(a_dict.keys()), set(CONNECTIONS_DICT.keys()),
                         "Mismatch in detected communication types")
        for comm_type, connections in CONNECTIONS_DICT.items():
            self.assertCountEqual(
                connections, a_dict[comm_type],
                "Mismatch in detected connections for "
                f"communication type {comm_type!r}")
Ejemplo n.º 3
0
from gazoo_device.utility import host_utils
import immutabledict

_TEST_PACKAGE = "foo_package"
_EXPECTED_KEY_DIR = os.path.join(config.KEYS_DIRECTORY, _TEST_PACKAGE)
_TEST_KEY_SSH_PRIVATE_NAME = "foo_key"
_EXPECTED_KEY_SSH_PRIVATE_PATH = os.path.join(_EXPECTED_KEY_DIR,
                                              _TEST_KEY_SSH_PRIVATE_NAME)
_TEST_KEY_SSH_PUBLIC_NAME = "foo_key.pub"
_EXPECTED_KEY_SSH_PUBLIC_PATH = os.path.join(_EXPECTED_KEY_DIR,
                                             _TEST_KEY_SSH_PUBLIC_NAME)
_TEST_KEY_OTHER_NAME = "bar_key"
_EXPECTED_KEY_OTHER_PATH = os.path.join(_EXPECTED_KEY_DIR,
                                        _TEST_KEY_OTHER_NAME)
_TEST_KEY_SSH_PRIVATE = data_types.KeyInfo(_TEST_KEY_SSH_PRIVATE_NAME,
                                           type=data_types.KeyType.SSH,
                                           package=_TEST_PACKAGE)
_TEST_KEY_SSH_PUBLIC = data_types.KeyInfo(_TEST_KEY_SSH_PUBLIC_NAME,
                                          type=data_types.KeyType.SSH,
                                          package=_TEST_PACKAGE)
_TEST_KEY_OTHER = data_types.KeyInfo(_TEST_KEY_OTHER_NAME,
                                     type=data_types.KeyType.OTHER,
                                     package=_TEST_PACKAGE)


class HostUtilsTests(unit_test_case.UnitTestCase):
    """Unit tests for gazoo_device.utility.host_utils.py."""
    def setUp(self):
        super().setUp()

        self.mock_download_key = mock.Mock()
Ejemplo n.º 4
0
DEVICES_KEYS = ["devices", "other_devices"]
OPTIONS_KEYS = ["device_options", "other_device_options"]
TESTBED_KEYS = ["testbeds"]

HUB_OPTION_ATTRIBUTES = ["alias"]
DEVICE_OPTION_ATTRIBUTES = [
    "alias", "power_switch", "power_port", "usb_hub", "location", "usb_port"
]

CLASS_PROPERTY_TYPES = (str, int, dict, type(None))

_BUILT_IN_EXTENSION_PACKAGE_NAME = "gazoo_device_controllers"
KEYS = immutabledict.immutabledict({
    "raspberrypi3_ssh_key": data_types.KeyInfo(
        file_name="raspberrypi3_ssh_key",
        type=data_types.KeyType.SSH,
        package=_BUILT_IN_EXTENSION_PACKAGE_NAME),
    "raspberrypi3_ssh_key_public": data_types.KeyInfo(
        file_name="raspberrypi3_ssh_key.pub",
        type=data_types.KeyType.SSH,
        package=_BUILT_IN_EXTENSION_PACKAGE_NAME),
    "unifi_switch_ssh_key": data_types.KeyInfo(
        file_name="unifi_switch_ssh_key",
        type=data_types.KeyType.SSH,
        package=_BUILT_IN_EXTENSION_PACKAGE_NAME),
    "unifi_switch_ssh_key_public": data_types.KeyInfo(
        file_name="unifi_switch_ssh_key.pub",
        type=data_types.KeyType.SSH,
        package=_BUILT_IN_EXTENSION_PACKAGE_NAME),
})
Ejemplo n.º 5
0
        """All health checks should be prefixed with "check_<...>"."""


class BadPrimaryDeviceMissingClassConstants(fake_devices.FakeGazooDeviceBase):
    """Primary device class which misses several required class constants."""


class BadPrimaryDeviceMisnamedCapability(GoodPrimaryDevice):
    """Primary device class which defines a capability under a wrong name."""
    @decorators.CapabilityDecorator(event_parser_default.EventParserDefault)
    def wrong_name(self):
        """The capability must be defined as "event_parser"."""


GoodKey = data_types.KeyInfo(file_name="good_key",
                             type=data_types.KeyType.SSH,
                             package=_TEST_PACKAGE_NAME)
BadKeyMismatchingPackage = data_types.KeyInfo(file_name="bad_key",
                                              type=data_types.KeyType.SSH,
                                              package="mismatching_name")


class GoodManagerCliMixin(fire_manager.FireManager):
    """A valid CLI FireManager mixin class."""
    def some_cli_command(self):
        pass


class PackageRegistrarTests(unit_test_case.UnitTestCase):
    """Unit tests for package_registrar.py."""
    def setUp(self):
Ejemplo n.º 6
0
    "INFO_HARDWARE_ARCHITECTURE": "uname -m",
    "REBOOT": "sudo reboot",
})
_REGEXES = immutabledict.immutabledict({})
_TIMEOUTS = immutabledict.immutabledict({})
# TODO(gdm-authors): You may need to change the value of _SSH_USERNAME for your device.
_SSH_USERNAME = "******"

_CONTROLLER_PACKAGE_DIR = os.path.abspath(os.path.dirname(__file__))
_LOG_EVENT_FILTER_DIR = os.path.join(_CONTROLLER_PACKAGE_DIR,
                                     "log_event_filters")

# _PACKAGE_NAME must match the name of the package.
_PACKAGE_NAME = "example_controller_package"
SSH_KEY_INFO = data_types.KeyInfo(file_name="linuxexample_ssh_key",
                                  type=data_types.KeyType.SSH,
                                  package=_PACKAGE_NAME)


class ExampleLinuxDevice(ssh_device.SshDevice):
    """Example primary device controller for a generic Linux device."""
    # Device controllers must correspond to a single device type.
    # Therefore, detect criteria must uniquely identify a single device
    # type. A generic Linux device controller doesn't satisfy this property,
    # but we'll cheat a bit for the purpose of this example.
    # GenericQuery.always_true query below will cause all devices GDM can SSH into
    # to be identified as ExampleLinuxDevice.
    DETECT_MATCH_CRITERIA = {
        detect_criteria.GenericQuery.always_true: True,
        # Real detection queries look like this:
        # detect_criteria.SshQuery.some_query_function: "regex"