Beispiel #1
0
    def header(self, max_price, last_checking=None,
               deadline=None, min_version="4"):
        if not last_checking:
            last_checking = time.time()
        if not deadline:
            deadline = timeout_to_deadline(36000)

        ret = TaskHeader(
            task_id=str(uuid4()),
            environment="DEFAULT",
            task_owner=Node(),
            max_price=max_price,
            deadline=deadline,
            min_version=min_version)
        if last_checking:
            ret.last_checking = last_checking
        return ret
Beispiel #2
0
    def test_header_serialization(self):
        node = dict(node_name="test node")
        docker_images = [
            dict(repository="repo_{}".format(i),
                 id="id_{}".format(i),
                 tag="tag_{}".format(i)) for i in xrange(4)
        ]

        task_header = TaskHeader("ABC",
                                 "xyz",
                                 "10.10.10.10",
                                 1023,
                                 "key",
                                 "DEFAULT",
                                 task_owner=node,
                                 docker_images=docker_images)
        # ignore dynamic properties
        task_header.last_checking = 0

        task_header_dict = task_header.to_dict()
        serialized = CBORSerializer.dumps(task_header_dict)
        deserialized = CBORSerializer.loads(serialized)
        task_header_from_dict = TaskHeader.from_dict(deserialized)

        # ignore dynamic properties
        task_header_from_dict.last_checking = 0

        assert task_header_from_dict.to_dict() == task_header_dict
        assert isinstance(task_header_from_dict.task_owner, Node)
        assert all([
            isinstance(di, DockerImage)
            for di in task_header_from_dict.docker_images
        ])

        task_header_bin = task_header.to_binary()
        bin_serialized = CBORSerializer.dumps(task_header_bin)
        bin_deserialized = CBORSerializer.loads(bin_serialized)

        assert bin_deserialized == task_header_bin