|
3 | 3 |
|
4 | 4 | import unittest |
5 | 5 | from pathlib import Path |
6 | | -from typing import Dict, List, Tuple |
7 | 6 | from unittest import mock |
8 | 7 | from unittest.mock import ANY, Mock, patch |
9 | 8 |
|
10 | 9 | import yaml |
11 | 10 | from toposort import CircularDependencyError |
12 | 11 |
|
13 | | -from juju import charmhub, constraints |
| 12 | +from juju import charmhub |
14 | 13 | from juju.bundle import ( |
15 | 14 | AddApplicationChange, |
16 | 15 | AddCharmChange, |
@@ -189,113 +188,13 @@ async def test_run_with_charmhub_charm(self): |
189 | 188 | constraints="constraints", |
190 | 189 | endpoint_bindings="endpoint_bindings", |
191 | 190 | resources=["resource1"], |
192 | | - storage={ |
193 | | - storage_label: constraints.parse_storage_constraint(storage_constraint) |
194 | | - }, |
| 191 | + storage={storage_label: storage_constraint}, |
195 | 192 | devices="devices", |
196 | 193 | channel="channel", |
197 | 194 | charm_origin=ANY, |
198 | 195 | num_units="num_units", |
199 | 196 | ) |
200 | 197 |
|
201 | | - async def test_run_with_storage_variations(self): |
202 | | - """Test that various valid storage constraints are parsed as expected |
203 | | - before model._deploy is called. |
204 | | -
|
205 | | - Uses the mock call logic from test_run_with_charmhub_charm, |
206 | | - which will run before this test. |
207 | | - """ |
208 | | - storage_arg_pairs: List[ |
209 | | - Tuple[Dict[str, str], Dict[str, constraints.StorageConstraintDict]] |
210 | | - ] = [ |
211 | | - # (storage_arg_for_change, storage_arg_for_deploy) |
212 | | - ( |
213 | | - {"some-label": "ebs,100G,1"}, |
214 | | - {"some-label": {"count": 1, "pool": "ebs", "size": 102400}}, |
215 | | - ), |
216 | | - ( |
217 | | - {"some-label": "ebs,2.1G,3"}, |
218 | | - {"some-label": {"count": 3, "pool": "ebs", "size": 2150}}, |
219 | | - ), |
220 | | - ( |
221 | | - {"some-label": "ebs,100G"}, |
222 | | - {"some-label": {"count": 1, "pool": "ebs", "size": 102400}}, |
223 | | - ), |
224 | | - ({"some-label": "ebs,2"}, {"some-label": {"count": 2, "pool": "ebs"}}), |
225 | | - ({"some-label": "200G,7"}, {"some-label": {"count": 7, "size": 204800}}), |
226 | | - ({"some-label": "ebs"}, {"some-label": {"count": 1, "pool": "ebs"}}), |
227 | | - ( |
228 | | - {"some-label": "10YB"}, |
229 | | - {"some-label": {"count": 1, "size": 11529215046068469760}}, |
230 | | - ), |
231 | | - ({"some-label": "1"}, {"some-label": {"count": 1}}), |
232 | | - ({"some-label": "-1"}, {"some-label": {"count": 1}}), |
233 | | - ({"some-label": ""}, {"some-label": {"count": 1}}), |
234 | | - ( |
235 | | - { |
236 | | - "some-label": "2.1G,3", |
237 | | - "data": "1MiB,70", |
238 | | - "logs": "ebs,-1", |
239 | | - }, |
240 | | - { |
241 | | - "some-label": {"count": 3, "size": 2150}, |
242 | | - "data": {"count": 70, "size": 1}, |
243 | | - "logs": {"count": 1, "pool": "ebs"}, |
244 | | - }, |
245 | | - ), |
246 | | - ] |
247 | | - for storage_arg_for_change, storage_arg_for_deploy in storage_arg_pairs: |
248 | | - change = AddApplicationChange( |
249 | | - 1, |
250 | | - [], |
251 | | - params={ |
252 | | - "charm": "charm", |
253 | | - "series": "series", |
254 | | - "application": "application", |
255 | | - "options": "options", |
256 | | - "constraints": "constraints", |
257 | | - "storage": storage_arg_for_change, |
258 | | - "endpoint-bindings": "endpoint_bindings", |
259 | | - "resources": "resources", |
260 | | - "devices": "devices", |
261 | | - "num-units": "num_units", |
262 | | - "channel": "channel", |
263 | | - }, |
264 | | - ) |
265 | | - # mock model |
266 | | - model = Mock() |
267 | | - model._deploy = mock.AsyncMock(return_value=None) |
268 | | - model._add_charmhub_resources = mock.AsyncMock(return_value=["resource1"]) |
269 | | - model.applications = {} |
270 | | - # mock context |
271 | | - context = Mock() |
272 | | - context.resolve.return_value = "ch:charm1" |
273 | | - context.origins = {"ch:charm1": Mock()} |
274 | | - context.trusted = False |
275 | | - context.model = model |
276 | | - # mock info_func |
277 | | - info_func = mock.AsyncMock(return_value=["12345", "name"]) |
278 | | - # patch and call |
279 | | - with patch.object(charmhub.CharmHub, "get_charm_id", info_func): |
280 | | - result = await change.run(context) |
281 | | - assert result == "application" |
282 | | - # asserts |
283 | | - model._deploy.assert_called_once() |
284 | | - model._deploy.assert_called_with( |
285 | | - charm_url="ch:charm1", |
286 | | - application="application", |
287 | | - series="series", |
288 | | - config="options", |
289 | | - constraints="constraints", |
290 | | - endpoint_bindings="endpoint_bindings", |
291 | | - resources=["resource1"], |
292 | | - storage=storage_arg_for_deploy, # we're testing this |
293 | | - devices="devices", |
294 | | - channel="channel", |
295 | | - charm_origin=ANY, |
296 | | - num_units="num_units", |
297 | | - ) |
298 | | - |
299 | 198 | async def test_run_with_charmhub_charm_no_channel(self): |
300 | 199 | """Test to verify if when the given channel is None, the channel |
301 | 200 | defaults to "local/stable", which is the default channel value for the |
@@ -347,9 +246,7 @@ async def test_run_with_charmhub_charm_no_channel(self): |
347 | 246 | constraints="constraints", |
348 | 247 | endpoint_bindings="endpoint_bindings", |
349 | 248 | resources=["resource1"], |
350 | | - storage={ |
351 | | - storage_label: constraints.parse_storage_constraint(storage_constraint) |
352 | | - }, |
| 249 | + storage={storage_label: storage_constraint}, |
353 | 250 | devices="devices", |
354 | 251 | channel="latest/stable", |
355 | 252 | charm_origin=ANY, |
@@ -397,9 +294,7 @@ async def test_run_local(self): |
397 | 294 | constraints="constraints", |
398 | 295 | endpoint_bindings="endpoint_bindings", |
399 | 296 | resources={}, |
400 | | - storage={ |
401 | | - storage_label: constraints.parse_storage_constraint(storage_constraint) |
402 | | - }, |
| 297 | + storage={storage_label: storage_constraint}, |
403 | 298 | devices="devices", |
404 | 299 | num_units="num_units", |
405 | 300 | channel="", |
@@ -452,9 +347,7 @@ async def test_run_no_series(self): |
452 | 347 | constraints="constraints", |
453 | 348 | endpoint_bindings="endpoint_bindings", |
454 | 349 | resources=["resource1"], |
455 | | - storage={ |
456 | | - storage_label: constraints.parse_storage_constraint(storage_constraint) |
457 | | - }, |
| 350 | + storage={storage_label: storage_constraint}, |
458 | 351 | devices="devices", |
459 | 352 | channel="channel", |
460 | 353 | charm_origin=ANY, |
|
0 commit comments