proxmox-rrd: fix regression tests
This commit is contained in:
parent
86b50e18ed
commit
a7ee3455da
@ -51,7 +51,7 @@ pub struct RRAConfig {
|
|||||||
/// Dump the RRD file in JSON format
|
/// Dump the RRD file in JSON format
|
||||||
pub fn dump_rrd(path: String) -> Result<(), Error> {
|
pub fn dump_rrd(path: String) -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(&PathBuf::from(path))?;
|
let rrd = RRD::load(&PathBuf::from(path), false)?;
|
||||||
serde_json::to_writer_pretty(std::io::stdout(), &rrd)?;
|
serde_json::to_writer_pretty(std::io::stdout(), &rrd)?;
|
||||||
println!("");
|
println!("");
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -69,7 +69,7 @@ pub fn dump_rrd(path: String) -> Result<(), Error> {
|
|||||||
/// RRD file information
|
/// RRD file information
|
||||||
pub fn rrd_info(path: String) -> Result<(), Error> {
|
pub fn rrd_info(path: String) -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(&PathBuf::from(path))?;
|
let rrd = RRD::load(&PathBuf::from(path), false)?;
|
||||||
|
|
||||||
println!("DST: {:?}", rrd.source.dst);
|
println!("DST: {:?}", rrd.source.dst);
|
||||||
|
|
||||||
@ -109,10 +109,10 @@ pub fn update_rrd(
|
|||||||
let time = time.map(|v| v as f64)
|
let time = time.map(|v| v as f64)
|
||||||
.unwrap_or_else(proxmox_time::epoch_f64);
|
.unwrap_or_else(proxmox_time::epoch_f64);
|
||||||
|
|
||||||
let mut rrd = RRD::load(&path)?;
|
let mut rrd = RRD::load(&path, false)?;
|
||||||
rrd.update(time, value);
|
rrd.update(time, value);
|
||||||
|
|
||||||
rrd.save(&path, CreateOptions::new())?;
|
rrd.save(&path, CreateOptions::new(), false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ pub fn fetch_rrd(
|
|||||||
end: Option<u64>,
|
end: Option<u64>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(&PathBuf::from(path))?;
|
let rrd = RRD::load(&PathBuf::from(path), false)?;
|
||||||
|
|
||||||
let data = rrd.extract_data(cf, resolution, start, end)?;
|
let data = rrd.extract_data(cf, resolution, start, end)?;
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ pub fn first_update_time(
|
|||||||
rra_index: usize,
|
rra_index: usize,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(&PathBuf::from(path))?;
|
let rrd = RRD::load(&PathBuf::from(path), false)?;
|
||||||
|
|
||||||
if rra_index >= rrd.rra_list.len() {
|
if rra_index >= rrd.rra_list.len() {
|
||||||
bail!("rra-index is out of range");
|
bail!("rra-index is out of range");
|
||||||
@ -202,7 +202,7 @@ pub fn first_update_time(
|
|||||||
/// Return the Unix timestamp of the last update
|
/// Return the Unix timestamp of the last update
|
||||||
pub fn last_update_time(path: String) -> Result<(), Error> {
|
pub fn last_update_time(path: String) -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(&PathBuf::from(path))?;
|
let rrd = RRD::load(&PathBuf::from(path), false)?;
|
||||||
|
|
||||||
println!("{}", rrd.source.last_update);
|
println!("{}", rrd.source.last_update);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -220,7 +220,7 @@ pub fn last_update_time(path: String) -> Result<(), Error> {
|
|||||||
/// Return the time and value from the last update
|
/// Return the time and value from the last update
|
||||||
pub fn last_update(path: String) -> Result<(), Error> {
|
pub fn last_update(path: String) -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(&PathBuf::from(path))?;
|
let rrd = RRD::load(&PathBuf::from(path), false)?;
|
||||||
|
|
||||||
let result = json!({
|
let result = json!({
|
||||||
"time": rrd.source.last_update,
|
"time": rrd.source.last_update,
|
||||||
@ -272,7 +272,7 @@ pub fn create_rrd(
|
|||||||
|
|
||||||
let rrd = RRD::new(dst, rra_list);
|
let rrd = RRD::new(dst, rra_list);
|
||||||
|
|
||||||
rrd.save(&path, CreateOptions::new())?;
|
rrd.save(&path, CreateOptions::new(), false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -302,7 +302,7 @@ pub fn resize_rrd(
|
|||||||
|
|
||||||
let path = PathBuf::from(&path);
|
let path = PathBuf::from(&path);
|
||||||
|
|
||||||
let mut rrd = RRD::load(&path)?;
|
let mut rrd = RRD::load(&path, false)?;
|
||||||
|
|
||||||
if rra_index >= rrd.rra_list.len() {
|
if rra_index >= rrd.rra_list.len() {
|
||||||
bail!("rra-index is out of range");
|
bail!("rra-index is out of range");
|
||||||
@ -331,7 +331,7 @@ pub fn resize_rrd(
|
|||||||
|
|
||||||
rrd.rra_list[rra_index] = new_rra;
|
rrd.rra_list[rra_index] = new_rra;
|
||||||
|
|
||||||
rrd.save(&path, CreateOptions::new())?;
|
rrd.save(&path, CreateOptions::new(), false)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -28,11 +28,11 @@ const RRD_V2_FN: &str = "./tests/testdata/cpu.rrd_v2";
|
|||||||
#[test]
|
#[test]
|
||||||
fn upgrade_from_rrd_v1() -> Result<(), Error> {
|
fn upgrade_from_rrd_v1() -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(Path::new(RRD_V1_FN))?;
|
let rrd = RRD::load(Path::new(RRD_V1_FN), true)?;
|
||||||
|
|
||||||
const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";
|
const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.upgraded";
|
||||||
let new_path = Path::new(RRD_V2_NEW_FN);
|
let new_path = Path::new(RRD_V2_NEW_FN);
|
||||||
rrd.save(new_path, CreateOptions::new())?;
|
rrd.save(new_path, CreateOptions::new(), true)?;
|
||||||
|
|
||||||
let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
|
let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
|
||||||
let _ = std::fs::remove_file(RRD_V2_NEW_FN);
|
let _ = std::fs::remove_file(RRD_V2_NEW_FN);
|
||||||
@ -45,11 +45,11 @@ fn upgrade_from_rrd_v1() -> Result<(), Error> {
|
|||||||
#[test]
|
#[test]
|
||||||
fn load_and_save_rrd_v2() -> Result<(), Error> {
|
fn load_and_save_rrd_v2() -> Result<(), Error> {
|
||||||
|
|
||||||
let rrd = RRD::load(Path::new(RRD_V2_FN))?;
|
let rrd = RRD::load(Path::new(RRD_V2_FN), true)?;
|
||||||
|
|
||||||
const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.saved";
|
const RRD_V2_NEW_FN: &str = "./tests/testdata/cpu.rrd_v2.saved";
|
||||||
let new_path = Path::new(RRD_V2_NEW_FN);
|
let new_path = Path::new(RRD_V2_NEW_FN);
|
||||||
rrd.save(new_path, CreateOptions::new())?;
|
rrd.save(new_path, CreateOptions::new(), true)?;
|
||||||
|
|
||||||
let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
|
let result = compare_file(RRD_V2_FN, RRD_V2_NEW_FN);
|
||||||
let _ = std::fs::remove_file(RRD_V2_NEW_FN);
|
let _ = std::fs::remove_file(RRD_V2_NEW_FN);
|
||||||
|
Loading…
Reference in New Issue
Block a user