qontract-reconcile 0.9.1rc273__py3-none-any.whl → 0.9.1rc275__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,93 @@
1
+ from collections.abc import (
2
+ Callable,
3
+ Mapping,
4
+ )
5
+ from typing import Any
6
+
7
+ from reconcile.saas_auto_promotions_manager.subscriber import (
8
+ ConfigHash,
9
+ Subscriber,
10
+ )
11
+
12
+ from .data_keys import (
13
+ CUR_CONFIG_HASHES,
14
+ CUR_SUBSCRIBER_REF,
15
+ DESIRED_REF,
16
+ DESIRED_TARGET_HASHES,
17
+ )
18
+
19
+
20
+ def test_has_config_hash_diff(
21
+ subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
22
+ ) -> None:
23
+ subscriber = subscriber_builder(
24
+ {
25
+ CUR_SUBSCRIBER_REF: "current_sha",
26
+ CUR_CONFIG_HASHES: [
27
+ ConfigHash(
28
+ channel="channel-a",
29
+ parent_saas="publisher_a",
30
+ target_config_hash="pub_a_hash",
31
+ ),
32
+ ConfigHash(
33
+ channel="channel-b",
34
+ parent_saas="publisher_b",
35
+ target_config_hash="pub_b_hash",
36
+ ),
37
+ ],
38
+ DESIRED_REF: "current_sha",
39
+ DESIRED_TARGET_HASHES: [
40
+ ConfigHash(
41
+ channel="channel-a",
42
+ parent_saas="publisher_a",
43
+ target_config_hash="pub_a_hash",
44
+ ),
45
+ ConfigHash(
46
+ channel="channel-b",
47
+ parent_saas="publisher_b",
48
+ target_config_hash="new_hash",
49
+ ),
50
+ ],
51
+ }
52
+ )
53
+ assert subscriber.has_diff()
54
+
55
+
56
+ def test_has_ref_diff(
57
+ subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
58
+ ) -> None:
59
+ subscriber = subscriber_builder(
60
+ {
61
+ CUR_SUBSCRIBER_REF: "current_sha",
62
+ CUR_CONFIG_HASHES: [],
63
+ DESIRED_REF: "new_sha",
64
+ DESIRED_TARGET_HASHES: [],
65
+ }
66
+ )
67
+ assert subscriber.has_diff()
68
+
69
+
70
+ def test_no_diff(
71
+ subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
72
+ ) -> None:
73
+ config_hashes = [
74
+ ConfigHash(
75
+ channel="channel-a",
76
+ parent_saas="publisher_a",
77
+ target_config_hash="pub_a_hash",
78
+ ),
79
+ ConfigHash(
80
+ channel="channel-b",
81
+ parent_saas="publisher_b",
82
+ target_config_hash="pub_b_hash",
83
+ ),
84
+ ]
85
+ subscriber = subscriber_builder(
86
+ {
87
+ CUR_SUBSCRIBER_REF: "current_sha",
88
+ CUR_CONFIG_HASHES: config_hashes,
89
+ DESIRED_REF: "current_sha",
90
+ DESIRED_TARGET_HASHES: list(reversed(config_hashes)),
91
+ }
92
+ )
93
+ assert not subscriber.has_diff()
@@ -1,6 +1,5 @@
1
1
  from collections.abc import (
2
2
  Callable,
3
- Iterable,
4
3
  Mapping,
5
4
  )
6
5
  from typing import Any
