Example #1
0
  def health_check(self):
    """Checks that the capability is ready to use.

    Raises:
        CapabilityNotReadyError: if unable to create auxiliary device for
        power switching.
    """
    unset_props = []
    if self.name is None:
      unset_props.append("device_usb_hub_name")
    if self.device_port is None:
      unset_props.append("device_usb_port")
    if unset_props:
      if self._settable:
        msg_format = ("If device is connected to Cambrionix, "
                      "set them via 'gdm set-prop {} <property> <value>'")
      else:
        msg_format = ("If device is connected to Cambrionix, "
                      "set them via 'gdm redetect {}")
      msg = msg_format.format(self._device_name)
      error_msg = "properties {} are unset. ".format(
          " and ".join(unset_props)) + msg
      raise errors.CapabilityNotReadyError(
          msg=error_msg, device_name=self._device_name)
    if not self._manager_weakref():
      raise errors.CapabilityNotReadyError(
          msg="Device class is closed. Unable to use capability",
          device_name=self._device_name)
    try:
      self._usb_hub = self._manager_weakref().create_device(self.name)
    except errors.DeviceError as err:
      raise errors.CapabilityNotReadyError(
          msg=str(err), device_name=self._device_name)
    self._healthy = True
  def health_check(self):
    """Checks that the capability is ready to use.

    Raises:
        CapabilityNotReadyError: if unable to create auxiliary device for
        power switching.
    """
    unset_props = []
    if not self.hub_name:
      unset_props.append(self._hub_name_prop)
    if not self.port_number:
      unset_props.append(self._primary_port_prop)
    if unset_props:
      msg_format = ("If device is connected to {}, "
                    "set them via 'gdm redetect {}'")
      msg = msg_format.format(self.hub_type, self._device_name)
      error_msg = "properties {} are unset. ".format(
          " and ".join(unset_props)) + msg
      raise errors.CapabilityNotReadyError(
          msg=error_msg, device_name=self._device_name)

    try:
      self._hub = self._create_device_func(self.hub_name)
      # Set up ethernet
      if self.ethernet_switch_address is not None:
        self._ethernet_switch = self._create_device_func(
            self.ethernet_switch_address)

    except errors.DeviceError as err:
      raise errors.CapabilityNotReadyError(
          msg=str(err), device_name=self._device_name)
    if self.ethernet_switch_address is not None:
      self._verify_switch_created(self._ethernet_switch)
    self._healthy = True
    def health_check(self):
        """Checks that the capability is ready to use.

    Raises:
      CapabilityNotReadyError: If expected properties are not set or
        unable to create auxiliary device for power switching.
    """
        unset_props = []
        if self.hub_name is None:
            unset_props.append(self._hub_name_prop)
        if self.port_number is None:
            unset_props.append(self._port_prop)
        if unset_props:
            if self._hub_type == _HUB_TYPE_CAMBRIONIX and self._usb_ports_discovered:
                msg_format = ("If device is connected to {}, "
                              "set them via 'gdm redetect {}'")
            else:
                msg_format = (
                    "If device is connected to {}, "
                    "set them via 'gdm set-prop {} <property> <value>'")
            msg = msg_format.format(self._hub_type, self._device_name)
            error_msg = "properties {} are unset. ".format(
                " and ".join(unset_props)) + msg
            raise errors.CapabilityNotReadyError(msg=error_msg,
                                                 device_name=self._device_name)
        try:
            self._hub = self._create_device_func(self.hub_name)
        except errors.DeviceError as err:
            raise errors.CapabilityNotReadyError(msg=str(err),
                                                 device_name=self._device_name)
        self._healthy = True
Example #4
0
 def _verify_switch_created(self, switch):
     """Verifies switch is created and has switch_power capability."""
     if not (hasattr(switch, "switch_power") and isinstance(
             switch.switch_power, switch_power_base.SwitchPowerBase)):
         raise errors.CapabilityNotReadyError(
             msg="'switch_power' capability is missing in hub device {} ({}),"
             " or is not an instance of SwitchPowerBase".format(
                 self.hub_name,
                 type(switch).__name__),
             device_name=self._device_name)
  def ethernet_on(self):
    """Turn on ethernet port.

    Raises:
      CapabilityNotReadyError: if unable to initiate ethernet_switch.
    """
    if not self.healthy:
      self.health_check()
    if not self._ethernet_switch:
      raise errors.CapabilityNotReadyError(
          device_name=self._device_name,
          msg="Not set up for ethernet switching.")
    self._ethernet_switch.switch_power.power_on(self.ethernet_port_number)
 def test_1343_recover_comm_power_unconfigured(self):
     """Test recovery with comm_power unconfigured."""
     self.uut.reset_capability("switchboard")
     with mock.patch.object(gazoo_device_base.GazooDeviceBase,
                            "has_capabilities",
                            return_value=True):
         self.uut.comm_power = mock.Mock(
             spec=comm_power_default.CommPowerDefault)
         self.uut.comm_power.cycle.side_effect = errors.CapabilityNotReadyError(
             "device", "Error")
         error = errors.SwitchboardCreationError(self.uut.name, "FtdiError")
         with self.assertRaisesRegex(errors.SwitchboardCreationError,
                                     str(error)):
             self.uut.recover(error)