1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561 | // Copyright (C) 2021-2024 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#include <config.h>
#include <database/db_exceptions.h>
#include <database/server.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcpsrv/config_backend_dhcp4_mgr.h>
#include <dhcpsrv/testutils/generic_cb_dhcp4_unittest.h>
#include <dhcpsrv/testutils/generic_cb_recovery_unittest.h>
#include <dhcpsrv/testutils/pgsql_generic_backend_unittest.h>
#include <dhcpsrv/testutils/test_utils.h>
#include <pgsql_cb_dhcp4.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <pgsql/testutils/pgsql_schema.h>
#include <testutils/multi_threading_utils.h>
#include <testutils/gtest_utils.h>
#include <boost/make_shared.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <boost/shared_ptr.hpp><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <gtest/gtest.h><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <map><--- Include file:
#include <sstream><--- Include file: not found. Please note: Cppcheck does not need standard library headers to get proper results.
using namespace isc;
using namespace isc::asiolink;
using namespace isc::db;
using namespace isc::db::test;
using namespace isc::data;
using namespace isc::dhcp;
using namespace isc::dhcp::test;
using namespace isc::process;
using namespace isc::test;
using namespace isc::util;
namespace ph = std::placeholders;
namespace {
/// @brief Test implementation of the PostgreSQL configuration backend.
///
/// It exposes protected members of the @c PgSqlConfigBackendDHCPv4.
class TestPgSqlConfigBackendDHCPv4 : public PgSqlConfigBackendDHCPv4 {
public:
/// @brief Constructor.
///
/// @param parameters A data structure relating keywords and values
/// concerned with the database.
explicit TestPgSqlConfigBackendDHCPv4(const DatabaseConnection::ParameterMap& parameters)
: PgSqlConfigBackendDHCPv4(parameters) {
}
using PgSqlConfigBackendDHCPv4::base_impl_;
};
/// @brief Test fixture class for @c PgSqlConfigBackendDHCPv4.
class PgSqlConfigBackendDHCPv4Test : public GenericConfigBackendDHCPv4Test {
public:
/// @brief Constructor.
PgSqlConfigBackendDHCPv4Test() {}
/// @brief Destructor.
virtual ~PgSqlConfigBackendDHCPv4Test() {}
/// @brief Creates the PostgreSQL back end schema
virtual void createSchema() {
createPgSQLSchema();
}
/// @brief Destroys the PostgreSQL back end schema
virtual void destroySchema() {
destroyPgSQLSchema();
}
/// @brief Returns a valid PostgreSQL back end specific connection
/// string
std::string validConnectionString() {
return (validPgSQLConnectionString());
}
/// @brief Instantiates an instance of a PostgreSQL DHCPv4 configuration
/// back end.
///
/// @params Connection parameters describing the back end to create.
///
/// @return Pointer to the newly created back end instance.
ConfigBackendDHCPv4Ptr backendFactory(db::DatabaseConnection::ParameterMap&
params) {
return (ConfigBackendDHCPv4Ptr(new TestPgSqlConfigBackendDHCPv4(params)));
}
/// @brief Counts rows in a selected table in PostgreSQL database.
///
/// This method can be used to verify that some configuration elements were
/// deleted from a selected table as a result of cascade delete or a trigger.
/// For example, deleting a subnet should trigger deletion of its address
/// pools and options. By counting the rows on each table we can determine
/// whether the deletion took place on all tables for which it was expected.
///
/// @param table Table name.
/// @return Number of rows in the specified table.
size_t countRows(const std::string& table) const {
auto p = boost::dynamic_pointer_cast<TestPgSqlConfigBackendDHCPv4>(cbptr_);
if (!p) {
ADD_FAILURE() << "cbptr_ does not cast to TestPgSqlConfigBackendDHCPv4";
return (0);
}
// Reuse the existing connection of the backend.
auto impl = boost::dynamic_pointer_cast<PgSqlConfigBackendImpl>(p->base_impl_);
auto& conn = impl->conn_;
return (PgSqlGenericBackendTest::countRows(conn, table));
}
};
TEST_F(PgSqlConfigBackendDHCPv4Test, getType) {<--- syntax error
getTypeTest("postgresql");
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getHost) {
getHostTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getPort) {
getPortTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateDeleteServerTest) {
createUpdateDeleteServerTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAndDeleteAllServersTest) {
getAndDeleteAllServersTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateDeleteGlobalParameter4Test) {
createUpdateDeleteGlobalParameter4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, globalParameters4WithServerTagsTest) {
globalParameters4WithServerTagsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, invalidOptionDefDataType4Test) {
invalidOptionDefDataType4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, allOptionDefDataTypes4Test) {
allOptionDefDataTypes4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllGlobalParameters4Test) {
getAllGlobalParameters4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedGlobalParameters4Test) {
getModifiedGlobalParameters4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, nullKeyErrorTest) {
nullKeyErrorTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateSubnet4SelectorsTest) {
createUpdateSubnet4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSubnet4Test) {
getSubnet4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSubnet4byIdSelectorsTest) {
getSubnet4byIdSelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSubnet4WithOptionalUnspecifiedTest) {
getSubnet4WithOptionalUnspecifiedTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSubnet4SharedNetworkTest) {
getSubnet4SharedNetworkTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSubnet4ByPrefixTest) {
getSubnet4ByPrefixTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSubnet4byPrefixSelectorsTest) {
getSubnet4byPrefixSelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllSubnets4Test) {
getAllSubnets4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllSubnets4SelectorsTest) {
getAllSubnets4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllSubnets4WithServerTagsTest) {
getAllSubnets4WithServerTagsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedSubnets4SelectorsTest) {
getModifiedSubnets4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteSubnet4Test) {
deleteSubnet4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteSubnet4ByIdSelectorsTest) {
deleteSubnet4ByIdSelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteSubnet4ByPrefixSelectorsTest) {
deleteSubnet4ByPrefixSelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteAllSubnets4SelectorsTest) {
deleteAllSubnets4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, unassignedSubnet4Test) {
unassignedSubnet4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedSubnets4Test) {
getModifiedSubnets4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, subnetLifetimeTest) {
subnetLifetimeTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSharedNetworkSubnets4Test) {
getSharedNetworkSubnets4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, subnetUpdatePoolsTest) {
subnetUpdatePoolsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, subnetOptionsTest) {
subnetOptionsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSharedNetwork4Test) {
getSharedNetwork4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSharedNetwork4SelectorsTest) {
getSharedNetwork4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateSharedNetwork4Test) {
createUpdateSharedNetwork4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateSharedNetwork4SelectorsTest) {
createUpdateSharedNetwork4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getSharedNetwork4WithOptionalUnspecifiedTest) {
getSharedNetwork4WithOptionalUnspecifiedTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteSharedNetworkSubnets4Test) {
deleteSharedNetworkSubnets4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllSharedNetworks4Test) {
getAllSharedNetworks4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllSharedNetworks4SelectorsTest) {
getAllSharedNetworks4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllSharedNetworks4WithServerTagsTest) {
getAllSharedNetworks4WithServerTagsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedSharedNetworks4Test) {
getModifiedSharedNetworks4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedSharedNetworks4SelectorsTest) {
getModifiedSharedNetworks4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteSharedNetwork4Test) {
deleteSharedNetwork4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteSharedNetwork4SelectorsTest) {
deleteSharedNetwork4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteAllSharedNetworks4SelectorsTest) {
deleteAllSharedNetworks4SelectorsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, unassignedSharedNetworkTest) {
unassignedSharedNetworkTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, sharedNetworkLifetimeTest) {
sharedNetworkLifetimeTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, sharedNetworkOptionsTest) {
sharedNetworkOptionsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getOptionDef4Test) {
getOptionDef4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, optionDefs4WithServerTagsTest) {
optionDefs4WithServerTagsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllOptionDefs4Test) {
getAllOptionDefs4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedOptionDefs4Test) {
getModifiedOptionDefs4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateDeleteOption4Test) {
createUpdateDeleteOption4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, globalOptions4WithServerTagsTest) {
globalOptions4WithServerTagsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getAllOptions4Test) {
getAllOptions4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedOptions4Test) {
getModifiedOptions4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateDeleteSubnetOption4Test) {
createUpdateDeleteSubnetOption4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateDeletePoolOption4Test) {
createUpdateDeletePoolOption4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateDeleteSharedNetworkOption4Test) {
createUpdateDeleteSharedNetworkOption4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, subnetOptionIdOrderTest) {
subnetOptionIdOrderTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, sharedNetworkOptionIdOrderTest) {
sharedNetworkOptionIdOrderTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, setAndGetAllClientClasses4Test) {
setAndGetAllClientClasses4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getClientClass4Test) {
getClientClass4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, createUpdateClientClass4OptionsTest) {
createUpdateClientClass4OptionsTest();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, getModifiedClientClasses4Test) {
getModifiedClientClasses4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteClientClass4Test) {
deleteClientClass4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, deleteAllClientClasses4Test) {
deleteAllClientClasses4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, clientClassDependencies4Test) {
clientClassDependencies4Test();
}
TEST_F(PgSqlConfigBackendDHCPv4Test, multipleAuditEntriesTest) {
multipleAuditEntriesTest();
}
/// @brief Test fixture for verifying database connection loss-recovery
/// behavior.
class PgSqlConfigBackendDHCPv4DbLostCallbackTest : public GenericConfigBackendDbLostCallbackTest {
public:
/// @brief Constructor
PgSqlConfigBackendDHCPv4DbLostCallbackTest() {};
/// @brief Destructor
virtual ~PgSqlConfigBackendDHCPv4DbLostCallbackTest() {};
/// @brief Creates the PostgreSQL CB schema.
virtual void createSchema() {
createPgSQLSchema();
}
/// @brief Destroys the PostgreSQL CB schema.
virtual void destroySchema() {
destroyPgSQLSchema();
}
/// @brief Method which returns a valid back end specific connection
/// string
virtual std::string validConnectionString() {
return (validPgSQLConnectionString());
}
/// @brief Method which returns an invalid back end specific connection
/// string.
virtual std::string invalidConnectionString() {
return (connectionString(PGSQL_VALID_TYPE, INVALID_NAME, VALID_HOST,
VALID_USER, VALID_PASSWORD));
}
/// @brief Registers PostgreSQL as a CB backend type.
virtual void registerBackendType() {
isc::dhcp::PgSqlConfigBackendDHCPv4::registerBackendType();
}
/// @brief Unregisters PostgreSQL as a CB backend type.
virtual void unregisterBackendType() {
isc::dhcp::PgSqlConfigBackendDHCPv4::unregisterBackendType();
}
/// @brief Sets the IOService instance in the CB implementation object.
///
/// @param io_service pointer to the IOService instance to use. It may be
/// an empty pointer.
virtual void setConfigBackendImplIOService(isc::asiolink::IOServicePtr io_service) {
isc::dhcp::PgSqlConfigBackendImpl::setIOService(io_service);
}
/// @brief Attempts to add a backend instance to the CB manager.
///
/// @param access Connection access string containing the database
/// connection parameters.
virtual void addBackend(const std::string& access) {
ConfigBackendDHCPv4Mgr::instance().addBackend(access);
}
/// @brief Fetches a collection of all the servers currently in
/// the CB database. This function is used to check the operability
/// of the CB backend.
ServerCollection getAllServers() {
return (ConfigBackendDHCPv4Mgr::instance().getPool()->getAllServers4(BackendSelector()));
}
};
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndRecoveredCallback) {
MultiThreadingTest mt(false);
testRetryOpenDbLostAndRecoveredCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndRecoveredCallbackMultiThreading) {
MultiThreadingTest mt(true);
testRetryOpenDbLostAndRecoveredCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndFailedCallback) {
MultiThreadingTest mt(false);
testRetryOpenDbLostAndFailedCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndFailedCallbackMultiThreading) {
MultiThreadingTest mt(true);
testRetryOpenDbLostAndFailedCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndRecoveredAfterTimeoutCallback) {
MultiThreadingTest mt(false);
testRetryOpenDbLostAndRecoveredAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndRecoveredAfterTimeoutCallbackMultiThreading) {
MultiThreadingTest mt(true);
testRetryOpenDbLostAndRecoveredAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndFailedAfterTimeoutCallback) {
MultiThreadingTest mt(false);
testRetryOpenDbLostAndFailedAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testRetryOpenDbLostAndFailedAfterTimeoutCallbackMultiThreading) {
MultiThreadingTest mt(true);
testRetryOpenDbLostAndFailedAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testNoCallbackOnOpenFailure) {
MultiThreadingTest mt(false);
testNoCallbackOnOpenFailure();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testNoCallbackOnOpenFailureMultiThreading) {
MultiThreadingTest mt(true);
testNoCallbackOnOpenFailure();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndRecoveredCallback) {
MultiThreadingTest mt(false);
testDbLostAndRecoveredCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndRecoveredCallbackMultiThreading) {
MultiThreadingTest mt(true);
testDbLostAndRecoveredCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndFailedCallback) {
MultiThreadingTest mt(false);
testDbLostAndFailedCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndFailedCallbackMultiThreading) {
MultiThreadingTest mt(true);
testDbLostAndFailedCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndRecoveredAfterTimeoutCallback) {
MultiThreadingTest mt(false);
testDbLostAndRecoveredAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndRecoveredAfterTimeoutCallbackMultiThreading) {
MultiThreadingTest mt(true);
testDbLostAndRecoveredAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndFailedAfterTimeoutCallback) {
MultiThreadingTest mt(false);
testDbLostAndFailedAfterTimeoutCallback();
}
TEST_F(PgSqlConfigBackendDHCPv4DbLostCallbackTest, testDbLostAndFailedAfterTimeoutCallbackMultiThreading) {
MultiThreadingTest mt(true);
testDbLostAndFailedAfterTimeoutCallback();
}
}
|