Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dev-tools/omdb/src/bin/omdb/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ mod db_metadata;
mod ereport;
mod saga;
mod sitrep;
mod system_version;
mod user_data_export;
mod whatis;

Expand Down Expand Up @@ -405,6 +406,8 @@ enum DbCommands {
Sleds(SledsArgs),
/// Show instances grouped by the sled they are running on
SledInstances(SledInstancesArgs),
/// Print the current target system release and the update date (print all of the releases when `--all` is present)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically don't mention command flags in the doc string.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Addressed in commit 1746781

SystemVersion(system_version::SystemVersionArgs),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not all components may be at the target release version at any given time. Having a "system-version" command could be confusing. It's probably more accurate to call it "target-release" :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the review, appreciate it :) I've changed it to target-release.

/// Print information about customer instances.
Instance(InstanceArgs),
/// Alias to `omdb instance list`.
Expand Down Expand Up @@ -1453,6 +1456,9 @@ impl DbArgs {
)
.await
}
DbCommands::SystemVersion(args) => {
system_version::cmd_db_system_version(&opctx, &datastore, &fetch_opts, args).await
}
DbCommands::Instance(InstanceArgs {
command: InstanceCommands::List(args),
}) => {
Expand Down
96 changes: 96 additions & 0 deletions dev-tools/omdb/src/bin/omdb/db/system_version.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! `omdb db system-version` subcommand
//!
//! Shows the current target release and date when update was requested.
//! When `--all` option is used, lists all target release records.

use crate::db::DbFetchOptions;
use crate::db::check_limit;
use crate::helpers::datetime_rfc3339_concise;
use anyhow::Context;
use async_bb8_diesel::AsyncRunQueryDsl;
use clap::Args;
use diesel::ExpressionMethods;
use diesel::QueryDsl;
use diesel::SelectableHelper;
use nexus_db_model::TargetRelease;
use nexus_db_model::TargetReleaseSource;
use nexus_db_queries::context::OpContext;
use nexus_db_queries::db::DataStore;
use nexus_db_schema::schema::target_release::dsl;
use tabled::Tabled;

#[derive(Debug, Args, Clone)]
pub(super) struct SystemVersionArgs {
/// List of target releases sorted from newest to oldest
#[clap(long)]
all: bool,
}

#[derive(Tabled)]
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")]
struct SystemVersionRow {
system_version: String,
time_requested: String,
}

pub(super) async fn cmd_db_system_version(
opctx: &OpContext,
datastore: &DataStore,
fetch_opts: &DbFetchOptions,
args: &SystemVersionArgs,
) -> Result<(), anyhow::Error> {
let releases = if args.all {
let limit = fetch_opts.fetch_limit;
let conn = datastore.pool_connection_for_tests().await?;
let releases: Vec<TargetRelease> = dsl::target_release
.select(TargetRelease::as_select())
.order_by(dsl::generation.desc())
.limit(i64::from(u32::from(limit)))
.load_async(&*conn)
.await
.context("listing target releases")?;
check_limit(&releases, limit, || {
String::from("listing target releases")
});
releases
} else {
vec![
datastore
.target_release_get_current(opctx)
.await
.context("fetching current target release")?,
]
};

let mut rows = Vec::with_capacity(releases.len());
for release in releases {
let system_version = match release
.release_source()
.context("interpreting target release source")?
{
TargetReleaseSource::Unspecified => "<unspecified>".to_string(),
TargetReleaseSource::SystemVersion(tuf_repo_id) => datastore
.tuf_repo_get_version(opctx, &tuf_repo_id)
.await
.with_context(|| format!("fetching TUF repo {tuf_repo_id}"))?
.to_string(),
};
rows.push(SystemVersionRow {
system_version,
time_requested: datetime_rfc3339_concise(&release.time_requested),
});
}

let table = tabled::Table::new(rows)
.with(tabled::settings::Style::empty())
.with(tabled::settings::Padding::new(1, 1, 0, 0))
.to_string();

println!("{}", table);

Ok(())
}
4 changes: 4 additions & 0 deletions dev-tools/omdb/tests/usage_errors.out
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Commands:
sitreps Show the current history of fault management situation reports
sleds Print information about sleds
sled-instances Show instances grouped by the sled they are running on
system-version Print the current target system release and the update date (print
all of the releases when `--all` is present)
instance Print information about customer instances
instances Alias to `omdb instance list`
network Print information about the network
Expand Down Expand Up @@ -210,6 +212,8 @@ Commands:
sitreps Show the current history of fault management situation reports
sleds Print information about sleds
sled-instances Show instances grouped by the sled they are running on
system-version Print the current target system release and the update date (print
all of the releases when `--all` is present)
instance Print information about customer instances
instances Alias to `omdb instance list`
network Print information about the network
Expand Down
Loading