Skip to content

Commit c5ecb15

Browse files
authored
Merge pull request #153 from cgwalters/status-cleanup
spec: Make status always required
2 parents 083c1af + 68419c6 commit c5ecb15

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
lines changed

ci/run-kola.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ storage:
2525
- path: /etc/ostree/auth.json
2626
contents:
2727
local: auth.json
28+
systemd:
29+
units:
30+
- name: zincati.service
31+
dropins:
32+
- name: disabled.conf
33+
contents: |
34+
[Unit]
35+
ConditionPathExists=/enoent
36+
2837
EOF
2938
butane -d . < pull-secret.bu > pull-secret.ign
3039
kola_args+=("--append-ignition" "pull-secret.ign")

lib/src/cli.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,26 +284,31 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
284284
prepare_for_write().await?;
285285
let sysroot = &get_locked_sysroot().await?;
286286
let repo = &sysroot.repo();
287-
let booted_deployment = &sysroot.require_booted_deployment()?;
288-
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
289-
// SAFETY: There must be a status if we have a booted deployment
290-
let status = host.status.unwrap();
287+
let (booted_deployment, _deployments, host) =
288+
crate::status::get_status_require_booted(sysroot)?;
291289
let imgref = host.spec.image.as_ref();
292290
// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
293-
if imgref.is_none() && status.booted.as_ref().map_or(false, |b| b.incompatible) {
291+
if imgref.is_none()
292+
&& host
293+
.status
294+
.booted
295+
.as_ref()
296+
.map_or(false, |b| b.incompatible)
297+
{
294298
return Err(anyhow::anyhow!(
295299
"Booted deployment contains local rpm-ostree modifications; cannot upgrade via bootc"
296300
));
297301
}
298302
let spec = RequiredHostSpec::from_spec(&host.spec)?;
299-
let booted_image = status
303+
let booted_image = host
304+
.status
300305
.booted
301306
.map(|b| b.query_image(repo))
302307
.transpose()?
303308
.flatten();
304309
let imgref = imgref.ok_or_else(|| anyhow::anyhow!("No image source specified"))?;
305310
// Find the currently queued digest, if any before we pull
306-
let staged = status.staged.as_ref();
311+
let staged = host.status.staged.as_ref();
307312
let staged_image = staged.as_ref().and_then(|s| s.image.as_ref());
308313
let mut changed = false;
309314
if opts.check {
@@ -365,8 +370,8 @@ async fn switch(opts: SwitchOpts) -> Result<()> {
365370

366371
let sysroot = &get_locked_sysroot().await?;
367372
let repo = &sysroot.repo();
368-
let booted_deployment = &sysroot.require_booted_deployment()?;
369-
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
373+
let (booted_deployment, _deployments, host) =
374+
crate::status::get_status_require_booted(sysroot)?;
370375

371376
let transport = ostree_container::Transport::try_from(opts.transport.as_str())?;
372377
let imgref = ostree_container::ImageReference {
@@ -419,9 +424,8 @@ async fn edit(opts: EditOpts) -> Result<()> {
419424
prepare_for_write().await?;
420425
let sysroot = &get_locked_sysroot().await?;
421426
let repo = &sysroot.repo();
422-
let booted_deployment = &sysroot.require_booted_deployment()?;
423-
let (_deployments, host) = crate::status::get_status(sysroot, Some(booted_deployment))?;
424-
427+
let (booted_deployment, _deployments, host) =
428+
crate::status::get_status_require_booted(sysroot)?;
425429
let new_host: Host = if opts.filename == "-" {
426430
let tmpf = tempfile::NamedTempFile::new()?;
427431
serde_yaml::to_writer(std::io::BufWriter::new(tmpf.as_file()), &host)?;

lib/src/privtests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ pub(crate) fn impl_run_container() -> Result<()> {
103103
assert!(ostree_ext::container_utils::is_ostree_container()?);
104104
let sh = Shell::new()?;
105105
let host: Host = serde_yaml::from_str(&cmd!(sh, "bootc status").read()?)?;
106-
let status = host.status.unwrap();
107-
assert!(status.is_container);
106+
assert!(host.status.is_container);
108107
for c in ["upgrade", "update"] {
109108
let o = Command::new("bootc").arg(c).output()?;
110109
let st = o.status;

lib/src/spec.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub struct Host {
1919
#[serde(default)]
2020
pub spec: HostSpec,
2121
/// The status
22-
pub status: Option<HostStatus>,
22+
#[serde(default)]
23+
pub status: HostStatus,
2324
}
2425

2526
#[derive(Serialize, Deserialize, Default, Debug, Clone, PartialEq, Eq)]
@@ -121,7 +122,7 @@ impl Host {
121122
metadata,
122123
},
123124
spec,
124-
status: None,
125+
status: Default::default(),
125126
}
126127
}
127128
}

lib/src/status.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,15 @@ impl BootEntry {
172172
}
173173
}
174174

175+
/// A variant of [`get_status`] that requires a booted deployment.
176+
pub(crate) fn get_status_require_booted(
177+
sysroot: &SysrootLock,
178+
) -> Result<(ostree::Deployment, Deployments, Host)> {
179+
let booted_deployment = sysroot.require_booted_deployment()?;
180+
let (deployments, host) = get_status(sysroot, Some(&booted_deployment))?;
181+
Ok((booted_deployment, deployments, host))
182+
}
183+
175184
/// Gather the ostree deployment objects, but also extract metadata from them into
176185
/// a more native Rust structure.
177186
pub(crate) fn get_status(
@@ -227,12 +236,12 @@ pub(crate) fn get_status(
227236
})
228237
.unwrap_or_default();
229238
let mut host = Host::new(OBJECT_NAME, spec);
230-
host.status = Some(HostStatus {
239+
host.status = HostStatus {
231240
staged,
232241
booted,
233242
rollback,
234243
is_container,
235-
});
244+
};
236245
Ok((deployments, host))
237246
}
238247

@@ -244,7 +253,7 @@ pub(crate) async fn status(opts: super::cli::StatusOpts) -> Result<()> {
244253
..Default::default()
245254
};
246255
let mut r = Host::new(OBJECT_NAME, HostSpec { image: None });
247-
r.status = Some(status);
256+
r.status = status;
248257
r
249258
} else {
250259
let sysroot = super::cli::get_locked_sysroot().await?;

0 commit comments

Comments
 (0)