github.com/platonnetwork/platon-go@v0.7.6/cases/tests/cmd/param/test_param.py (about) 1 import socket 2 import time 3 from copy import copy 4 import pytest 5 import allure 6 7 from common.connect import connect_web3, run_ssh 8 9 10 def isConnection(ip, port): 11 """ 12 Checks whether the specified port is open 13 :param ip: ip address 14 :param port: port 15 :return: boole 16 """ 17 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 18 try: 19 s.connect((ip, port)) 20 s.shutdown(2) 21 return True 22 except BaseException: 23 return False 24 25 26 def file_is_exist(ssh, path, file_name): 27 cmd_list = run_ssh( 28 ssh, "find {} -name {}".format(path, file_name)) 29 if len(cmd_list) > 0: 30 return file_name in cmd_list[0] 31 return False 32 33 34 def append_cmd_restart(global_test_env, cmd, node=None): 35 if node is None: 36 node = global_test_env.get_rand_node() 37 test_node = copy(node) 38 test_node.clean() 39 new_cfg = copy(global_test_env.cfg) 40 new_cfg.append_cmd = cmd 41 test_node.cfg = new_cfg 42 test_node.deploy_me(genesis_file=new_cfg.genesis_tmp) 43 return test_node 44 45 46 class TestStartParam(object): 47 48 @pytest.mark.compatibility 49 @allure.title("Test access rpcapi") 50 @pytest.mark.P3 51 def test_CMD_077(self, global_test_env): 52 env = global_test_env 53 node = env.get_rand_node() 54 modules = node.web3.manager.request_blocking("rpc_modules", []) 55 api_method = "debug" 56 assert modules.get(api_method) is not None 57 58 @pytest.mark.compatibility 59 @allure.title("Test to enable ws function") 60 @pytest.mark.P3 61 def test_CMD_078_CMD_081(self, global_test_env): 62 env = global_test_env 63 node = env.get_rand_node() 64 ws_url = "ws://{}:".format(node.host) 65 ws_port = node.wsport 66 if ws_port is None: 67 ws_port = 16000 68 node.wsport = ws_port 69 node.wsurl = "{}{}".format(ws_url, ws_port) 70 append_cmd_restart(global_test_env, None, node) 71 assert node.ws_web3.isConnected() 72 73 @allure.title("Test to enable wsapi function") 74 @pytest.mark.P3 75 def test_CMD_082(self, global_test_env): 76 env = global_test_env 77 node = env.get_rand_node() 78 if node.wsport is None: 79 node.wsport = 16000 80 node.wsurl = "ws://{}:{}".format(node.host, node.wsport) 81 append_cmd_restart(global_test_env, None, node) 82 modules = node.ws_web3.manager.request_blocking("rpc_modules", []) 83 api_method = "debug" 84 assert modules.get(api_method) is not None 85 86 @allure.title("Test to enable ipc function") 87 @pytest.mark.P3 88 @pytest.mark.compatibility 89 def test_enable_ipc(self, global_test_env): 90 env = global_test_env 91 node = env.get_rand_node() 92 assert file_is_exist(node.ssh, node.remote_data_dir, "platon.ipc") 93 94 @allure.title("Test off ipc function") 95 @pytest.mark.P3 96 def test_CMD_085(self, global_test_env): 97 test_node = append_cmd_restart(global_test_env, "--ipcdisable") 98 assert bool(1 - file_is_exist(test_node.ssh, test_node.remote_data_dir, "platon.ipc")) 99 100 @allure.title("Test configuration ipc file name") 101 @pytest.mark.P3 102 def test_CMD_086(self, global_test_env): 103 test_node = append_cmd_restart(global_test_env, "--ipcpath platon_test.ipc") 104 time.sleep(10) 105 assert file_is_exist(test_node.ssh, test_node.remote_data_dir, "platon_test.ipc") 106 107 @pytest.mark.compatibility 108 @allure.title("Test enable seed node") 109 @pytest.mark.P3 110 def test_CMD_089(self, global_test_env): 111 global_test_env.deploy_all() 112 env = global_test_env 113 normal_node = env.get_a_normal_node() 114 collusion_node = env.get_rand_node() 115 new_cfg = copy(env.cfg) 116 test_node = copy(normal_node) 117 test_node.clean() 118 new_cfg.is_need_static = False 119 new_cfg.append_cmd = "--bootnodes \"{}\"".format(collusion_node.enode) 120 test_node.cfg = new_cfg 121 test_node.deploy_me(genesis_file=new_cfg.genesis_tmp) 122 time.sleep(20) 123 node_peers = test_node.admin.peers 124 assert len(node_peers) == 1 125 assert node_peers[0]["id"] == collusion_node.node_id 126 127 @pytest.mark.compatibility 128 @allure.title("Test open p2p port") 129 @pytest.mark.P3 130 def test_CMD_090(self, global_test_env): 131 env = global_test_env 132 node = env.get_rand_node() 133 assert isConnection(node.host, int(node.p2p_port)) 134 135 @pytest.mark.compatibility 136 @allure.title("Test to enable the discovery function") 137 @pytest.mark.P3 138 def test_CMD_097(self, global_test_env): 139 env = global_test_env 140 node = env.get_rand_node() 141 node_info = node.admin.nodeInfo 142 discovery = node_info["ports"]["discovery"] 143 assert discovery != 0 144 145 @allure.title("Test off the discovery function") 146 @pytest.mark.P3 147 def test_CMD_098(self, global_test_env): 148 test_node = append_cmd_restart(global_test_env, "--nodiscover") 149 node_info = test_node.admin.nodeInfo 150 discovery = node_info["ports"]["discovery"] 151 assert discovery == 0 152 153 @allure.title("Test to enable pprof function") 154 @pytest.mark.P3 155 def test_CMD_115(self, global_test_env): 156 test_node = global_test_env.get_rand_node() 157 pprof = 6060 158 test_node = append_cmd_restart(global_test_env, 159 "--pprof --pprofaddr {} --pprofport {}".format(test_node.host, pprof), test_node) 160 assert isConnection(test_node.host, pprof) 161 162 @allure.title("Test to enable trace information file output") 163 @pytest.mark.P3 164 def test_CMD_119(self, global_test_env): 165 test_node = global_test_env.get_rand_node() 166 append_cmd_restart(global_test_env, "--trace {}/tracefile".format(test_node.remote_node_path), test_node) 167 time.sleep(10) 168 assert file_is_exist(test_node.ssh, test_node.remote_node_path, "tracefile") 169 170 @allure.title("Test open output cpufile content") 171 @pytest.mark.P3 172 def test_CMD_118(self, global_test_env): 173 test_node = global_test_env.get_rand_node() 174 append_cmd_restart(global_test_env, "--cpuprofile {}/cpufile".format(test_node.remote_node_path), test_node) 175 time.sleep(10) 176 assert file_is_exist(test_node.ssh, test_node.remote_node_path, "cpufile") 177 178 @allure.title("Test open indicator monitoring function") 179 @pytest.mark.P3 180 def test_CMD_121(self, global_test_env): 181 test_node = append_cmd_restart(global_test_env, "--metrics") 182 time.sleep(10) 183 metrics = test_node.debug.web3.manager.request_blocking("debug_metrics", [True]) 184 assert metrics.cbft.gauage.block.number > 0