Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging to snap install steps #119

Merged
merged 10 commits into from
Apr 14, 2024
7 changes: 6 additions & 1 deletion lib/charms/operator_libs_linux/v2/snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -580,10 +580,15 @@ 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}"
lucasgameiroborges marked this conversation as resolved.
Show resolved Hide resolved
)
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
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test was failing, looks like latest/edge is no longer part of the ouput of snap info juju, causing this regex search to fail. Since the focus of the test wasn't to install the revision of latest/edge in particular, I changed it to 3/stable.

ubuntu@ip-172-31-6-38:~$ snap info juju
name:      juju
summary:   Juju - a model-driven operator lifecycle manager for K8s and machines
publisher: Canonical✓
store-url: https://snapcraft.io/juju
contact:   https://canonical.com/
license:   AGPL-3.0
description: |
  A model-driven **universal operator lifecycle manager** for multi cloud and hybrid cloud
  application management on K8s and machines.
  
  **What is an operator lifecycle manager?**
  Kubernetes operators are containers with operations code, that drive your applications on K8s.
  Juju is an operator lifecycle manager that manages the installation, integration and configuration
  of operators on the cluster. Juju also extends the idea of operators to traditional application
  management on Linux and Windows servers, or cloud instances.
  
  **Model-driven operations and integration**
  Organise your operators into models, which group together applications that can be tightly
  integrated on the same substrate and operated by the same team. Capture resource allocation,
  storage, networking and integration information in the model to simplify ongoing operations.
  
  **Better day-2 operations**
  Each operator code package, called a charm, declares methods for actions like back, restore, or
  security audit. Calling these methods provides remote administration of the application with no
  low-level access required.
  
  **Learn more**
  
   - https://juju.is/
   - https://discourse.charmhub.io/
   - https://github.com/juju/juju
commands:
  - juju
services:
  juju.fetch-oci: oneshot, disabled, inactive
snap-id:      e2CPHpB1fUxcKtCyJTsm5t3hN9axJ0yj
tracking:     3/stable
refresh-date: 8 days ago, at 05:44 UTC
channels:
  3/stable:      3.4.2             2024-04-06 (26968)  98MB -
  3/candidate:   ↑                                          
  3/beta:        ↑                                          
  3/edge:        ↑                                          
  4.0/stable:    –                                          
  4.0/candidate: –                                          
  4.0/beta:      4.0-beta2         2024-01-11 (25984)  98MB -
  4.0/edge:      4.0-beta3-4211156 2024-04-04 (26932)  98MB -
  4/stable:      –                                          
  4/candidate:   –                                          
  4/beta:        4.0-beta2         2024-01-17 (25984)  98MB -
  4/edge:        ↑                                          
  3.5/stable:    –                                          
  3.5/candidate: –                                          
  3.5/beta:      –                                          
  3.5/edge:      3.5-beta1-9a37403 2024-04-04 (26924)  98MB -
  3.4/stable:    3.4.2             2024-04-06 (26968)  98MB -
  3.4/candidate: ↑                                          
  3.4/beta:      ↑                                          
  3.4/edge:      3.4.2-4023207     2024-04-04 (26925)  98MB -
  3.3/stable:    3.3.4             2024-04-10 (26984)  98MB -
  3.3/candidate: ↑                                          
  3.3/beta:      ↑                                          
  3.3/edge:      3.3.4-8705907     2024-04-04 (26922)  99MB -
  3.2/stable:    3.2.4             2023-11-22 (25443)  95MB -
  3.2/candidate: ↑                                          
  3.2/beta:      ↑                                          
  3.2/edge:      3.2.5-9e20221     2023-11-17 (25455)  95MB -
  3.1/stable:    3.1.8             2024-04-12 (26977)  95MB -
  3.1/candidate: ↑                                          
  3.1/beta:      ↑                                          
  3.1/edge:      3.1.8-810900f     2024-04-05 (26958)  95MB -
  2.9/stable:    2.9.49            2024-04-08 (26973) 120MB classic
  2.9/candidate: 2.9.49            2024-04-08 (26973) 120MB classic
  2.9/beta:      ↑                                          
  2.9/edge:      2.9.49-a0e0041    2024-04-04 (26919) 120MB classic
  2.8/stable:    2.8.13            2021-11-11 (17665)  74MB classic
  2.8/candidate: ↑                                          
  2.8/beta:      ↑                                          
  2.8/edge:      ↑                                          
installed:       3.4.2                        (26968)  98MB -


if match:
edge_revision = match.group(1)
Expand Down
Loading