Ejemplo n.º 1
0
 def test_validate_illegal_timeout(self):
     self.th_dict_repr['fixed_header']['subtask_timeout'] = "abc"
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "Subtask timeout is not a number"
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 2
0
 def test_validate_illegal_deadline(self):
     self.th_dict_repr['fixed_header']['deadline'] = datetime.now()
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "Deadline is not a timestamp"
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 3
0
 def test_validate_deadline_passed(self):
     self.th_dict_repr['fixed_header']['deadline'] = get_timestamp_utc() - 10
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "Deadline already passed"
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 4
0
 def test_validate_subtasks_count_too_low(self):
     self.th_dict_repr['fixed_header']['subtasks_count'] = -1
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         r"^Subtasks count is less than 1 {.*'subtasks_count': -1.*}$",
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 5
0
 def test_validate_no_subtasks_count(self):
     del self.th_dict_repr['fixed_header']['subtasks_count']
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         r"^Subtasks count is missing"
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 6
0
 def test_validate_subtasks_count_invalid_type(self):
     self.th_dict_repr['fixed_header']['subtasks_count'] = None
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         r"^Subtasks count is missing",
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 7
0
 def test_validate_no_task_owner_node_name(self):
     del self.th_dict_repr['fixed_header']['task_owner']['node_name']
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "node name missing",
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 8
0
 def test_validate_no_task_id(self):
     del self.th_dict_repr['fixed_header']['task_id']
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "Task ID missing",
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 9
0
 def test_validate_no_fixed_header(self):
     del self.th_dict_repr['fixed_header']
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "Fixed header is missing"
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 10
0
 def test_validate_negative_timeout(self):
     self.th_dict_repr['fixed_header']['subtask_timeout'] = -131
     with self.assertRaisesRegex(
         exceptions.TaskHeaderError,
         "Subtask timeout is less than 0",
     ):
         TaskHeader.validate(self.th_dict_repr)
Ejemplo n.º 11
0
    def add_task_header(self, th_dict_repr: dict) -> bool:
        try:
            TaskHeader.validate(th_dict_repr)
            header = TaskHeader.from_dict(th_dict_repr)
            if not self.verify_header_sig(header):
                raise ValueError("Invalid signature")

            if self.task_manager.is_this_my_task(header):
                return True  # Own tasks are not added to task keeper

            return self.task_keeper.add_task_header(header)

        except exceptions.TaskHeaderError as e:
            logger.warning("Wrong task header received: %s", e)
            return False
        except Exception:  # pylint: disable=broad-except
            logger.exception("Task header validation failed")
            return False
Ejemplo n.º 12
0
 def test_validate_ok(self):
     TaskHeader.validate(self.th_dict_repr)