diff options
author | Alberto Contreras <alberto.contreras@canonical.com> | 2023-03-02 05:02:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-01 21:02:17 -0700 |
commit | 635b5a52590922668c13549d087723597a5cce7e (patch) | |
tree | 77ff1c7929f37a35435b6bb413ed86da8b0d0ece | |
parent | d781e14cd86cd85900a3c289ae5671ec6e77916f (diff) | |
download | cloud-init-git-635b5a52590922668c13549d087723597a5cce7e.tar.gz |
cc_ubuntu_advantage: improve UA logs discovery
- Use log_time context manager to wrap log UA-API calls
- Add a log msg pointing to UA logs
-rw-r--r-- | cloudinit/config/cc_ubuntu_advantage.py | 16 | ||||
-rw-r--r-- | tests/unittests/config/test_cc_ubuntu_advantage.py | 8 |
2 files changed, 20 insertions, 4 deletions
diff --git a/cloudinit/config/cc_ubuntu_advantage.py b/cloudinit/config/cc_ubuntu_advantage.py index 9dd8f3a2..e4840a73 100644 --- a/cloudinit/config/cc_ubuntu_advantage.py +++ b/cloudinit/config/cc_ubuntu_advantage.py @@ -398,7 +398,11 @@ def _should_auto_attach(ua_section: dict) -> bool: # pylint: enable=import-error try: - result = should_auto_attach() + result = util.log_time( + logfunc=LOG.debug, + msg="Checking if the instance can be attached to Ubuntu Pro", + func=should_auto_attach, + ) except UserFacingError as ex: LOG.debug("Error during `should_auto_attach`: %s", ex) LOG.warning(ERROR_MSG_SHOULD_AUTO_ATTACH) @@ -440,7 +444,12 @@ def _auto_attach(ua_section: dict): enable_beta=enable_beta, ) try: - full_auto_attach(options=options) + util.log_time( + logfunc=LOG.debug, + msg="Attaching to Ubuntu Pro", + func=full_auto_attach, + kwargs={"options": options}, + ) except AlreadyAttachedError: if enable_beta is not None or enable is not None: # Only warn if the user defined some service to enable/disable. @@ -495,6 +504,9 @@ def handle( # ua-auto-attach.service had noop-ed as ua_section is not empty validate_schema_features(ua_section) + LOG.debug( + "To discover more log info, please check /var/log/ubuntu-advantage.log" + ) if _should_auto_attach(ua_section): _auto_attach(ua_section) diff --git a/tests/unittests/config/test_cc_ubuntu_advantage.py b/tests/unittests/config/test_cc_ubuntu_advantage.py index 34038cca..db76cf4e 100644 --- a/tests/unittests/config/test_cc_ubuntu_advantage.py +++ b/tests/unittests/config/test_cc_ubuntu_advantage.py @@ -1134,9 +1134,13 @@ class TestShouldAutoAttach: ) if expected_result is None: # UA API does respond assert should_auto_attach_value == _should_auto_attach(ua_section) + assert ( + "Checking if the instance can be attached to Ubuntu Pro took" + in caplog.text + ) else: # cloud-init does respond assert expected_result == _should_auto_attach(ua_section) - assert not caplog.text + assert not caplog.text class TestAutoAttach: @@ -1165,7 +1169,7 @@ class TestAutoAttach: "uaclient.api.u.pro.attach.auto.full_auto_attach.v1" ] = mock.Mock() _auto_attach(self.ua_section) - assert not caplog.text + assert "Attaching to Ubuntu Pro took" in caplog.text class TestAttach: |