Conversation
|
Blocked on #4443 |
518614c to
4bde734
Compare
4bde734 to
51f8a18
Compare
44acca0 to
aa53188
Compare
1efb436 to
919a85a
Compare
945eb56 to
c10ce07
Compare
| #: A prefix to use when invoking commands with ``sudo``. | ||
| sudo_prefix = string_guest_fact( | ||
| """ | ||
| Format facts for pretty printing. | ||
| if [ "$(whoami)" = "root" ]; then | ||
| echo '' | ||
| elif sudo -n true 1>&2; then | ||
| echo 'sudo' | ||
| else | ||
| echo '' | ||
| fi | ||
| """ | ||
| ) |
There was a problem hiding this comment.
I think we should keep the original design with each _query_* methods and have these functions contribute to an unordered dict for the actual string_guest_fact. The return of those could then be the variable from where it is accessed. So for sudo_prefix it can look like
def _query_sudo_prefix(self) -> str:
is_superuser = self._query_is_superuser()
can_sudo = self._query_can_sudo()
self.query_script["sudo_prefix"] = string_guest_fact(f"""
if [ "${is_superuser}" = true ]; then
sudo_prefix=""
elif [ "${can_sudo}" = true ]; then
sudo_prefix="sudo"
else
sudo_prefix=""
fi
""")
return "sudo_prefix"assignment vs echo here are interchangeable, just used the latter for logic clarity.
Using the unordered dict would help here to guarantee there is no duplicates of the query scripts while still guaranteeing that all query scripts were performed before it was requested.
There was a problem hiding this comment.
Do we even have to have an actual shell probe for "sudo prefix"? Seems like a mistake I haven't noticed before. It's derived from probes that do have actual stuff to discover, and this one seems like a mere crossroad once the rest is discovered. Might be just a (cached) property on top of is_superuser and can_sudo facts. I'll see what I can do.
There was a problem hiding this comment.
Well, not about sudo_prefix explicitly, but to figure out how to do probes that have dependencies on other probes, is_image_mode being the primary case where we hit it.
There was a problem hiding this comment.
Added "required probes" in 41e3dbec. Probes can now hint the script to emit some probes first, each probe is saved in a variable, later probes can use them in their snippets. I don't want to go back to _query_* methods, it's cumbersome and blocks fact collection in one go.
c10ce07 to
41e3dbe
Compare
TL;DR: guest fact discovery now runs as a single remote command, whose output is then parsed into values of individual facts. * Each fact attribute is now defined with a descriptor (see [1]). It keeps the proper type annotation, but we can attach more information. * Each probe is now a shell script snippet, and is attached to its owning fact. * Snippets are collected, joined, and the resulting script is executed. `GuestFacts` then processes the output, delivers discovered values to the right attributes. * No Python code in probes, custom Python code to handle decoding of the script output fully supported (and used, see package manager facts). For the tmt code, nothing changes, `GuestFacts` API remains the same. [1] https://docs.python.org/3/howto/descriptor.html
c16dbb7 to
26e8166
Compare
TL;DR: guest fact discovery now runs as a single remote command, whose
output is then parsed into values of individual facts.
keeps the proper type annotation, but we can attach more information.
owning fact.
GuestFactsthen processes the output, delivers discovered values tothe right attributes.
script output fully supported (and used, see package manager facts).
For the tmt code, nothing changes,
GuestFactsAPI remains the same.[1] https://docs.python.org/3/howto/descriptor.html
Pull Request Checklist