@@ -305,22 +305,22 @@ def test_deprecated_field_warnings(caplog: pytest.LogCaptureFixture) -> None:
305
305
(
306
306
"zabbix_cli" ,
307
307
30 ,
308
- "Config option [configopt]output_format[/] is deprecated. Use [configopt]app.output.format[/] instead ." ,
308
+ "Config option [configopt]output_format[/] is deprecated. Replaced by: [configopt]app.output.format[/]." ,
309
309
),
310
310
(
311
311
"zabbix_cli" ,
312
312
30 ,
313
- "Config option [configopt]system_id[/] is deprecated. Use [configopt]api.username[/] instead ." ,
313
+ "Config option [configopt]system_id[/] is deprecated. Replaced by: [configopt]api.username[/]." ,
314
314
),
315
315
(
316
316
"zabbix_cli" ,
317
317
30 ,
318
- "Config option [configopt]use_colors[/] is deprecated. Use [configopt]app.output.color[/] instead ." ,
318
+ "Config option [configopt]use_colors[/] is deprecated. Replaced by: [configopt]app.output.color[/]." ,
319
319
),
320
320
(
321
321
"zabbix_cli" ,
322
322
30 ,
323
- "Config option [configopt]use_paging[/] is deprecated. Use [configopt]app.output.paging[/] instead ." ,
323
+ "Config option [configopt]use_paging[/] is deprecated. Replaced by: [configopt]app.output.paging[/]." ,
324
324
),
325
325
(
326
326
"zabbix_cli" ,
@@ -351,18 +351,22 @@ def test_get_deprecated_fields_set() -> None:
351
351
DeprecatedField (
352
352
field_name = "app.output_format" ,
353
353
value = OutputFormat .JSON ,
354
- replacement = "app.output.format" ,
354
+ replacement = [ "app.output.format" ] ,
355
355
),
356
356
DeprecatedField (
357
357
field_name = "app.system_id" ,
358
358
value = "System-User" ,
359
- replacement = "api.username" ,
359
+ replacement = [ "api.username" ] ,
360
360
),
361
361
DeprecatedField (
362
- field_name = "app.use_colors" , value = True , replacement = "app.output.color"
362
+ field_name = "app.use_colors" ,
363
+ value = True ,
364
+ replacement = ["app.output.color" ],
363
365
),
364
366
DeprecatedField (
365
- field_name = "app.use_paging" , value = True , replacement = "app.output.paging"
367
+ field_name = "app.use_paging" ,
368
+ value = True ,
369
+ replacement = ["app.output.paging" ],
366
370
),
367
371
]
368
372
)
@@ -404,7 +408,7 @@ def _set_deprecated_fields_in_new_location(self) -> Self:
404
408
DeprecatedField (
405
409
field_name = "bar.qux_deprecated" ,
406
410
value = "test123" ,
407
- replacement = "bar.baz.qux" ,
411
+ replacement = [ "bar.baz.qux" ] ,
408
412
)
409
413
]
410
414
)
@@ -466,6 +470,13 @@ def test_get_deprecated_fields() -> None:
466
470
"app.use_colors" ,
467
471
"app.use_paging" ,
468
472
"app.system_id" ,
473
+ "app.default_hostgroups" ,
474
+ "app.default_admin_usergroups" ,
475
+ "app.default_create_user_usergroups" ,
476
+ "app.default_notification_users_usergroups" ,
477
+ "app.export_directory" ,
478
+ "app.export_format" ,
479
+ "app.export_timestamps" ,
469
480
]
470
481
)
471
482
@@ -484,13 +495,6 @@ def test_load_deprecated_config(tmp_path: Path) -> None:
484
495
verify_ssl = true
485
496
486
497
[app]
487
- default_hostgroups = ["All-hosts"]
488
- default_admin_usergroups = []
489
- default_create_user_usergroups = []
490
- default_notification_users_usergroups = ["All-notification-users"]
491
- export_directory = "{ tmp_path } /exports"
492
- export_format = "json"
493
- export_timestamps = false
494
498
use_session_file = true
495
499
auth_token_file = "{ tmp_path } /.zabbix-cli_auth_token"
496
500
auth_file = "{ tmp_path } /.zabbix-cli_auth"
@@ -499,6 +503,13 @@ def test_load_deprecated_config(tmp_path: Path) -> None:
499
503
bulk_mode = "strict"
500
504
501
505
# Deprecated options (moved)
506
+ default_hostgroups = ["All-hosts"]
507
+ default_admin_usergroups = ["All-admin-users"]
508
+ default_create_user_usergroups = ["All-users"]
509
+ default_notification_users_usergroups = ["All-notification-users"]
510
+ export_directory = "{ tmp_path } /exports"
511
+ export_format = "json"
512
+ export_timestamps = false
502
513
use_colors = false
503
514
use_paging = true
504
515
output_format = "json"
@@ -522,10 +533,21 @@ def test_load_deprecated_config(tmp_path: Path) -> None:
522
533
config = Config .from_file (conf )
523
534
524
535
# Check that the deprecated fields are assigned to the new fields
536
+ assert config .app .commands .create_host .hostgroups == ["All-hosts" ]
537
+ assert config .app .commands .create_hostgroup .rw_groups == ["All-admin-users" ]
538
+ assert config .app .commands .create_hostgroup .ro_groups == ["All-users" ]
539
+ assert config .app .commands .create_notification_user .usergroups == [
540
+ "All-notification-users"
541
+ ]
542
+ assert config .app .commands .create_user .usergroups == ["All-users" ]
543
+ assert config .app .commands .export .directory == tmp_path / "exports"
544
+ assert config .app .commands .export .format == OutputFormat .JSON
545
+ assert config .app .commands .export .timestamps is False
546
+
525
547
assert config .app .output .color is False
526
548
assert config .app .output .paging is True
527
549
assert config .app .output .format == OutputFormat .JSON
528
- assert config .api .username == "System-User"
550
+ assert config .api .username == "System-User" # assigned from app.system_id
529
551
530
552
531
553
def test_load_deprecated_config_with_new_and_old_options (tmp_path : Path ) -> None :
@@ -536,16 +558,45 @@ def test_load_deprecated_config_with_new_and_old_options(tmp_path: Path) -> None
536
558
"""
537
559
conf = tmp_path / "zabbix-cli.toml"
538
560
conf .write_text (
539
- """
540
- [api]
541
- username = "Admin"
561
+ f"""
562
+ ##### Deprecated options (should be ignored) #####
542
563
543
564
[app]
565
+ default_hostgroups = ["All-hosts-deprecated"]
566
+ default_admin_usergroups = ["All-admin-users-deprecated"]
567
+ default_create_user_usergroups = ["All-users-deprecated"]
568
+ default_notification_users_usergroups = ["All-notification-users-deprecated"]
569
+ export_directory = "{ tmp_path } /exports_deprecated"
570
+ export_format = "yaml"
571
+ export_timestamps = true
544
572
use_colors = false
545
573
use_paging = true
546
574
output_format = "json"
547
575
system_id = "System-User"
548
576
577
+ ##### New options (should be used) #####
578
+
579
+ [api]
580
+ username = "Admin"
581
+
582
+ [app.commands.create_user]
583
+ usergroups = ["All-users"]
584
+
585
+ [app.commands.create_notification_user]
586
+ usergroups = ["All-notification-users"]
587
+
588
+ [app.commands.create_host]
589
+ hostgroups = ["All-hosts"]
590
+
591
+ [app.commands.create_hostgroup]
592
+ ro_groups = ["All-users"]
593
+ rw_groups = ["All-admin-users"]
594
+
595
+ [app.commands.export]
596
+ directory = "{ tmp_path } /exports"
597
+ format = "json"
598
+ timestamps = false
599
+
549
600
[app.output]
550
601
color = true
551
602
format = "table"
@@ -555,6 +606,18 @@ def test_load_deprecated_config_with_new_and_old_options(tmp_path: Path) -> None
555
606
config = Config .from_file (conf )
556
607
557
608
# New fields should NOT be overwritten by deprecated fields
609
+ assert config .app .commands .create_host .hostgroups == ["All-hosts" ]
610
+ assert config .app .commands .create_hostgroup .rw_groups == ["All-admin-users" ]
611
+ assert config .app .commands .create_hostgroup .ro_groups == ["All-users" ]
612
+ assert config .app .commands .create_user .usergroups == ["All-users" ]
613
+ assert config .app .commands .create_notification_user .usergroups == [
614
+ "All-notification-users"
615
+ ]
616
+ assert config .app .commands .create_hostgroup .ro_groups == ["All-users" ]
617
+ assert config .app .commands .create_hostgroup .rw_groups == ["All-admin-users" ]
618
+ assert config .app .commands .export .directory == tmp_path / "exports"
619
+ assert config .app .commands .export .format == OutputFormat .JSON
620
+ assert config .app .commands .export .timestamps is False
558
621
assert config .api .username == "Admin"
559
622
assert config .app .output .color is True
560
623
assert config .app .output .paging is False
0 commit comments