From patchwork Tue Jun 14 07:04:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell Currey X-Patchwork-Id: 635055 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.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rTLTg5QL3z9t0S for ; Tue, 14 Jun 2016 17:13:27 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3rTLTg4nyzzDr2j for ; Tue, 14 Jun 2016 17:13:27 +1000 (AEST) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Received: from russell.cc (russell.cc [IPv6:2404:9400:2:0:216:3eff:fee0:3370]) (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 3rTLHz4pzrzDqmB for ; Tue, 14 Jun 2016 17:05:03 +1000 (AEST) Received: from snap.ozlabs.ibm.com (static-82-10.transact.net.au [122.99.82.10]) by russell.cc (OpenSMTPD) with ESMTPSA id 68ffca19 TLS version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO; Tue, 14 Jun 2016 07:04:59 +0000 (UTC) From: Russell Currey To: snowpatch@lists.ozlabs.org Date: Tue, 14 Jun 2016 17:04:49 +1000 Message-Id: <20160614070449.12503-3-ruscur@russell.cc> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20160614070449.12503-1-ruscur@russell.cc> References: <20160614070449.12503-1-ruscur@russell.cc> Subject: [snowpatch] [PATCH 2/2] Replace print messages with appropriate logging X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Russell Currey MIME-Version: 1.0 Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Replace existing print messages with appropriate levels of logging, and add a couple of new messages. There is still a lot more we should log, but this is a decent start. Signed-off-by: Russell Currey --- src/git.rs | 4 ++-- src/main.rs | 49 ++++++++++++++++++++++++++++++++++++------------- src/patchwork.rs | 4 ++-- src/settings.rs | 2 +- 4 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/git.rs b/src/git.rs index 413bd9e..679d387 100644 --- a/src/git.rs +++ b/src/git.rs @@ -47,7 +47,7 @@ pub fn pull(repo: &Repository) -> Result { .unwrap(); // TODO if output.status.success() { - println!("Pull: {}", String::from_utf8(output.clone().stdout).unwrap()); + debug!("Pull: {}", String::from_utf8(output.clone().stdout).unwrap()); return Ok(output); } else { return Err("Error: couldn't pull changes"); @@ -75,7 +75,7 @@ pub fn apply_patch(repo: &Repository, path: &Path) .unwrap(); // TODO if output.status.success() { - println!("Patch applied with text {}", + debug!("Patch applied with text {}", String::from_utf8(output.clone().stdout).unwrap()); return Ok(output); } else { diff --git a/src/main.rs b/src/main.rs index daf8923..67fd8f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,9 @@ extern crate toml; extern crate tempdir; extern crate docopt; extern crate url; +#[macro_use] +extern crate log; +extern crate env_logger; use git2::{Cred, BranchType, RemoteCallbacks, PushOptions}; @@ -91,7 +94,7 @@ fn run_tests(settings: &Config, project: &Project, tag: &str, branch_name: &str) let job_name = job_params.get("job").unwrap(); let mut jenkins_params = Vec::<(&str, &str)>::new(); for (param_name, param_value) in job_params.iter() { - println!("Param name {}, value {}", ¶m_name, ¶m_value); + debug!("Param name {}, value {}", ¶m_name, ¶m_value); match param_name.as_ref() { // TODO: Validate special parameter names in config at start of program "job" => { }, @@ -100,10 +103,10 @@ fn run_tests(settings: &Config, project: &Project, tag: &str, branch_name: &str) _ => jenkins_params.push((¶m_name, ¶m_value)), } } - println!("Starting job: {}", &job_name); + info!("Starting job: {}", &job_name); let res = jenkins.start_test(&job_name, jenkins_params) .unwrap_or_else(|err| panic!("Starting Jenkins test failed: {}", err)); - println!("{:?}", &res); + debug!("{:?}", &res); let build_url_real; loop { let build_url = jenkins.get_build_url(&res); @@ -112,9 +115,9 @@ fn run_tests(settings: &Config, project: &Project, tag: &str, branch_name: &str) None => { }, } } - println!("Build URL: {}", build_url_real); + debug!("Build URL: {}", build_url_real); jenkins.wait_build(&build_url_real); - println!("Job done!"); + info!("Jenkins job for {}/{} complete.", branch_name, job_name); results.push(TestResult { test_name: format!("{}/{}", branch_name.to_string(), job_name.to_string()), state: TestState::SUCCESS.string(), // TODO: get this from Jenkins @@ -147,20 +150,21 @@ fn test_patch(settings: &Config, project: &Project, path: &Path) -> Vec Vec { @@ -229,10 +233,13 @@ fn main() { .unwrap_or_else(|e| e.exit()); let settings = settings::parse(args.arg_config_file); + env_logger::init().unwrap_or_else(|e| panic!("Failed to start logger: {}", e)); + // The HTTP client we'll use to access the APIs // TODO: HTTPS support, not yet implemented in Hyper as of 0.9.6 let client = Arc::new(match env::var("http_proxy") { Ok(proxy_url) => { + debug!("snowpatch is using HTTP proxy {}", proxy_url); let proxy = Url::parse(&proxy_url).unwrap_or_else(|e| { panic!("http_proxy is malformed: {:?}, error: {}", proxy_url, e); }); @@ -243,17 +250,23 @@ fn main() { Client::with_http_proxy(proxy.host_str().unwrap().to_string(), proxy.port().unwrap_or(80)) }, - _ => Client::new() + _ => { + debug!("snowpatch starting without a HTTP proxy"); + Client::new() + } }); let mut patchwork = PatchworkServer::new(&settings.patchwork.url, &client); if settings.patchwork.user.is_some() { + debug!("Patchwork authentication set for user {}", + &settings.patchwork.user.clone().unwrap()); patchwork.set_authentication(&settings.patchwork.user.clone().unwrap(), &settings.patchwork.pass.clone()); } let patchwork = patchwork; if args.flag_mbox != "" && args.flag_project != "" { + info!("snowpatch is testing a local patch."); let patch = Path::new(&args.flag_mbox); match settings.projects.get(&args.flag_project) { None => panic!("Couldn't find project {}", args.flag_project), @@ -266,6 +279,7 @@ fn main() { } if args.flag_series > 0 { + info!("snowpatch is testing a series from Patchwork."); let series = patchwork.get_series(&(args.flag_series as u64)).unwrap(); match settings.projects.get(&series.project.linkname) { None => panic!("Couldn't find project {}", &series.project.linkname), @@ -284,20 +298,26 @@ fn main() { // Poll patchwork for new series. For each series, get patches, apply and test. 'daemon: loop { let series_list = patchwork.get_series_query().unwrap().results.unwrap(); + info!("snowpatch is ready to test new revisions from Patchwork."); for series in series_list { // If it's already been tested, we can skip it if series.test_state.is_some() { + debug!("Skipping already tested series {} ({})", series.name, series.id); continue; } match settings.projects.get(&series.project.linkname) { - None => continue, + None => { + debug!("Project {} not configured for series {} ({})", + &series.project.linkname, series.name, series.id); + continue; + }, Some(project) => { let patch = patchwork.get_patch(&series); let results = test_patch(&settings, &project, &patch); // Delete the temporary directory with the patch in it fs::remove_dir_all(patch.parent().unwrap()).unwrap_or_else( - |err| println!("Couldn't delete temp directory: {}", err)); + |err| error!("Couldn't delete temp directory: {}", err)); if project.push_results { for result in results { patchwork.post_test_result(result, &series.id, @@ -306,6 +326,8 @@ fn main() { } if args.flag_count > 0 { series_count += 1; + debug!("Tested {} series out of {}", + series_count, args.flag_count); if series_count >= args.flag_count { break 'daemon; } @@ -313,6 +335,7 @@ fn main() { } } } + info!("Finished testing new revisions, sleeping."); thread::sleep(Duration::new(settings.patchwork.polling_interval, 0)); } } diff --git a/src/patchwork.rs b/src/patchwork.rs index c8b9179..128c414 100644 --- a/src/patchwork.rs +++ b/src/patchwork.rs @@ -153,7 +153,7 @@ impl PatchworkServer { -> Result { let encoded = json::encode(&result).unwrap(); let headers = self.headers.clone(); - println!("JSON Encoded: {}", encoded); + debug!("JSON Encoded: {}", encoded); let res = try!(self.client.post(&format!( "{}{}/series/{}/revisions/{}/test-results/", &self.url, PATCHWORK_API, &series_id, &series_revision)) @@ -193,7 +193,7 @@ impl PatchworkServer { let mut mbox_resp = self.get_series_mbox(&series.id, &series.version) .unwrap(); - println!("Saving patch to file {}", path.display()); + debug!("Saving patch to file {}", path.display()); let mut mbox = File::create(&path).unwrap_or_else( |err| panic!("Couldn't create mbox file: {}", err)); io::copy(&mut mbox_resp, &mut mbox).unwrap_or_else( diff --git a/src/settings.rs b/src/settings.rs index 904370d..80d2759 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -86,7 +86,7 @@ pub fn parse(path: String) -> Config { for err in &parser.errors { let (loline, locol) = parser.to_linecol(err.lo); let (hiline, hicol) = parser.to_linecol(err.hi); - println!("TOML parsing error: {} in {} at {}:{}-{}:{}", + error!("TOML parsing error: {} in {} at {}:{}-{}:{}", err.desc, path, loline, locol, hiline, hicol); } panic!("Syntax error in TOML file, exiting.");