def update_storage(self) -> None: """Updates storage information.""" self.logger.debug("Updating storage") # Get storage information and update in shared state self.free_disk = self.get_free_disk() self.free_memory = self.get_free_memory() self.database_size = self.get_database_size() # Convert num strings to float free_disk = accessors.floatify_string(self.free_disk) free_memory = accessors.floatify_string(self.free_disk) # Check for low disk space (<50MB) if free_disk < 50.0 * constants.MEGABYTE: self.logger.warning("Low disk, remaining: {}".format( self.free_disk)) low_disk = True else: low_disk = False # Check for low memory (<10MB) if free_memory < 10.0 * constants.MEGABYTE: self.logger.warning("Low memory, remaining: {}".format( self.free_memory)) low_memory = True else: low_memory = False # Update status and notify cloud system if either resource is low if low_disk or low_memory: self.status = "Low resources, disk: {}, memory: {}".format( self.free_disk, self.free_memory) self.iot.publish_message("alert", self.status) # type: ignore else: self.status = "OK" # Clear disk if low if low_disk: self.clean_up_disk() self.clean_up_database(keep=50)
def test_floatify_string_invalid() -> None: string = "10.2Q" with pytest.raises(ValueError): float_ = accessors.floatify_string(string)
def test_floatify_string_giga() -> None: string = "11G" float_ = accessors.floatify_string(string) expected_float = 11.0 * constants.GIGABYTE assert float_ == expected_float
def test_floatify_string_mega() -> None: string = "10.2M" float_ = accessors.floatify_string(string) expected_float = 10.2 * constants.MEGABYTE assert float_ == expected_float
def test_floatify_string_kilo() -> None: string = "10.2K" float_ = accessors.floatify_string(string) expected_float = 10.2 * constants.KILOBYTE assert float_ == expected_float