How to use clone_phoromatic_server_result method of phoromatic class

Best Phoronix-test-suite code snippet using phoromatic.clone_phoromatic_server_result

phoromatic.php

Source:phoromatic.php Github

copy

Full Screen

...40 return 'The Phoromatic module contains the client support for interacting with Phoromatic and Phoromatic Tracker services.';41 }42 public static function user_commands()43 {44 return array('connect' => 'run_connection', 'explore' => 'explore_network', 'upload_result' => 'upload_unscheduled_result', 'set_root_admin_password' => 'set_root_admin_password', 'list_results' => 'recent_phoromatic_server_results', 'clone' => 'clone_phoromatic_server_result', 'export_results_for_account_schedules' => 'generate_export_result_schedule_dump');45 }46 public static function upload_unscheduled_result($args)47 {48 $server_setup = self::setup_server_addressing($args);49 if(!$server_setup)50 return false;51 $uploads = 0;52 foreach($args as $arg)53 {54 if(pts_types::is_result_file($arg))55 {56 $uploads++;57 echo PHP_EOL . 'Uploading: ' . $arg . PHP_EOL;58 $result_file = pts_types::identifier_to_object($arg);59 $server_response = self::upload_test_result($result_file);60 $server_response = json_decode($server_response, true);61 if(isset($server_response['phoromatic']['response']))62 echo ' Result Uploaded' . PHP_EOL;63 else64 echo ' Upload Failed' . PHP_EOL;65 }66 }67 if($uploads == 0)68 echo PHP_EOL . 'No Result Files Found To Upload.' . PHP_EOL;69 }70 public static function set_root_admin_password()71 {72 phoromatic_server::prepare_database();73 $root_admin_pw = phoromatic_server::read_setting('root_admin_pw');74 if($root_admin_pw != null)75 {76 do77 {78 $check_root_pw = pts_user_io::prompt_user_input('Please enter the existing root-admin password');79 }80 while(hash('sha256', 'PTS' . $check_root_pw) != $root_admin_pw);81 }82 echo PHP_EOL . 'The new root-admin password must be at least six characters long.' . PHP_EOL;83 do84 {85 $new_root_pw = pts_user_io::prompt_user_input('Please enter the new root-admin password');86 }87 while(strlen($new_root_pw) < 6);88 $new_root_pw = hash('sha256', 'PTS' . $new_root_pw);89 $root_admin_pw = phoromatic_server::save_setting('root_admin_pw', $new_root_pw);90 }91 public static function generate_export_result_schedule_dump($r)92 {93 phoromatic_server::prepare_database();94 if(isset($r[0]) && !empty($r[0]))95 {96 phoromatic_server::generate_result_export_dump($r[0]);97 }98 }99 public static function explore_network()100 {101 pts_client::$display->generic_heading('Phoromatic Servers');102 $archived_servers = pts_client::available_phoromatic_servers();103 $server_count = 0;104 foreach($archived_servers as $archived_server)105 {106 $response = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/server.php?phoromatic_info');107 if(!empty($response))108 {109 $response = json_decode($response, true);110 if($response && isset($response['pts']))111 {112 $server_count++;113 echo PHP_EOL . 'IP: ' . $archived_server['ip'] . PHP_EOL;114 echo 'HTTP PORT: ' . $archived_server['http_port'] . PHP_EOL;115 echo 'WEBSOCKET PORT: ' . $response['ws_port'] . PHP_EOL;116 echo 'SERVER: ' . $response['http_server'] . PHP_EOL;117 echo 'PHORONIX TEST SUITE: ' . $response['pts'] . ' [' . $response['pts_core'] . ']' . PHP_EOL;118 // TODO XXX fix/finish below code...119 if(false && ($ws = new phoromatic_client_comm_ws($archived_server['ip'], $response['ws_port'])))120 {121 // Query the WebSocket Server for some Phoromatic Server details122 $s = $ws->send(array('phoromatic' => array('event' => 'pts-version')));123 $s = $ws->send(array('phoromatic' => array('event' => 'download-cache')));124 $r = $ws->receive_until('download-cache');125 var_dump($r);126 }127 else128 {129 // Provide some other server info via HTTP130 $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/download-cache.php?repo');131 echo 'DOWNLOAD CACHE: ';132 if(!empty($repo))133 {134 $repo = json_decode($repo, true);135 if($repo && isset($repo['phoronix-test-suite']['download-cache']))136 {137 $total_file_size = 0;138 foreach($repo['phoronix-test-suite']['download-cache'] as $file_name => $inf)139 {140 $total_file_size += $repo['phoronix-test-suite']['download-cache'][$file_name]['file_size'];141 }142 echo count($repo['phoronix-test-suite']['download-cache']) . ' FILES / ' . round($total_file_size / 1000000) . ' MB CACHE SIZE';143 }144 }145 else146 {147 echo 'N/A';148 }149 }150 echo PHP_EOL;151 $repo = pts_network::http_get_contents('http://' . $archived_server['ip'] . ':' . $archived_server['http_port'] . '/openbenchmarking-cache.php?repos');152 echo 'SUPPORTED OPENBENCHMARKING.ORG REPOSITORIES:' . PHP_EOL;153 if(!empty($repo))154 {155 $repo = json_decode($repo, true);156 if($repo && is_array($repo['repos']))157 {158 foreach($repo['repos'] as $data)159 {160 echo ' ' . $data['title'] . ' - Last Generated: ' . date('d M Y H:i', $data['generated']) . PHP_EOL;161 }162 }163 }164 else165 {166 echo ' N/A' . PHP_EOL;167 }168 }169 }170 }171 if($server_count == 0)172 {173 echo PHP_EOL . 'No Phoromatic Servers detected.' . PHP_EOL . PHP_EOL;174 }175 }176 protected static function tick_thread()177 {178 static $last_phoromatic_log = 0;179 while(true)180 {181 $j = array();182 $log_size = pts_client::$pts_logger->get_log_file_size();183 if($log_size != $last_phoromatic_log)184 {185 $phoromatic_log = file_get_contents(pts_client::$pts_logger->get_log_file_location());186 $last_phoromatic_log = $log_size;187 $j['phoromatic']['client-log'] = $phoromatic_log;188 }189 foreach(phodevi::supported_sensors() as $sensor)190 {191 $j['phoromatic']['stats']['sensors'][phodevi::sensor_name($sensor)] = array('value' => phodevi::read_sensor($sensor), 'unit' => phodevi::read_sensor_unit($sensor));192 }193 $j['phoromatic']['stats']['uptime'] = ceil(phodevi::system_uptime() / 60);194 $server_response = phoromatic::upload_to_remote_server(array(195 'r' => 'tick',196 'j' => json_encode($j),197 ));198 $server_response = json_decode($server_response, true);199 if($server_response && isset($server_response['phoromatic']['tick_thread']))200 {201 switch($server_response['phoromatic']['tick_thread'])202 {203 case 'reboot':204 if(pts_client::executable_in_path('reboot'))205 {206 shell_exec('reboot');207 }208 break;209 case 'halt-testing':210 touch(PTS_USER_PATH . 'halt-testing');211 break;212 }213 }214 // Randomize the thread work a little bit to ensure not hitting the systems at the same time215 sleep(rand(60, 90));216 }217 }218 protected static function upload_to_remote_server($to_post, $server_address = null, $server_http_port = null, $account_id = null)219 {220 static $last_communication_minute = null;221 static $communication_attempts = 0;222 if($last_communication_minute == date('i') && $communication_attempts > 8)223 {224 // Something is wrong, Phoromatic shouldn't be communicating with server more than four times a minute225 return false;226 }227 else228 {229 if(date('i') != $last_communication_minute)230 {231 $last_communication_minute = date('i');232 $communication_attempts = 0;233 }234 $communication_attempts++;235 }236 if($server_address == null && self::$server_address != null)237 {238 $server_address = self::$server_address;239 }240 if($server_http_port == null && self::$server_http_port != null)241 {242 $server_http_port = self::$server_http_port;243 }244 if($account_id == null && self::$account_id != null)245 {246 $account_id = self::$account_id;247 }248 $to_post['aid'] = $account_id;249 $to_post['pts'] = PTS_VERSION;250 $to_post['pts_core'] = PTS_CORE_VERSION;251 $to_post['gsid'] = defined('PTS_GSID') ? PTS_GSID : null;252 $to_post['lip'] = pts_network::get_local_ip();253 $to_post['h'] = phodevi::system_hardware(true);254 $to_post['nm'] = pts_network::get_network_mac();255 $to_post['nw'] = implode(', ', pts_network::get_network_wol());256 $to_post['s'] = phodevi::system_software(true);257 $to_post['n'] = phodevi::read_property('system', 'hostname');258 $to_post['msi'] = PTS_MACHINE_SELF_ID;259 return pts_network::http_upload_via_post('http://' . $server_address . ':' . $server_http_port . '/phoromatic.php', $to_post, false);260 }261 protected static function update_system_status($current_task, $estimated_time_remaining = 0, $percent_complete = 0, $for_schedule = null, $estimate_to_next_comm = 0)262 {263 static $last_msg = null;264 // Avoid an endless flow of "idling" messages, etc265 if($current_task != $last_msg)266 pts_client::$pts_logger && pts_client::$pts_logger->log($current_task);267 $last_msg = $current_task;268 if(self::$limit_network_communication)269 {270 static $last_comm_time = 0;271 if(time() > ($last_comm_time + 800 + rand(0, 180)))272 {273 // It's been at least half hour since last update, so report in state...274 $last_comm_time = time();275 }276 else277 {278 return;279 }280 }281 return phoromatic::upload_to_remote_server(array(282 'r' => 'update_system_status',283 'a' => $current_task,284 'time' => $estimated_time_remaining,285 'pc' => $percent_complete,286 'sched' => (!empty($for_schedule) ? $for_schedule : self::$p_schedule_id),287 'bid' => (!empty(self::$benchmark_ticket_id) ? self::$benchmark_ticket_id : 0),288 'o' => $estimate_to_next_comm289 ));290 }291 public static function startup_ping_check($server_ip, $http_port)292 {293 $server_response = phoromatic::upload_to_remote_server(array(294 'r' => 'ping',295 ), $server_ip, $http_port);296 }297 protected static function setup_server_addressing($server_string = null)298 {299 self::$has_run_server_setup_func = true;300 if(isset($server_string[0]) && strpos($server_string[0], '/', strpos($server_string[0], ':')) > 6)301 {302 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to Phoromatic Server: ' . $server_string[0]);303 self::$account_id = substr($server_string[0], strrpos($server_string[0], '/') + 1);304 self::$server_address = substr($server_string[0], 0, strpos($server_string[0], ':'));305 self::$server_http_port = substr($server_string[0], strlen(self::$server_address) + 1, -1 - strlen(self::$account_id));306 pts_client::$display->generic_heading('Server IP: ' . self::$server_address . PHP_EOL . 'Server HTTP Port: ' . self::$server_http_port . PHP_EOL . 'Account ID: ' . self::$account_id);307 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);308 }309 else if(($last_server = trim(pts_module::read_file('last-phoromatic-server'))) && !empty($last_server))310 {311 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to connect to last server connection: ' . $last_server);312 $last_account_id = substr($last_server, strrpos($last_server, '/') + 1);313 $last_server_address = substr($last_server, 0, strpos($last_server, ':'));314 $last_server_http_port = substr($last_server, strlen($last_server_address) + 1, -1 - strlen($last_account_id));315 pts_client::$pts_logger && pts_client::$pts_logger->log('Last Server IP: ' . $last_server_address . ' Last Server HTTP Port: ' . $last_server_http_port . ' Last Account ID: ' . $last_account_id);316 for($i = 0; $i < 10; $i++)317 {318 $server_response = phoromatic::upload_to_remote_server(array(319 'r' => 'ping',320 ), $last_server_address, $last_server_http_port, $last_account_id);321 $server_response = json_decode($server_response, true);322 if($server_response && isset($server_response['phoromatic']['ping']))323 {324 self::$server_address = $last_server_address;325 self::$server_http_port = $last_server_http_port;326 self::$account_id = $last_account_id;327 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection restored');328 pts_client::register_phoromatic_server(self::$server_address, self::$server_http_port);329 break;330 }331 else332 {333 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection failed');334 sleep((12 * ($i + 1)));335 }336 }337 }338 if(self::$server_address == null)339 {340 $archived_servers = pts_client::available_phoromatic_servers();341 if(!empty($archived_servers))342 {343 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Servers');344 self::attempt_phoromatic_server_auto_discover($archived_servers);345 }346 }347 if(self::$server_address == null || self::$server_http_port == null || self::$account_id == null)348 {349 pts_client::$pts_logger && pts_client::$pts_logger->log('Phoromatic Server connection setup failed');350 echo PHP_EOL . 'You must pass the Phoromatic Server information as an argument to phoromatic.connect, or otherwise configure your network setup.' . PHP_EOL . ' e.g. phoronix-test-suite phoromatic.connect 192.168.1.2:5555/I0SSJY' . PHP_EOL . PHP_EOL;351 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !empty($archived_servers))352 {353 echo 'The Phoromatic client appears to be running as a system service/daemon so will attempt to continue auto-polling to find the Phoromatic Server.' . PHP_EOL . PHP_EOL;354 $success = false;355 do356 {357 pts_client::$pts_logger && pts_client::$pts_logger->log('Will auto-poll connected servers every 90 seconds looking for a claim by a Phoromatic Server');358 sleep(90);359 $success = self::attempt_phoromatic_server_auto_discover($archived_servers);360 }361 while($success == false);362 }363 else364 {365 return false;366 }367 }368 return true;369 }370 protected static function attempt_phoromatic_server_auto_discover(&$phoromatic_servers)371 {372 foreach($phoromatic_servers as &$archived_server)373 {374 pts_client::$pts_logger && pts_client::$pts_logger->log('Attempting to auto-discover Phoromatic Server on: ' . $archived_server['ip'] . ': ' . $archived_server['http_port']);375 $server_response = phoromatic::upload_to_remote_server(array(376 'r' => 'ping',377 ), $archived_server['ip'], $archived_server['http_port']);378 $server_response = json_decode($server_response, true);379 if($server_response && isset($server_response['phoromatic']['account_id']))380 {381 self::$server_address = $archived_server['ip'];382 self::$server_http_port = $archived_server['http_port'];383 self::$account_id = $server_response['phoromatic']['account_id'];384 return true;385 }386 }387 return false;388 }389 protected static function setup_system_environment()390 {391 if(is_writable('/boot/grub/grubenv') && pts_client::executable_in_path('grub-editenv'))392 {393 // In case system fails or reboots in process and don't want to hang on GRUB recordfail394 shell_exec('grub-editenv /boot/grub/grubenv unset recordfail 2>&1');395 }396 }397 public static function run_connection($args)398 {399 if(pts_client::create_lock(PTS_USER_PATH . 'phoromatic_lock') == false)400 {401 trigger_error('Phoromatic is already running.', E_USER_ERROR);402 return false;403 }404 define('PHOROMATIC_PROCESS', true);405 if(pts_client::$pts_logger == false)406 {407 pts_client::$pts_logger = new pts_logger();408 }409 pts_client::$pts_logger->log(pts_core::program_title(true) . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client');410 if(phodevi::system_uptime() < 60)411 {412 echo 'PHOROMATIC: Sleeping for 60 seconds as system freshly started.' . PHP_EOL;413 pts_client::$pts_logger->log('Sleeping for 60 seconds as system freshly started');414 sleep(60);415 }416 $server_setup = self::setup_server_addressing($args);417 //$http_comm = new phoromatic_client_comm_http();418 if(!$server_setup)419 {420 if(getenv('PTS_NO_REBOOT_ON_NETWORK_FAILURE') == false && PTS_IS_DAEMONIZED_SERVER_PROCESS)421 {422 if(pts_client::executable_in_path('reboot'))423 {424 shell_exec('reboot');425 sleep(5);426 }427 }428 return false;429 }430 $times_failed = 0;431 $has_success = false;432 $do_exit = false;433 $just_started = true;434 self::setup_system_environment();435 pts_client::$pts_logger->log('SYSTEM HARDWARE: ' . phodevi::system_hardware(true));436 pts_client::$pts_logger->log('SYSTEM SOFTWARE: ' . phodevi::system_software(true));437 while($do_exit == false)438 {439 $server_response = phoromatic::upload_to_remote_server(array(440 'r' => 'start',441 ));442 if($server_response == false)443 {444 $times_failed++;445 pts_client::$pts_logger->log('Server response failed');446 if($times_failed >= 2)447 {448 trigger_error('Communication with server failed.', E_USER_ERROR);449 if(PTS_IS_DAEMONIZED_SERVER_PROCESS == false && $times_failed > 5)450 {451 return false;452 }453 else if(PTS_IS_DAEMONIZED_SERVER_PROCESS && $times_failed > 10)454 {455 if(getenv('PTS_NO_REBOOT_ON_NETWORK_FAILURE') == false && pts_client::executable_in_path('reboot'))456 {457 shell_exec('reboot');458 sleep(5);459 }460 }461 }462 }463 else if(substr($server_response, 0, 1) == '[')464 {465 // Likely a notice/warning from server466 echo PHP_EOL . substr($server_response, 0, strpos($server_response, PHP_EOL)) . PHP_EOL;467 }468 else if(substr($server_response, 0, 1) == '{')469 {470 $times_failed = 0;471 $json = json_decode($server_response, true);472 if($has_success == false)473 {474 $has_success = true;475 pts_module::save_file('last-phoromatic-server', self::$server_address . ':' . self::$server_http_port . '/' . self::$account_id);476 }477 if($json != null)478 {479 if(isset($json['phoromatic']['error']) && !empty($json['phoromatic']['error']))480 {481 trigger_error($json['phoromatic']['error'], E_USER_ERROR);482 }483 if(isset($json['phoromatic']['response']) && !empty($json['phoromatic']['response']))484 {485 echo PHP_EOL . $json['phoromatic']['response'] . PHP_EOL;486 }487 }488 self::$limit_network_communication = isset($json['phoromatic']['settings']['LimitNetworkCommunication']) && pts_strings::string_bool($json['phoromatic']['settings']['LimitNetworkCommunication']);489 if(self::$limit_network_communication)490 {491 // Sleep to ensure network communication is somewhat random in case all systems started at same time492 sleep(0, 20);493 }494 if($just_started)495 {496 if(PTS_IS_DAEMONIZED_SERVER_PROCESS && !self::$limit_network_communication)497 {498 $pid = pcntl_fork();499 if($pid == 0)500 {501 // Start the tick thread502 self::tick_thread();503 }504 }505 $just_started = false;506 }507 if(isset($json['phoromatic']['pre_set_sys_env_vars']) && !empty($json['phoromatic']['pre_set_sys_env_vars']))508 {509 // pre_set_sys_env_vars was added during PTS 5.8 development510 // Sets environment variables on client as specified via the Phoromatic Server's systems page511 foreach(explode(';', $json['phoromatic']['pre_set_sys_env_vars']) as $i => $v_string)512 {513 $var = explode('=', $v_string);514 if(count($var) == 2)515 {516 putenv($var[0] . '=' . $var[1]);517 }518 }519 }520 switch(isset($json['phoromatic']['task']) ? $json['phoromatic']['task'] : null)521 {522 case 'install':523 phoromatic::update_system_status('Installing Tests');524 pts_test_suite::set_temporary_suite('pre-seed', $json['phoromatic']['test_suite']);525 pts_test_installer::standard_install('pre-seed', false, true);526 break;527 case 'benchmark':528 // Make sure all latest tests are available529 pts_openbenchmarking::refresh_repository_lists(null, true);530 $benchmark_timer = time();531 self::$is_running_as_phoromatic_node = true;532 $suite_identifier = sha1(time() . rand(2, 1000));533 pts_test_suite::set_temporary_suite($suite_identifier, $json['phoromatic']['test_suite']);534 self::$p_save_identifier = $json['phoromatic']['trigger_id'];535 $phoromatic_results_identifier = self::$p_save_identifier;536 $phoromatic_save_identifier = $json['phoromatic']['save_identifier'];537 self::$p_schedule_id = isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : false;538 self::$p_trigger_id = self::$p_save_identifier;539 $benchmark_ticket_id = isset($json['phoromatic']['benchmark_ticket_id']) ? $json['phoromatic']['benchmark_ticket_id'] : null;540 self::$benchmark_ticket_id = $benchmark_ticket_id;541 phoromatic::update_system_status('Running Benchmarks For: ' . $phoromatic_save_identifier);542 if(pts_strings::string_bool($json['phoromatic']['settings']['RunInstallCommand']))543 {544 if(isset($json['phoromatic']['pre_install_set_context']))545 {546 phoromatic::set_user_context($json['phoromatic']['pre_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_INSTALL');547 }548 pts_test_installer::standard_install($suite_identifier, pts_strings::string_bool($json['phoromatic']['settings']['ForceInstallTests']), true);549 if(isset($json['phoromatic']['post_install_set_context']))550 {551 phoromatic::set_user_context($json['phoromatic']['post_install_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_INSTALL');552 }553 }554 $env_vars = isset($json['phoromatic']['environment_variables']) ? pts_strings::parse_value_string_vars($json['phoromatic']['environment_variables']) : array();555 $is_stress_run = isset($env_vars['PTS_CONCURRENT_TEST_RUNS']) && $env_vars['PTS_CONCURRENT_TEST_RUNS'] > 1;556 // Do the actual running557 phodevi::clear_cache();558 if($is_stress_run)559 {560 self::$test_run_manager = new pts_stress_run_manager(array(561 'UploadResults' => false,562 'SaveResults' => false,563 'PromptForTestDescription' => false,564 'RunAllTestCombinations' => false,565 'PromptSaveName' => false,566 'PromptForTestIdentifier' => false,567 'OpenBrowser' => false568 ), true);569 if(self::$test_run_manager->initial_checks($suite_identifier, 'SHORT'))570 {571 if(self::$test_run_manager->load_tests_to_run($suite_identifier))572 {573 self::$test_run_manager->action_on_stress_log_set(array('phoromatic', 'upload_stress_log_sane'));574 self::$in_stress_mode = $phoromatic_save_identifier;575 self::$test_run_manager->multi_test_stress_run_execute($env_vars['PTS_CONCURRENT_TEST_RUNS'], $env_vars['TOTAL_LOOP_TIME']);576 self::$in_stress_mode = false;577 self::upload_stress_log(self::$test_run_manager->get_stress_log());578 }579 }580 self::$benchmark_ticket_id = null;581 break;582 }583 else584 {585 self::$test_run_manager = new pts_test_run_manager(array(586 'UploadResults' => (isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking'])),587 'SaveResults' => true,588 'RunAllTestCombinations' => false,589 'OpenBrowser' => false590 ), true);591 }592 if(self::$test_run_manager->initial_checks($suite_identifier, 'SHORT'))593 {594 // Load the tests to run595 if(self::$test_run_manager->load_tests_to_run($suite_identifier))596 {597 phoromatic::update_system_status('Tests In Run Queue: ' . implode(', ', self::$test_run_manager->get_tests_to_run_identifiers()));598 if(isset($json['phoromatic']['pre_run_set_context']))599 {600 phoromatic::set_user_context($json['phoromatic']['pre_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'PRE_RUN');601 }602 if(isset($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']) && pts_strings::string_bool($json['phoromatic']['settings']['UploadResultsToOpenBenchmarking']))603 {604 self::$test_run_manager->auto_upload_to_openbenchmarking();605 pts_openbenchmarking_client::override_client_setting('UploadSystemLogsByDefault', pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']));606 }607 // Save results?608 // Run the actual tests609 self::$test_run_manager->auto_save_results($phoromatic_save_identifier, $phoromatic_results_identifier, (isset($json['phoromatic']['test_description']) ? $json['phoromatic']['test_description'] : 'A Phoromatic run.'));610 self::$test_run_manager->pre_execution_process();611 self::$test_run_manager->call_test_runs();612 phoromatic::update_system_status('Benchmarks Completed For: ' . $phoromatic_save_identifier);613 self::$test_run_manager->post_execution_process();614 $elapsed_benchmark_time = time() - $benchmark_timer;615 // Handle uploading data to server616 $result_file = new pts_result_file(self::$test_run_manager->get_file_name());617 $upload_system_logs = pts_strings::string_bool($json['phoromatic']['settings']['UploadSystemLogs']);618 $server_response = self::upload_test_result($result_file, $upload_system_logs, (isset($json['phoromatic']['schedule_id']) ? $json['phoromatic']['schedule_id'] : null), $phoromatic_save_identifier, $json['phoromatic']['trigger_id'], $elapsed_benchmark_time, $benchmark_ticket_id);619 //pts_client::$pts_logger->log('DEBUG RESPONSE MESSAGE: ' . $server_response);620 if(!pts_strings::string_bool($json['phoromatic']['settings']['ArchiveResultsLocally']))621 {622 pts_client::remove_saved_result_file(self::$test_run_manager->get_file_name());623 }624 }625 if(isset($json['phoromatic']['post_run_set_context']))626 {627 phoromatic::set_user_context($json['phoromatic']['post_run_set_context'], self::$p_trigger_id, self::$p_schedule_id, 'POST_RUN');628 }629 }630 self::$p_schedule_id = null;631 self::$is_running_as_phoromatic_node = false;632 self::$benchmark_ticket_id = null;633 break;634 case 'reboot':635 echo PHP_EOL . 'Phoromatic received a remote command to reboot.' . PHP_EOL;636 phoromatic::update_system_status('Attempting System Reboot');637 if(pts_client::executable_in_path('reboot'))638 {639 shell_exec('reboot');640 sleep(5);641 }642 break;643 case 'shutdown-if-supports-wake':644 $supports_wol = false;645 foreach(pts_network::get_network_wol() as $net_device)646 {647 if(strpos($net_device, 'g') !== false)648 {649 $supports_wol = true;650 break;651 }652 }653 if(!$supports_wol)654 break;655 case 'shutdown':656 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))657 {658 self::run_client_update_script($json['phoromatic']['client_update_script']);659 sleep(10);660 }661 echo PHP_EOL . 'Phoromatic received a remote command to shutdown.' . PHP_EOL;662 phoromatic::update_system_status('Attempting System Shutdown');663 if(pts_client::executable_in_path('poweroff'))664 {665 shell_exec('poweroff');666 sleep(5);667 }668 break;669 case 'maintenance':670 echo PHP_EOL . 'Idling, system maintenance mode set by Phoromatic Server.' . PHP_EOL;671 phoromatic::update_system_status('Maintenance Mode');672 sleep(60);673 break;674 case 'idle':675 if(isset($json['phoromatic']['client_update_script']) && !empty($json['phoromatic']['client_update_script']))676 {677 self::run_client_update_script($json['phoromatic']['client_update_script']);678 }679 //echo PHP_EOL . 'Idling, waiting for task.' . PHP_EOL;680 phoromatic::update_system_status('Idling, Waiting For Task');681 break;682 case 'exit':683 echo PHP_EOL . 'Phoromatic received a remote command to exit.' . PHP_EOL;684 phoromatic::update_system_status('Exiting Phoromatic');685 $do_exit = true;686 break;687 }688 }689 if(!$do_exit)690 {691 if($server_response == false)692 sleep(rand(10, 30));693 else if(self::$limit_network_communication)694 sleep(60, 240);695 else696 sleep(60);697 }698 }699 pts_client::release_lock(PTS_USER_PATH . 'phoromatic_lock');700 }701 private static function upload_test_result(&$result_file, $upload_system_logs = true, $schedule_id = 0, $save_identifier = null, $trigger = null, $elapsed_time = 0, $benchmark_ticket_id = null)702 {703 $system_logs = null;704 $system_logs_hash = null;705 // TODO: Potentially integrate this code below shared with pts_openbenchmarking_client into a unified function for validating system log files706 $system_log_dir = PTS_SAVE_RESULTS_PATH . $result_file->get_identifier() . '/system-logs/';707 if(is_dir($system_log_dir) && $upload_system_logs)708 {709 $is_valid_log = true;710 $finfo = function_exists('finfo_open') ? finfo_open(FILEINFO_MIME_TYPE) : false;711 foreach(pts_file_io::glob($system_log_dir . '*') as $log_dir)712 {713 if($is_valid_log == false || !is_dir($log_dir))714 {715 $is_valid_log = false;716 break;717 }718 foreach(pts_file_io::glob($log_dir . '/*') as $log_file)719 {720 if(!is_file($log_file))721 {722 $is_valid_log = false;723 break;724 }725 if($finfo && substr(finfo_file($finfo, $log_file), 0, 5) != 'text/')726 {727 $is_valid_log = false;728 break;729 }730 }731 }732 if($is_valid_log)733 {734 $system_logs_zip = pts_client::create_temporary_file('.zip');735 pts_compression::zip_archive_create($system_logs_zip, $system_log_dir);736 if(filesize($system_logs_zip) == 0)737 {738 pts_client::$pts_logger && pts_client::$pts_logger->log('System log ZIP file failed to generate. Missing PHP ZIP support?');739 }740 else if(filesize($system_logs_zip) < 2097152)741 {742 // If it's over 2MB, probably too big743 $system_logs = base64_encode(file_get_contents($system_logs_zip));744 $system_logs_hash = sha1($system_logs);745 }746 else747 {748 // trigger_error('The systems log attachment is too large to upload to OpenBenchmarking.org.', E_USER_WARNING);749 }750 unlink($system_logs_zip);751 }752 }753 $composite_xml = $result_file->get_xml();754 $composite_xml_hash = sha1($composite_xml);755 $composite_xml_type = 'composite_xml';756 // Compress the result file XML if it's big757 if(isset($composite_xml[50000]) && function_exists('gzdeflate'))758 {759 $composite_xml_gz = gzdeflate($composite_xml);760 if($composite_xml_gz != false)761 {762 $composite_xml = $composite_xml_gz;763 $composite_xml_type = 'composite_xml_gz';764 }765 }766 // Upload to Phoromatic767 $times_tried = 0;768 do769 {770 if($times_tried > 0)771 {772 sleep(rand(5, 20));773 }774 $res = phoromatic::upload_to_remote_server(array(775 'r' => 'result_upload',776 //'ob' => $ob_data['id'],777 'sched' => $schedule_id,778 'bid' => $benchmark_ticket_id,779 'o' => $save_identifier,780 'ts' => $trigger,781 'et' => $elapsed_time,782 $composite_xml_type => base64_encode($composite_xml),783 'composite_xml_hash' => $composite_xml_hash,784 'system_logs_zip' => $system_logs,785 'system_logs_hash' => $system_logs_hash786 ));787 $times_tried++;788 }789 while($res == false && $times_tried < 4);790 return $res;791 }792 private static function upload_stress_log($stress_log)793 {794 // Upload Logs to Phoromatic795 if($stress_log == null || self::$benchmark_ticket_id == null)796 {797 return;798 }799 $times_tried = 0;800 do801 {802 if($times_tried > 0)803 {804 sleep(rand(5, 20));805 }806 $res = phoromatic::upload_to_remote_server(array(807 'r' => 'stress_log_upload',808 'bid' => self::$benchmark_ticket_id,809 'l' => $stress_log810 ));811 $times_tried++;812 }813 while($res == false && $times_tried < 4);814 return $res;815 }816 public static function upload_stress_log_sane($stress_log)817 {818 static $last_log_upload = 0;819 if(time() > ($last_log_upload + 60))820 {821 self::upload_stress_log($stress_log);822 $last_log_upload = time();823 }824 }825 public static function recent_phoromatic_server_results()826 {827 self::setup_server_addressing();828 $server_response = phoromatic::upload_to_remote_server(array('r' => 'list_results'));829 $server_response = json_decode($server_response, true);830 if(isset($server_response['phoromatic']['results']) && !empty($server_response['phoromatic']['results']))831 {832 foreach($server_response['phoromatic']['results'] as $pprid => $result)833 {834 echo sprintf('%-26ls - %-25ls - %-30ls', $result['Title'], $pprid, date('j M H:i', strtotime($result['UploadTime']))) . PHP_EOL;835 echo sprintf(' %-20ls - %-25ls' . PHP_EOL, $result['SystemName'], $result['GroupName']) . PHP_EOL;836 }837 }838 else839 echo PHP_EOL . 'No Phoromatic Server results discovered.';840 echo PHP_EOL;841 }842 public static function clone_phoromatic_server_result($args)843 {844 self::setup_server_addressing();845 $id = $args[0];846 $server_response = phoromatic::upload_to_remote_server(array('r' => 'clone_result', 'i' => $id));847 $server_response = json_decode($server_response, true);848 if(isset($server_response['phoromatic']['result']['composite_xml']) && !empty($server_response['phoromatic']['result']['composite_xml']))849 {850 $composite_xml = base64_decode($server_response['phoromatic']['result']['composite_xml']);851 $result_file = new pts_result_file($composite_xml);852 // TODO XXX: Add system log downloading support853 pts_client::save_test_result($id . '/composite.xml', $result_file->get_xml(), true);854 echo PHP_EOL . 'Result File Saved As: ' . $id . PHP_EOL . PHP_EOL;855 }856 else...

Full Screen

Full Screen

clone_phoromatic_server_result

Using AI Code Generation

copy

Full Screen

1require_once('phoromatic.php');2$phoromatic = new phoromatic();3$phoromatic->clone_phoromatic_server_result('1.php', '2.php');4require_once('phoromatic.php');5$phoromatic = new phoromatic();6$phoromatic->clone_phoromatic_server_result('1.php', '3.php');7require_once('phoromatic.php');8$phoromatic = new phoromatic();9$phoromatic->clone_phoromatic_server_result('1.php', '4.php');10require_once('phoromatic.php');11$phoromatic = new phoromatic();12$phoromatic->clone_phoromatic_server_result('1.php', '5.php');13require_once('phoromatic.php');14$phoromatic = new phoromatic();15$phoromatic->clone_phoromatic_server_result('1.php', '6.php');16require_once('phoromatic.php');17$phoromatic = new phoromatic();18$phoromatic->clone_phoromatic_server_result('1.php', '7.php');19require_once('phoromatic.php');20$phoromatic = new phoromatic();21$phoromatic->clone_phoromatic_server_result('1.php', '8.php');22require_once('phoromatic.php');23$phoromatic = new phoromatic();24$phoromatic->clone_phoromatic_server_result('1.php', '9.php');

Full Screen

Full Screen

clone_phoromatic_server_result

Using AI Code Generation

copy

Full Screen

1require_once('phoromatic.php');2require_once('classes/phoromatic_result.php');3$phoromatic = new phoromatic();4$phoromatic->clone_phoromatic_server_result('test', 'test2');5require_once('phoromatic.php');6require_once('classes/phoromatic_result.php');7$phoromatic = new phoromatic();8$phoromatic->get_phoromatic_server_results();9Fatal error: Call to undefined method phoromatic::get_phoromatic_server_results() in /var/www/html/Phoromatic/www/2.php on line 810require_once('phoromatic.php');11require_once('classes/phoromatic_result.php');12$phoromatic = new phoromatic();13$phoromatic->get_phoromatic_server_results();14Fatal error: Call to undefined method phoromatic::get_phoromatic_server_results() in /var/www/html/Phoromatic/www/2.php on line 815require_once('phoromatic.php');16require_once('classes/phoromatic_result.php');17$phoromatic = new phoromatic();18$phoromatic->get_phoromatic_server_results();19Fatal error: Call to undefined method phoromatic::get_phoromatic_server_results() in /var/www/html/Phoromatic/www/2.php on line 820require_once('phoromatic.php');21require_once('classes/phoromatic_result.php');22$phoromatic = new phoromatic();23$phoromatic->get_phoromatic_server_results();24Fatal error: Call to undefined method phoromatic::get_phoromatic_server_results() in /var/www/html/Phoromatic/www/2.php on line 8

Full Screen

Full Screen

clone_phoromatic_server_result

Using AI Code Generation

copy

Full Screen

1$phoromatic_account = 'account';2$phoromatic_password = 'password';3$phoromatic_system_id = 'system_id';4$phoromatic_result_id = 'result_id';5if( $phoromatic->clone_phoromatic_server_result($phoromatic_server, $phoromatic_account, $phoromatic_password, $phoromatic_system_id, $phoromatic_result_id) )6{7 echo 'Success!';8}9{10 echo 'Failure!';11}12$phoromatic_account = 'account';13$phoromatic_password = 'password';14$phoromatic_system_id = 'system_id';15$phoromatic_result_ids = array('result_id1', 'result_id2', 'result_id3');16if( $phoromatic->clone_phoromatic_server_results($phoromatic_server, $phoromatic_account, $phoromatic_password, $phoromatic_system_id, $phoromatic_result_ids) )17{18 echo 'Success!';19}20{21 echo 'Failure!';22}23$phoromatic_account = 'account';24$phoromatic_password = 'password';

Full Screen

Full Screen

clone_phoromatic_server_result

Using AI Code Generation

copy

Full Screen

1$phoromatic = new phoromatic();2$phoromatic->clone_phoromatic_server_result($id, $newname);3include_once('/var/www/phoromatic/server/classes/phoromatic.php');4include_once('/var/www/phoromatic/server/classes/phoromatic.php');5include_once('../server/classes/phoromatic.php');6include_once('../server/classes/phoromatic.php');7include_once('../server/classes/phoromatic.php');8include_once('../server/classes/phoromatic.php');

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful