function validateResourceData() { global $user; $return = array('error' => 0); $return['rscid'] = getContinuationVar('rscid', 0); $return['name'] = processInputVar('name', ARG_STRING); $return['startnum'] = processInputVar('startnum', ARG_NUMERIC); $return['endnum'] = processInputVar('endnum', ARG_NUMERIC); $return['owner'] = processInputVar('owner', ARG_STRING, "{$user['unityid']}@{$user['affiliation']}"); $return['type'] = processInputVar('type', ARG_STRING); $return['IPaddress'] = processInputVar('ipaddress', ARG_STRING); $return['privateIPaddress'] = processInputVar('privateipaddress', ARG_STRING); $return['eth0macaddress'] = processInputVar('privatemac', ARG_STRING); $return['eth1macaddress'] = processInputVar('publicmac', ARG_STRING); $return['startpubipaddress'] = processInputVar('startpubipaddress', ARG_STRING); $return['endpubipaddress'] = processInputVar('endpubipaddress', ARG_STRING); $return['startprivipaddress'] = processInputVar('startprivipaddress', ARG_STRING); $return['endprivipaddress'] = processInputVar('endprivipaddress', ARG_STRING); $return['startmac'] = processInputVar('startmac', ARG_STRING); $return['provisioningid'] = processInputVar('provisioningid', ARG_NUMERIC); $return['stateid'] = processInputVar('stateid', ARG_NUMERIC); $return['notes'] = processInputVar('notes', ARG_STRING); $return['vmprofileid'] = processInputVar('vmprofileid', ARG_NUMERIC); $return['platformid'] = processInputVar('platformid', ARG_NUMERIC); $return['scheduleid'] = processInputVar('scheduleid', ARG_NUMERIC); $return['ram'] = processInputVar('ram', ARG_NUMERIC); $return['cores'] = processInputVar('cores', ARG_NUMERIC); $return['procspeed'] = processInputVar('procspeed', ARG_NUMERIC); $return['network'] = processInputVar('network', ARG_NUMERIC); $return['predictivemoduleid'] = processInputVar('predictivemoduleid', ARG_NUMERIC); $return['natenabled'] = processInputVar('natenabled', ARG_NUMERIC); $return['nathostid'] = processInputVar('nathostid', ARG_NUMERIC); $return['nathostenabled'] = processInputVar('nathostenabled', ARG_NUMERIC); $return['natpublicIPaddress'] = processInputVar('natpublicipaddress', ARG_STRING); $return['natinternalIPaddress'] = processInputVar('natinternalipaddress', ARG_STRING); $return['location'] = processInputVar('location', ARG_STRING); $addmode = processInputVar('addmode', ARG_STRING); if (!is_null($addmode) && $addmode != 'single' && $addmode != 'multiple') { $return['error'] = 1; $return['errormsg'] = "Invalid Add mode submitted"; return $return; } $olddata = getContinuationVar('olddata'); if ($return['rscid'] == 0) { $return['mode'] = 'add'; } else { $return['mode'] = 'edit'; } $errormsg = array(); # hostname $hostreg = '/^[a-zA-Z0-9_][-a-zA-Z0-9_\\.]{1,49}$/'; if ($return['mode'] == 'add' && $addmode == 'multiple') { $hostreg = '/^[a-zA-Z0-9_%][-a-zA-Z0-9_\\.%]{1,49}$/'; } if (!preg_match($hostreg, $return['name'])) { $return['error'] = 1; $errormsg[] = "Hostname can only contain letters, numbers, dashes(-), periods(.), and underscores(_). It can be from 1 to 50 characters long"; } elseif ($this->checkForHostname($return['name'], $return['rscid'])) { $return['error'] = 1; $errormsg[] = "A computer already exists with this hostname."; } # add multiple if ($return['mode'] == 'add' && $addmode == 'multiple') { # startnum/endnum if ($return['startnum'] < 0 || $return['startnum'] > 255) { $return['error'] = 1; $errormsg[] = "Start must be from 0 to 255"; } if ($return['endnum'] < 0 || $return['endnum'] > 255) { $return['error'] = 1; $errormsg[] = "End must be from 0 to 255"; } if ($return['startnum'] >= 0 && $return['startnum'] <= 255 && $return['endnum'] >= 0 && $return['endnum'] <= 255 && $return['startnum'] > $return['endnum']) { $return['error'] = 1; $errormsg[] = "Start must be >= End"; } $checkhosts = array(); for ($i = $return['startnum']; $i <= $return['endnum']; $i++) { $checkhosts[] = str_replace('%', $i, $return['name']); } $allhosts = implode("','", $checkhosts); $query = "SELECT hostname FROM computer " . "WHERE hostname IN ('{$allhosts}') AND " . "deleted = 0"; $qh = doQuery($query); $exists = array(); while ($row = mysql_fetch_assoc($qh)) { $exists[] = $row['hostname']; } if (count($exists)) { $hosts = implode(', ', $exists); $return['error'] = 1; $errormsg[] = "There are already computers with these hostnames: {$hosts}"; } } else { $return['startnum'] = 0; $return['endnum'] = 0; } # owner if (!validateUserid($return['owner'])) { $return['error'] = 1; $errormsg[] = "Submitted owner is not valid"; } # type if (!preg_match('/^(blade|lab|virtualmachine)$/', $return['type'])) { $return['error'] = 1; $errormsg[] = "Submitted type is not valid"; } # edit or add single if ($return['rscid'] || $return['mode'] == 'add' && $addmode == 'single') { # ipaddress if (!validateIPv4addr($return['IPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } # private ipaddress if (strlen($return['privateIPaddress']) && !validateIPv4addr($return['privateIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Private IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } # eth0macaddress if (strlen($return['eth0macaddress'])) { if (!preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["eth0macaddress"])) { $return['error'] = 1; $errormsg[] = "Invalid Private MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif ($this->checkForMACaddress($return['eth0macaddress'], 0, $return['rscid'])) { $return['error'] = 1; $errormsg[] = "There is already a computer with this Private MAC address."; } } # eth1macaddress if (strlen($return['eth1macaddress'])) { if (!preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["eth1macaddress"])) { $return['error'] = 1; $errormsg[] = "Invalid Public MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif ($this->checkForMACaddress($return['eth1macaddress'], 1, $return['rscid'])) { $return['error'] = 1; $errormsg[] = "There is already a computer with this Public MAC address."; } } } else { $return['IPaddress'] = ''; $return['privateIPaddress'] = ''; $return['eth0macaddress'] = ''; $return['eth1macaddress'] = ''; } # add multiple if ($return['mode'] == 'add' && $addmode == 'multiple') { if (!validateIPv4addr($return['startpubipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Start Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if (!validateIPv4addr($return['endpubipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid End Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if (!validateIPv4addr($return['startprivipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Start Private IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if (!validateIPv4addr($return['endprivipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid End Private IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } $startpubiplong = ip2long($return['startpubipaddress']); $endpubiplong = ip2long($return['endpubipaddress']); if ($startpubiplong > $endpubiplong) { $return['error'] = 1; $errormsg[] = "Start Public IP Address must be lower or equal to End Public IP Address"; } elseif ($endpubiplong - $startpubiplong != $return['endnum'] - $return['startnum']) { $return['error'] = 1; $errormsg[] = "Public IP Address range does not equal Start/End range"; } $startpriviplong = ip2long($return['startprivipaddress']); $endpriviplong = ip2long($return['endprivipaddress']); if ($startpriviplong > $endpriviplong) { $return['error'] = 1; $errormsg[] = "Start Private IP Address must be lower or equal to End Private IP Address"; } elseif ($endpriviplong - $startpriviplong != $return['endnum'] - $return['startnum']) { $return['error'] = 1; $errormsg[] = "Private IP Address range does not equal Start/End range"; } $return['startpubiplong'] = $startpubiplong; $return['endpubiplong'] = $endpubiplong; $return['startpriviplong'] = $startpriviplong; $return['endpriviplong'] = $endpriviplong; $cnt = $endpubiplong - $startpubiplong + 1; if ($return['startmac'] != '') { if (!preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return['startmac'])) { $return['error'] = 1; $errormsg[] = "Invalid Start MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif ($this->checkMultiAddMacs($return['startmac'], $cnt, $msg, $macs)) { $return['error'] = 1; $errormsg[] = $msg; } $return['macs'] = $macs; } else { $return['macs'] = array(); } } else { $return['startpubipaddress'] = ''; $return['endpubipaddress'] = ''; $return['startprivipaddress'] = ''; $return['endprivipaddress'] = ''; $return['startmac'] = ''; } # provisioningid $provisioning = getProvisioning(); if (!array_key_exists($return['provisioningid'], $provisioning)) { $return['error'] = 1; $errormsg[] = "Invalid Provisioning Engine selected"; } else { $return['provisioning'] = $provisioning[$return['provisioningid']]['name']; } # stateid 2 - available, 10 - maintenance, 20 - vmhostinuse if (!preg_match('/^(2|10|20)$/', $return['stateid']) && ($return['mode'] == 'add' || $return['stateid'] != $olddata['stateid'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for State"; } # validate type/provisioning combinations $provtypes = getProvisioningTypes(); if (($return['mode'] == 'add' || $olddata['provisioningid'] != $return['provisioningid']) && !array_key_exists($return['provisioningid'], $provtypes[$return['type']])) { $return['error'] = 1; $errormsg[] = "Invalid Provisioning Engine selected for computer type"; } # validate type/provisioning/state combinations if ($return['mode'] == 'add' || $olddata['stateid'] != $return['stateid']) { if ($return['type'] == 'lab') { if ($return['stateid'] != 2 && $return['stateid'] != 10) { $return['error'] = 1; $errormsg[] = "Invalid state submitted for computer type Lab"; } } elseif ($return['type'] == 'virtualmachine') { if ($return['stateid'] != 10 && ($return['mode'] == 'add' || !is_numeric($olddata['vmhostid']) || $return['stateid'] != 2)) { $return['error'] = 1; $errormsg[] = "Invalid state submitted for computer type Virtual Machine"; } } elseif ($return['type'] == 'blade') { if ($provisioning[$return['provisioningid']]['name'] == 'none' && $return['stateid'] != 10 && $return['stateid'] != 20) { $return['error'] = 1; $errormsg[] = "Invalid state submitted for computer type Bare Metal"; } } } # notes if ($return['stateid'] == 10) { if (!preg_match('/^([-a-zA-Z0-9_\\. ,#\\(\\)=\\+:;]{0,5000})$/', $return['notes'])) { $return['error'] = 1; $errormsg[] = "Maintenance reason can be up to 5000 characters long and may only<br>contain letters, numbers, spaces and these characters: - , . _ # ( ) = + : ;"; } } else { $return['notes'] = ''; } # vmprofileid $profiles = getVMProfiles(); if ($return['type'] == 'blade' && $return['stateid'] == 20 && !array_key_exists($return['vmprofileid'], $profiles)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for VM Host Profile"; } # platformid $platforms = getPlatforms(); if (!array_key_exists($return['platformid'], $platforms)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Platform"; } # scheduleid $schedules = getSchedules(); if (!array_key_exists($return['scheduleid'], $schedules)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Schedule"; } # ram if ($return['ram'] < 500 || $return['ram'] > 16777215) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for RAM"; } # cores if ($return['cores'] < 1 || $return['cores'] > 255) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for No. Cores"; } # procspeed if ($return['procspeed'] < 500 || $return['procspeed'] > 10000) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Processor Speed"; } # network if (!preg_match('/^(10|100|1000|10000|100000)$/', $return['network'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Network"; } # predictivemoduleid $premodules = getPredictiveModules(); if (!array_key_exists($return['predictivemoduleid'], $premodules)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Predictive Loading Module"; } $naterror = 0; # natenabled if ($return['natenabled'] != 0 && $return['natenabled'] != 1) { $return['error'] = 1; $errormsg[] = "Invalid value for Connect Using NAT"; $naterror = 1; } # nathostid $nathosts = getNAThosts(); if ($return['natenabled'] && $return['nathostid'] == 0 || $return['nathostid'] != 0 && !array_key_exists($return['nathostid'], $nathosts)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for NAT Host"; $naterror = 1; } # nat change - check for active reservations $vclreloadid = getUserlistID('vclreload@Local'); if ($return['mode'] == 'edit') { if ($olddata['nathostid'] == '') { $olddata['nathostid'] = 0; } if (!$naterror && ($olddata['natenabled'] != $return['natenabled'] || $olddata['nathostid'] != $return['nathostid'])) { $query = "SELECT rq.id " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$return['rscid']} AND " . "rq.start <= NOW() AND " . "rq.end > NOW() AND " . "rq.stateid NOT IN (1,5,11,12) AND " . "rq.laststateid NOT IN (1,5,11,12) AND " . "rq.userid != {$vclreloadid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $return['error'] = 1; $errormsg[] = "This computer has an active reservation. NAT settings cannot be changed for computers having<br>active reservations."; } } } $nathosterror = 0; # nathostenabled if ($return['nathostenabled'] != 0 && $return['nathostenabled'] != 1) { $return['error'] = 1; $errormsg[] = "Invalid value for Use as NAT Host"; $nathosterror = 1; } # natpublicIPaddress if ($return['nathostenabled'] && ($return['mode'] == 'edit' || $addmode == 'single')) { if (!validateIPv4addr($return['natpublicIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid NAT Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; $nathosterror = 1; } # natinternalIPaddress if (!validateIPv4addr($return['natinternalIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid NAT Internal IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; $nathosterror = 1; } } # nat host change - check for active reservations if (!$nathosterror && $return['mode'] == 'edit') { if ($olddata['nathostenabled'] != $return['nathostenabled'] || $olddata['natpublicIPaddress'] != $return['natpublicIPaddress'] || $olddata['natinternalIPaddress'] != $return['natinternalIPaddress']) { $query = "SELECT rq.id " . "FROM request rq, " . "reservation rs, " . "nathostcomputermap nhcm, " . "nathost nh " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = nhcm.computerid AND " . "nhcm.nathostid = nh.id AND " . "nh.resourceid = {$olddata['resourceid']} AND " . "rq.start <= NOW() AND " . "rq.end > NOW() AND " . "rq.stateid NOT IN (1,5,11,12) AND " . "rq.laststateid NOT IN (1,5,11,12) AND " . "rq.userid != {$vclreloadid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $return['error'] = 1; $errormsg[] = "This computer is the NAT host for other computers that have active reservations. NAT host<br>settings cannot be changed while providing NAT for active reservations."; } } } # location if (!preg_match('/^([-a-zA-Z0-9_\\. ,@#\\(\\)]{0,255})$/', $return['location'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Location"; } if ($return['mode'] == 'add') { $return['addmode'] = $addmode; } if ($return['error']) { $return['errormsg'] = implode('<br>', $errormsg); } return $return; }
/** * Generate data for Test Specification * * @param string $spec_view_type can get one of the following values: * 'testproject','testplan','uncoveredtestcases' * * This setting change the processing done * to get the keywords. * And indicates the type of id (testproject/testplan) * contained in the argument tobj_id. * when using uncoveredtestcases tobj_id = testproject id * @param integer $tobj_id can be a testproject id, or testplan id. * @param integer $id node id, that we are using as root for the view we want to build * @param string $name * @param array $linked_items map where key=testcase_id * value map with following keys: * [testsuite_id] => 2732 * [tc_id] => 2733 * [z] => 100 ---> nodes_hierarchy.order * [name] => TC1 * [tcversion_id] => 2734 * [feature_id] => 9 --->> testplan_tcversions.ID * [execution_order] => 10 * [version] => 1 * [active] => 1 * [external_id] => 1 * [exec_id] => 1 * [tcversion_number] => 1 * [executed] => 2734 * [exec_on_tplan] => 2735 * [user_id] => * [type] => * [status] => * [assigner_id] => * [urgency] => 2 IMPORTANT: exists ONLY FOR LINKED TEST CASES * [exec_status] => b * [priority] => 4 // urgency*importance IMPORTANT: exists ONLY FOR LINKED TEST CASES * * @param array $map_node_tccount * @TODO probably this argument ($map_node_tccount) is not needed, but it will depend * of how this feature (gen_spec_view) will be used on other TL areas. * * @param map $filters keys * [keyword_id] default 0 * [tcase_id] default null, can be an array * * @param map $options keys * [write_button_only_if_linked] default 0 * [prune_unlinked_tcversions]: default 0. * Useful when working on spec_view_type='testplan'. * 1 -> will return only linked tcversion * 0 -> returns all test cases specs. * [add_custom_fields]: default=0 * useful when working on spec_view_type='testproject' * when doing test case assign to test plans. * 1 -> for every test case cfields of area 'testplan_design' * will be fetched and displayed. * 0 -> do nothing * * [$tproject_id]: default = null * useful to improve performance in custom field method calls * when add_custom_fields=1. * * * @return array every element is an associative array with the following * structure: (to get last updated info add debug code and print_r returned value) * [testsuite] => Array( [id] => 28 * [name] => TS1 ) * [testcases] => Array( [2736] => Array * ( * [id] => 2736 * [name] => TC2 * [tcversions] => Array * ( * [2738] => 2 // key=tcversion id,value=version * [2737] => 1 * ) * [tcversions_active_status] => Array * ( * [2738] => 1 // key=tcversion id,value=active status * [2737] => 1 * ) * [tcversions_execution_type] => Array * ( * [2738] => 1 * [2737] => 2 * ) * [tcversions_qty] => 2 * [linked_version_id] => 2737 * [executed] => no * [user_id] => 0 ---> !=0 if execution has been assigned * [feature_id] => 12 ---> testplan_tcversions.id * [execution_order] => 20 * [external_id] => 2 * [linked_ts] => 2009-06-10 23:00 * [linked_by] => 2 * [priority] => HIGH, MEDIUM or LOW * ) * [81] => Array( [id] => 81 * [name] => TC88) * ... * ) * [level] = * [write_buttons] => yes or no * level and write_buttons are used to generate the user interface * * Warning: * if the root element of the spec_view, has 0 test => then the default * structure is returned ( $result = array('spec_view'=>array(), 'num_tc' => 0)) * * @internal Revisions: * * 20100721 - asimon - BUGID 3406 - added user_assignments_per_build to options * * 20090808 - franciscom - changed interface to reduce number of arguments * * 20070707 - franciscom - BUGID 921 - problems with display order in execution screen * 20070630 - franciscom - added new logic to include in for inactive test cases, testcase version id. * This is needed to show testcases linked to testplans, but after be linked to * test plan, has been set to inactive on test project. * 20061105 - franciscom - added new data on output: [tcversions_qty] * used in the logic to filter out inactive tcversions, * and inactive test cases. * Counts the quantity of active versions of a test case. * If 0 => test case is considered INACTIVE * 20090625 - Eloff - added priority output */ function gen_spec_view(&$db, $spec_view_type = 'testproject', $tobj_id, $id, $name, &$linked_items, $map_node_tccount, $filters = null, $options = null, $tproject_id = null) { $out = array(); $result = array('spec_view' => array(), 'num_tc' => 0, 'has_linked_items' => 0); $my = array(); $my['options'] = array('write_button_only_if_linked' => 0, 'prune_unlinked_tcversions' => 0, 'add_custom_fields' => 0) + (array) $options; // BUGID 2797 - filter by test case execution type $my['filters'] = array('keywords' => 0, 'testcases' => null, 'exec_type' => null, 'importance' => null); foreach ($my as $key => $settings) { if (!is_null(${$key}) && is_array(${$key})) { $my[$key] = array_merge($my[$key], ${$key}); } } $write_status = $my['options']['write_button_only_if_linked'] ? 'no' : 'yes'; $is_tplan_view_type = $spec_view_type == 'testplan' ? 1 : 0; $is_uncovered_view_type = $spec_view_type == 'uncoveredtestcases' ? 1 : 0; if (!$is_tplan_view_type && is_null($tproject_id)) { $tproject_id = $tobj_id; } $testplan_id = $is_tplan_view_type ? $tobj_id : null; $tcase_mgr = new testcase($db); $hash_descr_id = $tcase_mgr->tree_manager->get_available_node_types(); $hash_id_descr = array_flip($hash_descr_id); // BUGID 2797 - filter by test case execution type $pfFilters = array('keyword_id' => $my['filters']['keywords'], 'tcase_id' => $my['filters']['testcases'], 'tcase_node_type_id' => $hash_descr_id['testcase'], 'execution_type' => $my['filters']['exec_type'], 'importance' => $my['filters']['importance']); // $test_spec = getTestSpecFromNode($db,$tcase_mgr,$linked_items,$tobj_id,$id,$spec_view_type,$filters); $test_spec = getTestSpecFromNode($db, $tcase_mgr, $linked_items, $tobj_id, $id, $spec_view_type, $pfFilters); $platforms = getPlatforms($db, $tproject_id, $testplan_id); $idx = 0; $a_tcid = array(); $a_tsuite_idx = array(); if (count($test_spec)) { $cfg = array('node_types' => $hash_id_descr, 'write_status' => $write_status, 'is_uncovered_view_type' => $is_uncovered_view_type); list($a_tcid, $a_tsuite_idx, $tsuite_tcqty, $out) = buildSkeleton($id, $name, $cfg, $test_spec, $platforms); } // This code has been replace (see below on Remove empty branches) // Once we have created array with testsuite and children testsuites // we are trying to remove nodes that has 0 test case count. // May be this can be done (as noted by schlundus during performance // analisys done on october 2008) in a better way, or better can be absolutely avoided. // // This process is needed to prune whole branches that are empty // Need to look for every call in TL and understand if this can be removed // if (!is_null($map_node_tccount)) { foreach ($out as $key => $elem) { if (isset($map_node_tccount[$elem['testsuite']['id']]) && $map_node_tccount[$elem['testsuite']['id']]['testcount'] == 0) { // why not unset ? $out[$key] = null; } } } // Collect information related to linked testcase versions if (!is_null($out) && count($out) > 0 && !is_null($out[0]) && count($a_tcid)) { $tcaseSet = $tcase_mgr->get_by_id($a_tcid, testcase::ALL_VERSIONS); $result = addLinkedVersionsInfo($tcaseSet, $a_tsuite_idx, $out, $linked_items); } // Try to prune empty test suites, to reduce memory usage and to remove elements // that do not need to be displayed on user interface. if (count($result['spec_view']) > 0) { removeEmptyTestSuites($result['spec_view'], $tcase_mgr->tree_manager, $my['options']['prune_unlinked_tcversions'] && $is_tplan_view_type, $hash_descr_id); } // Remove empty branches // Loop to compute test case qty ($tsuite_tcqty) on every level and prune test suite branchs that are empty if (count($result['spec_view']) > 0) { removeEmptyBranches($result['spec_view'], $tsuite_tcqty); } /** @TODO: maybe we can integrate this into already present loops above? */ // This is not right condition for identifing an empty test suite for the porpouse // of gen_spec_view(), because for following structure // TS1 // \--- TS2 // \--TC1 // \--TC2 // // \--- TS3 // \-- TXX // // When we are displaying a Test Specification we want to see previous structure // But if we apply this criteria for empty test suite, TS1 results empty and will // be removed -> WRONG // // Need to understand when this feature will be needed and then reimplement // // if ($prune_empty_tsuites) // { // foreach($result['spec_view'] as $key => $value) // { // if(is_null($value) || !isset($value['testcases']) || !count($value['testcases'])) // unset($result['spec_view'][$key]); // } // } // #1650 We want to manage custom fields when user is doing test case execution assigment if (count($result['spec_view']) > 0 && $my['options']['add_custom_fields']) { addCustomFieldsToView($result['spec_view'], $tproject_id, $tcase_mgr); } // -------------------------------------------------------------------------------------------- unset($tcase_mgr); // with array_values() we reindex array to avoid "holes" $result['spec_view'] = array_values($result['spec_view']); return $result; }
/** * */ function genSpecViewFlat(&$db, $spec_view_type = 'testproject', $tobj_id, $id, $name, &$linked_items, $map_node_tccount, $filters = null, $options = null, $tproject_id = null) { $out = array(); $result = array('spec_view' => array(), 'num_tc' => 0, 'has_linked_items' => 0); $my = array(); $my['options'] = array('write_button_only_if_linked' => 0, 'prune_unlinked_tcversions' => 0, 'add_custom_fields' => 0) + (array) $options; $my['filters'] = array('keywords' => 0, 'testcases' => null, 'exec_type' => null, 'importance' => null, 'cfields' => null); foreach ($my as $key => $settings) { if (!is_null(${$key}) && is_array(${$key})) { $my[$key] = array_merge($my[$key], ${$key}); } } $write_status = $my['options']['write_button_only_if_linked'] ? 'no' : 'yes'; $is_tplan_view_type = $spec_view_type == 'testplan' ? 1 : 0; $is_uncovered_view_type = $spec_view_type == 'uncoveredtestcases' ? 1 : 0; if (!$is_tplan_view_type && is_null($tproject_id)) { $tproject_id = $tobj_id; } $testplan_id = $is_tplan_view_type ? $tobj_id : null; $tcase_mgr = new testcase($db); $hash_descr_id = $tcase_mgr->tree_manager->get_available_node_types(); $hash_id_descr = array_flip($hash_descr_id); $key2map = array('keyword_id' => 'keywords', 'tcase_id' => 'testcases', 'execution_type' => 'exec_type', 'importance' => 'importance', 'cfields' => 'cfields', 'tcase_name' => 'tcase_name', 'status' => 'workflow_status'); $pfFilters = array('tcase_node_type_id' => $hash_descr_id['testcase']); foreach ($key2map as $tk => $fk) { $pfFilters[$tk] = isset($my['filters'][$fk]) ? $my['filters'][$fk] : null; } $test_spec = getTestSpecFromNode($db, $tcase_mgr, $linked_items, $tobj_id, $id, $spec_view_type, $pfFilters); $platforms = getPlatforms($db, $tproject_id, $testplan_id); $idx = 0; $a_tcid = array(); $a_tsuite_idx = array(); if (count($test_spec)) { $cfg = array('node_types' => $hash_id_descr, 'write_status' => $write_status, 'is_uncovered_view_type' => $is_uncovered_view_type); // $a_tsuite_idx // key: test case version id // value: index inside $out, where parent test suite of test case version id is located. // list($a_tcid, $a_tsuite_idx, $tsuite_tcqty, $out) = buildSkeletonFlat($id, $name, $cfg, $test_spec, $platforms); } // Collect information related to linked testcase versions // DAMMED 0!!!! $firtsElemIDX = key($out); if (!is_null($out) && count($out) > 0 && !is_null($out[$firtsElemIDX]) && count($a_tcid)) { $optGBI = array('output' => 'full_without_users', 'order_by' => " ORDER BY NHTC.node_order, NHTC.name, TCV.version DESC "); $tcaseVersionSet = $tcase_mgr->get_by_id($a_tcid, testcase::ALL_VERSIONS, null, $optGBI); $result = addLinkedVersionsInfo($tcaseVersionSet, $a_tsuite_idx, $out, $linked_items, $options); } if (count($result['spec_view']) > 0 && $my['options']['add_custom_fields']) { addCustomFieldsToView($result['spec_view'], $tproject_id, $tcase_mgr); } // -------------------------------------------------------------------------------------------- unset($tcase_mgr); // with array_values() we reindex array to avoid "holes" $result['spec_view'] = array_values($result['spec_view']); return $result; }
function viewImageDetails() { $imageid = getContinuationVar("imageid"); $images = getImages(1); $platforms = getPlatforms(); $oslist = getOSList(); print "<DIV align=center>\n"; print "<H2>Image Details</H2>\n"; print "<TABLE>\n"; /*print " <TR>\n"; print " <TH align=right>Short Name:</TH>\n"; print " <TD>" . $images[$imageid]["name"] . "</TD>\n"; print " </TR>\n";*/ print " <TR>\n"; print " <TH align=right>Long Name:</TH>\n"; print " <TD>" . $images[$imageid]["prettyname"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Owner:</TH>\n"; print " <TD>" . $images[$imageid]["owner"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Platform:</TH>\n"; print " <TD>" . $platforms[$images[$imageid]["platformid"]] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>OS:</TH>\n"; print " <TD>" . $oslist[$images[$imageid]["osid"]]["prettyname"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Minimum RAM (MB):</TH>\n"; print " <TD>" . $images[$imageid]["minram"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Minimum Num of Processors:</TH>\n"; print " <TD>" . $images[$imageid]["minprocnumber"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Minimum Processor Speed (MHz):</TH>\n"; print " <TD>" . $images[$imageid]["minprocspeed"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Minimum Network Speed (Mbps):</TH>\n"; print " <TD>" . $images[$imageid]["minnetwork"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Maximum Concurrent Usage:</TH>\n"; if ($images[$imageid]['maxconcurrent'] == '') { print " <TD>N/A</TD>\n"; } else { print " <TD>" . $images[$imageid]["maxconcurrent"] . "</TD>\n"; } print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Estimated Reload Time (min):</TH>\n"; print " <TD>" . $images[$imageid]["reloadtime"] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Available for checkout:</TH>\n"; if ($images[$imageid]["forcheckout"]) { print " <TD>yes</TD>\n"; } else { print " <TD>no</TD>\n"; } print " </TR>\n"; if (array_key_exists("checkuser", $images[$imageid])) { print " <TR>\n"; print " <TH align=right>Check for logged in user:</TH>\n"; if ($images[$imageid]["checkuser"]) { print " <TD>yes</TD>\n"; } else { print " <TD>no</TD>\n"; } print " </TR>\n"; } if (!empty($images[$imageid]["usergroupid"])) { print " <TR>\n"; print " <TH align=right>User group allowed to log in:</TH>\n"; print " <TD>{$images[$imageid]["usergroup"]}</TD>\n"; print " </TR>\n"; } if ($oslist[$images[$imageid]["osid"]]["type"] == 'windows') { print " <TR>\n"; print " <TH align=right>Use sysprep:</TH>\n"; if (array_key_exists("sysprep", $images[$imageid]) && $images[$imageid]["sysprep"] == 0) { print " <TD>no</TD>\n"; } else { print " <TD>yes</TD>\n"; } print " </TR>\n"; } if (array_key_exists("subimages", $images[$imageid]) && count($images[$imageid]["subimages"])) { print " <TR>\n"; print " <TH style=\"vertical-align:top; text-align:right;\">"; print "Subimages:</TH>\n"; print " <TD>\n"; foreach ($images[$imageid]["subimages"] as $imgid) { print "{$images[$imgid]["prettyname"]}<br>\n"; } print " </TD>\n"; print " </TR>\n"; } print "</TABLE>\n"; print "</DIV>\n"; }
function printComputerInfo($ipaddress, $stateid, $owner, $platformid, $scheduleid, $currentimgid, $ram, $numprocs, $procspeed, $network, $hostname, $compid, $type, $provisioningid) { $states = getStates(); $platforms = getPlatforms(); $schedules = getSchedules(); $images = getImages(); $provisioning = getProvisioning(); print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>Hostname:</TH>\n"; print " <TD>{$hostname}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>IP Address:</TH>\n"; print " <TD>{$ipaddress}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>State:</TH>\n"; print " <TD>" . $states[$stateid] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Owner:</TH>\n"; print " <TD>{$owner}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Platform:</TH>\n"; print " <TD>" . $platforms[$platformid] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Schedule:</TH>\n"; print " <TD>" . $schedules[$scheduleid]["name"] . "</TD>\n"; print " </TR>\n"; if (!empty($currentimgid)) { print " <TR>\n"; print " <TH align=right>Current Image:</TH>\n"; print " <TD>" . $images[$currentimgid]["prettyname"] . "</TD>\n"; print " </TR>\n"; } print " <TR>\n"; print " <TH align=right>RAM (MB):</TH>\n"; print " <TD>{$ram}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>No. Processors:</TH>\n"; print " <TD>{$numprocs}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Processor Speed (MHz):</TH>\n"; print " <TD>{$procspeed}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Network Speed (Mbps):</TH>\n"; print " <TD>{$network}</TD>\n"; print " </TR>\n"; if (!empty($compid)) { print " <TR>\n"; print " <TH align=right>Computer ID:</TH>\n"; print " <TD>{$compid}</TD>\n"; print " </TR>\n"; } print " <TR>\n"; print " <TH align=right>Type:</TH>\n"; print " <TD>{$type}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Provisioning Engine:</TH>\n"; print " <TD>" . $provisioning[$provisioningid]['prettyname'] . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; }