Beispiel #1
0
 def test_014_recover(self):
     """Verify recover can process known errors successfully."""
     with mock.patch.object(self.uut, "reboot"):
         self.uut.recover(
             errors.DeviceNotResponsiveError(self.uut.name, "some error"))
         self.assertTrue(self.uut.reboot.called,
                         "Expected reboot to be called")
Beispiel #2
0
 def test_37_get_persistent_prop_devices_unhealthy_devices(self):
     """Verify get_persistent_prop_devices returns empty json object."""
     self.addCleanup(logger.setLevel, logger.getEffectiveLevel())
     exception = errors.DeviceNotResponsiveError(
         self.first_name, "failed make_device_ready")
     with manager_test.MockOutDevices():
         with mock.patch.object(self.uut,
                                "get_device_configuration",
                                side_effect=exception):
             mock_devices_props = yaml.safe_load(
                 self.uut.get_persistent_prop_devices(
                     [self.first_name, self.second_name]))
             for device_name in mock_devices_props:
                 self.assertEqual(mock_devices_props[device_name], {})
Beispiel #3
0
  def check_device_responsiveness(self):
    """Check if the device is responsive on console.

    Raises:
        DeviceNotResponsiveError: if device is not responsive on console.
    """
    cmd, timeout = self.commands["GDM_HELLO"], self.timeouts["GDM_HELLO"]
    try:
      self.shell(cmd, timeout=timeout)
    except errors.DeviceError as err:
      raise errors.DeviceNotResponsiveError(
          self.name,
          "unable to execute command {!r} on device's shell".format(cmd),
          timeout=timeout,
          details=str(err))
    def check_ping_responsiveness(self):
        """Check if the auxiliary device responds to pings.

    Raises:
        DeviceNotResponsiveError: if no response to ping before the timeout.
    """
        try:
            common_utils.retry(self._ping,
                               is_successful=bool,
                               timeout=self._PING_TIMEOUT,
                               reraise=True)
        except Exception as err:
            raise errors.DeviceNotResponsiveError(self.name,
                                                  "failed to respond to ping",
                                                  timeout=self._PING_TIMEOUT,
                                                  details=str(err))
Beispiel #5
0
  def check_telnet_connect(self):
    """Verify it's possible to establish a telnet connection to the CLI.

    Raises:
        DeviceError: if telnet command returns a non zero exit status.
        DeviceNotResponsiveError: if no response to telnet command before
        the timeout.
    """
    try:
      response, return_code = self.shell(
          self.commands["TELNET"], include_return_code=True)

      if return_code != 0:
        raise errors.DeviceError(
            f'{self.name} command {self.commands["TELNET"]}'
            f' returned {return_code} exit status.')

    except Exception as err:
      raise errors.DeviceNotResponsiveError(
          self.name,
          "failed to establish telnet connection",
          timeout=self.timeouts["SHELL"],
          details=str(err))
Beispiel #6
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Unit test mixin for testing common device functionality."""
from unittest import mock

from absl.testing import parameterized
from gazoo_device import errors
from gazoo_device import manager
from gazoo_device.capabilities import usb_hub_default

_CDR_ERROR_1 = errors.DeviceNotResponsiveError("device-1234", "Not responsive")
_CDR_ERROR_2 = errors.DeviceNotBootupCompleteError("device-1234", "Offline")
_RECOVERY_ERROR = errors.DeviceError("Something went wrong")


class CommonTestMixin(parameterized.TestCase):
  """Unit test mixin for testing common device functionality."""

  @parameterized.named_parameters(
      ("manager_is_alive", mock.Mock(spec=manager.Manager), False),
      ("manager_is_dead", None, True))
  def test_get_manager(self, manager_weakref_return, error_expected):
    """Tests make_device_ready with setting 'check_only'."""
    with mock.patch.object(self.uut, "_manager_weakref",
                           return_value=manager_weakref_return):
      if error_expected:
Beispiel #7
0
 def test_008_recover(self, mock_is_pingable):
   self.uut.recover(errors.DeviceNotResponsiveError(self.uut.name, ""))
   self.assertEqual(mock_is_pingable.call_count, 3)
Beispiel #8
0
 def test_device_not_responsive_error_except_with_error_code(self):
     """Verifies correct error code for DeviceNotResponsiveError."""
     error = _raise_and_catch(
         errors.DeviceNotResponsiveError("device-1234", "test"))
     self.assertEqual(error.err_code, 33)
Beispiel #9
0
 def mock_make_device_ready(setting="on"):
     """Succeeds if health checks are skipped, but fails if they do run."""
     if setting == "off":
         return
     raise errors.DeviceNotResponsiveError(
         "sshdevice-0000", "Did not respond to 'foo' in 10s")