@@ -22,16 +21,21 @@ from .data_keys import (
22
21
 
23
22
  def test_single_new_config_hash(
24
23
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
25
- config_hashes_builder: Callable[
26
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
27
- ],
28
24
  ):
29
25
  subscriber = subscriber_builder(
30
26
  {
31
27
  CUR_SUBSCRIBER_REF: "current_sha",
32
28
  CUR_CONFIG_HASHES: [
33
- ("channel-a", "publisher_a", "pub_a_hash"),
34
- ("channel-b", "publisher_b", "pub_b_hash"),
29
+ ConfigHash(
30
+ channel="channel-a",
31
+ parent_saas="publisher_a",
32
+ target_config_hash="pub_a_hash",
33
+ ),
34
+ ConfigHash(
35
+ channel="channel-b",
36
+ parent_saas="publisher_b",
37
+ target_config_hash="pub_b_hash",
38
+ ),
35
39
  ],
36
40
  CHANNELS: {
37
41
  "channel-a": {
@@ -50,28 +54,39 @@ def test_single_new_config_hash(
50
54
  }
51
55
  )
52
56
  subscriber.compute_desired_state()
53
- expected_config_hashes = config_hashes_builder(
54
- [
55
- ("channel-a", "publisher_a", "new_pub_a_hash"),
56
- ("channel-b", "publisher_b", "pub_b_hash"),
57
- ]
58
- )
57
+ expected_config_hashes = [
58
+ ConfigHash(
59
+ channel="channel-a",
60
+ parent_saas="publisher_a",
61
+ target_config_hash="new_pub_a_hash",
62
+ ),
63
+ ConfigHash(
64
+ channel="channel-b",
65
+ parent_saas="publisher_b",
66
+ target_config_hash="pub_b_hash",
67
+ ),
68
+ ]
59
69
  assert subscriber.desired_ref == "current_sha"
60
70
  assert subscriber.desired_hashes == expected_config_hashes
61
71
 
62
72
 
63
73
  def test_both_new_config_hashes(
64
74
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
65
- config_hashes_builder: Callable[
66
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
67
- ],
68
75
  ):
69
76
  subscriber = subscriber_builder(
70
77
  {
71
78
  CUR_SUBSCRIBER_REF: "current_sha",
72
79
  CUR_CONFIG_HASHES: [
73
- ("channel-a", "publisher_a", "pub_a_hash"),
74
- ("channel-b", "publisher_b", "pub_b_hash"),
80
+ ConfigHash(
81
+ channel="channel-a",
82
+ parent_saas="publisher_a",
83
+ target_config_hash="pub_a_hash",
84
+ ),
85
+ ConfigHash(
86
+ channel="channel-b",
87
+ parent_saas="publisher_b",
88
+ target_config_hash="pub_b_hash",
89
+ ),
75
90
  ],
76
91
  CHANNELS: {
77
92
  "channel-a": {
@@ -90,28 +105,39 @@ def test_both_new_config_hashes(
90
105
  }
91
106
  )
92
107
  subscriber.compute_desired_state()
93
- expected_config_hashes = config_hashes_builder(
94
- [
95
- ("channel-a", "publisher_a", "new_pub_a_hash"),
96
- ("channel-b", "publisher_b", "new_pub_b_hash"),
97
- ]
98
- )
108
+ expected_config_hashes = [
109
+ ConfigHash(
110
+ channel="channel-a",
111
+ parent_saas="publisher_a",
112
+ target_config_hash="new_pub_a_hash",
113
+ ),
114
+ ConfigHash(
115
+ channel="channel-b",
116
+ parent_saas="publisher_b",
117
+ target_config_hash="new_pub_b_hash",
118
+ ),
119
+ ]
99
120
  assert subscriber.desired_ref == "current_sha"
100
121
  assert subscriber.desired_hashes == expected_config_hashes
101
122
 
102
123
 
103
124
  def test_both_new_config_hashes_one_bad_deployment(
104
125
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
105
- config_hashes_builder: Callable[
106
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
107
- ],
108
126
  ):
109
127
  subscriber = subscriber_builder(
110
128
  {
111
129
  CUR_SUBSCRIBER_REF: "current_sha",
112
130
  CUR_CONFIG_HASHES: [
113
- ("channel-a", "publisher_a", "pub_a_hash"),
114
- ("channel-b", "publisher_b", "pub_b_hash"),
131
+ ConfigHash(
132
+ channel="channel-a",
133
+ parent_saas="publisher_a",
134
+ target_config_hash="pub_a_hash",
135
+ ),
136
+ ConfigHash(
137
+ channel="channel-b",
138
+ parent_saas="publisher_b",
139
+ target_config_hash="pub_b_hash",
140
+ ),
115
141
  ],
116
142
  CHANNELS: {
117
143
  "channel-a": {
@@ -131,28 +157,39 @@ def test_both_new_config_hashes_one_bad_deployment(
131
157
  }
132
158
  )
133
159
  subscriber.compute_desired_state()
134
- expected_config_hashes = config_hashes_builder(
135
- [
136
- ("channel-a", "publisher_a", "pub_a_hash"),
137
- ("channel-b", "publisher_b", "new_pub_b_hash"),
138
- ]
139
- )
160
+ expected_config_hashes = [
161
+ ConfigHash(
162
+ channel="channel-a",
163
+ parent_saas="publisher_a",
164
+ target_config_hash="pub_a_hash",
165
+ ),
166
+ ConfigHash(
167
+ channel="channel-b",
168
+ parent_saas="publisher_b",
169
+ target_config_hash="new_pub_b_hash",
170
+ ),
171
+ ]
140
172
  assert subscriber.desired_ref == "current_sha"
141
173
  assert subscriber.desired_hashes == expected_config_hashes
142
174
 
143
175
 
144
176
  def test_both_new_config_hashes_all_bad_deployments(
145
177
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
146
- config_hashes_builder: Callable[
147
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
148
- ],
149
178
  ):
150
179
  subscriber = subscriber_builder(
151
180
  {
152
181
  CUR_SUBSCRIBER_REF: "current_sha",
153
182
  CUR_CONFIG_HASHES: [
154
- ("channel-a", "publisher_a", "pub_a_hash"),
155
- ("channel-b", "publisher_b", "pub_b_hash"),
183
+ ConfigHash(
184
+ channel="channel-a",
185
+ parent_saas="publisher_a",
186
+ target_config_hash="pub_a_hash",
187
+ ),
188
+ ConfigHash(
189
+ channel="channel-b",
190
+ parent_saas="publisher_b",
191
+ target_config_hash="pub_b_hash",
192
+ ),
156
193
  ],
157
194
  CHANNELS: {
158
195
  "channel-a": {
@@ -173,11 +210,17 @@ def test_both_new_config_hashes_all_bad_deployments(
173
210
  }
174
211
  )
175
212
  subscriber.compute_desired_state()
176
- expected_config_hashes = config_hashes_builder(
177
- [
178
- ("channel-a", "publisher_a", "pub_a_hash"),
179
- ("channel-b", "publisher_b", "pub_b_hash"),
180
- ]
181
- )
213
+ expected_config_hashes = [
214
+ ConfigHash(
215
+ channel="channel-a",
216
+ parent_saas="publisher_a",
217
+ target_config_hash="pub_a_hash",
218
+ ),
219
+ ConfigHash(
220
+ channel="channel-b",
221
+ parent_saas="publisher_b",
222
+ target_config_hash="pub_b_hash",
223
+ ),
224
+ ]
182
225
  assert subscriber.desired_ref == "current_sha"
183
226
  assert subscriber.desired_hashes == expected_config_hashes
@@ -1,6 +1,5 @@
1
1
  from collections.abc import (
2
2
  Callable,
3
- Iterable,
4
3
  Mapping,
5
4
  )
6
5
  from typing import Any
@@ -22,16 +21,21 @@ from .data_keys import (
22
21
 
23
22
  def test_no_change(
24
23
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
25
- config_hashes_builder: Callable[
26
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
27
- ],
28
24
  ):
29
25
  subscriber = subscriber_builder(
30
26
  {
31
27
  CUR_SUBSCRIBER_REF: "current_sha",
32
28
  CUR_CONFIG_HASHES: [
33
- ("channel-a", "publisher_a", "pub_a_hash"),
34
- ("channel-b", "publisher_b", "pub_b_hash"),
29
+ ConfigHash(
30
+ channel="channel-a",
31
+ parent_saas="publisher_a",
32
+ target_config_hash="pub_a_hash",
33
+ ),
34
+ ConfigHash(
35
+ channel="channel-b",
36
+ parent_saas="publisher_b",
37
+ target_config_hash="pub_b_hash",
38
+ ),
35
39
  ],
36
40
  CHANNELS: {
37
41
  "channel-a": {
@@ -50,28 +54,39 @@ def test_no_change(
50
54
  }
51
55
  )
52
56
  subscriber.compute_desired_state()
53
- expected_config_hashes = config_hashes_builder(
54
- [
55
- ("channel-a", "publisher_a", "pub_a_hash"),
56
- ("channel-b", "publisher_b", "pub_b_hash"),
57
- ]
58
- )
57
+ expected_config_hashes = [
58
+ ConfigHash(
59
+ channel="channel-a",
60
+ parent_saas="publisher_a",
61
+ target_config_hash="pub_a_hash",
62
+ ),
63
+ ConfigHash(
64
+ channel="channel-b",
65
+ parent_saas="publisher_b",
66
+ target_config_hash="pub_b_hash",
67
+ ),
68
+ ]
59
69
  assert subscriber.desired_ref == "current_sha"
60
70
  assert subscriber.desired_hashes == expected_config_hashes
61
71
 
62
72
 
63
73
  def test_moving_ref(
64
74
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
65
- config_hashes_builder: Callable[
66
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
67
- ],
68
75
  ):
69
76
  subscriber = subscriber_builder(
70
77
  {
71
78
  CUR_SUBSCRIBER_REF: "current_sha",
72
79
  CUR_CONFIG_HASHES: [
73
- ("channel-a", "publisher_a", "pub_a_hash"),
74
- ("channel-b", "publisher_b", "pub_b_hash"),
80
+ ConfigHash(
81
+ channel="channel-a",
82
+ parent_saas="publisher_a",
83
+ target_config_hash="pub_a_hash",
84
+ ),
85
+ ConfigHash(
86
+ channel="channel-b",
87
+ parent_saas="publisher_b",
88
+ target_config_hash="pub_b_hash",
89
+ ),
75
90
  ],
76
91
  CHANNELS: {
77
92
  "channel-a": {
@@ -90,28 +105,39 @@ def test_moving_ref(
90
105
  }
91
106
  )
92
107
  subscriber.compute_desired_state()
93
- expected_config_hashes = config_hashes_builder(
94
- [
95
- ("channel-a", "publisher_a", "pub_a_hash"),
96
- ("channel-b", "publisher_b", "pub_b_hash"),
97
- ]
98
- )
108
+ expected_config_hashes = [
109
+ ConfigHash(
110
+ channel="channel-a",
111
+ parent_saas="publisher_a",
112
+ target_config_hash="pub_a_hash",
113
+ ),
114
+ ConfigHash(
115
+ channel="channel-b",
116
+ parent_saas="publisher_b",
117
+ target_config_hash="pub_b_hash",
118
+ ),
119
+ ]
99
120
  assert subscriber.desired_ref == "new_sha"
100
121
  assert subscriber.desired_hashes == expected_config_hashes
101
122
 
102
123
 
103
124
  def test_moving_ref_mismatch(
104
125
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
105
- config_hashes_builder: Callable[
106
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
107
- ],
108
126
  ):
109
127
  subscriber = subscriber_builder(
110
128
  {
111
129
  CUR_SUBSCRIBER_REF: "current_sha",
112
130
  CUR_CONFIG_HASHES: [
113
- ("channel-a", "publisher_a", "pub_a_hash"),
114
- ("channel-b", "publisher_b", "pub_b_hash"),
131
+ ConfigHash(
132
+ channel="channel-a",
133
+ parent_saas="publisher_a",
134
+ target_config_hash="pub_a_hash",
135
+ ),
136
+ ConfigHash(
137
+ channel="channel-b",
138
+ parent_saas="publisher_b",
139
+ target_config_hash="pub_b_hash",
140
+ ),
115
141
  ],
116
142
  CHANNELS: {
117
143
  "channel-a": {
@@ -130,28 +156,39 @@ def test_moving_ref_mismatch(
130
156
  }
131
157
  )
132
158
  subscriber.compute_desired_state()
133
- expected_config_hashes = config_hashes_builder(
134
- [
135
- ("channel-a", "publisher_a", "pub_a_hash"),
136
- ("channel-b", "publisher_b", "pub_b_hash"),
137
- ]
138
- )
159
+ expected_config_hashes = [
160
+ ConfigHash(
161
+ channel="channel-a",
162
+ parent_saas="publisher_a",
163
+ target_config_hash="pub_a_hash",
164
+ ),
165
+ ConfigHash(
166
+ channel="channel-b",
167
+ parent_saas="publisher_b",
168
+ target_config_hash="pub_b_hash",
169
+ ),
170
+ ]
139
171
  assert subscriber.desired_ref == "current_sha"
140
172
  assert subscriber.desired_hashes == expected_config_hashes
141
173
 
142
174
 
143
175
  def test_moving_ref_bad_deployment(
144
176
  subscriber_builder: Callable[[Mapping[str, Any]], Subscriber],
145
- config_hashes_builder: Callable[
146
- [Iterable[tuple[str, str, str]]], frozenset[ConfigHash]
147
- ],
148
177
  ):
149
178
  subscriber = subscriber_builder(
150
179
  {
151
180
  CUR_SUBSCRIBER_REF: "current_sha",
152
181
  CUR_CONFIG_HASHES: [
153
- ("channel-a", "publisher_a", "pub_a_hash"),
154
- ("channel-b", "publisher_b", "pub_b_hash"),
182
+ ConfigHash(
183
+ channel="channel-a",
184
+ parent_saas="publisher_a",
185
+ target_config_hash="pub_a_hash",
186
+ ),
187
+ ConfigHash(
188
+ channel="channel-b",
189
+ parent_saas="publisher_b",
190
+ target_config_hash="pub_b_hash",
191
+ ),
155
192
  ],
156
193
  CHANNELS: {
157
194
  "channel-a": {
@@ -171,11 +208,17 @@ def test_moving_ref_bad_deployment(
171
208
  }
172
209
  )
173
210
  subscriber.compute_desired_state()
174
- expected_config_hashes = config_hashes_builder(
175
- [
176
- ("channel-a", "publisher_a", "pub_a_hash"),
177
- ("channel-b", "publisher_b", "pub_b_hash"),
178
- ]
179
- )
211
+ expected_config_hashes = [
212
+ ConfigHash(
213
+ channel="channel-a",
214
+ parent_saas="publisher_a",
215
+ target_config_hash="pub_a_hash",
216
+ ),
217
+ ConfigHash(
218
+ channel="channel-b",
219
+ parent_saas="publisher_b",
220
+ target_config_hash="pub_b_hash",
221
+ ),
222
+ ]
180
223
  assert subscriber.desired_ref == "current_sha"
181
224
  assert subscriber.desired_hashes == expected_config_hashes