[Merge] ~renanrodrigo/update-notifier:respect-phasing into update-notifier:master

Renan Rodrigo mp+438009 at code.launchpad.net
Tue Feb 28 21:28:36 UTC 2023



Diff comments:

> diff --git a/data/apt_check.py b/data/apt_check.py
> index 44bfd08..f4c68e6 100755
> --- a/data/apt_check.py
> +++ b/data/apt_check.py
> @@ -325,6 +325,29 @@ def has_esm_service(cache, esm_origin):
>      return False
>  
>  
> +def get_apt_pkg_esm_cache():
> +    """Get an apt_pkg cache with the ubuntu-advantage-tools esm data.
> +
> +    Set the configuration to get the u-a-t cache, then set it back to an empty
> +    configuration state and init again so other calls to Cache work as expected.
> +    """
> +    for key in apt_pkg.config.keys():
> +        if "Acquire" not in key:

Yes the purpose is right.
That's a good suggestion - I will change this.

> +            apt_pkg.config.clear(key)
> +    apt_pkg.config.set("Dir", "/var/lib/ubuntu-advantage/apt-esm/")

sure can do

> +    apt_pkg.init()
> +    try:
> +        esm_cache = apt_pkg.Cache(progress=None)

the init and config.set calls are not supposed to fail, and if they do, then there is some deeper issue and raising the exception will make the fail visible - as we have to call init again later to reset the state, for instance, it would be complicated to catch this and possibly rollback. So not worth catching errors there.
Anything wrong during Cache instance creation will throw the apt_pkg.Error - this happens for instance if the cache in disk does not exist at all (e.g. the specified "Dir" does not have the required files. In this case we don't care - just assume no Cache.
Now it turns the question to: why were the other calls in the try/catch block before? The answer is: we weren't calling those again to change back the configuration.

> +    except apt_pkg.Error:
> +        esm_cache = None
> +
> +    for key in apt_pkg.config.keys():
> +        apt_pkg.config.clear(key)
> +    apt_pkg.init()
> +
> +    return esm_cache
> +
> +
>  def init():
>      " init the system, be nice "
>      # FIXME: do a ionice here too?


-- 
https://code.launchpad.net/~renanrodrigo/update-notifier/+git/update-notifier/+merge/438009
Your team Ubuntu Core Development Team is subscribed to branch update-notifier:master.




More information about the Ubuntu-reviews mailing list