From patchwork Tue Feb 26 04:20:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 1048080 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 447lww1Wfdz9s4Z for ; Tue, 26 Feb 2019 15:20:48 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 447lwv4tQhzDqLH for ; Tue, 26 Feb 2019 15:20:47 +1100 (AEDT) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=au1.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=andrew.donnellan@au1.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 447lwd69WSzDqLH for ; Tue, 26 Feb 2019 15:20:33 +1100 (AEDT) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1Q4DW6n145111 for ; Mon, 25 Feb 2019 23:20:31 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2qvvhfv0w4-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 25 Feb 2019 23:20:30 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Feb 2019 04:20:28 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 26 Feb 2019 04:20:26 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1Q4KPIG57868386 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 26 Feb 2019 04:20:26 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D1217AE045 for ; Tue, 26 Feb 2019 04:20:25 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3B754AE04D for ; Tue, 26 Feb 2019 04:20:25 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 26 Feb 2019 04:20:25 +0000 (GMT) Received: from intelligence.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 24000A0129 for ; Tue, 26 Feb 2019 15:20:24 +1100 (AEDT) From: Andrew Donnellan To: snowpatch@lists.ozlabs.org Date: Tue, 26 Feb 2019 15:20:13 +1100 X-Mailer: git-send-email 2.11.0 X-TM-AS-GCONF: 00 x-cbid: 19022604-0008-0000-0000-000002C4E7D8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19022604-0009-0000-0000-000022312F47 Message-Id: <20190226042014.10707-1-andrew.donnellan@au1.ibm.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-26_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902260030 Subject: [snowpatch] [PATCH 1/2] main: Split run_tests() into loop and helper X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Split run_tests() into two functions, one to loop through the various jobs and the other to run individual tests. Later on, we probably want to spawn individual tests as separate threads. Signed-off-by: Andrew Donnellan --- src/main.rs | 96 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 55 insertions(+), 41 deletions(-) diff --git a/src/main.rs b/src/main.rs index b6c756815595..45f994179dbf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -65,7 +65,7 @@ mod jenkins; use jenkins::JenkinsBackend; mod settings; -use settings::{Config, Project}; +use settings::{Config, Job, Project}; mod git; @@ -102,6 +102,56 @@ struct Args { flag_project: String, } +fn run_test( + jenkins: &JenkinsBackend, + project: &Project, + tag: &str, + branch_name: &str, + job: &Job, +) -> TestResult { + let mut jenkins_params = Vec::<(&str, &str)>::new(); + for (param_name, param_value) in &job.parameters { + // TODO(ajd): do this more neatly + debug!("Param name {}, value {}", ¶m_name, ¶m_value); + jenkins_params.push((param_name, param_value)); + } + jenkins_params.push((&job.remote, &project.remote_uri)); + jenkins_params.push((&job.branch, tag)); + + info!("Starting job: {}", &job.title); + let res = jenkins + .start_test(&job.job, jenkins_params) + .unwrap_or_else(|err| panic!("Starting Jenkins test failed: {}", err)); + debug!("{:?}", &res); + let build_handle_real; + loop { + let build_handle = jenkins.get_build_handle(&res); + if let Ok(handle) = build_handle { + build_handle_real = handle; + break; + } // TODO: Handle error + } + debug!("Build URL: {}", build_handle_real); + jenkins.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly + let mut test_result = jenkins.get_build_result(&build_handle_real).unwrap(); + info!("Jenkins job for {}/{} complete.", branch_name, job.title); + if test_result == TestState::Fail && job.warn_on_fail { + test_result = TestState::Warning; + } + + TestResult { + description: match jenkins.get_description(&build_handle_real, &job.parameters) { + Some(description) => Some(description), + None => Some( + format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(), + ), + }, + state: test_result, + context: Some(job.title.replace("/", "_")), + target_url: Some(jenkins.get_results_url(&build_handle_real, &job.parameters)), + } +} + fn run_tests( settings: &Config, client: Arc, @@ -123,46 +173,10 @@ fn run_tests( debug!("Skipping hefty test {}", job.title); continue; } - let mut jenkins_params = Vec::<(&str, &str)>::new(); - for (param_name, param_value) in &job.parameters { - // TODO(ajd): do this more neatly - debug!("Param name {}, value {}", ¶m_name, ¶m_value); - jenkins_params.push((param_name, param_value)); - } - jenkins_params.push((&job.remote, &project.remote_uri)); - jenkins_params.push((&job.branch, tag)); - - info!("Starting job: {}", &job.title); - let res = jenkins - .start_test(&job.job, jenkins_params) - .unwrap_or_else(|err| panic!("Starting Jenkins test failed: {}", err)); - debug!("{:?}", &res); - let build_handle_real; - loop { - let build_handle = jenkins.get_build_handle(&res); - if let Ok(handle) = build_handle { - build_handle_real = handle; - break; - } // TODO: Handle error - } - debug!("Build URL: {}", build_handle_real); - jenkins.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly - let mut test_result = jenkins.get_build_result(&build_handle_real).unwrap(); - info!("Jenkins job for {}/{} complete.", branch_name, job.title); - if test_result == TestState::Fail && job.warn_on_fail { - test_result = TestState::Warning; - } - results.push(TestResult { - description: match jenkins.get_description(&build_handle_real, &job.parameters) { - Some(description) => Some(description), - None => Some( - format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(), - ), - }, - state: test_result, - context: Some(job.title.replace("/", "_")), - target_url: Some(jenkins.get_results_url(&build_handle_real, &job.parameters)), - }); + + let result = run_test(&jenkins, &project, &tag, &branch_name, &job); + + results.push(result); } results } From patchwork Tue Feb 26 04:20:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 1048079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 447lwp2P8xz9s4Z for ; Tue, 26 Feb 2019 15:20:42 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 447lwn39BjzDqLP for ; Tue, 26 Feb 2019 15:20:41 +1100 (AEDT) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=au1.ibm.com (client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com; envelope-from=andrew.donnellan@au1.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=au1.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 447lwc61XWzDqHZ for ; Tue, 26 Feb 2019 15:20:32 +1100 (AEDT) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x1Q4EjLa092672 for ; Mon, 25 Feb 2019 23:20:30 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qvt12hau9-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 25 Feb 2019 23:20:29 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 26 Feb 2019 04:20:28 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 26 Feb 2019 04:20:26 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x1Q4KPWh59900130 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 26 Feb 2019 04:20:25 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9F017A4054 for ; Tue, 26 Feb 2019 04:20:25 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E42BA405C for ; Tue, 26 Feb 2019 04:20:25 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Tue, 26 Feb 2019 04:20:25 +0000 (GMT) Received: from intelligence.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 33187A0243 for ; Tue, 26 Feb 2019 15:20:24 +1100 (AEDT) From: Andrew Donnellan To: snowpatch@lists.ozlabs.org Date: Tue, 26 Feb 2019 15:20:14 +1100 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190226042014.10707-1-andrew.donnellan@au1.ibm.com> References: <20190226042014.10707-1-andrew.donnellan@au1.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 19022604-0020-0000-0000-0000031B3C60 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19022604-0021-0000-0000-0000216C9FD2 Message-Id: <20190226042014.10707-2-andrew.donnellan@au1.ibm.com> MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-02-26_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902260030 Subject: [snowpatch] [PATCH 2/2] main: De-Jenkinsify run_test() X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Make run_test() generic on the CIBackend trait rather than Jenkins specific. Signed-off-by: Andrew Donnellan --- src/main.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 45f994179dbf..aabf4a0d1ca8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -103,44 +103,44 @@ struct Args { } fn run_test( - jenkins: &JenkinsBackend, + backend: &CIBackend, project: &Project, tag: &str, branch_name: &str, job: &Job, ) -> TestResult { - let mut jenkins_params = Vec::<(&str, &str)>::new(); + let mut params = Vec::<(&str, &str)>::new(); for (param_name, param_value) in &job.parameters { // TODO(ajd): do this more neatly debug!("Param name {}, value {}", ¶m_name, ¶m_value); - jenkins_params.push((param_name, param_value)); + params.push((param_name, param_value)); } - jenkins_params.push((&job.remote, &project.remote_uri)); - jenkins_params.push((&job.branch, tag)); + params.push((&job.remote, &project.remote_uri)); + params.push((&job.branch, tag)); info!("Starting job: {}", &job.title); - let res = jenkins - .start_test(&job.job, jenkins_params) - .unwrap_or_else(|err| panic!("Starting Jenkins test failed: {}", err)); + let res = backend + .start_test(&job.job, params) + .unwrap_or_else(|err| panic!("Starting test failed: {}", err)); debug!("{:?}", &res); let build_handle_real; loop { - let build_handle = jenkins.get_build_handle(&res); + let build_handle = backend.get_build_handle(&res); if let Ok(handle) = build_handle { build_handle_real = handle; break; } // TODO: Handle error } debug!("Build URL: {}", build_handle_real); - jenkins.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly - let mut test_result = jenkins.get_build_result(&build_handle_real).unwrap(); - info!("Jenkins job for {}/{} complete.", branch_name, job.title); + backend.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly + let mut test_result = backend.get_build_result(&build_handle_real).unwrap(); + info!("Test job for {}/{} complete.", branch_name, job.title); if test_result == TestState::Fail && job.warn_on_fail { test_result = TestState::Warning; } TestResult { - description: match jenkins.get_description(&build_handle_real, &job.parameters) { + description: match backend.get_description(&build_handle_real, &job.parameters) { Some(description) => Some(description), None => Some( format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(), @@ -148,7 +148,7 @@ fn run_test( }, state: test_result, context: Some(job.title.replace("/", "_")), - target_url: Some(jenkins.get_results_url(&build_handle_real, &job.parameters)), + target_url: Some(backend.get_results_url(&build_handle_real, &job.parameters)), } }