Skip to content

Commit cf89d5a

Browse files
committed
Add delay before preingestion time checks
1 parent 8722fd0 commit cf89d5a

2 files changed

Lines changed: 55 additions & 6 deletions

File tree

crates/api-core/src/tests/host_bmc_firmware_test.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,6 +2339,7 @@ async fn test_preingestion_time_sync_ok(
23392339
.into_inner();
23402340

23412341
let addr = response.address.as_str();
2342+
let ip_addr = IpAddr::from_str(addr).unwrap();
23422343
// Insert endpoint with current versions that are up to date
23432344
insert_endpoint_version(&mut txn, addr, "6.00.30.00", "1.13.2", false).await?;
23442345
txn.commit().await?;
@@ -2349,6 +2350,8 @@ async fn test_preingestion_time_sync_ok(
23492350
// then check firmware and complete.
23502351
mgr.run_single_iteration().await?;
23512352

2353+
// Second iteration applies site NTP servers and records when that
2354+
// succeeded, but does not check BMC time until the convergence wait elapses.
23522355
mgr.run_single_iteration().await?;
23532356

23542357
let actions = env.redfish_sim.actions_since(&timepoint);
@@ -2360,6 +2363,36 @@ async fn test_preingestion_time_sync_ok(
23602363
"Expected SetNtpServers when site NTP is configured"
23612364
);
23622365

2366+
let mut txn = pool.begin().await.unwrap();
2367+
let endpoints = db::explored_endpoints::find_all_by_ip(ip_addr, &mut txn).await?;
2368+
let endpoint = endpoints.first().expect("Endpoint should exist");
2369+
assert!(
2370+
matches!(
2371+
endpoint.preingestion_state,
2372+
PreingestionState::SetNtpServers {
2373+
set_at: Some(_),
2374+
attempts: 0
2375+
}
2376+
),
2377+
"Expected SetNtpServers wait after applying NTP, got: {:?}",
2378+
endpoint.preingestion_state
2379+
);
2380+
txn.commit().await?;
2381+
2382+
// The next iteration should still wait for BMC NTP convergence.
2383+
mgr.run_single_iteration().await?;
2384+
2385+
let mut txn = pool.begin().await.unwrap();
2386+
db::explored_endpoints::set_preingestion_set_ntp_servers(
2387+
ip_addr,
2388+
Some(chrono::Utc::now() - chrono::TimeDelta::minutes(3)),
2389+
0,
2390+
&mut txn,
2391+
)
2392+
.await?;
2393+
txn.commit().await?;
2394+
2395+
// Once the convergence wait has elapsed, time sync and firmware checks complete.
23632396
mgr.run_single_iteration().await?;
23642397

23652398
let mut txn = pool.begin().await.unwrap();

crates/preingestion-manager/src/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ const INITIAL_BMC_RESET_MAX_ATTEMPTS: u32 = 3;
7979

8080
/// How many times to attempt configuring site NTP servers before giving up.
8181
const SET_NTP_SERVERS_MAX_ATTEMPTS: u32 = 3;
82+
/// How long to wait for NTP servers to converge before checking time sync.
83+
const SET_NTP_SERVERS_CONVERGENCE_WAIT: chrono::TimeDelta = chrono::TimeDelta::minutes(1);
8284

8385
pub struct PreingestionManager {
8486
static_info: Arc<PreingestionManagerStatic>,
@@ -1515,12 +1517,26 @@ impl PreingestionManagerStatic {
15151517
set_at: Option<&DateTime<Utc>>,
15161518
attempts: u32,
15171519
) -> PreingestionManagerResult<bool> {
1518-
if self.ntp_servers.is_empty()
1519-
|| attempts >= SET_NTP_SERVERS_MAX_ATTEMPTS
1520-
|| set_at.is_some()
1521-
{
1520+
if self.ntp_servers.is_empty() || attempts >= SET_NTP_SERVERS_MAX_ATTEMPTS {
1521+
tracing::info!(
1522+
"{} has no NTP servers configured or max attempts reached; running initial checks",
1523+
endpoint.address
1524+
);
1525+
return self.run_initial_checks(db, endpoint).await;
1526+
}
1527+
1528+
if let Some(set_at) = set_at {
1529+
let elapsed = Utc::now().signed_duration_since(*set_at);
1530+
if elapsed < SET_NTP_SERVERS_CONVERGENCE_WAIT {
1531+
tracing::info!(
1532+
"{} waiting for BMC NTP servers to converge before checking time sync",
1533+
endpoint.address
1534+
);
1535+
return Ok(false);
1536+
}
1537+
15221538
tracing::info!(
1523-
"{} NTP setup is complete, unavailable, or exhausted; running initial checks",
1539+
"{} BMC NTP convergence wait complete; running initial checks",
15241540
endpoint.address
15251541
);
15261542
return self.run_initial_checks(db, endpoint).await;
@@ -1556,7 +1572,7 @@ impl PreingestionManagerStatic {
15561572
}
15571573

15581574
tracing::info!(
1559-
"{} set NTP servers; running initial checks on next iteration",
1575+
"{} set NTP servers; waiting for BMC time to converge",
15601576
endpoint.address
15611577
);
15621578
db.with_txn(|txn| {

0 commit comments

Comments
 (0)