Skip to content
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

Addresses for propolis instances at SLED_PREFIX + 0xFFFF #4777

Merged
merged 7 commits into from
Jan 10, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add a test for schema migration for 24.0.0
andrewjstone committed Jan 10, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f5f99fc31e92790a17473cfc41bde6e1c6a177b6
73 changes: 73 additions & 0 deletions nexus/tests/integration_tests/schema.rs
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ use pretty_assertions::{assert_eq, assert_ne};
use similar_asserts;
use slog::Logger;
use std::collections::{BTreeMap, BTreeSet};
use std::net::IpAddr;
use std::path::PathBuf;
use tokio::time::timeout;
use tokio::time::Duration;
@@ -192,6 +193,7 @@ enum AnySqlType {
String(String),
TextArray(Vec<String>),
Uuid(Uuid),
Inet(IpAddr),
// TODO: This isn't exhaustive, feel free to add more.
//
// These should only be necessary for rows where the database schema changes also choose to
@@ -234,6 +236,12 @@ impl From<Uuid> for AnySqlType {
}
}

impl From<IpAddr> for AnySqlType {
fn from(value: IpAddr) -> Self {
Self::Inet(value)
}
}

impl AnySqlType {
fn as_str(&self) -> &str {
match self {
@@ -279,6 +287,9 @@ impl<'a> tokio_postgres::types::FromSql<'a> for AnySqlType {
ty, raw,
)?));
}
if IpAddr::accepts(ty) {
return Ok(AnySqlType::Inet(IpAddr::from_sql(ty, raw)?));
}

use tokio_postgres::types::Kind;
match ty.kind() {
@@ -941,6 +952,13 @@ const POOL1: Uuid = Uuid::from_u128(0x11116001_5c3d_4647_83b0_8f3515da7be1);
const POOL2: Uuid = Uuid::from_u128(0x22226001_5c3d_4647_83b0_8f3515da7be1);
const POOL3: Uuid = Uuid::from_u128(0x33336001_5c3d_4647_83b0_8f3515da7be1);

// "513D" -> "Sled"
const SLED1: Uuid = Uuid::from_u128(0x1111513d_5c3d_4647_83b0_8f3515da7be1);
const SLED2: Uuid = Uuid::from_u128(0x2222513d_5c3d_4647_83b0_8f3515da7be1);

// "7AC4" -> "Rack"
const RACK1: Uuid = Uuid::from_u128(0x11117ac4_5c3d_4647_83b0_8f3515da7be1);

fn before_23_0_0(client: &Client) -> BoxFuture<'_, ()> {
Box::pin(async move {
// Create two silos
@@ -1024,6 +1042,57 @@ fn after_23_0_0(client: &Client) -> BoxFuture<'_, ()> {
})
}

fn before_24_0_0(client: &Client) -> BoxFuture<'_, ()> {
// IP addresses were pulled off dogfood sled 16
Box::pin(async move {
// Create two sleds
client
.batch_execute(&format!(
"INSERT INTO sled
(id, time_created, time_modified, time_deleted, rcgen, rack_id,
is_scrimlet, serial_number, part_number, revision,
usable_hardware_threads, usable_physical_ram, reservoir_size, ip,
port, last_used_address, provision_state) VALUES

('{SLED1}', now(), now(), NULL, 1, '{RACK1}', true, 'abcd', 'defg',
'1', 64, 12345678, 77, 'fd00:1122:3344:104::1', 12345,
'fd00:1122:3344:104::1ac', 'provisionable'),
('{SLED2}', now(), now(), NULL, 1, '{RACK1}', false, 'zzzz', 'xxxx',
'2', 64, 12345678, 77,'fd00:1122:3344:107::1', 12345,
'fd00:1122:3344:107::d4', 'provisionable');
"
))
.await
.expect("Failed to create sleds");
})
}

fn after_24_0_0(client: &Client) -> BoxFuture<'_, ()> {
Box::pin(async {
// Confirm that the ip_pool_resource objects have been created
// by the migration.
andrewjstone marked this conversation as resolved.
Show resolved Hide resolved
let rows = client
.query("SELECT last_used_address FROM sled ORDER BY id", &[])
.await
.expect("Failed to sled last_used_address");
let last_used_addresses = process_rows(&rows);

let expected_addr_1: IpAddr =
"fd00:1122:3344:104::ffff".parse().unwrap();
let expected_addr_2: IpAddr =
"fd00:1122:3344:107::ffff".parse().unwrap();

assert_eq!(
last_used_addresses[0].values,
vec![ColumnValue::new("last_used_address", expected_addr_1)]
);
assert_eq!(
last_used_addresses[1].values,
vec![ColumnValue::new("last_used_address", expected_addr_2)]
);
})
}

// Lazily initializes all migration checks. The combination of Rust function
// pointers and async makes defining a static table fairly painful, so we're
// using lazy initialization instead.
@@ -1037,6 +1106,10 @@ fn get_migration_checks() -> BTreeMap<SemverVersion, DataMigrationFns> {
SemverVersion(semver::Version::parse("23.0.0").unwrap()),
DataMigrationFns { before: Some(before_23_0_0), after: after_23_0_0 },
);
map.insert(
SemverVersion(semver::Version::parse("24.0.0").unwrap()),
DataMigrationFns { before: Some(before_24_0_0), after: after_24_0_0 },
);

map
}