def check_disk_anomalies(self): """ Here in Alarm is written the threshold to say if we're in disk alarm or not. Therefore the function "report" the amount of free space and the evaluation + alarm shift is performed here. workingdir: is performed a percentage check (at least 1% and an absolute comparison) "unusable node" threshold: happen when the space is really shitty. https://github.com/globaleaks/GlobaLeaks/issues/297 https://github.com/globaleaks/GlobaLeaks/issues/872 """ self.measured_freespace, self.measured_totalspace = get_disk_space( self.state.settings.working_path) disk_space = 0 disk_message = "" accept_submissions = True old_accept_submissions = State.accept_submissions for c in get_disk_anomaly_conditions(self.measured_freespace, self.measured_totalspace): if c['condition']: disk_space = c['alarm_level'] info_msg = c['info_msg']() if disk_space == 2: disk_message = "[FATAL] Disk anomaly, submissions disabled: %s" % info_msg else: # == 1 disk_message = "[WARNING]: Disk anomaly: %s" % info_msg accept_submissions = c['accept_submissions'] break # This check is temporarily, want to be verified that the switch can be # logged as part of the Anomalies via this function old_alarm_level = self.alarm_levels['disk_space'] if old_alarm_level != disk_space: if disk_message: log.err(disk_message) else: log.err("Available disk space returned to normal levels") # the value is set here with a single assignment in order to # minimize possible race conditions resetting/settings the values self.alarm_levels['disk_space'] = disk_space self.alarm_levels['disk_message'] = disk_message # if not on testing change accept_submission to the new value State.accept_submissions = accept_submissions if not self.state.settings.testing else True if old_accept_submissions != State.accept_submissions: log.info("Switching disk space availability from: %s to %s", old_accept_submissions, accept_submissions) # Must invalidate the cache here becuase accept_subs served in /public has changed ApiCache.invalidate()
def set_onion_service_info(store, hostname, key): node_fact = NodeFactory(store) node_fact.set_val(u'onionservice', hostname) priv_fact = PrivateFactory(store) priv_fact.set_val(u'tor_onion_key', key) State.tenant_cache[1].onionservice = hostname ApiCache.invalidate()
def init_callback(ret): log.info('Initialization of hidden-service %s completed.', ephs.hostname, tid=tid) if not hostname and not key: del self.startup_semaphore[tid] if tid in State.tenant_cache: self.hs_map[ephs.hostname] = ephs yield set_onion_service_info(tid, ephs.hostname, ephs.private_key) else: yield ephs.remove_from_tor(self.tor_conn.protocol) tid_list = list(set([1, tid])) for x in tid_list: ApiCache().invalidate(x) ApiCache().invalidate(x) yield refresh_memory_variables(tid_list)
def initialization(self): # we need to reset settings.session to keep each test independent Sessions.clear() # we need to reset ApiCache to keep each test independent ApiCache.invalidate()
def setUp(self): yield helpers.TestGL.setUp(self) ApiCache.invalidate()
def test_cache(self): self.assertEqual(ApiCache.memory_cache_dict, {}) self.assertIsNone(ApiCache.get(1, "passante_di_professione", "it")) self.assertIsNone(ApiCache.get(1, "passante_di_professione", "en")) self.assertIsNone(ApiCache.get(2, "passante_di_professione", "ca")) ApiCache.set(1, "passante_di_professione", "it", 'text/plain', 'ititit') ApiCache.set(1, "passante_di_professione", "en", 'text/plain', 'enenen') ApiCache.set(2, "passante_di_professione", "ca", 'text/plain', 'cacaca') self.assertTrue("passante_di_professione" in ApiCache.memory_cache_dict[1]) self.assertTrue("passante_di_professione" in ApiCache.memory_cache_dict[2]) self.assertIsNone(ApiCache.get(1, "passante_di_professione", "ca")) self.assertTrue("it" in ApiCache.memory_cache_dict[1]['passante_di_professione']) self.assertTrue("en" in ApiCache.memory_cache_dict[1]['passante_di_professione']) self.assertIsNone(ApiCache.get(1, "passante_di_professione", "ca")) self.assertEqual(ApiCache.get(1, "passante_di_professione", "it")[1], gzipdata('ititit')) self.assertEqual(ApiCache.get(1, "passante_di_professione", "en")[1], gzipdata('enenen')) self.assertEqual(ApiCache.get(2, "passante_di_professione", "ca")[1], gzipdata('cacaca')) ApiCache.invalidate() self.assertEqual(ApiCache.memory_cache_dict, {})