Exemple #1
0
    def create_net(self, nodes_count):
        global PROCESSES
        global ADDRESSES

        for unuse in range(nodes_count):
            if not ADDRESSES:
                n_node = 'init-fabnet'
                i = 1900
            else:
                n_node = random.choice(ADDRESSES)
                i = int(ADDRESSES[-1].split(':')[-1])+1
                self._wait_node(n_node)

            address = '127.0.0.1:%s'%i
            ADDRESSES.append(address)

            home = '/tmp/node_%s'%i
            if os.path.exists(home):
                shutil.rmtree(home)
            os.mkdir(home)
            os.system('cp fabnet_core/tests/cert/test_certs.ca %s/'%home)

            logger.warning('{SNP} STARTING NODE %s'%address)
            if n_node == 'init-fabnet':
                ntype = 'MGMT'
                Config.load(os.path.join(home, 'fabnet.conf'))
                Config.update_config({'db_engine': 'mongodb', \
                        'db_conn_str': "mongodb://127.0.0.1/%s"%MONITOR_DB,\
                        'COLLECT_NODES_STAT_TIMEOUT': 1, \
                        'mgmt_cli_port': 2323,
                        'AUTH_KEY_CHANGE_PERIOD': 2, \
                        'mgmt_rest_port': 9923})
                print open(os.path.join(home, 'fabnet.conf')).read()
            else:
                ntype = 'Base'

            args = ['/usr/bin/python', './fabnet_core/bin/fabnet-node', address, n_node, 'NODE%.02i'%i, home, ntype, \
                    KS_PATH, '--input-pwd', '--nodaemon']
            if DEBUG:
                args.append('--debug')
            print ' '.join(args)
            #p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,\
            p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=sys.stdout,\
                    env={'FABNET_PLUGINS_CONF': 'tests/plugins.yaml', 'PYTHONPATH': os.path.abspath('.')})
            p.stdin.write(KS_PASSWD+'\n')
            logger.warning('{SNP} PROCESS STARTED')
            time.sleep(1)

            PROCESSES.append(p)
            #if len(ADDRESSES) > 2:
            #    self._check_stat(address)

        for address in ADDRESSES:
            self._check_stat(address)

        time.sleep(1.5)
        print 'NETWORK STARTED'
Exemple #2
0
    def create_net(self, nodes_count):
        global PROCESSES
        global ADDRESSES

        for unuse in range(nodes_count):
            if not ADDRESSES:
                n_node = "init-fabnet"
                i = 1900
            else:
                n_node = random.choice(ADDRESSES)
                i = int(ADDRESSES[-1].split(":")[-1]) + 1
                self._wait_node(n_node)

            address = "127.0.0.1:%s" % i
            ADDRESSES.append(address)

            home = "/tmp/node_%s" % i
            if os.path.exists(home):
                shutil.rmtree(home)
            os.mkdir(home)

            logger.warning("{SNP} STARTING NODE %s" % address)
            if n_node == "init-fabnet":
                ntype = "Monitor"
                Config.load(os.path.join(home, "node_config"))
                Config.update_config(
                    {"db_engine": "postgresql", "db_conn_str": "dbname=%s user=postgres" % MONITOR_DB}, "Monitor"
                )
            else:
                ntype = "DHT"
            args = [
                "/usr/bin/python",
                "./fabnet/bin/fabnet-node",
                address,
                n_node,
                "%.02i" % i,
                home,
                ntype,
                "--nodaemon",
            ]
            if DEBUG:
                args.append("--debug")
            p = subprocess.Popen(args)
            logger.warning("{SNP} PROCESS STARTED")
            time.sleep(1)

            PROCESSES.append(p)
            # if len(ADDRESSES) > 2:
            #    self._check_stat(address)

        for address in ADDRESSES:
            self._check_stat(address)

        time.sleep(1.5)
        print "NETWORK STARTED"
Exemple #3
0
def create_monitor(neigbour):
    os.system('rm -rf %s'%monitoring_home)
    os.system('mkdir %s'%monitoring_home)
    Config.load(os.path.join(monitoring_home, 'node_config'))
    Config.update_config({'db_engine': 'postgresql', \
        'db_conn_str': "dbname=%s user=postgres"%MONITOR_DB}, 'Monitor')
    address = '%s:%s'%('127.0.0.1', 1989)
    logger.warning('{SNP} STARTING MONITORING NODE %s'%address)
    mon_p = subprocess.Popen(['/usr/bin/python', './fabnet/bin/fabnet-node', address, neigbour, 'monitor', monitoring_home, 'Monitor', '--nodaemon'])
    logger.warning('{SNP} PROCESS STARTED')
    time.sleep(1)
    return mon_p
Exemple #4
0
 def update_config(self, config, section=None):
     Config.update_config(config, section=section)
import unittest
import threading
import time
import os
import logging
import json
import shutil
from datetime import datetime

from fabnet.utils.logger import logger
from fabnet.dht_mgmt.fs_mapped_ranges import FSHashRanges, TmpFile

from fabnet.core.config import Config
Config.update_config({'WAIT_FILE_MD_TIMEDELTA': 0.1}, 'DHT')

logger.setLevel(logging.DEBUG)

TEST_FS_RANGE_DIR = '/tmp/test_fs_ranges'
START_RANGE_HASH = '%040x'%0
END_RANGE_HASH = '%040x'%10000000000


def tmpdata(data, f_end=''):
    fname = '/tmp/tmpdata' + f_end
    tmp = TmpFile(fname, data)
    return fname, tmp


class WriteThread(threading.Thread):
    def __init__(self, fs_ranges, start, end):
        threading.Thread.__init__(self)
 def update_config(self, config):
     Config.update_config(config)