Exemple #1
0
    def test_get_credentials_missing_section(self):
        """ Test reading the credentials from a configuration file where the
        credentials section is missing (uninitialized). """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        username, password = ("*****@*****.**", "password")

        self.mox.StubOutWithMock(SafeConfigParser, "get")
        self.mox.StubOutWithMock(SafeConfigParser, "add_section")
        self.mox.StubOutWithMock(SafeConfigParser, "set")
        self.mox.StubOutWithMock(__builtin__, "raw_input")

        config = ConfigurationParser()
        config.parse(mock_file)
        error = NoSectionError("credentials")
        config.get("credentials", "username").AndRaise(error)

        config.add_section("credentials")

        raw_input(mox.IgnoreArg()).AndReturn(username)
        raw_input(mox.IgnoreArg()).AndReturn(password)

        config.set("credentials", "username", username)
        config.set("credentials", "password", password)

        self.mox.ReplayAll()

        self.assertEquals((username, password), credentials.get_credentials())
    def test_setting_option(self):
        """ Test setting an option - this should be a simple delegate to
        SafeConfigParser.set, with a write upon successful set. """

        mock_file = self.mox.CreateMockAnything()
        mock_file.closed = False
        mock_file.name = "foobar"

        self.mox.StubOutWithMock(SafeConfigParser, "read")
        self.mox.StubOutWithMock(SafeConfigParser, "set")
        self.mox.StubOutWithMock(SafeConfigParser, "write")

        SafeConfigParser.read(mock_file.name)
        SafeConfigParser.set("credentials", "username", "foo")
        mock_file.truncate(0)
        mock_file.flush()
        SafeConfigParser.write(mock_file)

        self.mox.ReplayAll()
        
        config = ConfigurationParser()
        config.parse(mock_file)
        config.set("credentials", "username", "foo")
Exemple #3
0
 def create_producer_node(self, account, path, p2p_address):
     try:
         nodepath = join(path, self.folder_scheme + account.name)
         if not os.path.isdir(nodepath):
             os.makedirs(nodepath)
         os.chdir(nodepath)
         config = ConfigurationParser()
         config.read(join(self.parent_dir, 'config/template_config.ini'))
         config.set('blocks-dir', join(nodepath, 'blocks'))
         config.set('http-server-address',
                    '0.0.0.0:' + str(self.get_open_port()))
         p2p_port = str(self.get_open_port())
         config.set('p2p-listen-endpoint', '0.0.0.0:' + p2p_port)
         config.set('p2p-server-address',
                    '%s:%s' % (str(p2p_address), str(p2p_port)))
         config.set('producer-name', account.name)
         config.set('signature-provider',
                    self.create_sig_provider(account.keypair))
         plugins = ['eosio::producer_plugin']
         config.append('plugin', plugins)
         config.write(join(nodepath, 'config.ini'))
         copyfile(join(self.parent_dir, 'config/genesis.json'),
                  join(nodepath, "genesis.json"))
         node = Node(account.name, nodepath)
         return node
     except FileNotFoundError as e:
         print(e)
Exemple #4
0
 def start_full(self, path, p2p_address, http_port, p2p_port):
     try:
         nodepath = join(path, self.folder_scheme + 'genesis')
         if not os.path.isdir(nodepath):
             os.makedirs(nodepath)
         os.chdir(nodepath)
         config = ConfigurationParser()
         config.read(join(self.parent_dir, 'config/template_config.ini'))
         config.set('blocks-dir', join(nodepath, 'blocks'))
         config.set('http-server-address', '0.0.0.0:' + http_port)
         config.set('p2p-listen-endpoint', '0.0.0.0:' + p2p_port)
         config.set('p2p-server-address', '%s:%s' % (p2p_address, p2p_port))
         config.set('enable-stale-production', True)
         config.set('producer-name', 'eosio')
         pair = self.wallet.create_import()
         self.edit_new_genesis(pair.public)
         config.set('signature-provider', self.create_sig_provider(pair))
         plugins = [
             'eosio::http_plugin', 'eosio::chain_plugin',
             'eosio::chain_api_plugin', 'eosio::history_plugin',
             'eosio::history_api_plugin', 'eosio::net_plugin',
             'eosio::net_api_plugin', 'eosio::producer_plugin'
         ]
         config.append('plugin', plugins)
         config.write(join(nodepath, 'config.ini'))
         copyfile(join(self.parent_dir, 'config/genesis.json'),
                  join(nodepath, "genesis.json"))
         node = Node('genesis', nodepath)
         node.start(3.0)
         self.update_node_state(node)
         self.save()
     except FileNotFoundError as e:
         print(e)