def test_20_log_success(self): """Places logs in the file and invokes log and stops when requested.""" with manager_test.MockOutDevices(): self._create_log_file(2) self.uut.log("sshdevice-0000", os.path.basename(self.device_log_file), duration=.2)
def test_14_health_check_success_with_recover(self, mock_close): """Test FireManager.health_check(recover=True) success.""" with manager_test.MockOutDevices(): self.uut.health_check("sshdevice-0000", recover=True) fake_devices.FakeSSHDevice.make_device_ready.assert_called_with( setting="on") mock_close.assert_called_once()
def test_issue_devices_match_no_matches_raises_exception(self): """Test issue_devices_match raising an exception if no devices match.""" with manager_test.MockOutDevices(): with self.assertRaisesRegex(errors.DeviceError, "No devices match"): self.uut.issue_devices_match("sshdevice-1", "make_device_ready", setting="off")
def test_36_get_persistent_prop_devices_success(self): """Verify get_persistent_prop_devices returns persistent device props.""" self.addCleanup(logger.setLevel, logger.getEffectiveLevel()) with manager_test.MockOutDevices(): 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: expected_props = manager_test.FAKE_DEVICES["devices"][ device_name] self.assertEqual(mock_devices_props[device_name], expected_props)
def test_19_log_file_never_created(self): """Ensures stream device raises error if log file is never created.""" with mock.patch.object(fire_manager, "MAX_TIME_TO_WAIT_FOR_INITATION", new=0.1): with self.assertRaisesRegex( errors.DeviceError, "Log file not created within 0.1 seconds"): with manager_test.MockOutDevices(): self.uut.log("sshdevice-0000", self.device_log_file, duration=0.1)
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], {})
def test_15_health_check_raises_on_error(self, mock_close): """Test that FireManager.health_check() raises when health checks fail.""" 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") with manager_test.MockOutDevices(): with mock.patch.object(fake_devices.FakeSSHDevice, "make_device_ready", side_effect=mock_make_device_ready): with self.assertRaises(errors.DeviceNotResponsiveError): self.uut.health_check("sshdevice-0000") fake_devices.FakeSSHDevice.make_device_ready.assert_called_with( setting="check_only") mock_close.assert_called_once()
def test_17_get_prop_single_property(self): """Test FireManager.get_prop() retrieves a single property successfully.""" with manager_test.MockOutDevices(): self.uut.get_prop("sshdevice-0000", "firmware_version")
def test_16_get_prop(self): """Test FireManager.get_prop() retrieves all properties successfully.""" with manager_test.MockOutDevices(): self.uut.get_prop("sshdevice-0000")
def test_12_exec(self): """Test that FireManager.exec() does not run health checks.""" with manager_test.MockOutDevices(): self.uut.exec("sshdevice-0000") fake_devices.FakeSSHDevice.make_device_ready.assert_called_once_with( "off")
def test_11_issue(self): """Test that FireManager.issue() runs all health checks.""" with manager_test.MockOutDevices(): self.uut.issue("sshdevice-0000") fake_devices.FakeSSHDevice.make_device_ready.assert_called_once_with( "on")