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
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions common/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ const GZ_ADDRESS_INDEX: usize = 2;
/// The maximum number of addresses per sled reserved for RSS.
pub const RSS_RESERVED_ADDRESSES: u16 = 32;

// The maximum number of addresses per sled reserved for control plane services.
pub const CP_SERVICES_RESERVED_ADDRESSES: u16 = 0xFFFF;
smklein marked this conversation as resolved.
Show resolved Hide resolved

/// Wraps an [`Ipv6Network`] with a compile-time prefix length.
#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Hash, PartialEq, Eq)]
#[schemars(rename = "Ipv6Subnet")]
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-model/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use omicron_common::api::external::SemverVersion;
///
/// This should be updated whenever the schema is changed. For more details,
/// refer to: schema/crdb/README.adoc
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(23, 0, 1);
pub const SCHEMA_VERSION: SemverVersion = SemverVersion::new(24, 0, 0);

table! {
disk (id) {
Expand Down
4 changes: 3 additions & 1 deletion nexus/db-model/src/sled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,9 @@ impl SledUpdate {
pub fn into_insertable(self) -> Sled {
let last_used_address = {
let mut segments = self.ip().segments();
segments[7] += omicron_common::address::RSS_RESERVED_ADDRESSES;
// We allocate the entire last segment to control plane services
segments[7] =
omicron_common::address::CP_SERVICES_RESERVED_ADDRESSES;
ipv6::Ipv6Addr::from(Ipv6Addr::from(segments))
};
Sled {
Expand Down
34 changes: 3 additions & 31 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1286,7 +1286,6 @@ mod test {
// Test sled-specific IPv6 address allocation
#[tokio::test]
async fn test_sled_ipv6_address_allocation() {
use omicron_common::address::RSS_RESERVED_ADDRESSES as STATIC_IPV6_ADDRESS_OFFSET;
use std::net::Ipv6Addr;

let logctx = dev::test_setup_log("test_sled_ipv6_address_allocation");
Expand Down Expand Up @@ -1322,41 +1321,14 @@ mod test {
datastore.sled_upsert(sled2).await.unwrap();

let ip = datastore.next_ipv6_address(&opctx, sled1_id).await.unwrap();
let expected_ip = Ipv6Addr::new(
0xfd00,
0x1de,
0,
0,
0,
0,
0,
2 + STATIC_IPV6_ADDRESS_OFFSET,
);
let expected_ip = Ipv6Addr::new(0xfd00, 0x1de, 0, 0, 0, 0, 1, 0);
assert_eq!(ip, expected_ip);
let ip = datastore.next_ipv6_address(&opctx, sled1_id).await.unwrap();
let expected_ip = Ipv6Addr::new(
0xfd00,
0x1de,
0,
0,
0,
0,
0,
3 + STATIC_IPV6_ADDRESS_OFFSET,
);
let expected_ip = Ipv6Addr::new(0xfd00, 0x1de, 0, 0, 0, 0, 1, 1);
assert_eq!(ip, expected_ip);

let ip = datastore.next_ipv6_address(&opctx, sled2_id).await.unwrap();
let expected_ip = Ipv6Addr::new(
0xfd00,
0x1df,
0,
0,
0,
0,
0,
2 + STATIC_IPV6_ADDRESS_OFFSET,
);
let expected_ip = Ipv6Addr::new(0xfd00, 0x1df, 0, 0, 0, 0, 1, 0);
assert_eq!(ip, expected_ip);

let _ = db.cleanup().await;
Expand Down
73 changes: 73 additions & 0 deletions nexus/tests/integration_tests/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions schema/crdb/24.0.0/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
UPDATE omicron.public.sled
SET last_used_address = (netmask(set_masklen(ip, 64)) & ip) + 0xFFFF
WHERE time_deleted is null;
2 changes: 1 addition & 1 deletion schema/crdb/dbinit.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3258,7 +3258,7 @@ INSERT INTO omicron.public.db_metadata (
version,
target_version
) VALUES
( TRUE, NOW(), NOW(), '23.0.1', NULL)
( TRUE, NOW(), NOW(), '24.0.0', NULL)
ON CONFLICT DO NOTHING;

COMMIT;
Loading