diff options
Diffstat (limited to 'test')
16 files changed, 464 insertions, 4 deletions
| diff --git a/test/integration/integration_config.yml b/test/integration/integration_config.yml deleted file mode 100644 index 6b47a35d..00000000 --- a/test/integration/integration_config.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -win_output_dir: 'C:\ansible_testing' -output_dir: ~/ansible_testing diff --git a/test/integration/target-prefixes.network b/test/integration/target-prefixes.network index 2d0f40cd..0c45ebaf 100644 --- a/test/integration/target-prefixes.network +++ b/test/integration/target-prefixes.network @@ -1 +1 @@ -vyos +vyos
\ No newline at end of file diff --git a/test/integration/targets/prepare_vyos_tests/tasks/main.yaml b/test/integration/targets/prepare_vyos_tests/tasks/main.yaml index a156ea47..1a81fb17 100644 --- a/test/integration/targets/prepare_vyos_tests/tasks/main.yaml +++ b/test/integration/targets/prepare_vyos_tests/tasks/main.yaml @@ -5,6 +5,8 @@    vars:      lines: |        set interfaces ethernet eth0 address dhcp +      set interfaces ethernet eth0 speed auto +      set interfaces ethernet eth0 duplex auto        set interfaces ethernet eth1        set interfaces ethernet eth2        delete interfaces loopback lo diff --git a/test/integration/targets/vyos_lldp_interfaces/defaults/main.yaml b/test/integration/targets/vyos_lldp_interfaces/defaults/main.yaml new file mode 100644 index 00000000..164afead --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/defaults/main.yaml @@ -0,0 +1,3 @@ +--- +testcase: "[^_].*" +test_items: [] diff --git a/test/integration/targets/vyos_lldp_interfaces/meta/main.yaml b/test/integration/targets/vyos_lldp_interfaces/meta/main.yaml new file mode 100644 index 00000000..f88bce55 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/meta/main.yaml @@ -0,0 +1,2 @@ +dependencies: +  - prepare_vyos_tests diff --git a/test/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml b/test/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml new file mode 100644 index 00000000..655e51ee --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tasks/cli.yaml @@ -0,0 +1,19 @@ +--- +- name: Collect all cli test cases +  find: +    paths: "{{ role_path }}/tests/cli" +    patterns: "{{ testcase }}.yaml" +    use_regex: true +  register: test_cases +  delegate_to: localhost + +- name: Set test_items +  set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}" + +- name: Run test case (connection=network_cli) +  include: "{{ test_case_to_run }}" +  vars: +    ansible_connection: network_cli +  with_items: "{{ test_items }}" +  loop_control: +    loop_var: test_case_to_run diff --git a/test/integration/targets/vyos_lldp_interfaces/tasks/main.yaml b/test/integration/targets/vyos_lldp_interfaces/tasks/main.yaml new file mode 100644 index 00000000..415c99d8 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml new file mode 100644 index 00000000..80f7d1a1 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate.yaml @@ -0,0 +1,14 @@ +--- +- name: Setup +  network.cli.cli_config: +    config: "{{ lines }}" +  vars: +    lines: | +      set service lldp interface eth1 +      set service lldp interface eth1 location civic-based country-code US +      set service lldp interface eth1 location civic-based ca-type 0 ca-value ENGLISH +      set service lldp interface eth2 +      set service lldp interface eth2 location coordinate-based latitude 33.524449N +      set service lldp interface eth2 location coordinate-based altitude 2200 +      set service lldp interface eth2 location coordinate-based datum WGS84 +      set service lldp interface eth2 location coordinate-based longitude 222.267255W diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml new file mode 100644 index 00000000..ee9a9bda --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_populate_intf.yaml @@ -0,0 +1,10 @@ +--- +- name: Setup +  network.cli.cli_config: +    config: "{{ lines }}" +  vars: +    lines: | +      set service lldp interface eth2 +      set service lldp interface eth2 location civic-based country-code US +      set service lldp interface eth2 location civic-based ca-type 0 ca-value ENGLISH +      set service lldp interface eth2 disable diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml new file mode 100644 index 00000000..e3abbdb3 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/_remove_config.yaml @@ -0,0 +1,8 @@ +--- +- name: Remove Config +  network.cli.cli_config: +    config: "{{ lines }}" +  vars: +    lines: | +      delete service lldp interface +      delete service lldp  diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml new file mode 100644 index 00000000..bd7c713f --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/deleted.yaml @@ -0,0 +1,46 @@ +--- +- debug: +    msg: "Start vyos_lldp_interfaces deleted integration tests ansible_connection={{ ansible_connection }}" + +- include_tasks: _populate.yaml + +- block: +  - name: Delete attributes of given LLDP interfaces. +    vyos.vyos.vyos_lldp_interfaces: &deleted +      config: +        - name: 'eth1' +        - name: 'eth2' +      state: deleted +    register: result + +  - name: Assert that the before dicts were correctly generated +    assert: +      that: +        - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + +  - name: Assert that the correct set of commands were generated +    assert: +      that: +        - "{{ deleted['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + +  - name: Assert that the after dicts were correctly generated +    assert: +      that: +        - "{{ deleted['after'] | symmetric_difference(result['after']) |length == 0 }}" + +  - name: Delete attributes of given interfaces (IDEMPOTENT) +    vyos.vyos.vyos_lldp_interfaces: *deleted +    register: result + +  - name: Assert that the previous task was idempotent +    assert: +      that: +        - "result.changed == false" +        - "result.commands|length == 0" + +  - name: Assert that the before dicts were correctly generated +    assert: +      that: +        - "{{ deleted['after'] | symmetric_difference(result['before']) |length == 0 }}" +  always: +  - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml new file mode 100644 index 00000000..ae5b10b2 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/merged.yaml @@ -0,0 +1,58 @@ +--- +- debug: +      msg: "START vyos_lldp_interfaces merged integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: +  - name: Merge the provided configuration with the exisiting running configuration +    vyos.vyos.vyos_lldp_interfaces: &merged +        config: +           - name: 'eth1' +             location: +               civic_based:  +                 country_code: 'US'  +                 ca_info: +                   - ca_type: 0  +                     ca_value: 'ENGLISH'   + +           - name: 'eth2' +             location: +               coordinate_based:  +                altitude: 2200  +                datum: 'WGS84' +                longitude: '222.267255W' +                latitude: '33.524449N'       +        state: merged +    register: result + +  - name: Assert that before dicts were correctly generated +    assert: +        that: "{{ merged['before'] | symmetric_difference(result['before']) |length == 0 }}" + +  - name: Assert that correct set of commands were generated +    assert: +        that: +            - "{{ merged['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + +  - name: Assert that after dicts was correctly generated +    assert: +        that: +            - "{{ merged['after'] | symmetric_difference(result['after']) |length == 0 }}" + +  - name: Merge the provided configuration with the existing running configuration (IDEMPOTENT) +    vyos.vyos.vyos_lldp_interfaces: *merged +    register: result + +  - name: Assert that the previous task was idempotent +    assert: +        that: +            - "result['changed'] == false" + +  - name: Assert that before dicts were correctly generated +    assert: +        that: +            - "{{ merged['after'] | symmetric_difference(result['before']) |length == 0 }}" + +  always: +  - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml new file mode 100644 index 00000000..eedb563e --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/overridden.yaml @@ -0,0 +1,49 @@ +--- +- debug: +      msg: "START vyos_lldp_interfaces overridden integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate_intf.yaml + +- block: +  - name: Overrides all device configuration with provided configuration +    vyos.vyos.vyos_lldp_interfaces: &overridden +       config: +        - name: 'eth2' +          location: +            elin: '0000000911' +       state: overridden +    register: result + +  - name: Assert that before dicts were correctly generated +    assert: +        that: +            - "{{ populate_intf | symmetric_difference(result['before']) |length == 0 }}" + +  - name: Assert that correct commands were generated +    assert: +        that: +            - "{{ overridden['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + +  - name: Assert that after dicts were correctly generated +    assert: +        that: +            - "{{ overridden['after'] | symmetric_difference(result['after']) |length == 0 }}" + +  - name: Overrides all device configuration with provided configurations (IDEMPOTENT) +    vyos.vyos.vyos_lldp_interfaces: *overridden +    register: result + +  - name: Assert that the previous task was idempotent +    assert: +        that: +            - "result['changed'] == false" + +  - name: Assert that before dicts were correctly generated +    assert: +        that: +            - "{{ overridden['after'] | symmetric_difference(result['before']) |length == 0 }}" + +  always: +  - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml new file mode 100644 index 00000000..07fec9ed --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/replaced.yaml @@ -0,0 +1,63 @@ +--- +- debug: +      msg: "START vyos_lldp_interfaces replaced integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- include_tasks: _populate.yaml + +- block: +  - name: Replace device configurations of listed LLDP interfaces with provided configurations +    vyos.vyos.vyos_lldp_interfaces: &replaced +        config: +           - name: 'eth2' +             enable: false +             location: +               civic_based:  +                 country_code: 'US'  +                 ca_info: +                   - ca_type: 0  +                     ca_value: 'ENGLISH' + +           - name: 'eth1' +             enable: false +             location: +               coordinate_based:  +                altitude: 2200  +                datum: 'WGS84' +                longitude: '222.267255W' +                latitude: '33.524449N' +        state: replaced +    register: result + +  - name: Assert that correct set of commands were generated +    assert: +        that: +            - "{{ replaced['commands'] | symmetric_difference(result['commands']) |length == 0 }}" + +  - name: Assert that before dicts are correctly generated +    assert: +        that: +            - "{{ populate | symmetric_difference(result['before']) |length == 0 }}" + +  - name: Assert that after dict is correctly generated +    assert: +        that: +            - "{{ replaced['after'] | symmetric_difference(result['after']) |length == 0 }}" + +  - name: Replace device configurations of listed LLDP interfaces with provided configurarions (IDEMPOTENT) +    vyos.vyos.vyos_lldp_interfaces: *replaced +    register: result + +  - name: Assert that task was idempotent +    assert: +        that: +            - "result['changed'] == false" + +  - name: Assert that before dict is correctly generated +    assert: +        that: +            - "{{ replaced['after'] | symmetric_difference(result['before']) |length == 0 }}" + +  always: +  - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml b/test/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml new file mode 100644 index 00000000..d97cf9c4 --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/tests/cli/rtt.yaml @@ -0,0 +1,57 @@ +--- +- debug: +    msg: "START vyos_lldp_interfaces round trip integration tests on connection={{ ansible_connection }}" + +- include_tasks: _remove_config.yaml + +- block: +  - name: Apply the provided configuration (base config) +    vyos.vyos.vyos_lldp_interfaces: +      config: +        - name: 'eth1' +          location: +            civic_based:  +              country_code: 'US'  +              ca_info: +                - ca_type: 0  +                  ca_value: 'ENGLISH' + +      state: merged +    register: base_config + +  - name: Gather lldp_interfaces facts +    vyos.vyos.vyos_facts: +      gather_subset: +        - default +      gather_network_resources: +        - lldp_interfaces + +  - name: Apply the provided configuration (config to be reverted) +    vyos.vyos.vyos_lldp_interfaces: +      config: +        - name: 'eth2' +          location: +            coordinate_based:  +             altitude: 2200  +             datum: 'WGS84' +             longitude: '222.267255W' +             latitude: '33.524449N'         +      state: merged +    register: result + +  - name: Assert that changes were applied +    assert: +      that: "{{ round_trip['after'] | symmetric_difference(result['after']) |length == 0 }}" + +  - name: Revert back to base config using facts round trip +    vyos.vyos.vyos_lldp_interfaces: +      config: "{{ ansible_facts['network_resources']['lldp_interfaces'] }}" +      state: overridden +    register: revert + +  - name: Assert that config was reverted +    assert: +      that: "{{ base_config['after'] | symmetric_difference(revert['after']) |length == 0 }}" + +  always: +  - include_tasks: _remove_config.yaml diff --git a/test/integration/targets/vyos_lldp_interfaces/vars/main.yaml b/test/integration/targets/vyos_lldp_interfaces/vars/main.yaml new file mode 100644 index 00000000..6f33343c --- /dev/null +++ b/test/integration/targets/vyos_lldp_interfaces/vars/main.yaml @@ -0,0 +1,130 @@ +--- +merged: +  before: [] + + +  commands: +    - "set service lldp interface eth1 location civic-based country-code 'US'" +    - "set service lldp interface eth1 location civic-based ca-type 0 ca-value 'ENGLISH'" +    - "set service lldp interface eth1" +    - "set service lldp interface eth2 location coordinate-based latitude '33.524449N'" +    - "set service lldp interface eth2 location coordinate-based altitude '2200'" +    - "set service lldp interface eth2 location coordinate-based datum 'WGS84'" +    - "set service lldp interface eth2 location coordinate-based longitude '222.267255W'" +    - "set service lldp interface eth2 location coordinate-based latitude '33.524449N'" +    - "set service lldp interface eth2 location coordinate-based altitude '2200'" +    - "set service lldp interface eth2 location coordinate-based datum 'WGS84'" +    - "set service lldp interface eth2 location coordinate-based longitude '222.267255W'" +    - "set service lldp interface eth2" + +  after: +    - name: 'eth1' +      location: +        civic_based:  +          country_code: 'US'  +          ca_info: +            - ca_type: 0  +              ca_value: 'ENGLISH'   + +    - name: 'eth2' +      location: +        coordinate_based:  +         altitude: 2200  +         datum: 'WGS84' +         longitude: '222.267255W' +         latitude: '33.524449N'   + +populate: +  - name: 'eth1' +    location: +      civic_based:  +        country_code: 'US'  +        ca_info: +          - ca_type: 0  +            ca_value: 'ENGLISH'   + +  - name: 'eth2' +    location: +      coordinate_based:  +       altitude: 2200  +       datum: 'WGS84' +       longitude: '222.267255W' +       latitude: '33.524449N'   + +replaced: +  commands: +    - "delete service lldp interface eth2 location" +    - "set service lldp interface eth2 'disable'" +    - "set service lldp interface eth2 location civic-based country-code 'US'" +    - "set service lldp interface eth2 location civic-based ca-type 0 ca-value 'ENGLISH'" +    - "delete service lldp interface eth1 location" +    - "set service lldp interface eth1 'disable'" +    - "set service lldp interface eth1 location coordinate-based latitude '33.524449N'" +    - "set service lldp interface eth1 location coordinate-based altitude '2200'" +    - "set service lldp interface eth1 location coordinate-based datum 'WGS84'" +    - "set service lldp interface eth1 location coordinate-based longitude '222.267255W'" + +  after: +    - name: 'eth2' +      enable: false +      location: +        civic_based:  +          country_code: 'US'  +          ca_info: +            - ca_type: 0  +              ca_value: 'ENGLISH'   + +    - name: 'eth1' +      enable: false +      location: +        coordinate_based:  +         altitude: 2200  +         datum: 'WGS84' +         longitude: '222.267255W' +         latitude: '33.524449N'   + +populate_intf: +  - name: 'eth2' +    enable: false +    location: +      civic_based:  +        country_code: 'US'  +        ca_info: +          - ca_type: 0  +            ca_value: 'ENGLISH'   + +overridden: +  commands: +    - "delete service lldp interface eth2 location"  +    - "delete service lldp interface eth2 'disable'"  +    - "set service lldp interface eth2 location elin '0000000911'" + +  after: +    - name: 'eth2' +      location: +        elin: 0000000911 + +deleted: +  commands: +    - "delete service lldp interface eth1" +    - "delete service lldp interface eth2" + +  after: [] + +round_trip: +  after: +    - name: 'eth1' +      location: +        civic_based:  +          country_code: 'US'  +          ca_info: +            - ca_type: 0  +              ca_value: 'ENGLISH' + +    - name: 'eth2' +      location: +        coordinate_based:  +         altitude: 2200  +         datum: 'WGS84' +         longitude: '222.267255W' +         latitude: '33.524449N' | 
