Ejemplo n.º 1
0
    def put(self, field_id):
        """
        Update a single field's attributes.

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body, requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False

        response = yield update_field(field_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(
            self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(202)  # Updated
        self.finish(response)
Ejemplo n.º 2
0
    def put(self, *uriargs):
        """
        Request: adminNodeDesc
        Response: adminNodeDesc
        Errors: InvalidInputFormat

        Changes the node public node configuration settings.
        """
        request = self.validate_message(self.request.body,
                requests.adminNodeDesc)

        yield update_node(request, language=self.request.language)

        # align the memory variables with the new updated data
        yield import_memory_variables()

        node_description = yield admin_serialize_node(self.request.language)

        # update 'node' cache calling the 'public' side of /node
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate('node')
        GLApiCache.set('node', self.request.language, public_node_desc)

        self.set_status(202) # Updated
        self.finish(node_description)
Ejemplo n.º 3
0
    def put(self, field_id):
        """
        Update a single field's attributes.

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        request = self.validate_message(self.request.body,
                                        requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False

        response = yield update_field(field_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(202) # Updated
        self.finish(response)
Ejemplo n.º 4
0
    def post(self, *uriargs):
        """
        Create a new field.

        Request: FieldDesc
        Response: FieldDesc
        Errors: InvalidInputFormat, FieldIdNotFound
        """
        tmp = json.loads(self.request.body)
        if 'template_id' in tmp and tmp['template_id'] != '':
            request = self.validate_message(self.request.body,
                                            requests.FieldDescFromTemplate)
        else:
            request = self.validate_message(self.request.body,
                                            requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False
        response = yield create_field(request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(201)
        self.finish(response)
Ejemplo n.º 5
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: AdminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)
        GLApiCache.invalidate()

        self.set_status(200) # Ok and return no content
        self.finish()
Ejemplo n.º 6
0
    def delete(self, field_id, *uriargs):
        """
        Delete a single field.

        Request: None
        Response: None
        Errors: InvalidInputFormat, FieldIdNotFound
        """
        yield delete_field(field_id, False)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
Ejemplo n.º 7
0
    def delete(self, receiver_id):
        """
        Delete the specified receiver.

        Parameters: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        GLApiCache.invalidate()

        self.set_status(200) # OK and return not content
        self.finish()
Ejemplo n.º 8
0
    def put(self, receiver_id):
        """
        Update the specified receiver.

        Parameters: receiver_id
        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound, ContextId
        """
        request = self.validate_message(self.request.body, requests.AdminReceiverDesc)

        response = yield update_receiver(receiver_id, request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201)
        self.finish(response)
Ejemplo n.º 9
0
    def put(self):
        """
        Update the node infos.

        Request: AdminNodeDesc
        Response: AdminNodeDesc
        Errors: InvalidInputFormat
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminNodeDesc)

        node_description = yield update_node(request, True, self.request.language)
        GLApiCache.invalidate()

        self.set_status(202) # Updated
        self.finish(node_description)
Ejemplo n.º 10
0
 def test_invalidate(self):
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it", self.mario, "come", "una", "catapulta!")
     self.assertTrue("passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertEqual(pdp_it, "come una catapulta!")
     yield GLApiCache.invalidate("passante_di_professione")
     self.assertTrue("passante_di_professione" not in GLApiCache.memory_cache_dict)
Ejemplo n.º 11
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id, False)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
Ejemplo n.º 12
0
    def post(self):
        """
        Get the specified receiver.

        Request: AdminReceiverDesc
        Response: AdminReceiverDesc
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminReceiverDesc)

        response = yield create_receiver(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201) # Created
        self.finish(response)
Ejemplo n.º 13
0
    def post(self):
        """
        Create a new context.

        Request: AdminContextDesc
        Response: AdminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminContextDesc)

        response = yield create_context(request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(201) # Created
        self.finish(response)
Ejemplo n.º 14
0
    def delete(self, field_id):
        """
        Delete a single field.

        :param field_id:
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        yield delete_field(field_id, False)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(
            self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
Ejemplo n.º 15
0
    def get(self, field_id, *uriargs):
        """
        Get the field identified by field_id

        :param field_id:
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, False, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
        self.finish(response)
Ejemplo n.º 16
0
    def delete(self, context_id, *uriargs):
        """
        Request: adminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        # contexts update causes also receivers update
        GLApiCache.invalidate('receivers')

        self.set_status(200) # Ok and return no content
        self.finish()
Ejemplo n.º 17
0
    def initialization(self):
        self.responses = []

        def mock_write(cls, response=None):
            # !!!
            # Here we are making the assumption that every time write() get's
            # called it contains *all* of the response message.
            if response:
                self.responses.append(response)

        self._handler.write = mock_write
        # we make the assumption that we will always use call finish on write.
        self._handler.finish = mock_write

        # we need to reset settings.session to keep each test independent
        GLSetting.sessions = dict()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
Ejemplo n.º 18
0
    def put(self, context_id):
        """
        Update the specified context.

        Parameters: context_id
        Request: AdminContextDesc
        Response: AdminContextDesc
        Errors: InvalidInputFormat, ContextIdNotFound, ReceiverIdNotFound

        Updates the specified context.
        """
        request = self.validate_message(self.request.body,
                                        requests.AdminContextDesc)

        response = yield update_context(context_id, request, self.request.language)
        GLApiCache.invalidate()

        self.set_status(202) # Updated
        self.finish(response)
Ejemplo n.º 19
0
    def put(self):
        """
        Parameters: None
        Request: ReceiverReceiverDesc
        Response: ReceiverReceiverDesc
        Errors: ReceiverIdNotFound, InvalidInputFormat, InvalidAuthentication, TipIdNotFound
        """
        request = self.validate_message(self.request.body, requests.ReceiverReceiverDesc)

        receiver_status = yield update_receiver_settings(self.current_user.user_id,
                                                         request, self.request.language)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.invalidate('receivers')
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        self.set_status(200)
        self.finish(receiver_status)
Ejemplo n.º 20
0
    def delete(self, receiver_id, *uriargs):
        """
        Parameter: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.invalidate('receivers')
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        # receivers update causes also contexts update
        GLApiCache.invalidate('contexts')

        self.set_status(200) # OK and return not content
        self.finish()
Ejemplo n.º 21
0
    def initialization(self):
        self.responses = []

        def mock_write(cls, response=None):
            # !!!
            # Here we are making the assumption that every time write() get's
            # called it contains *all* of the response message.
            if response:
                self.responses.append(response)

        self._handler.write = mock_write
        # we make the assumption that we will always use call finish on write.
        self._handler.finish = mock_write

        # we need to reset settings.session to keep each test independent
        GLSetting.sessions = dict()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
Ejemplo n.º 22
0
    def put(self):
        """
        Update the node infos.

        Request: adminNodeDesc
        Response: adminNodeDesc
        Errors: InvalidInputFormat
        """
        request = self.validate_message(self.request.body,
                                        requests.adminNodeDesc)

        node_description = yield update_node(request, True, self.request.language)

        # update 'node' cache calling the 'public' side of /node
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate('node')
        GLApiCache.set('node', self.request.language, public_node_desc)

        self.set_status(202) # Updated
        self.finish(node_description)
Ejemplo n.º 23
0
    def post(self, *uriargs):
        """
        Request: adminContextDesc
        Response: adminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body, requests.adminContextDesc)

        response = yield create_context(request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        # contexts update causes also receivers update
        GLApiCache.invalidate('receivers')

        self.set_status(201) # Created
        self.finish(response)
Ejemplo n.º 24
0
    def get(self, field_id):
        """
        Get the field identified by field_id

        :param field_id:
        :return: the serialized field
        :rtype: FieldDesc
        :raises FieldIdNotFound: if there is no field with such id.
        :raises InvalidInputFormat: if validation fails.
        """
        response = yield get_field(field_id, False, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(
            self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(200)
        self.finish(response)
Ejemplo n.º 25
0
 def test_invalidate(self):
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
     pdp_it = yield GLApiCache.get("passante_di_professione", "it",
                                   self.mario, "come", "una", "catapulta!")
     self.assertTrue(
         "passante_di_professione" in GLApiCache.memory_cache_dict)
     self.assertEqual(pdp_it, "come una catapulta!")
     yield GLApiCache.invalidate("passante_di_professione")
     self.assertTrue(
         "passante_di_professione" not in GLApiCache.memory_cache_dict)
Ejemplo n.º 26
0
    def delete(self, receiver_id):
        """
        Delete the specified receiver.

        Parameters: receiver_id
        Request: None
        Response: None
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        yield delete_receiver(receiver_id)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.invalidate('receivers')
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        # receivers update causes also contexts update
        GLApiCache.invalidate('contexts')

        self.set_status(200) # OK and return not content
        self.finish()
Ejemplo n.º 27
0
    def put(self, context_id):
        """
        Update the specified context.

        Parameters: context_id
        Request: adminContextDesc
        Response: adminContextDesc
        Errors: InvalidInputFormat, ContextIdNotFound, ReceiverIdNotFound

        Updates the specified context.
        """

        request = self.validate_message(self.request.body,
                                        requests.adminContextDesc)

        response = yield update_context(context_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        # contexts update causes also receivers update and
        # node update due to 'configured' based on context-receiver association
        GLApiCache.invalidate('receivers')
        GLApiCache.invalidate('node')

        self.set_status(202) # Updated
        self.finish(response)
Ejemplo n.º 28
0
    def post(self):
        """
        Get the specified receiver.

        Request: adminReceiverDesc
        Response: adminReceiverDesc
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.adminReceiverDesc)

        response = yield create_receiver(request, self.request.language)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.invalidate('receivers')
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        # receivers update causes also contexts update and
        # node update due to 'configured' based on context-receiver association
        GLApiCache.invalidate('contexts')
        GLApiCache.invalidate('node')

        self.set_status(201) # Created
        self.finish(response)
Ejemplo n.º 29
0
    def post(self, *uriargs):
        """
        """

        request = self.validate_message(self.request.body,
                requests.wizardFirstSetup)

        yield wizard(request, self.request.language)

        # align the memory variables with the new updated data
        yield import_memory_variables()

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate('node')
        GLApiCache.invalidate('contexts')
        GLApiCache.invalidate('receivers')
        GLApiCache.set('node', self.request.language, public_node_desc)
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.set('contexts', self.request.language, public_contexts_list)
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        self.set_status(201) # Created
        self.finish()
Ejemplo n.º 30
0
    def put(self, receiver_id, *uriargs):
        """
        Request: adminReceiverDesc
        Response: adminReceiverDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound, ContextId

        Update information about a Receiver, return the instance updated.
        """
        request = self.validate_message(self.request.body, requests.adminReceiverDesc)

        response = yield update_receiver(receiver_id, request, self.request.language)

        # get the updated list of receivers, and update the cache
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.invalidate('receivers')
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        # receivers update causes also contexts update
        GLApiCache.invalidate('contexts')

        self.set_status(201)
        self.finish(response)
Ejemplo n.º 31
0
    def post(self):
        """
        Create a new field.

        :return: the serialized field
        :rtype: FieldDesc
        :raises InvalidInputFormat: if validation fails.
        """
        try:
            tmp = json.loads(self.request.body)
        except ValueError:
            raise errors.InvalidInputFormat("Invalid JSON format")

        if isinstance(tmp, dict) and 'template_id' in tmp:
            request = self.validate_message(self.request.body,
                                            requests.FieldFromTemplateDesc)

            # enforce difference between /admin/field and /admin/fieldtemplate
            request['is_template'] = False
            response = yield create_field_from_template(
                request, self.request.language)

        else:
            request = self.validate_message(self.request.body,
                                            requests.FieldDesc)

            # enforce difference between /admin/field and /admin/fieldtemplate
            request['is_template'] = False
            response = yield create_field(request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(
            self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(201)
        self.finish(response)
Ejemplo n.º 32
0
    def put(self, field_id, *uriargs):
        """
        Update a single field's attributes.

        Request: FieldDesc
        Response: FieldDesc
        Errors: InvalidInputFormat, FieldIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.FieldDesc)

        # enforce difference between /admin/field and /admin/fieldtemplate
        request['is_template'] = False

        response = yield update_field(field_id, request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(202) # Updated
        self.finish(response)
Ejemplo n.º 33
0
    def setUp(self):
        """
        override default handlers' get_store with a mock store used for testing/
        """
        yield TestGLWithPopulatedDB.setUp(self)
        self.responses = []

        def mock_write(cls, response=None):
            # !!!
            # Here we are making the assumption that every time write() get's
            # called it contains *all* of the response message.
            if response:
                self.responses.append(response)

        self._handler.write = mock_write
        # we make the assumption that we will always use call finish on write.
        self._handler.finish = mock_write

        # we need to reset settings.session to keep each test independent
        GLSetting.sessions = dict()

        # we need to reset GLApiCache to keep each test independent
        GLApiCache.invalidate()
Ejemplo n.º 34
0
    def post(self):
        """
        Create a new context.

        Request: adminContextDesc
        Response: adminContextDesc
        Errors: InvalidInputFormat, ReceiverIdNotFound
        """
        request = self.validate_message(self.request.body,
                                        requests.adminContextDesc)

        response = yield create_context(request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        # contexts update causes also receivers update
        GLApiCache.invalidate('receivers')

        self.set_status(201) # Created
        self.finish(response)
Ejemplo n.º 35
0
    def post(self):
        """
        Create a new field.

        :return: the serialized field
        :rtype: FieldDesc
        :raises InvalidInputFormat: if validation fails.
        """
        try:
            tmp = json.loads(self.request.body)
        except ValueError:
            raise errors.InvalidInputFormat("Invalid JSON format")

        if isinstance(tmp, dict) and 'template_id' in tmp:
            request = self.validate_message(self.request.body,
                                            requests.FieldFromTemplateDesc)

            # enforce difference between /admin/field and /admin/fieldtemplate
            request['is_template'] = False
            response = yield create_field_from_template(request, self.request.language)

        else:
            request = self.validate_message(self.request.body,
                                            requests.FieldDesc)

            # enforce difference between /admin/field and /admin/fieldtemplate
            request['is_template'] = False
            response = yield create_field(request, self.request.language)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        self.set_status(201)
        self.finish(response)
Ejemplo n.º 36
0
    def post(self):
        """
        """

        request = self.validate_message(self.request.body,
                requests.wizardFirstSetup)

        yield wizard(request, self.request.language)

        # cache must be updated in particular to set wizard_done = True
        public_node_desc = yield anon_serialize_node(self.request.language)
        GLApiCache.invalidate('node')
        GLApiCache.invalidate('contexts')
        GLApiCache.invalidate('receivers')
        GLApiCache.set('node', self.request.language, public_node_desc)
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.set('contexts', self.request.language, public_contexts_list)
        public_receivers_list = yield get_public_receiver_list(self.request.language)
        GLApiCache.set('receivers', self.request.language, public_receivers_list)

        self.set_status(201) # Created
        self.finish()
Ejemplo n.º 37
0
    def delete(self, context_id):
        """
        Delete the specified context.

        Request: adminContextDesc
        Response: None
        Errors: InvalidInputFormat, ContextIdNotFound
        """
        yield delete_context(context_id)

        # get the updated list of contexts, and update the cache
        public_contexts_list = yield get_public_context_list(self.request.language)
        GLApiCache.invalidate('contexts')
        GLApiCache.set('contexts', self.request.language, public_contexts_list)

        # contexts update causes also receivers update and
        # node update due to 'configured' based on context-receiver association
        GLApiCache.invalidate('receivers')
        GLApiCache.invalidate('node')

        self.set_status(200) # Ok and return no content
        self.finish()
Ejemplo n.º 38
0
    def setUp(self):
        yield helpers.TestGL.setUp(self)

        GLApiCache.invalidate()
Ejemplo n.º 39
0
    def check_disk_anomalies(self, free_workdir_bytes, total_workdir_bytes, free_ramdisk_bytes, total_ramdisk_bytes):
        """
        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)
        ramdisk: a 2kbytes is expected at least to store temporary encryption keys

        "unusable node" threshold: happen when the space is really shitty.
        https://github.com/globaleaks/GlobaLeaks/issues/297
        https://github.com/globaleaks/GlobaLeaks/issues/872
        """

        Alarm.latest_measured_freespace = free_workdir_bytes

        disk_space = 0
        disk_message = ""
        accept_submissions = True
        old_accept_submissions = GLSetting.memory_copy.accept_submissions

        for c in get_disk_anomaly_conditions(free_workdir_bytes,
                                             total_workdir_bytes,
                                             free_ramdisk_bytes,
                                             total_ramdisk_bytes):
            if c['condition']:
                disk_space = c['stress_level']

                info_msg = c['info_msg'](free_workdir_bytes,
                                         total_workdir_bytes,
                                         free_ramdisk_bytes,
                                         total_ramdisk_bytes)

                if disk_space == 3:
                    disk_message = "Fatal (Submission disabled): %s" % info_msg
                elif disk_space == 2:
                    disk_message = "Critical (Submission near to be disabled): %s" % info_msg
                else:  # == 1
                    disk_message = "Warning: %s" % info_msg

                accept_submissions = c['accept_submissions']

                log.err(disk_message)

                break

        # the value is setted here with a single assignment in order to
        # minimize possible race conditions resetting/settings the values
        Alarm.stress_levels['disk_space'] = disk_space
        Alarm.stress_levels['disk_message'] = disk_message
        GLSetting.memory_copy.accept_submissions = accept_submissions

        if old_accept_submissions != GLSetting.memory_copy.accept_submissions:
            log.info("Switching disk space availability from: %s to %s" % (
                "True" if old_accept_submissions else "False",
                "False" if old_accept_submissions else "True"))

            # Invalidate the cache of node avoiding accesses to the db from here;
            # import GLApiCache in order to avoid circular import error
            from globaleaks.handlers.base import GLApiCache
            GLApiCache.invalidate('node')
Ejemplo n.º 40
0
    def setUp(self):
        yield helpers.TestGL.setUp(self) 

        GLApiCache.invalidate()