Module: KeaApiStubs

Defined in:
spec/fixtures/kea_api_stubs.rb

Overview

This module provides a set of helper methods that return mock data structures, mimicking the JSON responses from the ISC Kea API. This allows us to test the client and services without needing a live Kea server.

Instance Method Summary collapse

Instance Method Details

#config_get_multi_subnetHash

A config-get with multiple subnets for managed_subnets filtering tests.

Returns:

  • (Hash)

    A hash with two subnets.



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'spec/fixtures/kea_api_stubs.rb', line 105

def config_get_multi_subnet
  {
    "Dhcp4" => {
      "subnet4" => [
        {
          "id" => 1,
          "subnet" => "192.168.1.0/24",
          "pools" => [{ "pool" => "192.168.1.10-192.168.1.20" }],
          "option-data" => [{ "name" => "routers", "data" => "192.168.1.1" }],
          "reservations" => []
        },
        {
          "id" => 2,
          "subnet" => "10.0.0.0/24",
          "pools" => [{ "pool" => "10.0.0.10-10.0.0.100" }],
          "option-data" => [{ "name" => "routers", "data" => "10.0.0.1" }],
          "reservations" => []
        }
      ]
    }
  }
end

#config_get_with_optionsHash

A config-get response with subnet-level options and reservation options.

Returns:

  • (Hash)

    A hash representing a richer Kea DHCPv4 configuration.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'spec/fixtures/kea_api_stubs.rb', line 29

def config_get_with_options
  {
    "Dhcp4" => {
      "subnet4" => [
        {
          "id" => 1,
          "subnet" => "192.168.1.0/24",
          "pools" => [{ "pool" => "192.168.1.10-192.168.1.20" }],
          "next-server" => "192.168.1.254",
          "boot-file-name" => "pxelinux.0",
          "option-data" => [
            { "name" => "routers", "data" => "192.168.1.1" },
            { "name" => "domain-name-servers", "data" => "8.8.8.8,8.8.4.4" },
            { "name" => "domain-name", "data" => "example.com" },
            { "name" => "ntp-servers", "data" => "192.168.1.253" }
          ],
          "reservations" => [
            {
              "hw-address" => "aa:bb:cc:dd:ee:ff",
              "ip-address" => "192.168.1.5",
              "hostname" => "pxe-host",
              "next-server" => "192.168.1.254",
              "boot-file-name" => "pxelinux.0",
              "option-data" => [
                { "name" => "routers", "data" => "192.168.1.1" },
                { "name" => "domain-name-servers", "data" => "10.0.0.1,10.0.0.2" }
              ]
            }
          ]
        }
      ]
    }
  }
end

#config_get_with_placeholdersHash

A config-get whose boot fields hold Kea's "unset" placeholders: next-server "0.0.0.0" and an empty boot-file-name, at both subnet and reservation level.

Returns:

  • (Hash)

    A hash representing a Kea config with placeholder boot values.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'spec/fixtures/kea_api_stubs.rb', line 67

def config_get_with_placeholders
  {
    "Dhcp4" => {
      "subnet4" => [
        {
          "id" => 1,
          "subnet" => "192.168.1.0/24",
          "pools" => [{ "pool" => "192.168.1.10-192.168.1.20" }],
          "next-server" => "0.0.0.0",
          "boot-file-name" => "",
          "option-data" => [{ "name" => "routers", "data" => "192.168.1.1" }],
          "reservations" => [
            {
              "hw-address" => "aa:bb:cc:dd:ee:ff", "ip-address" => "192.168.1.5", "hostname" => "plain-host",
              "next-server" => "0.0.0.0", "boot-file-name" => "", "option-data" => []
            }
          ]
        }
      ]
    }
  }
end

#error_responseHash

An error response from the API.

Returns:

  • (Hash)

    A hash representing a generic API error.



158
159
160
# File 'spec/fixtures/kea_api_stubs.rb', line 158

def error_response
  { "result" => 1, "text" => "Something went wrong." }
end

#reservation_get_all_successHash

A successful 'reservation-get-all' response (hosts-database backend present). Includes the static reservation from successful_config_get (to exercise dedup) plus a database-only reservation.

Returns:

  • (Hash)

    A hash containing a list of host reservations.



94
95
96
97
98
99
100
101
# File 'spec/fixtures/kea_api_stubs.rb', line 94

def reservation_get_all_success
  {
    "hosts" => [
      { "hw-address" => "aa:bb:cc:dd:ee:ff", "ip-address" => "192.168.1.5", "hostname" => "test-host", "option-data" => [] },
      { "hw-address" => "11:22:33:44:55:66", "ip-address" => "192.168.1.30", "hostname" => "db-host", "option-data" => [] }
    ]
  }
end

#successful_config_getHash

A successful response for a 'config-get' command.

Returns:

  • (Hash)

    A hash representing the Kea DHCPv4 configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'spec/fixtures/kea_api_stubs.rb', line 9

def successful_config_get
  {
    "Dhcp4" => {
      "subnet4" => [
        {
          "id" => 1,
          "subnet" => "192.168.1.0/24",
          "pools" => [{ "pool" => "192.168.1.10-192.168.1.20" }],
          "option-data" => [{ "name" => "routers", "data" => "192.168.1.1" }],
          "reservations" => [
            { "hw-address" => "aa:bb:cc:dd:ee:ff", "ip-address" => "192.168.1.5", "hostname" => "test-host" }
          ]
        }
      ]
    }
  }
end

#successful_lease_delHash

A successful response for a 'lease4-del' command.

Returns:

  • (Hash)

    A hash indicating success.



152
153
154
# File 'spec/fixtures/kea_api_stubs.rb', line 152

def successful_lease_del
  { "result" => 0, "text" => "Lease deleted successfully." }
end

#successful_lease_getHash

A successful response for a 'lease4-get-all' command with one active lease.

Returns:

  • (Hash)

    A hash containing a list of leases.



130
131
132
133
134
135
136
# File 'spec/fixtures/kea_api_stubs.rb', line 130

def successful_lease_get
  {
    "leases" => [
      { "ip-address" => "192.168.1.11", "hw-address" => "ff:ee:dd:cc:bb:aa", "cltt" => 1678886400, "expire" => 1678890000 }
    ]
  }
end

#successful_reservation_addHash

A successful response for a 'reservation-add' command.

Returns:

  • (Hash)

    A hash indicating success.



140
141
142
# File 'spec/fixtures/kea_api_stubs.rb', line 140

def successful_reservation_add
  { "result" => 0, "text" => "Reservation added successfully." }
end

#successful_reservation_delHash

A successful response for a 'reservation-del' command.

Returns:

  • (Hash)

    A hash indicating success.



146
147
148
# File 'spec/fixtures/kea_api_stubs.rb', line 146

def successful_reservation_del
  { "result" => 0, "text" => "Reservation deleted successfully." }
end