-
Notifications
You must be signed in to change notification settings - Fork 83
Add system-version to omdb db #10481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
72260dd
23d8c9c
1746781
dd347a4
1422646
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,6 +190,7 @@ mod db_metadata; | |
| mod ereport; | ||
| mod saga; | ||
| mod sitrep; | ||
| mod system_version; | ||
| mod user_data_export; | ||
| mod whatis; | ||
|
|
||
|
|
@@ -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) | ||
| SystemVersion(system_version::SystemVersionArgs), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| /// Print information about customer instances. | ||
| Instance(InstanceArgs), | ||
| /// Alias to `omdb instance list`. | ||
|
|
@@ -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), | ||
| }) => { | ||
|
|
||
| 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(()) | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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