From d9129cb7ddc4a4dfdaa5ae0a61dad64913385fc3 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 18:07:53 +0000 Subject: [PATCH 01/10] add logs to snap install steps --- lib/charms/operator_libs_linux/v2/snap.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 871ff5de..c94b9ea8 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -83,7 +83,7 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 4 +LIBPATCH = 5 # Regex to locate 7-bit C1 ANSI sequences @@ -580,10 +580,13 @@ def ensure( # We are installing or refreshing a snap. if self._state not in (SnapState.Present, SnapState.Latest): # The snap is not installed, so we install it. + logger.info(f"Installing snap {self._name} revision {revision}, tracking {channel}") self._install(channel, cohort, revision) else: # The snap is installed, but we are changing it (e.g., switching channels). + logger.info(f"Refreshing snap {self._name} to revision {revision} in {channel}") self._refresh(channel=channel, cohort=cohort, revision=revision, devmode=devmode) + logger.info("The snap installation completed successfully") self._update_snap_apps() self._state = state From fd18231efff94b2a2fc872598d9d26255adfd265 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 18:16:55 +0000 Subject: [PATCH 02/10] fix linting --- lib/charms/operator_libs_linux/v2/snap.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index c94b9ea8..540536af 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -580,7 +580,9 @@ def ensure( # We are installing or refreshing a snap. if self._state not in (SnapState.Present, SnapState.Latest): # The snap is not installed, so we install it. - logger.info(f"Installing snap {self._name} revision {revision}, tracking {channel}") + logger.info( + f"Installing snap {self._name} revision {revision}, tracking {channel}" + ) self._install(channel, cohort, revision) else: # The snap is installed, but we are changing it (e.g., switching channels). From 6db419e267c086bb4eeb6f522cff39d9905275b2 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 18:48:39 +0000 Subject: [PATCH 03/10] debug failing test --- tests/integration/test_snap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/test_snap.py b/tests/integration/test_snap.py index 464bc59b..a4a2e770 100644 --- a/tests/integration/test_snap.py +++ b/tests/integration/test_snap.py @@ -176,6 +176,7 @@ def test_snap_ensure_revision(): edge_revision = None for line in snap_info_juju: + logger.info(line) match = re.search(r"latest/edge.*\((\d+)\)", line) if match: From d8968d7d34b882a06722cb5738fb0a7454ffcae1 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 19:13:51 +0000 Subject: [PATCH 04/10] remove test log --- tests/integration/test_snap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/integration/test_snap.py b/tests/integration/test_snap.py index a4a2e770..464bc59b 100644 --- a/tests/integration/test_snap.py +++ b/tests/integration/test_snap.py @@ -176,7 +176,6 @@ def test_snap_ensure_revision(): edge_revision = None for line in snap_info_juju: - logger.info(line) match = re.search(r"latest/edge.*\((\d+)\)", line) if match: From 8c6520da77998c4359fa112329029c2a7dfed86e Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 19:29:52 +0000 Subject: [PATCH 05/10] fix test snap channel for juju --- tests/integration/test_snap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_snap.py b/tests/integration/test_snap.py index 464bc59b..640b5681 100644 --- a/tests/integration/test_snap.py +++ b/tests/integration/test_snap.py @@ -176,7 +176,7 @@ def test_snap_ensure_revision(): edge_revision = None for line in snap_info_juju: - match = re.search(r"latest/edge.*\((\d+)\)", line) + match = re.search(r"3/stable.*\((\d+)\)", line) if match: edge_revision = match.group(1) From 050c5f9a2d63ccabcc75ad66007ef1e1bceae173 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 19:55:36 +0000 Subject: [PATCH 06/10] print full failing test error --- lib/charms/operator_libs_linux/v2/snap.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 540536af..4fe52556 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -277,6 +277,7 @@ def _snap(self, command: str, optargs: Optional[Iterable[str]] = None) -> str: try: return subprocess.check_output(args, universal_newlines=True) except CalledProcessError as e: + logger.warning(e) raise SnapError( "Snap: {!r}; command {!r} failed with output = {!r}".format( self._name, args, e.output From 9ab21c72d4e1dffede571cd1a1aa1811847d0f4e Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 19:59:26 +0000 Subject: [PATCH 07/10] remove test waring log --- lib/charms/operator_libs_linux/v2/snap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 4fe52556..540536af 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -277,7 +277,6 @@ def _snap(self, command: str, optargs: Optional[Iterable[str]] = None) -> str: try: return subprocess.check_output(args, universal_newlines=True) except CalledProcessError as e: - logger.warning(e) raise SnapError( "Snap: {!r}; command {!r} failed with output = {!r}".format( self._name, args, e.output From 78ca9e8735230cd617e8a20512c2c045db650f3b Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 20:12:20 +0000 Subject: [PATCH 08/10] Trigger CI tests From cec221d5e89f783fad2a066a3f3941679f2d2212 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 21:48:01 +0000 Subject: [PATCH 09/10] remove f-string from loggers + log on snap error --- lib/charms/operator_libs_linux/v2/snap.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 540536af..36840192 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -277,6 +277,7 @@ def _snap(self, command: str, optargs: Optional[Iterable[str]] = None) -> str: try: return subprocess.check_output(args, universal_newlines=True) except CalledProcessError as e: + logger.error("Error when running %s command: %s", " ".join(args), e) raise SnapError( "Snap: {!r}; command {!r} failed with output = {!r}".format( self._name, args, e.output @@ -581,12 +582,14 @@ def ensure( if self._state not in (SnapState.Present, SnapState.Latest): # The snap is not installed, so we install it. logger.info( - f"Installing snap {self._name} revision {revision}, tracking {channel}" + "Installing snap %s, revision %s, tracking %s", self._name, revision, channel ) self._install(channel, cohort, revision) else: # The snap is installed, but we are changing it (e.g., switching channels). - logger.info(f"Refreshing snap {self._name} to revision {revision} in {channel}") + logger.info( + "Refreshing snap %s, revision %s, tracking %s", self._name, revision, channel + ) self._refresh(channel=channel, cohort=cohort, revision=revision, devmode=devmode) logger.info("The snap installation completed successfully") From a87a8daa6fe9132a819d0e215e41096c3d9feaf7 Mon Sep 17 00:00:00 2001 From: lucasgameiroborges Date: Sun, 14 Apr 2024 21:53:59 +0000 Subject: [PATCH 10/10] remove test log --- lib/charms/operator_libs_linux/v2/snap.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/charms/operator_libs_linux/v2/snap.py b/lib/charms/operator_libs_linux/v2/snap.py index 36840192..ef426775 100644 --- a/lib/charms/operator_libs_linux/v2/snap.py +++ b/lib/charms/operator_libs_linux/v2/snap.py @@ -277,7 +277,6 @@ def _snap(self, command: str, optargs: Optional[Iterable[str]] = None) -> str: try: return subprocess.check_output(args, universal_newlines=True) except CalledProcessError as e: - logger.error("Error when running %s command: %s", " ".join(args), e) raise SnapError( "Snap: {!r}; command {!r} failed with output = {!r}".format( self._name, args, e.output