1
1
# Copyright 2023 Canonical Ltd.
2
2
# See LICENSE file for licensing details.
3
-
3
+ import pathlib
4
+ import platform
4
5
5
6
import ops
6
7
import pytest
8
+ import tomli
9
+
7
10
from charms .tempo_coordinator_k8s .v0 .charm_tracing import charm_tracing_disabled
8
11
9
12
import snap
@@ -29,6 +32,28 @@ def disable_tenacity_retry(monkeypatch):
29
32
monkeypatch .setattr (f"tenacity.{ retry_class } .__call__" , lambda * args , ** kwargs : False )
30
33
31
34
35
+ class _MockRefresh :
36
+ in_progress = False
37
+ next_unit_allowed_to_refresh = True
38
+ workload_allowed_to_start = True
39
+ app_status_higher_priority = None
40
+ unit_status_higher_priority = None
41
+
42
+ def __init__ (self , _ , / ):
43
+ pass
44
+
45
+ def update_snap_revision (self ):
46
+ pass
47
+
48
+ @property
49
+ def pinned_snap_revision (self ):
50
+ with pathlib .Path ("refresh_versions.toml" ).open ("rb" ) as file :
51
+ return tomli .load (file )["snap" ]["revisions" ][platform .machine ()]
52
+
53
+ def unit_status_lower_priority (self , * , workload_is_running = True ):
54
+ return None
55
+
56
+
32
57
@pytest .fixture (autouse = True )
33
58
def patch (monkeypatch ):
34
59
monkeypatch .setattr (
@@ -41,9 +66,8 @@ def patch(monkeypatch):
41
66
"mysql_shell.Shell.get_mysql_router_user_for_unit" , lambda * args , ** kwargs : None
42
67
)
43
68
monkeypatch .setattr ("mysql_shell.Shell.is_router_in_cluster_set" , lambda * args , ** kwargs : True )
44
- monkeypatch .setattr ("upgrade.Upgrade.in_progress" , False )
45
- monkeypatch .setattr ("upgrade.Upgrade.versions_set" , True )
46
- monkeypatch .setattr ("upgrade.Upgrade.is_compatible" , True )
69
+ monkeypatch .setattr ("charm_refresh.Machines" , _MockRefresh )
70
+ monkeypatch .setattr ("relations.database_requires.RelationEndpoint.does_relation_exist" , lambda * args , ** kwargs : True )
47
71
48
72
49
73
# flake8: noqa: C901
@@ -102,6 +126,7 @@ def restart(self, services: list[str] = []):
102
126
"snap.Snap._run_command" ,
103
127
lambda * args , ** kwargs : "null" , # Use "null" for `json.loads()`
104
128
)
129
+ monkeypatch .setattr ("snap.Snap.install" , lambda * args , ** kwargs : None )
105
130
monkeypatch .setattr ("snap._Path.read_text" , lambda * args , ** kwargs : "" )
106
131
monkeypatch .setattr ("snap._Path.write_text" , lambda * args , ** kwargs : None )
107
132
monkeypatch .setattr ("snap._Path.unlink" , lambda * args , ** kwargs : None )
0 commit comments