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

agama config load/store for "product" uses the HTTP API #1563

Merged
merged 14 commits into from
Sep 10, 2024

Conversation

mvidner
Copy link
Contributor

@mvidner mvidner commented Aug 30, 2024

Problem

Product and registration part of the migration of the CLI from D-Bus API to HTTP API:

Solution

  • Added ProductHTTPClient
  • Kept (D-Bus) ProductClient because it serves as the backend for the above
  • Added ManagerHTTPClient, /api/manager/probe_sync is called after the product changes

Testing

  • Added a new unit test
  • Tested manually

Screenshots

No

@mvidner
Copy link
Contributor Author

mvidner commented Sep 4, 2024

#1272 switched /api/manager/probe to not wait for the D-Bus reply

@coveralls
Copy link

coveralls commented Sep 5, 2024

Coverage Status

coverage: 71.833% (+0.05%) from 71.788%
when pulling 11c4c5e on http-client-product
into 9d30030 on master.

@mvidner mvidner marked this pull request as ready for review September 5, 2024 14:15
// BaseHTTPClient did not anticipate POST without request body
let dummy_body: Vec<u8> = vec![];
self.client
.post_void("/manager/probe_sync", &dummy_body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of a dummy Vec<u8>, you could use just the void type.

Suggested change
.post_void("/manager/probe_sync", &dummy_body)
.post_void("/manager/probe_sync", &())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting... I thought your solution would elegantly produce an empty body but instead the body has the 4 characters: null 🧐

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had not thought about that, but I guess it makes sense. Alternatively, we could make the argument an Option<T>. I do not know what is better.

rust/agama-server/src/manager/web.rs Outdated Show resolved Hide resolved
testing_using_container.sh Show resolved Hide resolved
rust/agama-lib/src/product/http_client.rs Outdated Show resolved Hide resolved
rust/agama-lib/src/product/http_client.rs Outdated Show resolved Hide resolved
rust/agama-lib/src/product/http_client.rs Outdated Show resolved Hide resolved
…ionInfo}

move them from web.rs for use by ProductHTTPClient
compared to the D-Bus ManagerClient,
it has only the probe method which is the only one used by CLI

BUT now config load with product and patterns SOMETIMES fails with no such
pattern... does the probe, which spawns a new thread in the web server, make a
race?
This fixes the following scenario:

```console
agama # cat rust/agama-lib/share/examples/profile_tw_gnome.json
{
  "software": {
    "patterns": [
      "gnome"
    ]
  }
}
agama # systemctl restart agama
agama # agama config load < rust/agama-lib/share/examples/profile_gnome.json
Anyhow(Backend call failed with status 400 and text '{"error":"Agama service error: Failed to find these patterns: [\"gnome\"]"}')
agama # systemctl restart agama
agama # PROBE_SYNC=1 agama config load < rust/agama-lib/share/examples/profile_gnome.json
agama #
```

The asynchronous probing, introduced in PR#1272 results in a race(?) and an
error when performing the second PUT:

```
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: GET /api/software/config
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: PUT /api/software/config
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: POST /api/manager/probe
Sep 03 11:20:06 2cf2b88a0524 agama-web-server[9357]: request: PUT /api/software/config
```
that is, "null".

The server will ignore it anyway and it is shorter in the client code compared
to the empty array.
@mvidner mvidner merged commit ff3cf07 into master Sep 10, 2024
2 checks passed
@mvidner mvidner deleted the http-client-product branch September 10, 2024 14:59
@imobachgs imobachgs mentioned this pull request Sep 20, 2024
imobachgs added a commit that referenced this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants