rust/client: Make status be a method
In trying to use the API in ostree's tests, this feels like an obvious change.
This commit is contained in:
parent
45a59fc7f8
commit
182cae05d6
@ -98,14 +98,16 @@ impl Deployment {
|
||||
}
|
||||
}
|
||||
|
||||
fn cli_cmd(c: &CliClient) -> Command {
|
||||
impl CliClient {
|
||||
/// Create an invocation of the client binary
|
||||
fn cli_cmd(&self) -> Command {
|
||||
let mut cmd = Command::new("rpm-ostree");
|
||||
cmd.env("RPMOSTREE_CLIENT_ID", c.agent_id.as_str());
|
||||
cmd.env("RPMOSTREE_CLIENT_ID", self.agent_id.as_str());
|
||||
cmd
|
||||
}
|
||||
}
|
||||
|
||||
/// Gather a snapshot of the system status.
|
||||
pub fn query_status(c: &CliClient) -> Result<Status> {
|
||||
/// Gather a snapshot of the system status.
|
||||
pub fn query_status(&self) -> Result<Status> {
|
||||
// Retry on temporary activation failures, see
|
||||
// https://github.com/coreos/rpm-ostree/issues/2531
|
||||
let pause = std::time::Duration::from_secs(1);
|
||||
@ -113,7 +115,8 @@ pub fn query_status(c: &CliClient) -> Result<Status> {
|
||||
let mut retries = 0;
|
||||
let cmd_res = loop {
|
||||
retries += 1;
|
||||
let res = cli_cmd(c)
|
||||
let res = self
|
||||
.cli_cmd()
|
||||
.args(&["status", "--json"])
|
||||
.output()
|
||||
.context("failed to spawn 'rpm-ostree status'")?;
|
||||
@ -134,4 +137,5 @@ pub fn query_status(c: &CliClient) -> Result<Status> {
|
||||
|
||||
Ok(serde_json::from_slice(&cmd_res.stdout)
|
||||
.context("failed to parse 'rpm-ostree status' output")?)
|
||||
}
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ fn update_os_tree(opts: &SyntheticUpgradeOpts) -> Result<()> {
|
||||
// to update the client bindings when adding new fields.
|
||||
fn validate_parse_status() -> Result<()> {
|
||||
let c = rpmostree_client::CliClient::new("tests");
|
||||
let s = rpmostree_client::query_status(&c).map_err(anyhow::Error::msg)?;
|
||||
let s = c.query_status().map_err(anyhow::Error::msg)?;
|
||||
assert_ne!(s.deployments.len(), 0);
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user