Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sebastian Schrader
Kea
Commits
c1862585
Commit
c1862585
authored
Mar 05, 2017
by
Francis Dupont
Committed by
Tomek Mrugalski
Mar 07, 2017
Browse files
[fdunparse2] Snapshot for 4o6-subnet fix
parent
0beffc6e
Changes
22
Hide whitespace changes
Inline
Side-by-side
src/bin/dhcp4/tests/Makefile.am
View file @
c1862585
...
...
@@ -95,6 +95,7 @@ dhcp4_unittests_SOURCES += decline_unittest.cc
dhcp4_unittests_SOURCES
+=
kea_controller_unittest.cc
dhcp4_unittests_SOURCES
+=
dhcp4to6_ipc_unittest.cc
dhcp4_unittests_SOURCES
+=
simple_parser4_unittest.cc
dhcp4_unittests_SOURCES
+=
get_config_unittest.cc get_config_unittest.h
nodist_dhcp4_unittests_SOURCES
=
marker_file.h test_libraries.h
...
...
src/bin/dhcp4/tests/config_parser_unittest.cc
View file @
c1862585
...
...
@@ -31,6 +31,7 @@
#include "test_libraries.h"
#include "test_data_files_config.h"
#include "dhcp4_test_utils.h"
#include "get_config_unittest.h"
#include <boost/foreach.hpp>
#include <boost/scoped_ptr.hpp>
...
...
@@ -628,12 +629,15 @@ TEST_F(Dhcp4ParserTest, bogusCommand) {
/// pool definition.
TEST_F
(
Dhcp4ParserTest
,
emptySubnet
)
{
std
::
string
config
=
"{ "
+
genIfaceConfig
()
+
","
+
"
\"
rebind-timer
\"
: 2000, "
"
\"
renew-timer
\"
: 1000, "
"
\"
subnet4
\"
: [ ], "
"
\"
valid-lifetime
\"
: 4000 }"
;
ConstElementPtr
json
;
EXPECT_NO_THROW
(
json
=
parseDHCP4
(
"{ "
+
genIfaceConfig
()
+
","
+
"
\"
rebind-timer
\"
: 2000, "
"
\"
renew-timer
\"
: 1000, "
"
\"
subnet4
\"
: [ ], "
"
\"
valid-lifetime
\"
: 4000 }"
));
EXPECT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -655,6 +659,7 @@ TEST_F(Dhcp4ParserTest, unspecifiedRenewTimer) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -689,6 +694,7 @@ TEST_F(Dhcp4ParserTest, unspecifiedRebindTimer) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -723,6 +729,7 @@ TEST_F(Dhcp4ParserTest, subnetGlobalDefaults) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -774,6 +781,7 @@ TEST_F(Dhcp4ParserTest, multipleSubnets) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
int
cnt
=
0
;
// Number of reconfigurations
...
...
@@ -832,6 +840,7 @@ TEST_F(Dhcp4ParserTest, multipleSubnetsExplicitIDs) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
int
cnt
=
0
;
// Number of reconfigurations
do
{
...
...
@@ -1040,6 +1049,7 @@ TEST_F(Dhcp4ParserTest, nextServerGlobal) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1070,6 +1080,7 @@ TEST_F(Dhcp4ParserTest, nextServerSubnet) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1168,6 +1179,7 @@ TEST_F(Dhcp4ParserTest, nextServerOverride) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1206,8 +1218,10 @@ TEST_F(Dhcp4ParserTest, echoClientId) {
ConstElementPtr
json_false
;
ASSERT_NO_THROW
(
json_false
=
parseDHCP4
(
config_false
));
extractConfig
(
config_false
);
ConstElementPtr
json_true
;
ASSERT_NO_THROW
(
json_true
=
parseDHCP4
(
config_true
));
extractConfig
(
config_true
);
// Let's check the default. It should be true
ASSERT_TRUE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
getEchoClientId
());
...
...
@@ -1248,6 +1262,7 @@ TEST_F(Dhcp4ParserTest, matchClientIdNoGlobal) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
ASSERT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1285,6 +1300,7 @@ TEST_F(Dhcp4ParserTest, matchClientIdGlobal) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
ASSERT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1317,6 +1333,7 @@ TEST_F(Dhcp4ParserTest, subnetLocal) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1357,6 +1374,7 @@ TEST_F(Dhcp4ParserTest, multiplePools) {
"
\"
valid-lifetime
\"
: 4000 }"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
ASSERT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1429,6 +1447,7 @@ TEST_F(Dhcp4ParserTest, poolPrefixLen) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -1585,6 +1604,7 @@ TEST_F(Dhcp4ParserTest, optionDefIpv4Address) {
"}"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
,
true
));
extractConfig
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
...
...
@@ -1651,6 +1671,7 @@ TEST_F(Dhcp4ParserTest, optionDefRecord) {
"}"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
));
extractConfig
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
...
...
@@ -1705,6 +1726,7 @@ TEST_F(Dhcp4ParserTest, optionDefMultiple) {
"}"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
));
extractConfig
(
config
);
// Make sure that the option definitions do not exist yet.
ASSERT_FALSE
(
CfgMgr
::
instance
().
getStagingCfg
()
->
...
...
@@ -1813,6 +1835,7 @@ TEST_F(Dhcp4ParserTest, optionDefArray) {
"}"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
));
extractConfig
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
...
...
@@ -1855,6 +1878,7 @@ TEST_F(Dhcp4ParserTest, optionDefEncapsulate) {
"}"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
));
extractConfig
(
config
);
// Make sure that the particular option definition does not exist.
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
...
...
@@ -2056,6 +2080,7 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
"}"
;
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
));
extractConfig
(
config
);
OptionDefinitionPtr
def
=
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgOptionDef
()
->
get
(
DHCP4_OPTION_SPACE
,
109
);
...
...
@@ -2112,6 +2137,7 @@ TEST_F(Dhcp4ParserTest, optionStandardDefOverride) {
" } ]"
"}"
;
ASSERT_NO_THROW
(
json
=
parseOPTION_DEF
(
config
));
extractConfig
(
config
);
// Use the configuration string to create new option definition.
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -2155,6 +2181,7 @@ TEST_F(Dhcp4ParserTest, optionDataDefaultsGlobal) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
...
...
@@ -2225,6 +2252,7 @@ TEST_F(Dhcp4ParserTest, optionDataDefaultsSubnet) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
...
...
@@ -2306,6 +2334,7 @@ TEST_F(Dhcp4ParserTest, optionDataTwoSpaces) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -2381,6 +2410,7 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -2437,6 +2467,7 @@ TEST_F(Dhcp4ParserTest, optionDataEncapsulate) {
"}"
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
ASSERT_TRUE
(
status
);
...
...
@@ -2498,6 +2529,7 @@ TEST_F(Dhcp4ParserTest, optionDataInSingleSubnet) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
...
...
@@ -2646,6 +2678,7 @@ TEST_F(Dhcp4ParserTest, optionDataInMultipleSubnets) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
...
...
@@ -2920,6 +2953,7 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -2976,6 +3010,7 @@ TEST_F(Dhcp4ParserTest, stdOptionDataEncapsulate) {
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
ASSERT_TRUE
(
status
);
...
...
@@ -3055,6 +3090,7 @@ TEST_F(Dhcp4ParserTest, vendorOptionsHex) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -3110,6 +3146,7 @@ TEST_F(Dhcp4ParserTest, vendorOptionsCsv) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -3287,6 +3324,7 @@ TEST_F(Dhcp4ParserTest, selectedInterfaces) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
...
...
@@ -3326,6 +3364,7 @@ TEST_F(Dhcp4ParserTest, allInterfaces) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
...
...
@@ -3424,6 +3463,7 @@ TEST_F(Dhcp4ParserTest, d2ClientConfig) {
// Convert the JSON string to configuration elements.
ConstElementPtr
config
;
ASSERT_NO_THROW
(
config
=
parseDHCP4
(
config_str
,
true
));
extractConfig
(
config_str
);
// Pass the configuration in for parsing.
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
config
));
...
...
@@ -3523,6 +3563,7 @@ TEST_F(Dhcp4ParserTest, subnetRelayInfo) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -3710,6 +3751,7 @@ TEST_F(Dhcp4ParserTest, reservations) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
...
...
@@ -3861,6 +3903,7 @@ TEST_F(Dhcp4ParserTest, reservationWithOptionDefinition) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
,
true
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
x
=
configureDhcp4Server
(
*
srv_
,
json
));
checkResult
(
x
,
0
);
...
...
@@ -4045,6 +4088,7 @@ TEST_F(Dhcp4ParserTest, hostReservationPerSubnet) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
hr_config
));
extractConfig
(
hr_config
);
ConstElementPtr
result
;
EXPECT_NO_THROW
(
result
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4092,6 +4136,7 @@ TEST_F(Dhcp4ParserTest, declineTimerDefault) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4113,6 +4158,7 @@ TEST_F(Dhcp4ParserTest, dhcp4o6portDefault) {
"}"
;
ConstElementPtr
config
;
ASSERT_NO_THROW
(
config
=
parseDHCP4
(
config_txt
));
extractConfig
(
config_txt
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
config
));
...
...
@@ -4138,6 +4184,7 @@ TEST_F(Dhcp4ParserTest, declineTimer) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4193,6 +4240,7 @@ TEST_F(Dhcp4ParserTest, expiredLeasesProcessing) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4263,6 +4311,7 @@ TEST_F(Dhcp4ParserTest, 4o6default) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4297,6 +4346,7 @@ TEST_F(Dhcp4ParserTest, 4o6subnet) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4393,6 +4443,7 @@ TEST_F(Dhcp4ParserTest, 4o6iface) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4429,6 +4480,7 @@ TEST_F(Dhcp4ParserTest, 4o6subnetIface) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4467,6 +4519,7 @@ TEST_F(Dhcp4ParserTest, 4o6subnetInterfaceId) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4517,6 +4570,7 @@ TEST_F(Dhcp4ParserTest, validClientClassDictionary) {
ConstElementPtr
json
;
ASSERT_NO_THROW
(
json
=
parseDHCP4
(
config
));
extractConfig
(
config
);
ConstElementPtr
status
;
EXPECT_NO_THROW
(
status
=
configureDhcp4Server
(
*
srv_
,
json
));
...
...
@@ -4563,6 +4617,7 @@ TEST_F(Dhcp4ParserTest, invalidClientClassDictionary) {
// Test verifies that regular configuration does not provide any user context
// in the address pool.
TEST_F
(
Dhcp4ParserTest
,
poolUserContextMissing
)
{
extractConfig
(
PARSER_CONFIGS
[
0
]);
PoolPtr
pool
;
getPool
(
string
(
PARSER_CONFIGS
[
0
]),
0
,
0
,
pool
);
ASSERT_TRUE
(
pool
);
...
...
@@ -4572,6 +4627,7 @@ TEST_F(Dhcp4ParserTest, poolUserContextMissing) {
// Test verifies that it's possible to specify empty user context in the
// address pool.
TEST_F
(
Dhcp4ParserTest
,
poolUserContextEmpty
)
{
extractConfig
(
PARSER_CONFIGS
[
1
]);
PoolPtr
pool
;
getPool
(
string
(
PARSER_CONFIGS
[
1
]),
0
,
0
,
pool
);
ASSERT_TRUE
(
pool
);
...
...
@@ -4586,6 +4642,7 @@ TEST_F(Dhcp4ParserTest, poolUserContextEmpty) {
// Test verifies that it's possible to specify parameters in the user context
// in the address pool.
TEST_F
(
Dhcp4ParserTest
,
poolUserContextData
)
{
extractConfig
(
PARSER_CONFIGS
[
2
]);
PoolPtr
pool
;
getPool
(
string
(
PARSER_CONFIGS
[
2
]),
0
,
0
,
pool
);
ASSERT_TRUE
(
pool
);
...
...
@@ -4619,6 +4676,7 @@ TEST_F(Dhcp4ParserTest, poolUserContextData) {
// Test verifies that it's possible to specify parameters in the user context
// in the min-max address pool.
TEST_F
(
Dhcp4ParserTest
,
pooMinMaxlUserContext
)
{
extractConfig
(
PARSER_CONFIGS
[
3
]);
PoolPtr
pool
;
getPool
(
string
(
PARSER_CONFIGS
[
3
]),
0
,
0
,
pool
);
ASSERT_TRUE
(
pool
);
...
...
src/bin/dhcp4/tests/dhcp4_test_utils.cc
View file @
c1862585
...
...
@@ -70,6 +70,7 @@ Dhcpv4SrvTest::Dhcpv4SrvTest()
subnet_
->
getCfgOption
()
->
add
(
opt_routers
,
false
,
DHCP4_OPTION_SPACE
);
CfgMgr
::
instance
().
clear
();
CfgMgr
::
instance
().
setFamily
(
AF_INET
);
CfgMgr
::
instance
().
getStagingCfg
()
->
getCfgSubnets4
()
->
add
(
subnet_
);
CfgMgr
::
instance
().
commit
();
...
...
src/bin/dhcp4/tests/get_config_unittest.cc
0 → 100644
View file @
c1862585
// Copyright (C) 2017 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 <cc/command_interpreter.h>
#include <cc/data.h>
#include <cc/simple_parser.h>
#include <cc/cfg_to_element.h>
#include <dhcp/tests/iface_mgr_test_config.h>
#include <dhcpsrv/cfgmgr.h>
#include <dhcp4/tests/dhcp4_test_utils.h>
#include <dhcp4/tests/get_config_unittest.h>
#include <dhcp4/dhcp4_srv.h>
#include <dhcp4/json_config_parser.h>
#include <dhcp4/simple_parser4.h>
#include <boost/algorithm/string.hpp>
#include <gtest/gtest.h>
#include <iostream>
#include <string>
#include <sstream>
#include <list>
using
namespace
isc
::
config
;
using
namespace
isc
::
data
;
using
namespace
isc
::
dhcp
;
using
namespace
isc
::
dhcp
::
test
;
namespace
{
/// @name How to fill configurations
///
/// Copy get_config_unittest.cc.skel into get_config_unittest.cc
///
/// For the extracted configurations define the EXTRACT_CONFIG and
/// recompile this file. Run dhcp4_unittests on Dhcp4ParserTest
/// redirecting the standard error to a temporary file, e.g. by
/// @code
/// ./dhcp4_unittests --gtest_filter="Dhcp4Parser*" > /dev/null 2> x
/// @endcode
///
/// Update EXTRACTED_CONFIGS with the file content
///
/// When configurations have been extracted the corresponding unparsed
/// configurations must be generated. To do that define GENERATE_ACTION
/// and recompile this file. Run dhcp4_unittests on Dhcp4GetConfigTest
/// redirecting the standard error to a temporary file, e.g. by
/// @code
/// ./dhcp4_unittests --gtest_filter="Dhcp4GetConfig*" > /dev/null 2> u
/// @endcode
///
/// Update UNPARSED_CONFIGS with the file content, recompile this file
/// without EXTRACT_CONFIG and GENERATE_ACTION.
///
/// @note Check for failures at each step!
/// @note The tests of this file do not check if configs returned
/// by @ref isc::dhcp::CfgToElement::ToElement() are complete.
/// This has to be done manually.
///
///@{
/// @brief extracted configurations
const
char
*
EXTRACTED_CONFIGS
[]
=
{
// "to be replaced"
};
/// @brief unparsed configurations
const
char
*
UNPARSED_CONFIGS
[]
=
{
// "to be replaced"
};
/// @brief the number of configurations
const
size_t
max_config_counter
=
sizeof
(
EXTRACTED_CONFIGS
)
/
sizeof
(
char
*
);
///@}
/// @brief the extraction counter
///
/// < 0 means do not extract, >= 0 means extract on extractConfig() calls
/// and increment
#ifdef EXTRACT_CONFIG
int
extract_count
=
0
;
#else
int
extract_count
=
-
1
;
#endif
/// @brief the generate action
/// false means do nothing, true means unparse extracted configurations
#ifdef GENERATE_ACTION
const
bool
generate_action
=
true
;
#else
const
bool
generate_action
=
false
;
static_assert
(
max_config_counter
==
sizeof
(
UNPARSED_CONFIGS
)
/
sizeof
(
char
*
),
"unparsed configurations must be generated"
);
#endif
/// @brief format and output a configuration
void
outputFormatted
(
const
std
::
string
&
config
)
{
// pretty print it
ConstElementPtr
json
=
parseJSON
(
config
);
std
::
string
prettier
=
prettyPrint
(
json
,
4
,
4
);
// get it as a line array
std
::
list
<
std
::
string
>
lines
;
boost
::
split
(
lines
,
prettier
,
boost
::
is_any_of
(
"
\n
"
));
// add escapes using again JSON
std
::
list
<
std
::
string
>
escapes
;
while
(
!
lines
.
empty
())
{
const
std
::
string
&
line
=
lines
.
front
();
ConstElementPtr
escaping
=
Element
::
create
(
line
+
"
\n
"
);
escapes
.
push_back
(
escaping
->
str
());
lines
.
pop_front
();
}
// output them on std::cerr
while
(
!
escapes
.
empty
())
{
std
::
cerr
<<
"
\n
"
<<
escapes
.
front
();
escapes
.
pop_front
();
}
}
};
namespace
isc
{
namespace
dhcp
{
namespace
test
{
/// @ref isc::dhcp::test::extractConfig in the header
void
extractConfig
(
const
std
::
string
&
config
)
{
// skip when disable
if
(
extract_count
<
0
)
{
return
;
}
// mark beginning
if
(
extract_count
==
0
)
{
// header (note there is no trailer)
std
::
cerr
<<
"/// put this after const char* EXTRACTED_CONFIGS[] = {
\n
"
;
}
else
{
// end of previous configuration
std
::
cerr
<<
",
\n
"
;
}
std
::
cerr
<<
" // CONFIGURATION "
<<
extract_count
;
try
{
outputFormatted
(
config
);
}
catch
(...)
{
// mark error
std
::
cerr
<<
"
\n
//// got an error
\n
"
;
}
++
extract_count
;
}
};
};
};
namespace
{
/// Test fixture class (code from Dhcp4ParserTest)
class
Dhcp4GetConfigTest
:
public
::
testing
::
TestWithParam
<
size_t
>
{
public:
Dhcp4GetConfigTest
()
:
rcode_
(
-
1
)
{
// Open port 0 means to not do anything at all. We don't want to
// deal with sockets here, just check if configuration handling
// is sane.
srv_
.
reset
(
new
Dhcpv4Srv
(
0
));
// Create fresh context.
resetConfiguration
();
}
~
Dhcp4GetConfigTest
()
{
resetConfiguration
();
};