name: Enable Inline l2 configuration in PacketFence
testcases:
- name: get_login_token
  steps:
  - type: get_login_token

- name: configure_interface_inlinel2_as_type_inline_l2
  steps:
  - type: http
    method: PATCH
    url: '{{.pfserver_webadmin_url}}/api/v1/config/interface/inlinel2'
    ignore_verify_ssl: true
    body: >-
     {
       "id": "inlinel2",
       "isClone": false,
       "isNew": false,
       "prefixRouteName": "",
       "additional_listening_daemons": [],
       "coa": null,
       "dhcpd_enabled": "enabled",
       "dns": "8.8.8.8",
       "high_availability": 0,
       "hwaddr": "92:ed:ee:36:e9:6a",
       "ifindex": "10",
       "ipv6_address": null,
       "ipv6_prefix": null,
       "is_running": true,
       "master": null,
       "name": "inlinel2",
       "nat_enabled": "enabled",
       "network": null,
       "network_iseditable": false,
       "networks": [],
       "not_editable": false,
       "reg_network": null,
       "split_network": null,
       "type": "inlinel2",
       "vip": null,
       "vlan": null,
       "ipaddress": "{{.inline_l2.pf_portal}}",
       "netmask": "255.255.255.0"
     }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200

- name: configure_inline_l2_network
  steps:
  - type: http
    method: PATCH
    url: '{{.pfserver_webadmin_url}}/api/v1/config/l2_network/{{.inline_l2.networks}}'
    ignore_verify_ssl: true
    body: >-
     {
       "id": "{{.inline_l2.networks}}",
       "isClone": false,
       "isNew": false,
       "algorithm": 1,
       "description": null,
       "dhcp_default_lease_time": "30",
       "dhcp_end": "{{.inline_l2.node.ipaddress}}",
       "dhcp_max_lease_time": "30",
       "dhcp_start": "{{.inline_l2.node.ipaddress}}",
       "dns": "8.8.8.8",
       "ip_assigned": null,
       "ip_reserved": null,
       "netflow_accounting_enabled": "enabled",
       "netmask": "255.255.255.0",
       "not_deletable": false,
       "not_sortable": false,
       "pool_backend": "memory",
       "portal_fqdn": null,
       "type": "inlinel2"
     }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200

- name: create_a_user
  steps:
  - type: http
    method: POST
    url: '{{.pfserver_webadmin_url}}/api/v1/users'
    ignore_verify_ssl: true
    body: >-
     {
       "valid_from": "2021-12-06 00:00:00",
       "expiration": null,
       "actions": [
         {
           "type": "set_role",
           "value": "1"
         },
         {
           "type": "set_access_duration",
           "value": "1h"
         }
       ],
       "pid_overwrite": 0,
       "pid": "iastigmate",
       "email": "iastigmate@test.ca",
       "sponsor": "",
       "password": "password",
       "login_remaining": null,
       "gender": "",
       "title": "",
       "firstname": "Igmout",
       "lastname": "Astigmate",
       "nickname": "",
       "company": "",
       "telephone": "",
       "cell_phone": "",
       "work_phone": "",
       "address": "",
       "apartment_number": "",
       "building_number": "",
       "room_number": "",
       "anniversary": "",
       "birthday": "",
       "psk": "",
       "notes": "",
       "custom_field_1": "",
       "custom_field_2": "",
       "custom_field_3": "",
       "custom_field_4": "",
       "custom_field_5": "",
       "custom_field_6": "",
       "custom_field_7": "",
       "custom_field_8": "",
       "custom_field_9": ""
     }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 201

- name: assign_a_password_to_the_user
  steps:
  - type: http
    method: POST
    url: '{{.pfserver_webadmin_url}}/api/v1/user/iastigmate/password'
    ignore_verify_ssl: true
    body: >-
     {
       "quiet": true,
       "valid_from": "2021-12-06 00:00:00",
       "expiration": "{{.inline_lx_iastigmate.password.expiration}}",
       "actions": [
         {
           "type": "set_role",
           "value": "1"
         },
         {
           "type": "set_access_duration",
           "value": "1h"
         }
       ],
       "pid_overwrite": 0,
       "pid": "iastigmate",
       "email": "iastigmate@test.ca",
       "sponsor": "",
       "password": "password",
       "login_remaining": null,
       "gender": "",
       "title": "",
       "firstname": "Igmout",
       "lastname": "Astigmate",
       "nickname": "",
       "company": "",
       "telephone": "",
       "cell_phone": "",
       "work_phone": "",
       "address": "",
       "apartment_number": "",
       "building_number": "",
       "room_number": "",
       "anniversary": "",
       "birthday": "",
       "psk": "",
       "notes": "",
       "custom_field_1": "",
       "custom_field_2": "",
       "custom_field_3": "",
       "custom_field_4": "",
       "custom_field_5": "",
       "custom_field_6": "",
       "custom_field_7": "",
       "custom_field_8": "",
       "custom_field_9": "",
       "access_duration": "1h",
       "access_level": null,
       "can_sponsor": null,
       "category": "1",
       "unregdate": null
     }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 201

- name: configure_snat_interface_for_passthroughs
  steps:
  - type: http
    method: PATCH
    url: '{{.pfserver_webadmin_url}}/api/v1/config/base/network'
    ignore_verify_ssl: true
    body: >-
      {
        "interfaceSNAT":"eth0"
      }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200
      - result.bodyjson.message ShouldEqual "Settings updated"

- name: configure_snat_interface_for_inline
  steps:
  - type: http
    method: PATCH
    url: '{{.pfserver_webadmin_url}}/api/v1/config/base/inline'
    ignore_verify_ssl: true
    body: >-
     {
       "id": "inline",
       "interfaceSNAT": "eth0"
     }
    headers:
      "Authorization": "{{.get_login_token.result.token}}"
      "Content-Type": "application/json"
    assertions:
      - result.statuscode ShouldEqual 200

- name: restart_iptables
  steps:
  - type: perl_iptables_restart

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_pfdns_service
  steps:
  - type: exec
    script: systemctl restart packetfence-pfdns

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_pfdhcp_service
  steps:
  - type: exec
    script: systemctl restart packetfence-pfdhcp

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_haproxy-portal_service
  steps:
  - type: exec
    script: systemctl restart packetfence-haproxy-portal

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_keepalived_service
  steps:
  - type: exec
    script: systemctl restart packetfence-keepalived

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_pfdhcplistener_service
  steps:
  - type: exec
    script: systemctl restart packetfence-pfdhcplistener

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_pfacct_service
  steps:
  - type: exec
    script: systemctl restart packetfence-pfacct

    # let service restarts
  - type: exec
    script: sleep 5

- name: restart_pfqueue_service
  steps:
  - type: systemctl_service_restart
    service: packetfence-pfqueue-backend
    time_to_sleep: 5

  - type: systemctl_service_restart
    service: packetfence-pfqueue-go
    time_to_sleep: 5

