コード例 #1
0
    def test_allow(self):
        self.deny_list_path.write_text(
            "{}\nNode1 \nNode2\nNode3\n\tNode4 ".format(ALL_EXCEPT_ALLOWED))

        acl = get_acl(self.new_path)
        assert acl._allow_set == {"Node1", "Node2", "Node3", "Node4"}

        self.assertEqual((True, ''), acl.is_allowed("Node1"))
        self.assertEqual((False, 'node is not whitelisted'),
                         acl.is_allowed("some other node"))
コード例 #2
0
    def test_deny(self):
        self.deny_list_path.write_text("Node1 \nNode2\nNode3\n\tNode4 ")

        acl = get_acl(self.new_path)
        keys = set(acl._deny_deadlines.keys())
        assert keys == {"Node1", "Node2", "Node3", "Node4"}

        self.assertEqual((False, 'node is blacklisted'),
                         acl.is_allowed("Node1"))
        self.assertEqual((True, ''), acl.is_allowed("some other node"))
コード例 #3
0
    def test_deny_timeout(self):
        acl = get_acl(self.new_path)

        acl.disallow("Node1", timeout_seconds=10)
        self.assertEqual((False, 'node is blacklisted'),
                         acl.is_allowed("Node1"))
        assert "Node1" in acl._deny_deadlines

        with freeze_time("2018-01-01 00:00:30"):
            assert "Node1" in acl._deny_deadlines
            self.assertEqual((True, ''), acl.is_allowed("Node1"))
            assert "Node1" not in acl._deny_deadlines
コード例 #4
0
    def __init__(self, data_dir,
                 successful_downloads=True, successful_uploads=True, **_kwargs):

        ResourceHandshakeSessionMixin.__init__(self)

        self.send = Mock()
        self.disconnect = Mock()
        self.dropped = Mock()

        self.content_to_pull = str(uuid.uuid4())
        self.successful_downloads = successful_downloads
        self.successful_uploads = successful_uploads

        self.address = "192.168.0.11"
        self.key_id = str(uuid.uuid4())
        self.address = '1.2.3.4'
        self.data_dir = data_dir

        dir_manager = DirManager(data_dir)
        storage = ResourceStorage(dir_manager,
                                  dir_manager.get_task_resource_dir)
        resource_manager = Mock(
            storage=storage,
            content_to_pull=str(uuid.uuid4()).replace('-', ''),
            successful_uploads=successful_uploads,
            successful_downloads=successful_downloads,
        )
        resource_manager.add_file = types.MethodType(_add_file,
                                                     resource_manager)
        resource_manager.add_file_org = types.MethodType(
            HyperdriveResourceManager.add_file,
            resource_manager
        )
        resource_manager.pull_resource = types.MethodType(_pull_resource,
                                                          resource_manager)
        resource_manager.pull_resource_org = types.MethodType(
            HyperdriveResourceManager.pull_resource,
            resource_manager
        )

        self.task_server = Mock(
            client=Mock(datadir=data_dir),
            node=Mock(key=str(uuid.uuid4())),
            acl=get_acl(Path(data_dir)),
            resource_handshakes=dict(),
            task_manager=Mock(
                task_result_manager=Mock(
                    resource_manager=resource_manager
                )
            )
        )
コード例 #5
0
    def test_deny_disallow_persistence(self):
        self.deny_list_path.touch()

        acl = get_acl(self.new_path)
        acl.disallow('node_id1', persist=True)
        acl.disallow('node_id2', persist=True)
        acl.disallow('node_id1', persist=True)

        saved_nodes = self.deny_list_path.read_text().split()
        self.assertEqual(sorted(saved_nodes), ['node_id1', 'node_id2'])
        self.assertEqual((False, 'node is blacklisted'),
                         acl.is_allowed("node_id1"))
        self.assertEqual((False, 'node is blacklisted'),
                         acl.is_allowed("node_id2"))
        self.assertEqual((True, ''), acl.is_allowed("node_id3"))
コード例 #6
0
    def test_allow_disallow_persistence(self):
        self.deny_list_path.write_text('\n'.join(
            (ALL_EXCEPT_ALLOWED, 'node_id1', 'node_id2')))

        acl = get_acl(self.new_path)
        acl.disallow('node_id1', persist=True)
        acl.disallow('node_id3', persist=True)
        acl.disallow('node_id1', persist=True)

        saved_nodes = self.deny_list_path.read_text().split()
        self.assertEqual(sorted(saved_nodes), [ALL_EXCEPT_ALLOWED, 'node_id2'])

        self.assertEqual((False, 'node is not whitelisted'),
                         acl.is_allowed("node_id1"))
        self.assertEqual((True, ''), acl.is_allowed("node_id2"))
        self.assertEqual((False, 'node is not whitelisted'),
                         acl.is_allowed("node_id3"))
コード例 #7
0
ファイル: taskserver.py プロジェクト: U0001F3A2/golem
    def __init__(self,
                 node,
                 config_desc: ClientConfigDescriptor,
                 client,
                 use_ipv6=False,
                 use_docker_manager=True,
                 task_archiver=None,
                 apps_manager=AppsManager(),
                 task_finished_cb=None) -> None:
        self.client = client
        self.keys_auth = client.keys_auth
        self.config_desc = config_desc

        self.node = node
        self.task_archiver = task_archiver
        self.task_keeper = TaskHeaderKeeper(
            environments_manager=client.environments_manager,
            node=self.node,
            min_price=config_desc.min_price,
            task_archiver=task_archiver)
        self.task_manager = TaskManager(
            config_desc.node_name,
            self.node,
            self.keys_auth,
            root_path=TaskServer.__get_task_manager_root(client.datadir),
            use_distributed_resources=config_desc.
            use_distributed_resource_management,
            tasks_dir=os.path.join(client.datadir, 'tasks'),
            apps_manager=apps_manager,
            finished_cb=task_finished_cb,
        )
        benchmarks = self.task_manager.apps_manager.get_benchmarks()
        self.benchmark_manager = BenchmarkManager(
            node_name=config_desc.node_name,
            task_server=self,
            root_path=self.get_task_computer_root(),
            benchmarks=benchmarks)
        self.task_computer = TaskComputer(
            task_server=self,
            use_docker_manager=use_docker_manager,
            finished_cb=task_finished_cb)
        self.task_connections_helper = TaskConnectionsHelper()
        self.task_connections_helper.task_server = self
        self.task_sessions = {}
        self.task_sessions_incoming = weakref.WeakSet()

        self.max_trust = 1.0
        self.min_trust = 0.0

        self.last_messages = []
        self.last_message_time_threshold = config_desc.task_session_timeout

        self.results_to_send = {}
        self.failures_to_send = {}

        self.use_ipv6 = use_ipv6

        self.forwarded_session_request_timeout = \
            config_desc.waiting_for_task_session_timeout
        self.forwarded_session_requests = {}
        self.response_list = {}
        self.acl = get_acl(Path(client.datadir))
        self.resource_handshakes = {}

        network = TCPNetwork(
            ProtocolFactory(SafeProtocol, self, SessionFactory(TaskSession)),
            use_ipv6)
        PendingConnectionsServer.__init__(self, config_desc, network)
        # instantiate ReceivedMessageHandler connected to self
        # to register in golem.network.concent.handlers_library
        from golem.network.concent import \
            received_handler as concent_received_handler
        self.concent_handler = \
            concent_received_handler.TaskServerMessageHandler(self)

        dispatcher.connect(self.income_listener, signal='golem.income')

        dispatcher.connect(self.finished_task_listener,
                           signal='golem.taskmanager')
コード例 #8
0
 def test_no_file(self):
     acl = get_acl(self.new_path)
     assert acl._deny_deadlines == dict()
     self.assertEqual((True, ''), acl.is_allowed("some node"))
コード例 #9
0
 def test_file_empty(self):
     self.deny_list_path.touch()
     acl = get_acl(self.new_path)
     assert acl._deny_deadlines == dict()