def test_node(self): try: server = None address = '127.0.0.1:1987' server = Node('127.0.0.1', 1987, '/tmp', 'test_node', ks_path=None, ks_passwd=None, node_type='BASE') server.start(None) time.sleep(.5) fri_client = FriClient() params = {} packet_obj = FabnetPacketRequest(method='UpdateNodeConfig', parameters=params, sync=True) resp = fri_client.call_sync(address, packet_obj) self.assertNotEqual(resp.ret_code, 0) params = {'config': {'TEST_CONFIG': 'str', 'TEST_INT': 234}} packet_obj = FabnetPacketRequest(method='UpdateNodeConfig', parameters=params, sync=True) resp = fri_client.call_sync(address, packet_obj) self.assertEqual(resp.ret_code, 0, resp.ret_message) packet_obj = FabnetPacketRequest(method='GetNodeConfig', sync=True) resp = fri_client.call_sync(address, packet_obj) self.assertEqual(resp.ret_code, 0, resp.ret_message) self.assertEqual(resp.ret_parameters['test_config'], 'str') self.assertEqual(resp.ret_parameters['test_int'], 234) time.sleep(.2) except Exception, err: print 'ERROR: %s'%err raise err
def test_node(self): try: server = None address = "127.0.0.1:1987" server = Node("127.0.0.1", 1987, "/tmp", "test_node", ks_path=None, ks_passwd=None, node_type="BASE") server.start(None) time.sleep(0.5) fri_client = FriClient() params = {} packet_obj = FabnetPacketRequest(method="UpdateNodeConfig", parameters=params, sync=True) resp = fri_client.call_sync(address, packet_obj) self.assertNotEqual(resp.ret_code, 0) params = {"config": {"TEST": {"TEST_CONFIG": "str", "TEST_INT": 234}}} packet_obj = FabnetPacketRequest(method="UpdateNodeConfig", parameters=params, sync=True) resp = fri_client.call_sync(address, packet_obj) self.assertEqual(resp.ret_code, 0, resp.ret_message) packet_obj = FabnetPacketRequest(method="GetNodeConfig", sync=True) resp = fri_client.call_sync(address, packet_obj) self.assertEqual(resp.ret_code, 0, resp.ret_message) self.assertTrue("TEST" in resp.ret_parameters, resp.ret_parameters) self.assertEqual(resp.ret_parameters["TEST"]["TEST_CONFIG"], "str") self.assertEqual(resp.ret_parameters["TEST"]["TEST_INT"], 234) time.sleep(0.2) except Exception, err: print "ERROR: %s" % err raise err
def run(self): address = '127.0.0.1:%s'%self.port if self.is_monitor: node_type = 'Monitor' else: node_type = 'DHT' config = {'WAIT_RANGE_TIMEOUT': 0.1, 'INIT_DHT_WAIT_NEIGHBOUR_TIMEOUT': 0.1, 'MONITOR_DHT_RANGES_TIMEOUT': 1, 'CHECK_HASH_TABLE_TIMEOUT': 1, 'WAIT_FILE_MD_TIMEDELTA': 0.1, 'WAIT_DHT_TABLE_UPDATE': 0.2} config.update(self.config) node = Node('127.0.0.1', self.port, self.home_dir, 'node_%s'%self.port, ks_path=None, ks_passwd=None, node_type=node_type, config=config) node.start(self.neighbour) self.__lock.acquire() try: self.operator = OperatorClient('node_%s'%self.port) self.stopped = False finally: self.__lock.release() while not self.stopped: time.sleep(0.1) node.stop()
def test_node(self): try: server = None address = '127.0.0.1:1987' node = Node('127.0.0.1', 1987, '/tmp', 'node_stat_test', ks_path=None, ks_passwd=None, node_type='BASE') node.start(None) server = node time.sleep(1) packet = { 'method': 'NodeStatistic', 'sender': '', 'parameters': {'reset_op_stat': True}, 'sync': True} packet_obj = FabnetPacketRequest(**packet) client = FriClient() ret_packet = client.call_sync('127.0.0.1:1987', packet_obj) time.sleep(1.5) packet['parameters']['base_info'] = True packet_obj = FabnetPacketRequest(**packet) ret_packet = client.call_sync('127.0.0.1:1987', packet_obj) self.assertEqual(isinstance(ret_packet, FabnetPacketResponse), True) self.assertEqual(ret_packet.ret_code, 0, ret_packet.ret_message) print json.dumps(ret_packet.ret_parameters) self.assertEqual(ret_packet.ret_parameters['BaseInfo']['node_name'], 'node_stat_test') self.assertEqual(ret_packet.ret_parameters['BaseInfo']['home_dir'], '/tmp') self.assertEqual(ret_packet.ret_parameters['BaseInfo']['node_types'], ['Base']) self.assertEqual(int(ret_packet.ret_parameters['NeighboursInfo']['uppers_balance']), -1) self.assertEqual(int(ret_packet.ret_parameters['NeighboursInfo']['superiors_balance']), -1) self.assertTrue(float(ret_packet.ret_parameters['SystemInfo']['loadavg_5']) >= 0) self.assertTrue(float(ret_packet.ret_parameters['SystemInfo']['loadavg_10']) >= 0) self.assertTrue(float(ret_packet.ret_parameters['SystemInfo']['loadavg_15']) >= 0) self.assertTrue(len(ret_packet.ret_parameters['SystemInfo']['fabnet_version'])>0) self.assertTrue(len(ret_packet.ret_parameters['SystemInfo']['uptime']) > 0) self.assertTrue(float(ret_packet.ret_parameters['FriAgentWMStat']['workers']) > 0) self.assertTrue(float(ret_packet.ret_parameters['FriAgentWMStat']['busy']) == 0) self.assertTrue(float(ret_packet.ret_parameters['OperatorWorkerWMStat']['workers']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperatorWorkerWMStat']['busy']) >= 1) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorWMStat']['workers']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorWMStat']['busy']) == 0) self.assertTrue(float(ret_packet.ret_parameters['FriServerProcStat']['threads']) > 0) self.assertTrue(float(ret_packet.ret_parameters['FriServerProcStat']['memory']) > 1000) self.assertTrue(float(ret_packet.ret_parameters['OperatorProcStat']['threads']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperatorProcStat']['memory']) > 1000) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorProcStat']['threads']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorProcStat']['memory']) > 1000) self.assertTrue(ret_packet.ret_parameters['OperationsProcTime']['NodeStatistic'] > 0) self.assertEqual(ret_packet.ret_parameters['OperationsProcTime']['TopologyCognition'], 0) time.sleep(.2) finally: if server: server.stop()
def run(self): address = '127.0.0.1:%s'%self.port home_dir = '/tmp/node_%s'%self.port if os.path.exists(home_dir): os.system('rm -rf %s'%home_dir) os.mkdir(home_dir) node_name = 'node%s'%self.port node = Node('127.0.0.1', self.port, home_dir, node_name, ks_path=None, ks_passwd=None, node_type='BASE') node.start(self.neighbour) self.node = node self.stopped = False while not self.stopped: time.sleep(0.1) node.stop()
def test_node(self): try: server = None address = '127.0.0.1:1987' if os.path.exists('/tmp/test_node_stat'): os.system('rm -rf /tmp/test_node_stat') os.system('mkdir /tmp/test_node_stat') os.system('cp ./tests/cert/test_certs.ca /tmp/test_node_stat/') node = Node('127.0.0.1', 1987, '/tmp/test_node_stat', 'node_stat_test', ks_path=VALID_STORAGE, ks_passwd=PASSWD, node_type='BASE') node.start(None) server = node time.sleep(1) packet = { 'method': 'NodeStatistic', 'sender': '', 'parameters': {'reset_op_stat': True, 'test_val': '232eq'}, 'sync': True} packet_obj = FabnetPacketRequest(**packet) reset_op_stat = packet_obj.bool_get('reset_op_stat') self.assertEqual(reset_op_stat, True) self.assertEqual(packet_obj.bool_get('reset_op_stat2', False), False) with self.assertRaises(FriException): packet_obj.bool_get('reset_op_stat2') self.assertEqual(packet_obj.int_get('reset_op_stat'), 1) self.assertEqual(packet_obj.str_get('reset_op_stat'), 'True') with self.assertRaises(FriException): packet_obj.int_get('test_val') packet_obj.str_get('test_val') key_storage = init_keystore(VALID_STORAGE, PASSWD) client = FriClient(key_storage) self.assertEqual(client.get_session_id(), None) ret_packet = client.call_sync('127.0.0.1:1987', packet_obj) self.assertNotEqual(client.get_session_id(), None) time.sleep(1.5) packet['parameters']['base_info'] = True packet_obj = FabnetPacketRequest(**packet) ret_packet = client.call_sync('127.0.0.1:1987', packet_obj) self.assertEqual(isinstance(ret_packet, FabnetPacketResponse), True) self.assertEqual(ret_packet.ret_code, 0, ret_packet.ret_message) print json.dumps(ret_packet.ret_parameters) self.assertEqual(ret_packet.ret_parameters['BaseInfo']['node_name'], 'node_stat_test') self.assertEqual(ret_packet.ret_parameters['BaseInfo']['home_dir'], '/tmp/test_node_stat') self.assertEqual(ret_packet.ret_parameters['BaseInfo']['node_types'], ['base']) self.assertEqual(int(ret_packet.ret_parameters['NeighboursInfo']['uppers_balance']), -1) self.assertEqual(int(ret_packet.ret_parameters['NeighboursInfo']['superiors_balance']), -1) self.assertTrue(float(ret_packet.ret_parameters['SystemInfo']['loadavg_5']) >= 0) self.assertTrue(float(ret_packet.ret_parameters['SystemInfo']['loadavg_10']) >= 0) self.assertTrue(float(ret_packet.ret_parameters['SystemInfo']['loadavg_15']) >= 0) self.assertTrue(len(ret_packet.ret_parameters['SystemInfo']['core_version'])>0) self.assertTrue(len(ret_packet.ret_parameters['SystemInfo']['node_version'])>0) self.assertTrue(len(ret_packet.ret_parameters['SystemInfo']['installed_version'])>0) self.assertTrue(len(ret_packet.ret_parameters['SystemInfo']['uptime']) > 0) self.assertTrue(float(ret_packet.ret_parameters['FriAgentWMStat']['workers']) > 0) self.assertTrue(float(ret_packet.ret_parameters['FriAgentWMStat']['busy']) == 0) self.assertTrue(float(ret_packet.ret_parameters['OperatorWorkerWMStat']['workers']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperatorWorkerWMStat']['busy']) >= 1) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorWMStat']['workers']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorWMStat']['busy']) == 0) self.assertTrue(float(ret_packet.ret_parameters['FriServerProcStat']['threads']) > 0) self.assertTrue(float(ret_packet.ret_parameters['FriServerProcStat']['memory']) > 1000) self.assertTrue(float(ret_packet.ret_parameters['OperatorProcStat']['threads']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperatorProcStat']['memory']) > 1000) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorProcStat']['threads']) > 0) self.assertTrue(float(ret_packet.ret_parameters['OperationsProcessorProcStat']['memory']) > 1000) self.assertTrue(ret_packet.ret_parameters['OperationsProcTime']['NodeStatistic'] > 0) self.assertEqual(ret_packet.ret_parameters['OperationsProcTime']['TopologyCognition'], 0) time.sleep(.2) finally: if server: server.stop()