Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Kea
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
416
Issues
416
List
Boards
Labels
Service Desk
Milestones
Merge Requests
67
Merge Requests
67
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
ISC Open Source Projects
Kea
Commits
3179f303
Commit
3179f303
authored
Jan 31, 2019
by
Marcin Siodelski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[
#429
,
!217
] Removed StampedValue::toElement.
parent
ac9507a0
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
16 additions
and
238 deletions
+16
-238
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp4/json_config_parser.cc
+10
-30
src/bin/dhcp4/json_config_parser.h
src/bin/dhcp4/json_config_parser.h
+1
-6
src/bin/dhcp4/tests/config_backend_unittest.cc
src/bin/dhcp4/tests/config_backend_unittest.cc
+0
-61
src/lib/cc/stamped_value.cc
src/lib/cc/stamped_value.cc
+0
-54
src/lib/cc/stamped_value.h
src/lib/cc/stamped_value.h
+5
-12
src/lib/cc/tests/stamped_value_unittest.cc
src/lib/cc/tests/stamped_value_unittest.cc
+0
-75
No files found.
src/bin/dhcp4/json_config_parser.cc
View file @
3179f303
...
...
@@ -744,18 +744,19 @@ void addGlobalsToConfig(SrvConfigPtr external_cfg, data::StampedValueCollection&
const
auto
&
index
=
cb_globals
.
get
<
StampedValueNameIndexTag
>
();
for
(
auto
cb_global
=
index
.
begin
();
cb_global
!=
index
.
end
();
++
cb_global
)
{
// If the global is an explicit member of SrvConfig handle it that way.
if
(
handleExplicitGlobal
(
external_cfg
,
(
*
cb_global
)
))
{
if
(
(
*
cb_global
)
->
amNull
(
))
{
continue
;
}
//
Otherwise it must be added to the implicitly configured globals
if
(
handle
Im
plicitGlobal
(
external_cfg
,
(
*
cb_global
)))
{
//
If the global is an explicit member of SrvConfig handle it that way.
if
(
handle
Ex
plicitGlobal
(
external_cfg
,
(
*
cb_global
)))
{
continue
;
}
isc_throw
(
DhcpConfigError
,
"Config backend supplied unsupported global: "
<<
(
*
cb_global
)
->
getName
()
<<
" = "
<<
(
*
cb_global
)
->
getValue
());
}
else
{
// Otherwise it must be added to the implicitly configured globals
handleImplicitGlobal
(
external_cfg
,
(
*
cb_global
));
}
}
}
...
...
@@ -780,29 +781,8 @@ bool handleExplicitGlobal(SrvConfigPtr external_cfg, const data::StampedValuePtr
return
(
was_handled
);
}
bool
handleImplicitGlobal
(
SrvConfigPtr
external_cfg
,
const
data
::
StampedValuePtr
&
cb_global
)
{
// @todo One day we convert it based on the type stored in StampedValue, but
// that day is not today. For now, if we find it in the global defaults use
// the element type there.
for
(
auto
global_default
:
SimpleParser4
::
GLOBAL4_DEFAULTS
)
{
if
(
global_default
.
name_
==
cb_global
->
getName
())
{
ElementPtr
element
=
cb_global
->
toElement
(
global_default
.
type_
);
external_cfg
->
addConfiguredGlobal
(
cb_global
->
getName
(),
element
);
return
(
true
);
}
}
// We didn't find it in the default list, so is it an optional implicit?
const
std
::
string
&
name
=
cb_global
->
getName
();
if
((
name
==
"renew-timer"
)
||
(
name
==
"rebind-timer"
))
{
ElementPtr
element
=
cb_global
->
toElement
(
Element
::
integer
);
external_cfg
->
addConfiguredGlobal
(
cb_global
->
getName
(),
element
);
return
(
true
);
}
return
(
false
);
void
handleImplicitGlobal
(
SrvConfigPtr
external_cfg
,
const
data
::
StampedValuePtr
&
cb_global
)
{
external_cfg
->
addConfiguredGlobal
(
cb_global
->
getName
(),
cb_global
->
getElementValue
());
}
};
// end of isc::dhcp namespace
...
...
src/bin/dhcp4/json_config_parser.h
View file @
3179f303
...
...
@@ -129,12 +129,7 @@ bool handleExplicitGlobal(SrvConfigPtr external_cfg,
///
/// @param external_cfg SrvConfig instance to update
/// @param cb_global global parameter supplied by configuration backend
///
/// @return true if the global is recognized as a supported global, false
/// otherwise
///
/// @throw BadValue if the global's value is not the expected data type
bool
handleImplicitGlobal
(
SrvConfigPtr
external_cfg
,
void
handleImplicitGlobal
(
SrvConfigPtr
external_cfg
,
const
data
::
StampedValuePtr
&
cb_global
);
};
// end of isc::dhcp namespace
...
...
src/bin/dhcp4/tests/config_backend_unittest.cc
View file @
3179f303
...
...
@@ -207,67 +207,6 @@ public:
TestConfigBackendDHCPv4Ptr
db2_
;
///< Second configuration backend instance
};
// This test verifies that an implicit global whose data value
// does not match the expected type is detected.
TEST_F
(
Dhcp4CBTest
,
implicitGlobalWrongType
)
{
string
base_config
=
"{
\n
"
"
\"
config-control
\"
: {
\n
"
"
\"
config-databases
\"
: [ {
\n
"
"
\"
type
\"
:
\"
memfile
\"
,
\n
"
"
\"
host
\"
:
\"
db1
\"
\n
"
" },{
\n
"
"
\"
type
\"
:
\"
memfile
\"
,
\n
"
"
\"
host
\"
:
\"
db2
\"
\n
"
" }
\n
"
" ]
\n
"
" }
\n
"
"}
\n
"
;
extractConfig
(
base_config
);
// Make some globals:
// @todo StampedValue is going to be extended to hold type.
StampedValuePtr
badGlobal
(
new
StampedValue
(
"valid-lifetime"
,
"not an int"
));
db1_
->
createUpdateGlobalParameter4
(
ServerSelector
::
ALL
(),
badGlobal
);
// Should fail to merge with an error.
configure
(
base_config
,
CONTROL_RESULT_ERROR
,
"StampedValue::toElement: integer value expected for:"
" valid-lifetime, value is: not an int"
);
}
// This test verifies that unknown externally configured
// globals is detected.
TEST_F
(
Dhcp4CBTest
,
unknownGlobal
)
{
string
base_config
=
"{
\n
"
"
\"
config-control
\"
: {
\n
"
"
\"
config-databases
\"
: [ {
\n
"
"
\"
type
\"
:
\"
memfile
\"
,
\n
"
"
\"
host
\"
:
\"
db1
\"
\n
"
" },{
\n
"
"
\"
type
\"
:
\"
memfile
\"
,
\n
"
"
\"
host
\"
:
\"
db2
\"
\n
"
" }
\n
"
" ]
\n
"
" }
\n
"
"}
\n
"
;
extractConfig
(
base_config
);
// Make some globals:
// @todo StampedValue is going to be extended to hold type.
StampedValuePtr
badGlobal
(
new
StampedValue
(
"bogus-global"
,
"some value"
));
db1_
->
createUpdateGlobalParameter4
(
ServerSelector
::
ALL
(),
badGlobal
);
// Should fail to merge with an error.
configure
(
base_config
,
CONTROL_RESULT_ERROR
,
"Config backend supplied unsupported global:"
" bogus-global = some value"
);
}
// This test verifies that externally configured globals are
// merged correctly into staging configuration.
// @todo enable test when SrvConfig can merge globals.
...
...
src/lib/cc/stamped_value.cc
View file @
3179f303
...
...
@@ -179,59 +179,5 @@ StampedValue::validateAccess(Element::types type) const {
}
}
ElementPtr
StampedValue
::
toElement
(
Element
::
types
elem_type
)
{
ElementPtr
element
;
switch
(
elem_type
)
{
case
Element
::
string
:
{
element
.
reset
(
new
StringElement
(
value_
));
break
;
}
case
Element
::
integer
:
{
try
{
int64_t
int_value
=
boost
::
lexical_cast
<
int64_t
>
(
value_
);
element
.
reset
(
new
IntElement
(
int_value
));
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
BadValue
,
"StampedValue::toElement: integer value expected for: "
<<
name_
<<
", value is: "
<<
value_
);
}
break
;
}
case
Element
::
boolean
:
{
bool
bool_value
;
if
(
value_
==
std
::
string
(
"true"
))
{
bool_value
=
true
;
}
else
if
(
value_
==
std
::
string
(
"false"
))
{
bool_value
=
false
;
}
else
{
isc_throw
(
BadValue
,
"StampedValue::toElement: boolean value specified as "
<<
name_
<<
", value is: "
<<
value_
<<
", expected true or false"
);
}
element
.
reset
(
new
BoolElement
(
bool_value
));
break
;
}
case
Element
::
real
:
{
try
{
double
dbl_value
=
boost
::
lexical_cast
<
double
>
(
value_
);
element
.
reset
(
new
DoubleElement
(
dbl_value
));
}
catch
(
const
std
::
exception
&
ex
)
{
isc_throw
(
BadValue
,
"StampedValue::toElement: real number value expected for: "
<<
name_
<<
", value is: "
<<
value_
);
}
break
;
}
default:
isc_throw
(
BadValue
,
"StampedValue::toElement: unsupported element type "
<<
elem_type
<<
" for: "
<<
name_
);
break
;
}
return
(
element
);
}
}
// end of namespace isc::data
}
// end of namespace isc
src/lib/cc/stamped_value.h
View file @
3179f303
...
...
@@ -143,18 +143,6 @@ public:
/// type.
int64_t
getSignedIntegerValue
()
const
;
/// @brief Creates an Element with the appropriate value
///
/// @param etype type of Element to create
/// @todo If StampedValue is extended to contain the Element::type
/// this parameter can be done away with.
///
/// @return A pointer to the new Element
/// @throw BadValue if the current value is invalid for the
/// requested element type. InvalidOperation if the requested
/// type is unsupported.
ElementPtr
toElement
(
const
Element
::
types
etype
);
/// @brief Returns value as a boolean.
///
/// @return Stored value as a boolean.
...
...
@@ -169,6 +157,11 @@ public:
/// type.
double
getDoubleValue
()
const
;
/// @brief Returns the value as @c Element.
ConstElementPtr
getElementValue
()
const
{
return
(
value_
);
}
private:
/// @brief Checks if the values passed to the constructors
...
...
src/lib/cc/tests/stamped_value_unittest.cc
View file @
3179f303
...
...
@@ -156,79 +156,4 @@ TEST(StampedValueTest, createFailures) {
EXPECT_THROW
(
StampedValue
::
create
(
"bar"
,
"1"
,
Element
::
null
),
TypeError
);
}
// Tests that Elements can be created from stamped values.
TEST
(
StampedValueTest
,
toElement
)
{
ElementPtr
elem
;
boost
::
scoped_ptr
<
StampedValue
>
value
;
// Make sure we can create a StringElement.
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"boo"
)));
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
string
));
ASSERT_EQ
(
Element
::
string
,
elem
->
getType
());
ASSERT_EQ
(
"boo"
,
elem
->
stringValue
());
// Make non-string types fail.
ASSERT_THROW
(
value
->
toElement
(
Element
::
integer
),
BadValue
);
ASSERT_THROW
(
value
->
toElement
(
Element
::
boolean
),
BadValue
);
ASSERT_THROW
(
value
->
toElement
(
Element
::
real
),
BadValue
);
// Make sure we can create a IntElement.
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"777"
)));
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
integer
));
ASSERT_EQ
(
Element
::
integer
,
elem
->
getType
());
ASSERT_EQ
(
777
,
elem
->
intValue
());
// String should work.
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
string
));
ASSERT_EQ
(
"777"
,
elem
->
stringValue
());
// Real should work.
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
real
));
ASSERT_EQ
(
777.0
,
elem
->
doubleValue
());
// Boolean will fail.
ASSERT_THROW
(
value
->
toElement
(
Element
::
boolean
),
BadValue
);
// Make sure we can create a Boolean.
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"true"
)));
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
boolean
));
ASSERT_EQ
(
Element
::
boolean
,
elem
->
getType
());
ASSERT_TRUE
(
elem
->
boolValue
());
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"false"
)));
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
boolean
));
ASSERT_EQ
(
Element
::
boolean
,
elem
->
getType
());
ASSERT_FALSE
(
elem
->
boolValue
());
// String should work.
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
string
));
ASSERT_EQ
(
"false"
,
elem
->
stringValue
());
// Make numerics should fail.
ASSERT_THROW
(
value
->
toElement
(
Element
::
integer
),
BadValue
);
ASSERT_THROW
(
value
->
toElement
(
Element
::
real
),
BadValue
);
// Make sure only lower case "true" and "false" works for Booleans.
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"TRUE"
)));
ASSERT_THROW
(
value
->
toElement
(
Element
::
boolean
),
BadValue
);
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"FALSE"
)));
ASSERT_THROW
(
value
->
toElement
(
Element
::
boolean
),
BadValue
);
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"nonsens"
)));
ASSERT_THROW
(
value
->
toElement
(
Element
::
boolean
),
BadValue
);
// Make sure we can create a DoubleElement.
ASSERT_NO_THROW
(
value
.
reset
(
new
StampedValue
(
"foo"
,
"45.0"
)));
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
real
));
ASSERT_EQ
(
Element
::
real
,
elem
->
getType
());
ASSERT_EQ
(
45.0
,
elem
->
doubleValue
());
// String should work.
ASSERT_NO_THROW
(
elem
=
value
->
toElement
(
Element
::
string
));
ASSERT_EQ
(
"45.0"
,
elem
->
stringValue
());
// Int and Boolean should fail.
ASSERT_THROW
(
value
->
toElement
(
Element
::
integer
),
BadValue
);
ASSERT_THROW
(
value
->
toElement
(
Element
::
boolean
),
BadValue
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment