Esempio n. 1
0
 def test_get_config(self):
     node_config = CommonConfig(section="Node",
                                noption1="noption1",
                                noption2=24242,
                                noption3="2.24024")
     cfg_file = self.additional_dir_content([1])[0]
     cfg = SimpleConfig(node_config, cfg_file)
     node_config2 = cfg.get_node_config()
     self.assertEqual(node_config.section, node_config2.section)
     self.assertEqual(node_config.noption1, node_config2.noption1)
     self.assertEqual(node_config.noption2, node_config2.noption2)
     self.assertEqual(node_config.noption3, node_config2.noption3)
Esempio n. 2
0
    def test_config_file(self):
        node_config = CommonConfig(section="Node",
                                   noption1="noption1",
                                   noption2=24242,
                                   noption3="2.24024")
        cfg_file = self.additional_dir_content([1])[0]
        cfg = SimpleConfig(node_config, cfg_file)
        self.assertTrue(isinstance(cfg, SimpleConfig))
        with open(cfg_file) as f:
            text = f.read()
        self.assertIn("noption1 = noption1", text)
        self.assertIn("noption2 = 24242", text)
        self.assertIn("noption3 = 2.24024", text)

        node_config = CommonConfig(section="Node",
                                   noption1="noptionY",
                                   noption2=14242,
                                   noption3="1.24024")
        SimpleConfig(node_config, cfg_file)
        with open(cfg_file) as f:
            text = f.read()
        self.assertIn("noption1 = noption1", text)
        self.assertIn("noption2 = 24242", text)
        self.assertIn("noption3 = 2.24024", text)
        node_config = CommonConfig(section="Node",
                                   noption1="noptionY",
                                   noption3="1.24024",
                                   noption4="NEWOPTION")
        SimpleConfig(node_config, cfg_file)

        with open(cfg_file) as f:
            text = f.read()
        self.assertIn("noption1 = noption1", text)
        self.assertIn("noption2 = 24242", text)
        self.assertIn("noption3 = 2.24024", text)
        self.assertIn("noption4 = NEWOPTION", text)

        SimpleConfig(node_config, cfg_file, keep_old=False)

        with open(cfg_file) as f:
            text = f.read()
        self.assertIn("noption1 = noption1", text)
        self.assertNotIn("noption2 = 24242", text)
        self.assertIn("noption3 = 2.24024", text)
        self.assertIn("noption4 = NEWOPTION", text)

        SimpleConfig(node_config, cfg_file, refresh=True, keep_old=False)

        with open(cfg_file) as f:
            text = f.read()
        self.assertIn("noption1 = noption1", text)
        self.assertIn("noption3 = 2.24024", text)
        self.assertIn("noption4 = NEWOPTION", text)
Esempio n. 3
0
    def load_config(cls, datadir, cfg_file_name=CONFIG_FILENAME):

        # FIXME: This check is only for transition to separated datadirs.
        cfg_file = path.join(datadir, cfg_file_name)
        if cfg_file in cls.__loaded_configs:
            raise RuntimeError("Config has been loaded: {}".format(cfg_file))
        cls.__loaded_configs.add(cfg_file)

        node_config = NodeConfig(
            node_name="",
            node_address="",
            public_address="",
            eth_account="",
            use_ipv6=USE_IP6,
            start_port=START_PORT,
            end_port=END_PORT,
            rpc_address=RPC_ADDRESS,
            rpc_port=RPC_PORT,
            # peers
            seed_host="",
            seed_port=START_PORT,
            opt_peer_num=OPTIMAL_PEER_NUM,
            # flags
            accept_tasks=ACCEPT_TASKS,
            send_pings=SEND_PINGS,
            # hardware
            hardware_preset_name=CUSTOM_HARDWARE_PRESET_NAME,
            # price and trust
            min_price=MIN_PRICE,
            max_price=MAX_PRICE,
            requesting_trust=REQUESTING_TRUST,
            computing_trust=COMPUTING_TRUST,
            # benchmarks
            estimated_lux_performance="0",
            estimated_blender_performance="0",
            # intervals
            pings_interval=PINGS_INTERVALS,
            getting_peers_interval=GETTING_PEERS_INTERVAL,
            getting_tasks_interval=GETTING_TASKS_INTERVAL,
            task_request_interval=TASK_REQUEST_INTERVAL,
            node_snapshot_interval=NODE_SNAPSHOT_INTERVAL,
            network_check_interval=NETWORK_CHECK_INTERVAL,
            max_results_sending_delay=MAX_SENDING_DELAY,
            # timeouts
            p2p_session_timeout=P2P_SESSION_TIMEOUT,
            task_session_timeout=TASK_SESSION_TIMEOUT,
            resource_session_timeout=RESOURCE_SESSION_TIMEOUT,
            use_waiting_for_task_timeout=USE_WAITING_FOR_TASK_TIMEOUT,
            waiting_for_task_timeout=WAITING_FOR_TASK_TIMEOUT,
            waiting_for_task_session_timeout=WAITING_FOR_TASK_SESSION_TIMEOUT,
            forwarded_session_request_timeout=FORWARDED_SESSION_REQUEST_TIMEOUT
        )

        cfg = SimpleConfig(node_config, cfg_file, keep_old=False)
        return AppConfig(cfg, cfg_file)
Esempio n. 4
0
    def change_config(self, cfg_desc):
        if not isinstance(cfg_desc, ClientConfigDescriptor):
            raise TypeError("Incorrect config descriptor type: {}."
                            " Should be ClientConfigDescriptor".format(
                                type(cfg_desc)))

        for var, val in vars(cfg_desc).iteritems():
            setter = "set_{}".format(var)
            if not hasattr(self, setter):
                logger.info(
                    "Cannot set unknown config property: {} = {}".format(
                        var, val))
                continue

            set_func = getattr(self, setter)
            set_func(val)

        SimpleConfig(self._cfg.get_node_config(),
                     self.config_file,
                     refresh=True)
Esempio n. 5
0
 def change_config(self):
     return EnvironmentsConfig(
         SimpleConfig(self._cfg.get_node_config(),
                      self.cfg_file,
                      refresh=True), self.cfg_file)
Esempio n. 6
0
    def load_config(cls, environments, datadir):
        cfg_file = path.join(datadir, CONFIG_FILENAME)
        cfg = SimpleConfig(NodeConfig(environments), cfg_file, refresh=False)

        return EnvironmentsConfig(cfg, cfg_file)