We are isolating the creation of both caches (normal apt and esm cache)
on the get_pkg_candidate_version function. This is just to make this
function safer regarding the handling of the global apt configuration
Since we are using the context manager to create the esm cache,
we don't need to manually create it anymore. Additionally, we understand
that the context manager should properly handle the apt configuration,
but we are removing that extra line to make the code safer, since this could
cause errors on scenarios we cannot anticipate
yaml: catch and surface errors with the yaml installation
When working on the fix of LP #2007241 and LP #2007234, some logic was
implemented to import only the system-installed yaml package. However,
after further discussion, the team, with the help of reviewers,
concluded that this is indeed an error, and should be just treated
correctly to avoid a crash (and consequently an oops report).
This commit substitutes the previous logic with two exception handlers:
one for the missing yaml package, another for any yaml package which
cannot perform the basic operations we need.
Since we are now migrating some of the uaclient.conf items
into a different file, we are also leaving a backup file
behind, uaclient.conf.dpkg-bak, in case the user has made some
comments on the original config file. This will allow the
user to retrieve those comments if needed
Some apt functions require us to change the global apt config.
Since we might be changing behavior on other parts of the code
that require apt functionality, we are now using a context manager
to guarantee that the original system config is kept after
we call an apt function