1# -*- coding: utf-8 -*- 2# Copyright 2020 Red Hat 3# GNU General Public License v3.0+ 4# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) 5 6############################################# 7# WARNING # 8############################################# 9# 10# This file is auto generated by the resource 11# module builder playbook. 12# 13# Do not edit this file manually. 14# 15# Changes to this file will be over written 16# by the resource module builder. 17# 18# Changes should be made in the model used to 19# generate this file or in the resource module 20# builder template. 21# 22############################################# 23 24from __future__ import absolute_import, division, print_function 25 26__metaclass__ = type 27 28from ansible_collections.junipernetworks.junos.tests.unit.compat.mock import ( 29 patch, 30) 31from ansible_collections.junipernetworks.junos.plugins.modules import ( 32 junos_logging_global, 33) 34from ansible_collections.junipernetworks.junos.tests.unit.modules.utils import ( 35 set_module_args, 36) 37from .junos_module import TestJunosModule, load_fixture 38 39 40class TestJunosLogging_globalModule(TestJunosModule): 41 module = junos_logging_global 42 43 def setUp(self): 44 super(TestJunosLogging_globalModule, self).setUp() 45 46 self.mock_lock_configuration = patch( 47 "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.lock_configuration" 48 ) 49 self.lock_configuration = self.mock_lock_configuration.start() 50 51 self.mock_unlock_configuration = patch( 52 "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.junos.unlock_configuration" 53 ) 54 self.unlock_configuration = self.mock_unlock_configuration.start() 55 56 self.mock_load_config = patch( 57 "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.logging_global.logging_global.load_config" 58 ) 59 self.load_config = self.mock_load_config.start() 60 61 self.mock_commit_configuration = patch( 62 "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.config.logging_global.logging_global.commit_configuration" 63 ) 64 self.mock_commit_configuration = self.mock_commit_configuration.start() 65 66 self.mock_execute_show_command = patch( 67 "ansible_collections.junipernetworks.junos.plugins.module_utils.network.junos.facts.logging_global.logging_global." 68 "Logging_globalFacts.get_device_data" 69 ) 70 self.execute_show_command = self.mock_execute_show_command.start() 71 72 def tearDown(self): 73 super(TestJunosLogging_globalModule, self).tearDown() 74 self.mock_load_config.stop() 75 self.mock_lock_configuration.stop() 76 self.mock_unlock_configuration.stop() 77 self.mock_commit_configuration.stop() 78 self.mock_execute_show_command.stop() 79 80 def load_fixtures( 81 self, commands=None, format="text", changed=False, filename=None 82 ): 83 def load_from_file(*args, **kwargs): 84 output = load_fixture("junos_logging_global_config.cfg") 85 return output 86 87 self.execute_show_command.side_effect = load_from_file 88 89 def test_junos_logging_global_merged_archive_01(self): 90 set_module_args( 91 dict( 92 config=dict( 93 archive=dict( 94 set=True, 95 files=10, 96 file_size=65578, 97 no_binary_data=True, 98 no_world_readable=True, 99 ) 100 ), 101 state="merged", 102 ) 103 ) 104 commands = [ 105 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 106 "<nc:syslog><nc:archive><nc:files>10</nc:files>" 107 "<nc:no-binary-data/><nc:size>65578</nc:size><nc:no-world-readable/>" 108 "</nc:archive></nc:syslog></nc:system>" 109 ] 110 result = self.execute_module(changed=True, commands=commands) 111 self.assertEqual(sorted(result["commands"]), sorted(commands)) 112 113 def test_junos_logging_global_merged_console_02(self): 114 set_module_args( 115 dict( 116 config=dict( 117 console=dict( 118 any=dict(level="info"), 119 authorization=dict(level="any"), 120 change_log=dict(level="critical"), 121 ftp=dict(level="none"), 122 ) 123 ), 124 state="merged", 125 ) 126 ) 127 result = self.execute_module(changed=True) 128 self.assertIn( 129 "<nc:console><nc:name>any</nc:name><nc:info/>", 130 str(result["commands"]), 131 ) 132 self.assertIn( 133 "<nc:console><nc:name>authorization</nc:name><nc:any/>", 134 str(result["commands"]), 135 ) 136 self.assertIn( 137 "<nc:console><nc:name>change-log</nc:name><nc:critical/>", 138 str(result["commands"]), 139 ) 140 self.assertIn( 141 "<nc:console><nc:name>ftp</nc:name><nc:none/>", 142 str(result["commands"]), 143 ) 144 145 def test_junos_logging_global_merged_files_03(self): 146 set_module_args( 147 dict( 148 config=dict( 149 files=[dict(name="file101", allow_duplicates=True)] 150 ), 151 state="merged", 152 ) 153 ) 154 commands = [ 155 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 156 "<nc:syslog><nc:file><nc:name>file101</nc:name>" 157 "<nc:allow-duplicates/></nc:file></nc:syslog></nc:system>" 158 ] 159 result = self.execute_module(changed=True, commands=commands) 160 self.assertEqual(sorted(result["commands"]), sorted(commands)) 161 162 def test_junos_logging_global_merged_files_04(self): 163 set_module_args( 164 dict( 165 config=dict( 166 files=[ 167 dict( 168 name="file102", 169 allow_duplicates=True, 170 any=dict(level="any"), 171 structured_data=dict(set=True), 172 ), 173 dict( 174 name="file103", 175 archive=dict( 176 set=True, 177 no_binary_data=True, 178 files=10, 179 file_size=65578, 180 no_world_readable=True, 181 ), 182 explicit_priority=True, 183 match="^set*", 184 match_strings=["^delete", "^prompt"], 185 ), 186 ] 187 ), 188 state="merged", 189 ) 190 ) 191 commands = [ 192 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 193 "<nc:syslog><nc:file><nc:name>file102</nc:name><nc:allow-duplicates/>" 194 "<nc:contents><nc:name>any</nc:name><nc:any/></nc:contents>" 195 "<nc:structured-data/></nc:file><nc:file><nc:name>file103</nc:name>" 196 "<nc:archive><nc:files>10</nc:files><nc:no-binary-data/>" 197 "<nc:size>65578</nc:size><nc:no-world-readable/>" 198 "</nc:archive><nc:explicit-priority/><nc:match>^set*</nc:match>" 199 "<nc:match-strings>^delete</nc:match-strings>" 200 "<nc:match-strings>^prompt</nc:match-strings></nc:file></nc:syslog></nc:system>" 201 ] 202 result = self.execute_module(changed=True, commands=commands) 203 self.assertEqual(sorted(result["commands"]), sorted(commands)) 204 205 def test_junos_logging_global_merged_hosts_05(self): 206 set_module_args( 207 dict( 208 config=dict( 209 hosts=[ 210 dict( 211 name="host222", 212 exclude_hostname=True, 213 allow_duplicates=True, 214 ) 215 ] 216 ), 217 state="merged", 218 ) 219 ) 220 commands = [ 221 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 222 "<nc:syslog><nc:host><nc:name>host222</nc:name><nc:allow-duplicates/>" 223 "<nc:exclude-hostname/></nc:host></nc:syslog></nc:system>" 224 ] 225 result = self.execute_module(changed=True, commands=commands) 226 self.assertEqual(sorted(result["commands"]), sorted(commands)) 227 228 def test_junos_logging_global_merged_hosts_idempotent_06(self): 229 set_module_args( 230 dict( 231 config=dict( 232 hosts=[ 233 dict( 234 name="host111", 235 exclude_hostname=True, 236 allow_duplicates=True, 237 any=dict(level="any"), 238 structured_data=dict(set=True, brief=True), 239 facility_override="ftp", 240 log_prefix="field", 241 match="^set*", 242 match_strings=["^delete", "^prompt"], 243 port=1231, 244 routing_instance="inst11", 245 source_address="11.11.11.11", 246 ) 247 ] 248 ), 249 state="merged", 250 ) 251 ) 252 result = self.execute_module(changed=True) 253 self.assertEqual(result["before"], result["after"]) 254 255 def test_junos_logging_global_merged_07(self): 256 set_module_args( 257 dict( 258 config=dict( 259 allow_duplicates=True, 260 routing_instance="inst11", 261 log_rotate_frequency=45, 262 source_address="33.33.33.33", 263 time_format=dict(millisecond=True, year=True), 264 ), 265 state="merged", 266 ) 267 ) 268 commands = [ 269 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 270 "<nc:syslog><nc:allow-duplicates/><nc:log-rotate-frequency>45</nc:log-rotate-frequency>" 271 "<nc:routing-instance>inst11</nc:routing-instance><nc:source-address>33.33.33.33</nc:source-address>" 272 "<nc:time-format><nc:millisecond/><nc:year/></nc:time-format></nc:syslog></nc:system>" 273 ] 274 result = self.execute_module(changed=True, commands=commands) 275 self.assertEqual(sorted(result["commands"]), sorted(commands)) 276 277 def test_junos_logging_global_merged_user_08(self): 278 set_module_args( 279 dict( 280 config=dict( 281 users=[ 282 dict(name="user1", allow_duplicates=True), 283 dict( 284 name="user2", 285 allow_duplicates=True, 286 any=dict(level="any"), 287 user=dict(level="info"), 288 ), 289 ] 290 ), 291 state="merged", 292 ) 293 ) 294 result = self.execute_module(changed=True) 295 self.assertIn( 296 "<nc:user><nc:name>user1</nc:name><nc:allow-duplicates/>", 297 str(result["commands"]), 298 ) 299 self.assertIn( 300 "<nc:user><nc:name>user2</nc:name><nc:allow-duplicates/>", 301 str(result["commands"]), 302 ) 303 self.assertIn( 304 "<nc:contents><nc:name>any</nc:name><nc:any/></nc:contents>", 305 str(result["commands"]), 306 ) 307 308 def test_junos_logging_global_replaced_user_09(self): 309 set_module_args( 310 dict( 311 config=dict( 312 users=[ 313 dict(name="user1", allow_duplicates=True), 314 dict( 315 name="user2", 316 allow_duplicates=True, 317 any=dict(level="any"), 318 user=dict(level="info"), 319 ), 320 ] 321 ), 322 state="replaced", 323 ) 324 ) 325 result = self.execute_module(changed=True) 326 self.assertIn( 327 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', 328 str(result["commands"]), 329 ) 330 self.assertIn( 331 '<nc:syslog delete="delete"/><nc:syslog><nc:user><nc:name>user1</nc:name>', 332 str(result["commands"]), 333 ) 334 self.assertIn( 335 "<nc:allow-duplicates/></nc:user><nc:user><nc:name>user2</nc:name>", 336 str(result["commands"]), 337 ) 338 self.assertIn( 339 "</nc:contents></nc:user></nc:syslog></nc:system>", 340 str(result["commands"]), 341 ) 342 343 def test_junos_logging_global_overridden_user_10(self): 344 set_module_args( 345 dict( 346 config=dict( 347 users=[ 348 dict(name="user1", allow_duplicates=True), 349 dict( 350 name="user2", 351 allow_duplicates=True, 352 any=dict(level="any"), 353 user=dict(level="info"), 354 ), 355 ] 356 ), 357 state="overridden", 358 ) 359 ) 360 result = self.execute_module(changed=True) 361 self.assertIn( 362 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">', 363 str(result["commands"]), 364 ) 365 self.assertIn( 366 '<nc:syslog delete="delete"/><nc:syslog><nc:user><nc:name>user1</nc:name>', 367 str(result["commands"]), 368 ) 369 self.assertIn( 370 "<nc:allow-duplicates/></nc:user><nc:user><nc:name>user2</nc:name>", 371 str(result["commands"]), 372 ) 373 374 def test_junos_logging_global_deleted_user_11(self): 375 set_module_args(dict(config=dict(), state="deleted")) 376 commands = [ 377 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 378 '<nc:syslog delete="delete"/></nc:system>' 379 ] 380 result = self.execute_module(changed=True, commands=commands) 381 self.assertEqual(sorted(result["commands"]), sorted(commands)) 382 383 def test_junos_logging_global_rendered_12(self): 384 set_module_args( 385 dict( 386 config=dict( 387 archive=dict( 388 set=True, 389 files=10, 390 file_size=65578, 391 no_binary_data=True, 392 no_world_readable=True, 393 ) 394 ), 395 state="rendered", 396 ) 397 ) 398 rendered = ( 399 '<nc:system xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">' 400 "<nc:syslog><nc:archive><nc:files>10</nc:files><nc:no-binary-data/>" 401 "<nc:size>65578</nc:size><nc:no-world-readable/></nc:archive></nc:syslog></nc:system>" 402 ) 403 result = self.execute_module(changed=False) 404 405 self.assertEqual(sorted(result["rendered"]), sorted(rendered)) 406 407 def test_junos_logging_global_parsed_13(self): 408 parsed_str = """ 409 <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> 410 <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> 411 <version>18.4R1-S2.4</version> 412 <system> 413 <syslog> 414 <archive> 415 <size>65578</size> 416 <files>10</files> 417 <no-world-readable/> 418 <no-binary-data/> 419 </archive> 420 <user> 421 <name>user1</name> 422 <allow-duplicates/> 423 </user> 424 <user> 425 <name>user2</name> 426 <contents> 427 <name>any</name> 428 <any/> 429 </contents> 430 <contents> 431 <name>user</name> 432 <info/> 433 </contents> 434 <allow-duplicates/> 435 </user> 436 <host> 437 <name>host111</name> 438 <contents> 439 <name>any</name> 440 <any/> 441 </contents> 442 <match>^set*</match> 443 <allow-duplicates/> 444 <port>1231</port> 445 <facility-override>ftp</facility-override> 446 <log-prefix>field</log-prefix> 447 <source-address>11.1.1.11</source-address> 448 <routing-instance>inst11</routing-instance> 449 <exclude-hostname/> 450 <match-strings>^delete</match-strings> 451 <match-strings>^prompt</match-strings> 452 <structured-data> 453 <brief/> 454 </structured-data> 455 </host> 456 <allow-duplicates/> 457 <file> 458 <name>file101</name> 459 <allow-duplicates/> 460 </file> 461 <file> 462 <name>file102</name> 463 <contents> 464 <name>any</name> 465 <any/> 466 </contents> 467 <allow-duplicates/> 468 <structured-data> 469 </structured-data> 470 </file> 471 <file> 472 <name>file103</name> 473 <match>^set*</match> 474 <archive> 475 <size>65578</size> 476 <files>10</files> 477 <no-world-readable/> 478 <no-binary-data/> 479 </archive> 480 <explicit-priority/> 481 <match-strings>^delete</match-strings> 482 <match-strings>^prompt</match-strings> 483 </file> 484 <console> 485 <name>any</name> 486 <info/> 487 </console> 488 <console> 489 <name>authorization</name> 490 <any/> 491 </console> 492 <console> 493 <name>ftp</name> 494 <none/> 495 </console> 496 <console> 497 <name>change-log</name> 498 <critical/> 499 </console> 500 <time-format> 501 <year/> 502 <millisecond/> 503 </time-format> 504 <source-address>33.33.33.33</source-address> 505 <routing-instance>inst11</routing-instance> 506 <log-rotate-frequency>45</log-rotate-frequency> 507 </syslog> 508 </system> 509 </configuration> 510 </rpc-reply> 511 """ 512 set_module_args(dict(running_config=parsed_str, state="parsed")) 513 result = self.execute_module(changed=False) 514 parsed_dict = { 515 "allow_duplicates": True, 516 "archive": { 517 "file_size": 65578, 518 "files": 10, 519 "no_binary_data": True, 520 "no_world_readable": True, 521 }, 522 "console": { 523 "any": {"level": "info"}, 524 "authorization": {"level": "any"}, 525 "change_log": {"level": "critical"}, 526 "ftp": {"level": "none"}, 527 }, 528 "files": [ 529 {"allow_duplicates": True, "name": "file101"}, 530 { 531 "allow_duplicates": True, 532 "any": {"level": "any"}, 533 "name": "file102", 534 "structured_data": {"set": True}, 535 }, 536 { 537 "archive": { 538 "file_size": 65578, 539 "files": 10, 540 "no_binary_data": True, 541 "no_world_readable": True, 542 }, 543 "explicit_priority": True, 544 "match": "^set*", 545 "match_strings": ["^delete", "^prompt"], 546 "name": "file103", 547 }, 548 ], 549 "hosts": [ 550 { 551 "allow_duplicates": True, 552 "any": {"level": "any"}, 553 "exclude_hostname": True, 554 "facility_override": "ftp", 555 "log_prefix": "field", 556 "match": "^set*", 557 "match_strings": ["^delete", "^prompt"], 558 "name": "host111", 559 "port": 1231, 560 "routing_instance": "inst11", 561 "source_address": "11.1.1.11", 562 "structured_data": {"brief": True}, 563 } 564 ], 565 "log_rotate_frequency": 45, 566 "routing_instance": "inst11", 567 "source_address": "33.33.33.33", 568 "time_format": {"millisecond": True, "year": True}, 569 "users": [ 570 {"allow_duplicates": True, "name": "user1"}, 571 { 572 "allow_duplicates": True, 573 "any": {"level": "any"}, 574 "name": "user2", 575 "user": {"level": "info"}, 576 }, 577 ], 578 } 579 self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) 580 581 def test_junos_logging_global_gathered_14(self): 582 """ 583 :return: 584 """ 585 set_module_args(dict(state="gathered")) 586 result = self.execute_module(changed=False) 587 gather_list = { 588 "hosts": [ 589 { 590 "name": "host111", 591 "allow_duplicates": True, 592 "any": {"level": "any"}, 593 "exclude_hostname": True, 594 "facility_override": "ftp", 595 "log_prefix": "field", 596 "match": "^set*", 597 "match_strings": ["^delete", "^prompt"], 598 "port": 1231, 599 "routing_instance": "inst11", 600 "source_address": "11.1.1.11", 601 "structured_data": {"brief": True}, 602 } 603 ] 604 } 605 self.assertEqual(sorted(gather_list), sorted(result["gathered"])) 606 607 def test_junos_logging_global_parsed_15(self): 608 parsed_str = """ 609 <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> 610 <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> 611 <version>18.4R1-S2.4</version> 612 <system> 613 <syslog> 614 <archive> 615 <size>65578</size> 616 <files>10</files> 617 <world-readable/> 618 <binary-data/> 619 </archive> 620 <user> 621 <name>user1</name> 622 <allow-duplicates/> 623 </user> 624 <user> 625 <name>user2</name> 626 <contents> 627 <name>any</name> 628 <any/> 629 </contents> 630 <contents> 631 <name>user</name> 632 <info/> 633 </contents> 634 <allow-duplicates/> 635 </user> 636 <host> 637 <name>host111</name> 638 <contents> 639 <name>any</name> 640 <any/> 641 </contents> 642 <match>^set*</match> 643 <allow-duplicates/> 644 <port>1231</port> 645 <facility-override>ftp</facility-override> 646 <log-prefix>field</log-prefix> 647 <source-address>11.1.1.11</source-address> 648 <routing-instance>inst11</routing-instance> 649 <exclude-hostname/> 650 <match-strings>^delete</match-strings> 651 <match-strings>^prompt</match-strings> 652 <structured-data> 653 <brief/> 654 </structured-data> 655 </host> 656 <allow-duplicates/> 657 <file> 658 <name>file101</name> 659 <allow-duplicates/> 660 <archive-sites> 661 <name>www.antsiblr.com</name> 662 </archive-sites> 663 </file> 664 <file> 665 <name>file102</name> 666 <contents> 667 <name>any</name> 668 <any/> 669 </contents> 670 <allow-duplicates/> 671 <structured-data> 672 </structured-data> 673 </file> 674 <file> 675 <name>file103</name> 676 <match>^set*</match> 677 <archive> 678 <size>65578</size> 679 <files>10</files> 680 <no-world-readable/> 681 <no-binary-data/> 682 </archive> 683 <explicit-priority/> 684 <match-strings>^delete</match-strings> 685 <match-strings>^prompt</match-strings> 686 </file> 687 <console> 688 <name>any</name> 689 <info/> 690 </console> 691 <console> 692 <name>authorization</name> 693 <any/> 694 </console> 695 <console> 696 <name>ftp</name> 697 <none/> 698 </console> 699 <console> 700 <name>change-log</name> 701 <critical/> 702 </console> 703 <time-format> 704 </time-format> 705 <source-address>33.33.33.33</source-address> 706 <routing-instance>inst11</routing-instance> 707 <log-rotate-frequency>45</log-rotate-frequency> 708 </syslog> 709 </system> 710 </configuration> 711 </rpc-reply> 712 """ 713 set_module_args(dict(running_config=parsed_str, state="parsed")) 714 result = self.execute_module(changed=False) 715 parsed_dict = { 716 "allow_duplicates": True, 717 "archive": { 718 "file_size": 65578, 719 "files": 10, 720 "no_binary_data": True, 721 "no_world_readable": True, 722 }, 723 "console": { 724 "any": {"level": "info"}, 725 "authorization": {"level": "any"}, 726 "change_log": {"level": "critical"}, 727 "ftp": {"level": "none"}, 728 }, 729 "files": [ 730 { 731 "allow_duplicates": True, 732 "name": "file101", 733 "archive_sites": ["www.antsiblr.com"], 734 }, 735 { 736 "allow_duplicates": True, 737 "any": {"level": "any"}, 738 "name": "file102", 739 "structured_data": {"set": True}, 740 }, 741 { 742 "archive": { 743 "file_size": 65578, 744 "files": 10, 745 "binary_data": True, 746 "world_readable": True, 747 }, 748 "explicit_priority": True, 749 "match": "^set*", 750 "match_strings": ["^delete", "^prompt"], 751 "name": "file103", 752 }, 753 ], 754 "hosts": [ 755 { 756 "allow_duplicates": True, 757 "any": {"level": "any"}, 758 "exclude_hostname": True, 759 "facility_override": "ftp", 760 "log_prefix": "field", 761 "match": "^set*", 762 "match_strings": ["^delete", "^prompt"], 763 "name": "host111", 764 "port": 1231, 765 "routing_instance": "inst11", 766 "source_address": "11.1.1.11", 767 "structured_data": {"brief": True}, 768 } 769 ], 770 "log_rotate_frequency": 45, 771 "routing_instance": "inst11", 772 "source_address": "33.33.33.33", 773 "time_format": {"set": True}, 774 "users": [ 775 {"allow_duplicates": True, "name": "user1"}, 776 { 777 "allow_duplicates": True, 778 "any": {"level": "any"}, 779 "name": "user2", 780 "user": {"level": "info"}, 781 }, 782 ], 783 } 784 self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) 785 786 def test_junos_logging_global_parsed_16(self): 787 parsed_str = """ 788 <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> 789 <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> 790 <version>18.4R1-S2.4</version> 791 <system> 792 <syslog> 793 <archive> 794 <size>65578</size> 795 <files>10</files> 796 <world-readable/> 797 <binary-data/> 798 </archive> 799 <user> 800 <name>user1</name> 801 <allow-duplicates/> 802 <match-strings>^delete</match-strings> 803 <match-strings>^prompt</match-strings> 804 </user> 805 <user> 806 <name>user2</name> 807 <contents> 808 <name>any</name> 809 <any/> 810 </contents> 811 <contents> 812 <name>user</name> 813 <info/> 814 </contents> 815 <allow-duplicates/> 816 </user> 817 <host> 818 <name>host111</name> 819 <contents> 820 <name>any</name> 821 <any/> 822 </contents> 823 <match>^set*</match> 824 <allow-duplicates/> 825 <port>1231</port> 826 <facility-override>ftp</facility-override> 827 <log-prefix>field</log-prefix> 828 <source-address>11.1.1.11</source-address> 829 <routing-instance>inst11</routing-instance> 830 <exclude-hostname/> 831 <match-strings>^delete</match-strings> 832 <match-strings>^prompt</match-strings> 833 <structured-data> 834 <brief/> 835 </structured-data> 836 </host> 837 <allow-duplicates/> 838 <file> 839 <name>file101</name> 840 <allow-duplicates/> 841 <archive-sites> 842 <name>www.antsiblr.com</name> 843 <name>www.antsiblr2.com</name> 844 </archive-sites> 845 <contents> 846 <name>any</name> 847 <any/> 848 </contents> 849 <contents> 850 <name>authorization</name> 851 <any/> 852 </contents> 853 <structured-data> 854 <brief/> 855 </structured-data> 856 </file> 857 <console> 858 <name>any</name> 859 <info/> 860 </console> 861 <console> 862 <name>authorization</name> 863 <any/> 864 </console> 865 <console> 866 <name>ftp</name> 867 <none/> 868 </console> 869 <console> 870 <name>change-log</name> 871 <critical/> 872 </console> 873 <time-format> 874 </time-format> 875 <source-address>33.33.33.33</source-address> 876 <routing-instance>inst11</routing-instance> 877 <log-rotate-frequency>45</log-rotate-frequency> 878 </syslog> 879 </system> 880 </configuration> 881 </rpc-reply> 882 """ 883 set_module_args(dict(running_config=parsed_str, state="parsed")) 884 result = self.execute_module(changed=False) 885 parsed_dict = { 886 "allow_duplicates": True, 887 "archive": { 888 "file_size": 65578, 889 "files": 10, 890 "no_binary_data": True, 891 "no_world_readable": True, 892 }, 893 "console": { 894 "any": {"level": "info"}, 895 "authorization": {"level": "any"}, 896 "change_log": {"level": "critical"}, 897 "ftp": {"level": "none"}, 898 }, 899 "files": [ 900 { 901 "allow_duplicates": True, 902 "name": "file101", 903 "archive_sites": ["www.antsiblr.com", "www.antsiblr2.com"], 904 "any": {"level": "any"}, 905 "authorization": {"level": "any"}, 906 "structured_data": {"brief": True}, 907 } 908 ], 909 "hosts": [ 910 { 911 "allow_duplicates": True, 912 "any": {"level": "any"}, 913 "exclude_hostname": True, 914 "facility_override": "ftp", 915 "log_prefix": "field", 916 "match": "^set*", 917 "match_strings": ["^delete", "^prompt"], 918 "name": "host111", 919 "port": 1231, 920 "routing_instance": "inst11", 921 "source_address": "11.1.1.11", 922 "structured_data": {"brief": True}, 923 } 924 ], 925 "log_rotate_frequency": 45, 926 "routing_instance": "inst11", 927 "source_address": "33.33.33.33", 928 "time_format": {"set": True}, 929 "users": [ 930 { 931 "allow_duplicates": True, 932 "name": "user1", 933 "match_strings": ["^delete", "^prompt"], 934 }, 935 { 936 "allow_duplicates": True, 937 "any": {"level": "any"}, 938 "name": "user2", 939 "user": {"level": "info"}, 940 }, 941 ], 942 } 943 self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) 944 945 def test_junos_logging_global_parsed_17(self): 946 parsed_str = """ 947 <rpc-reply message-id="urn:uuid:0cadb4e8-5bba-47f4-986e-72906227007f"> 948 <configuration changed-seconds="1590139550" changed-localtime="2020-05-22 09:25:50 UTC"> 949 <version>18.4R1-S2.4</version> 950 <system> 951 <syslog> 952 <user> 953 <name>user1</name> 954 <match>^set*</match> 955 <match-strings>^delete</match-strings> 956 <contents> 957 <name>user</name> 958 <info/> 959 </contents> 960 </user> 961 <host> 962 <name>host111</name> 963 <contents> 964 <name>any</name> 965 <any/> 966 </contents> 967 <contents> 968 <name>authorization</name> 969 <any/> 970 </contents> 971 <match-strings>^delete</match-strings> 972 <structured-data> 973 </structured-data> 974 </host> 975 <file> 976 <name>file101</name> 977 <match-strings>^delete</match-strings> 978 <archive> 979 <archive-sites> 980 <name>www.antsiblr.com</name> 981 </archive-sites> 982 <archive-sites> 983 <name>www.antsiblr2.com</name> 984 </archive-sites> 985 </archive> 986 </file> 987 </syslog> 988 </system> 989 </configuration> 990 </rpc-reply> 991 """ 992 set_module_args(dict(running_config=parsed_str, state="parsed")) 993 result = self.execute_module(changed=False) 994 parsed_dict = { 995 "files": [ 996 { 997 "allow_duplicates": True, 998 "name": "file101", 999 "archive": { 1000 "archive_sites": [ 1001 "www.antsiblr.com", 1002 "www.antsiblr2.com", 1003 ] 1004 }, 1005 "any": {"level": "any"}, 1006 "authorization": {"level": "any"}, 1007 "structured_data": {"brief": True}, 1008 } 1009 ], 1010 "hosts": [ 1011 { 1012 "any": {"level": "any"}, 1013 "authorization": {"level": "any"}, 1014 "match_strings": ["^delete"], 1015 "name": "host111", 1016 "structured_data": {"set": True}, 1017 } 1018 ], 1019 "users": [ 1020 { 1021 "name": "user1", 1022 "user": {"level": "info"}, 1023 "match": "^set*", 1024 "match_strings": ["^delete"], 1025 } 1026 ], 1027 } 1028 self.assertEqual(sorted(parsed_dict), sorted(result["parsed"])) 1029