<commit_before>---
- name: Test junos_rpc module
  hosts: all
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
##################################################
####    TEST 1                                  ##
##################################################
    - name: "Execute single RPC get-software-information without any kwargs"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
      register: test1
      ignore_errors: True
      tags: [ test1 ]

    - name: Check TEST 1
      assert:
        that:
          - test1|succeeded
      tags: [ test1 ]

##################################################
####    TEST 2                                  ##
##################################################
    - name: "Get Device Configuration with dest"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpc: get-config
        dest: get_config.conf
      register: test2
      ignore_errors: True
      tags: [ test2 ]

    - name: Check that the get_config.conf exists
      stat:
        path: get_config.conf
      register: stat_result

    - name: Check TEST 2
      assert:
        that:
          - test2|succeeded
          - stat_result.stat.exists == True
      tags: [ test2 ]

    - name: Clean up TEST 2


#################

    - name: "Get Device Configuration in text"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpc: get-interface-information
        kwargs: "interface_name=em0"
        format: text
      register: test3
      ignore_errors: True
      tags: [ test3 ]

    - name: Check TEST 3
      assert:
        that:
          - test3|succeeded
      tags: [ test3 ]

#################

    - name: "Execute multiple RPCs without any kwargs"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
          - "get-interface-information"
      register: test4
      ignore_errors: True
      tags: [ test4 ]

    - name: Check TEST 4
      assert:
        that:
          - test4|succeeded
      tags: [ test4 ]

#################

    - name: "Execute multiple RPCs with multiple kwargs"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
          - "get-interface-information"
        kwargs:
          - {}
          - "interface_name=em0"
      register: test5
      ignore_errors: True
      tags: [ test5 ]

    - name: Check TEST 5
      assert:
        that:
          - test5|succeeded
      tags: [ test5 ]

#################
    - name: Creates directory
      file:
        path: out
        state: directory

    - name: "Execute multiple RPCs with multiple kwargs and dest-dir"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
          - "get-interface-information"
        kwargs:
          - {}
          - "interface_name=em0"
        dest_dir: "out"
      register: test6
      ignore_errors: True
      tags: [ test6 ]

    - name: Check that the get_config.conf exists
      stat:
        path: out
      register: stat_result_1

    - name: Check TEST 6
      assert:
        that:
          - test6|succeeded
          - stat_result_1.stat.exists == True
      tags: [ test6 ]

#################

    - name: Get Device Configuration for interface
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpc: get-config
        filter_xml: "<configuration><interfaces/></configuration>"
      register: test7
      ignore_errors: True
      tags: [ test7 ]

    - name: Check TEST 7
      assert:
        that:
          - test7|succeeded
      tags: [ test7 ]

#################<commit_msg>Fixed tests for juniper_junos_rpc<commit_after>---
- name: Test junos_rpc module
  hosts: all
  connection: local
  gather_facts: no
  roles:
    - Juniper.junos

  tasks:
#################
    - name: "Execute single RPC get-software-information without any kwargs"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
      register: test1
      ignore_errors: True
      tags: [ test1 ]

    - name: Check TEST 1
      assert:
        that:
          - test1|succeeded
      tags: [ test1 ]

#################
    - name: "Get Device Configuration with dest"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpc: get-config
        dest: get_config.conf
      register: test2
      ignore_errors: True
      tags: [ test2 ]

    - name: Check that the get_config.conf exists
      stat:
        path: get_config.conf
      register: stat_result

    - name: Check TEST 2
      assert:
        that:
          - test2|succeeded
          - stat_result.stat.exists == True
      tags: [ test2 ]

    - name: Clean up TEST 2
      file:
        path: get_config.conf
        state: absent


#################

    - name: "Get Device Configuration in text"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpc: get-interface-information
        kwargs: "interface_name=em0"
        format: text
      register: test3
      ignore_errors: True
      tags: [ test3 ]

    - name: Check TEST 3
      assert:
        that:
          - test3|succeeded
      tags: [ test3 ]

#################

    - name: "Execute multiple RPCs without any kwargs"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
          - "get-interface-information"
      register: test4
      ignore_errors: True
      tags: [ test4 ]

    - name: Check TEST 4
      assert:
        that:
          - test4|succeeded
      tags: [ test4 ]

#################

    - name: "Execute multiple RPCs with multiple kwargs"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
          - "get-interface-information"
        kwargs:
          - {}
          - "interface_name=em0"
      register: test5
      ignore_errors: True
      tags: [ test5 ]

    - name: Check TEST 5
      assert:
        that:
          - test5|succeeded
      tags: [ test5 ]

#################
    - name: Creates directory
      file:
        path: out
        state: directory

    - name: "Execute multiple RPCs with multiple kwargs and dest-dir"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "get-software-information"
          - "get-interface-information"
        kwargs:
          - {}
          - "interface_name=em0"
        dest_dir: "out"
      register: test6
      ignore_errors: True
      tags: [ test6 ]

    - name: Check that the get_config.conf exists
      stat:
        path: out
      register: stat_result_1

    - name: Check TEST 6
      assert:
        that:
          - test6|succeeded
          - stat_result_1.stat.exists == True
      tags: [ test6 ]

    - name: Clean up TEST 6
      file:
        path: get_config.conf
        state: absent

#################
    - name: Get Device Configuration for interface
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpc: get-config
        filter_xml: "<configuration><interfaces/></configuration>"
      register: test7
      ignore_errors: True
      tags: [ test7 ]

    - name: Check TEST 7
      assert:
        that:
          - test7|succeeded
      tags: [ test7 ]

#################
    - name: "Execute wrong RPC to generate RPC error"
      juniper_junos_rpc:
        host: "{{ ansible_ssh_host }}"
        port: "{{ ansible_ssh_port }}"
        user: "{{ ansible_ssh_user }}"
        passwd: "{{ <PASSWORD> }}"
        rpcs:
          - "wrong-rpc"
      register: test8
      ignore_errors: True
      tags: [ test5 ]

    - name: Check TEST 8
      assert:
        that:
          - test8|failed
      tags: [ test8 ]

#################
{'fraction_non_alphanumeric': 0.15411137812140843, 'fraction_numerical': 0.009403406122662208, 'mean_word_length': 1.8344684631329582, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4799272', 'n_tokens_mistral': 3079, 'n_tokens_neox': 2923, 'n_words': 658}