|
1 | 1 | import logging |
2 | 2 | import os |
3 | 3 |
|
4 | | -from virttest import data_dir, error_context, remote, utils_misc |
| 4 | +from virttest import data_dir, error_context, remote, utils_misc, utils_net, utils_netperf |
5 | 5 |
|
6 | 6 | LOG_JOB = logging.getLogger("avocado.test") |
7 | 7 |
|
@@ -147,3 +147,56 @@ def netperf_record(results, filter_list, header=False, base="17", fbase="2"): |
147 | 147 | record += "%s|" % format_result(results[key], base=base, fbase=fbase) |
148 | 148 | record = record.rstrip("|") |
149 | 149 | return record, key_list |
| 150 | + |
| 151 | + |
| 152 | +def compile_netperf_pkg(params, env, address): |
| 153 | + """ |
| 154 | + Prepare and compile netperf binaries on the target system |
| 155 | +
|
| 156 | + :param params: Test parameters dictionary configs |
| 157 | + :param env: Test environment object |
| 158 | + :param address: localhost, vm name, or ip address |
| 159 | + :return: netserver_path, netperf_path |
| 160 | + """ |
| 161 | + if address in ("localhost", "127.0.0.1",): |
| 162 | + target_ip = utils_net.get_host_ip_address(params) |
| 163 | + install_path = params.get("server_path", "/var/tmp") |
| 164 | + user = params.get("hostusername", "root") |
| 165 | + pwd = params.get("hostpassword", "") |
| 166 | + elif address in params.get('vms', '').split(): |
| 167 | + vm = env.get_vm(address) |
| 168 | + vm.verify_alive() |
| 169 | + target_ip = vm.get_address() |
| 170 | + install_path = params.get("client_path", "/var/tmp") |
| 171 | + user = params.get("username", "") |
| 172 | + pwd = params.get("password", "") |
| 173 | + else: |
| 174 | + target_ip = address |
| 175 | + install_path = params.get("server_path", "/var/tmp") |
| 176 | + user = params.get("remote_username", "") |
| 177 | + pwd = params.get("remote_password", "") |
| 178 | + |
| 179 | + netperf_link = params.get("netperf_link") |
| 180 | + netperf_src = os.path.join(data_dir.get_deps_dir("netperf"), netperf_link) |
| 181 | + |
| 182 | + LOG_JOB.info(f"Instantiating NetperfServer on {address} (IP: {target_ip})...") |
| 183 | + n_server = utils_netperf.NetperfServer( |
| 184 | + address=target_ip, |
| 185 | + netperf_path=install_path, |
| 186 | + md5sum=params.get("pkg_md5sum", ""), |
| 187 | + netperf_source=netperf_src, |
| 188 | + username=user, |
| 189 | + password=pwd, |
| 190 | + compile_option="--enable-demo=yes", |
| 191 | + install=True |
| 192 | + ) |
| 193 | + |
| 194 | + nserver_path = n_server.netserver_path |
| 195 | + nperf_path = n_server.netperf_path |
| 196 | + |
| 197 | + if n_server.session: |
| 198 | + n_server.session.close() |
| 199 | + if n_server.package and hasattr(n_server.package, "_release_session"): |
| 200 | + n_server.package._release_session() |
| 201 | + |
| 202 | + return nserver_path, nperf_path |
0 commit comments