-
Notifications
You must be signed in to change notification settings - Fork 83
nexus: trim trailing nulls in omicron.public.ereport serials
#10452
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
Merged
+182
−2
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
165 changes: 165 additions & 0 deletions
165
nexus/tests/integration_tests/data_migrations/ereport_trim_serial_trailing_nulls.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| // 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/. | ||
|
|
||
| use super::super::schema::{DataMigrationFns, MigrationContext}; | ||
| use futures::future::BoxFuture; | ||
| use pretty_assertions::assert_eq; | ||
| use uuid::Uuid; | ||
|
|
||
| // Ereport restart IDs — one per test case. | ||
| const CLEAN_SERIAL: Uuid = | ||
| Uuid::from_u128(25800001_0000_0000_0000_000000000001); | ||
| const NULL_PADDED_SERIAL: Uuid = | ||
| Uuid::from_u128(25800001_0000_0000_0000_000000000002); | ||
| const NULL_SERIAL: Uuid = Uuid::from_u128(25800001_0000_0000_0000_000000000003); | ||
|
|
||
| const COLLECTOR: Uuid = Uuid::from_u128(25800002_0000_0000_0000_000000000001); | ||
|
|
||
| pub(crate) fn checks() -> DataMigrationFns { | ||
| DataMigrationFns::new().before(before).after(after) | ||
| } | ||
|
|
||
| fn before<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> { | ||
| Box::pin(async move { | ||
| // Insert ereport rows with various serial_number values: | ||
| // 1. A clean serial number with no trailing nulls. | ||
| // 2. A serial number with trailing null bytes. | ||
| // 3. A NULL serial_number (should remain NULL). | ||
| ctx.client | ||
| .batch_execute(&format!( | ||
| " | ||
| INSERT INTO omicron.public.ereport ( | ||
| restart_id, ena, time_collected, collector_id, | ||
| serial_number, report, reporter, slot_type, slot | ||
| ) VALUES | ||
| ('{CLEAN_SERIAL}', 1, now(), '{COLLECTOR}', | ||
| 'BRM42220031', | ||
| '{{}}', 'sp', 'sled', 0), | ||
| ('{NULL_PADDED_SERIAL}', 1, now(), '{COLLECTOR}', | ||
| E'2EKRJYKV\\x00\\x00\\x00', | ||
| '{{}}', 'sp', 'sled', 1), | ||
| ('{NULL_SERIAL}', 1, now(), '{COLLECTOR}', | ||
| NULL, | ||
| '{{}}', 'sp', 'sled', 2); | ||
| " | ||
| )) | ||
| .await | ||
| .expect( | ||
| "failed to insert test data for ereport-trim-serial-trailing-nulls" | ||
| ); | ||
|
|
||
| // Verify that the null-padded serial number actually has the expected | ||
| // nulls in it. | ||
| let rows = ctx | ||
| .client | ||
| .query( | ||
| &format!( | ||
| "SELECT restart_id, serial_number | ||
| FROM omicron.public.ereport | ||
| WHERE restart_id IN ( | ||
| '{CLEAN_SERIAL}', | ||
| '{NULL_PADDED_SERIAL}', | ||
| '{NULL_SERIAL}' | ||
| ) | ||
| ORDER BY restart_id" | ||
| ), | ||
| &[], | ||
| ) | ||
| .await | ||
| .expect("failed to query ereport rows after migration"); | ||
|
|
||
| assert_eq!(rows.len(), 3, "expected 3 test ereport rows"); | ||
|
|
||
| for row in &rows { | ||
| let id: Uuid = row.get("restart_id"); | ||
| let serial: Option<String> = row.get("serial_number"); | ||
|
|
||
| match id { | ||
| id if id == CLEAN_SERIAL => { | ||
| assert_eq!(serial.as_deref(), Some("BRM42220031"),); | ||
| } | ||
| id if id == NULL_PADDED_SERIAL => { | ||
| assert_eq!( | ||
| serial.as_deref(), | ||
| Some("2EKRJYKV\0\0\0"), | ||
| "2EKRJYKV should be null-padded", | ||
| ); | ||
| } | ||
| id if id == NULL_SERIAL => { | ||
| assert_eq!(serial, None, "NULL serial_number be None"); | ||
| } | ||
| other => panic!("unexpected restart_id: {other}"), | ||
| } | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| fn after<'a>(ctx: &'a MigrationContext<'a>) -> BoxFuture<'a, ()> { | ||
| Box::pin(async move { | ||
| // Verify the serial numbers after the migration. | ||
| let rows = ctx | ||
| .client | ||
| .query( | ||
| &format!( | ||
| "SELECT restart_id, serial_number | ||
| FROM omicron.public.ereport | ||
| WHERE restart_id IN ( | ||
| '{CLEAN_SERIAL}', | ||
| '{NULL_PADDED_SERIAL}', | ||
| '{NULL_SERIAL}' | ||
| ) | ||
| ORDER BY restart_id" | ||
| ), | ||
| &[], | ||
| ) | ||
| .await | ||
| .expect("failed to query ereport rows after migration"); | ||
|
|
||
| assert_eq!(rows.len(), 3, "expected 3 test ereport rows"); | ||
|
|
||
| for row in &rows { | ||
| let id: Uuid = row.get("restart_id"); | ||
| let serial: Option<String> = row.get("serial_number"); | ||
|
|
||
| match id { | ||
| id if id == CLEAN_SERIAL => { | ||
| assert_eq!( | ||
| serial.as_deref(), | ||
| Some("BRM42220031"), | ||
| "clean serial number should be unchanged" | ||
| ); | ||
| } | ||
| id if id == NULL_PADDED_SERIAL => { | ||
| assert_eq!( | ||
| serial.as_deref(), | ||
| Some("2EKRJYKV"), | ||
| "serial with trailing NUL bytes should be trimmed" | ||
| ); | ||
| } | ||
| id if id == NULL_SERIAL => { | ||
| assert_eq!( | ||
| serial, None, | ||
| "NULL serial_number should remain NULL" | ||
| ); | ||
| } | ||
| other => panic!("unexpected restart_id: {other}"), | ||
| } | ||
| } | ||
|
|
||
| // Clean up test data. | ||
| ctx.client | ||
| .batch_execute(&format!( | ||
| " | ||
| DELETE FROM omicron.public.ereport | ||
| WHERE restart_id IN ( | ||
| '{CLEAN_SERIAL}', | ||
| '{NULL_PADDED_SERIAL}', | ||
| '{NULL_SERIAL}' | ||
| ); | ||
| " | ||
| )) | ||
| .await | ||
| .unwrap(); | ||
| }) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| -- Strip trailing NUL (\0) characters from the serial_number column in the | ||
| -- ereport table. The service processor null-pads OXV2 serial numbers. MGS | ||
| -- was stripping these trailing NULLs when collecting the inventory, but | ||
| -- not when ingesting ereports. This was fixed in | ||
| -- https://github.com/oxidecomputer/management-gateway-service#491 | ||
|
hawkw marked this conversation as resolved.
|
||
| -- so we can now update any previously-nully ereport serials to match. | ||
| SET LOCAL disallow_full_table_scans = off; | ||
|
|
||
| UPDATE omicron.public.ereport | ||
| SET serial_number = rtrim(serial_number, chr(0)) | ||
| WHERE serial_number IS NOT NULL | ||
| AND serial_number != rtrim(serial_number, chr(0)); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Lovely test cases!