示例#1
0
    def test_rotate_log(self):
        """Tests max_log_size and auto log rotation features."""
        old_log_file_name = self.device.log_file_name
        expected_log_filename = log_process.get_next_log_filename(
            old_log_file_name)
        expected_message = "Special message to trigger at least one log rotation"
        max_log_size = len(expected_message) * 10
        self.device.switchboard.set_max_log_size(max_log_size)
        time.sleep(.5)  # Allow time for set_max_log_size to complete.

        try:
            for _ in range(20):
                self.device.switchboard.add_log_note(expected_message)
            end_time = time.time() + 3
            while (old_log_file_name == self.device.log_file_name
                   and time.time() < end_time):
                time.sleep(0.1)
            self.assertTrue(
                os.path.exists(old_log_file_name),
                f"Expected old log file name {old_log_file_name} to exist")
            self.assertTrue(
                os.path.exists(expected_log_filename),
                f"Expected new log file name {expected_log_filename} to exist")
            self.assertNotEqual(
                old_log_file_name, self.device.log_file_name,
                f"Expected log file name to change from {old_log_file_name}")
        finally:
            # Disable log rotation (the default) after the test.
            self.device.switchboard.set_max_log_size(0)
 def test_110_gazoo_device_base_log_file_name(self):
     """Verify log_file_name property works as expected."""
     old_log_filename = self.uut.log_file_name
     # Create fake rotated log file
     next_log_filename = log_process.get_next_log_filename(old_log_filename)
     with open(next_log_filename, "w+") as log_file:
         log_file.write("")
     actual_log_filename = self.uut.log_file_name
     self.assertNotEqual(
         old_log_filename, actual_log_filename,
         "Expected {} != {}".format(old_log_filename, actual_log_filename))
示例#3
0
    def test_003_get_next_log_filename_with_counter(self):
        """Test get_next_log_filename handles file with log counter."""
        current_log_filename = (
            "/tmp/TestSuite.prefix-device-0203-20180912-111222.99998.txt")
        expected_log_filename = (
            "/tmp/TestSuite.prefix-device-0203-20180912-111222.99999.txt")

        log_filename = log_process.get_next_log_filename(current_log_filename)
        self.assertEqual(
            expected_log_filename, log_filename,
            "Expected log filename {} found {}".format(expected_log_filename,
                                                       log_filename))
示例#4
0
  def log_file_name(self) -> str:
    """Current device log file name in use.

    Returns:
      Path to current device log file name.

    When the device has been recently created it might be possible that the log
    file path does not yet exist, but will be created very soon. The caller is
    expected to check if the file path returned exists. The caller should refer
    to this property often because log rotation might cause the log path to
    change depending on the max_log_size value currently in use.
    """
    current_log_filename = self._log_file_name

    # Check if log file has rotated to next log filename
    next_log_filename = log_process.get_next_log_filename(current_log_filename)
    while os.path.exists(next_log_filename):
      current_log_filename = next_log_filename
      next_log_filename = log_process.get_next_log_filename(
          current_log_filename)
    return current_log_filename
示例#5
0
    def test_1510_rotate_log(self):
        """Verify max_log_size and auto log rotation feature works."""
        try:
            old_log_file_name = self.device.log_file_name
            expected_log_filename = log_process.get_next_log_filename(
                old_log_file_name)
            expected_message = "Special message to trigger at least one log rotation"
            max_log_size = len(expected_message) * 10
            self.device.switchboard.set_max_log_size(max_log_size)

            try:
                for _ in range(20):
                    self.device.switchboard.add_log_note(expected_message)
                end_time = time.time() + 3
                while old_log_file_name == self.device.log_file_name and time.time(
                ) < end_time:
                    time.sleep(0.1)
                asserts.assert_true(
                    os.path.exists(old_log_file_name),
                    "Expected old log file name {} to exist".format(
                        old_log_file_name))
                asserts.assert_true(
                    os.path.exists(expected_log_filename),
                    "Expected new log file name {} to exist".format(
                        expected_log_filename))
                actual_log_file_name = self.device.log_file_name
                asserts.assert_true(
                    old_log_file_name != actual_log_file_name,
                    "Expected log file name to change from {}".format(
                        old_log_file_name))
            finally:
                # Disable log rotation (the default) after the test to prevent normal device logs
                # from creating on the order of 100-1000 log files due to small max log size.
                self.device.switchboard.set_max_log_size(0)

        except errors.GazooDeviceError as err:
            if "not yet available" not in repr(err):
                raise