diff options
author | Marcin Siodelski <marcin@isc.org> | 2018-10-18 12:12:25 +0200 |
---|---|---|
committer | Marcin Siodelski <marcin@isc.org> | 2018-10-18 13:35:08 +0200 |
commit | 892ab41d3554bb7e225b921df4d2873547ce8c2c (patch) | |
tree | 2cd62aa0b78fc74ef697fe0f686404109015a25a /src | |
parent | [#93,!63] Implemented getHost() and getPort() MySQL backend functions. (diff) | |
download | kea-892ab41d3554bb7e225b921df4d2873547ce8c2c.tar.xz kea-892ab41d3554bb7e225b921df4d2873547ce8c2c.zip |
[#93,!63] Throw exception if the server selector is unassigned.
Diffstat (limited to 'src')
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc | 123 | ||||
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h | 26 | ||||
-rw-r--r-- | src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc | 6 | ||||
-rw-r--r-- | src/lib/database/server_selector.h | 7 | ||||
-rw-r--r-- | src/lib/database/tests/server_selector_unittest.cc | 4 |
5 files changed, 165 insertions, 1 deletions
diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc index 6e6d4e05c2..dfcff9c910 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.cc @@ -185,7 +185,10 @@ public: void createUpdateGlobalParameter4(const db::ServerSelector& server_selector, const StampedValuePtr& value) { - MySqlTransaction transaction(conn_); + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } auto tag = getServerTag(server_selector, "creating or updating global parameter"); @@ -197,6 +200,8 @@ public: MySqlBinding::createString(value->getName()) }; + MySqlTransaction transaction(conn_); + // Try to update the existing row. if (conn_.updateDeleteQuery(MySqlConfigBackendDHCPv4Impl::UPDATE_GLOBAL_PARAMETER4, in_bindings) == 0) { @@ -656,6 +661,11 @@ public: void createUpdateSubnet4(const ServerSelector& server_selector, const Subnet4Ptr& subnet) { + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating subnet"); // Convert DHCPv4o6 interface id to text. @@ -984,6 +994,12 @@ public: /// network doesn't exist. SharedNetwork4Ptr getSharedNetwork4(const ServerSelector& server_selector, const std::string& name) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "fetching shared network"); MySqlBindingCollection in_bindings = { @@ -1043,6 +1059,12 @@ public: /// @param subnet Pointer to the shared network to be inserted or updated. void createUpdateSharedNetwork4(const ServerSelector& server_selector, const SharedNetwork4Ptr& shared_network) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating shared network"); MySqlBindingCollection in_bindings = { @@ -1142,6 +1164,11 @@ public: void createUpdateOption4(const ServerSelector& server_selector, const OptionDescriptorPtr& option) { + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating global option"); MySqlBindingCollection in_bindings = { @@ -1187,6 +1214,11 @@ public: const SubnetID& subnet_id, const OptionDescriptorPtr& option) { + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating subnet level option"); @@ -1258,6 +1290,11 @@ public: const uint64_t pool_id, const OptionDescriptorPtr& option) { + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating pool level option"); @@ -1304,6 +1341,12 @@ public: void createUpdateOption4(const ServerSelector& server_selector, const std::string& shared_network_name, const OptionDescriptorPtr& option) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating shared" " network level option"); @@ -1354,6 +1397,12 @@ public: OptionDefinitionPtr getOptionDef4(const ServerSelector& server_selector, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "fetching option definition"); OptionDefContainer option_defs; @@ -1418,6 +1467,12 @@ public: OptionDescriptorPtr getOption4(const ServerSelector& server_selector, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "fetching global option"); OptionContainer options; @@ -1488,6 +1543,12 @@ public: const SubnetID& subnet_id, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "fetching subnet level option"); OptionContainer options; @@ -1517,6 +1578,12 @@ public: const uint64_t pool_id, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "fetching pool level option"); OptionContainer options; @@ -1546,6 +1613,12 @@ public: const std::string& shared_network_name, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "fetching shared network" " level option"); @@ -1568,6 +1641,12 @@ public: /// @param option_def Pointer to the option definition to be inserted or updated. void createUpdateOptionDef4(const ServerSelector& server_selector, const OptionDefinitionPtr& option_def) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "creating or updating option definition"); ElementPtr record_types = Element::createList(); @@ -1645,6 +1724,12 @@ public: uint64_t deleteOptionDef4(const ServerSelector& server_selector, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting option definition"); MySqlBindingCollection in_bindings = { @@ -1666,6 +1751,12 @@ public: uint64_t deleteOption4(const ServerSelector& server_selector, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting global option"); MySqlBindingCollection in_bindings = { @@ -1690,6 +1781,12 @@ public: const SubnetID& subnet_id, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting option for a subnet"); MySqlBindingCollection in_bindings = { @@ -1716,6 +1813,12 @@ public: const IOAddress& pool_end_address, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting option for a pool"); MySqlBindingCollection in_bindings = { @@ -1743,6 +1846,12 @@ public: const std::string& shared_network_name, const uint16_t code, const std::string& space) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting option for a shared network"); MySqlBindingCollection in_bindings = { @@ -1765,6 +1874,12 @@ public: /// @return Number of deleted options. uint64_t deleteOptions4(const ServerSelector& server_selector, const Subnet4Ptr& subnet) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting options for a subnet"); MySqlBindingCollection in_bindings = { @@ -1785,6 +1900,12 @@ public: /// @return Number of deleted options. uint64_t deleteOptions4(const ServerSelector& server_selector, const SharedNetwork4Ptr& shared_network) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, "deleting options for a shared network"); MySqlBindingCollection in_bindings = { diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h index 0e5fba1841..65b38017d7 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_dhcp4.h @@ -32,6 +32,7 @@ public: /// @param server_selector Server selector. /// @param subnet_prefix Prefix of the subnet to be retrieved. /// @return Pointer to the retrieved subnet or NULL if not found. + /// @throw NotImplemented if server selector is "unassigned". virtual Subnet4Ptr getSubnet4(const db::ServerSelector& server_selector, const std::string& subnet_prefix) const; @@ -41,6 +42,7 @@ public: /// @param server_selector Server selector. /// @param subnet_id Identifier of a subnet to be retrieved. /// @return Pointer to the retrieved subnet or NULL if not found. + /// @throw NotImplemented if server selector is "unassigned". virtual Subnet4Ptr getSubnet4(const db::ServerSelector& server_selector, const SubnetID& subnet_id) const; @@ -65,6 +67,7 @@ public: /// @param server_selector Server selector. /// @param name Name of the shared network to be retrieved. /// @return Pointer to the shared network or NULL if not found. + /// @throw NotImplemented if server selector is "unassigned". virtual SharedNetwork4Ptr getSharedNetwork4(const db::ServerSelector& server_selector, const std::string& name) const; @@ -93,6 +96,7 @@ public: /// @param code Code of the option to be retrieved. /// @param space Option space of the option to be retrieved. /// @return Pointer to the option definition or NULL if not found. + /// @throw NotImplemented if server selector is "unassigned". virtual OptionDefinitionPtr getOptionDef4(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space) const; @@ -121,6 +125,7 @@ public: /// @param server_selector Server selector. /// @return Pointer to the retrieved option descriptor or null if /// no option was found. + /// @throw NotImplemented if server selector is "unassigned". virtual OptionDescriptorPtr getOption4(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space) const; @@ -148,6 +153,7 @@ public: /// @param server_selector Server selector. /// @param name Name of the global parameter to be retrieved. /// @return Value of the global parameter. + /// @throw NotImplemented if server selector is "unassigned". virtual data::StampedValuePtr getGlobalParameter4(const db::ServerSelector& server_selector, const std::string& name) const; @@ -170,6 +176,7 @@ public: /// /// @param server_selector Server selector. /// @param subnet Subnet to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateSubnet4(const db::ServerSelector& server_selector, const Subnet4Ptr& subnet); @@ -178,6 +185,7 @@ public: /// /// @param server_selector Server selector. /// @param shared_network Shared network to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateSharedNetwork4(const db::ServerSelector& server_selector, const SharedNetwork4Ptr& shared_network); @@ -186,6 +194,7 @@ public: /// /// @param server_selector Server selector. /// @param option_def Option definition to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateOptionDef4(const db::ServerSelector& server_selector, const OptionDefinitionPtr& option_def); @@ -194,6 +203,7 @@ public: /// /// @param server_selector Server selector. /// @param option Option to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateOption4(const db::ServerSelector& server_selector, const OptionDescriptorPtr& option); @@ -204,6 +214,7 @@ public: /// @param shared_network_name Name of a shared network to which option /// belongs. /// @param option Option to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateOption4(const db::ServerSelector& server_selector, const std::string& shared_network_name, @@ -214,6 +225,7 @@ public: /// @param server_selector Server selector. /// @param subnet_id Identifier of a subnet to which option belongs. /// @param option Option to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateOption4(const db::ServerSelector& server_selector, const SubnetID& subnet_id, @@ -227,6 +239,7 @@ public: /// @param pool_end_address Upper bound address of the pool to which the /// option belongs. /// @param option Option to be added or updated. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateOption4(const db::ServerSelector& server_selector, const asiolink::IOAddress& pool_start_address, @@ -238,6 +251,7 @@ public: /// @param server_selector Server selector. /// @param name Name of the global parameter. /// @param value Value of the global parameter. + /// @throw NotImplemented if server selector is "unassigned". virtual void createUpdateGlobalParameter4(const db::ServerSelector& server_selector, const data::StampedValuePtr& value); @@ -247,6 +261,7 @@ public: /// @param server_selector Server selector. /// @param subnet_prefix Prefix of the subnet to be deleted. /// @return Number of deleted subnets. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteSubnet4(const db::ServerSelector& server_selector, const std::string& subnet_prefix); @@ -256,6 +271,7 @@ public: /// @param server_selector Server selector. /// @param subnet_id Identifier of the subnet to be deleted. /// @return Number of deleted subnets. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteSubnet4(const db::ServerSelector& server_selector, const SubnetID& subnet_id); @@ -263,6 +279,7 @@ public: /// /// @param server_selector Server selector. /// @return Number of deleted subnets. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteAllSubnets4(const db::ServerSelector& server_selector); @@ -271,6 +288,7 @@ public: /// @param server_selector Server selector. /// @param name Name of the shared network to be deleted. /// @return Number of deleted shared networks. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteSharedNetwork4(const db::ServerSelector& server_selector, const std::string& name); @@ -288,6 +306,7 @@ public: /// @param code Code of the option to be deleted. /// @param space Option space of the option to be deleted. /// @return Number of deleted option definitions. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteOptionDef4(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space); @@ -296,6 +315,7 @@ public: /// /// @param server_selector Server selector. /// @return Number of deleted option definitions. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteAllOptionDefs4(const db::ServerSelector& server_selector); @@ -305,6 +325,7 @@ public: /// @param code Code of the option to be deleted. /// @param space Option space of the option to be deleted. /// @return Number of deleted options. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteOption4(const db::ServerSelector& server_selector, const uint16_t code, const std::string& space); @@ -316,6 +337,7 @@ public: /// option belongs to /// @param code Code of the deleted option. /// @param space Option space of the deleted option. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteOption4(const db::ServerSelector& server_selector, const std::string& shared_network_name, @@ -330,6 +352,7 @@ public: /// @param code Code of the deleted option. /// @param space Option space of the deleted option. /// @return Number of deleted options. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteOption4(const db::ServerSelector& server_selector, const SubnetID& subnet_id, const uint16_t code, const std::string& space); @@ -344,6 +367,7 @@ public: /// @param code Code of the deleted option. /// @param space Option space of the deleted option. /// @return Number of deleted options. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteOption4(const db::ServerSelector& server_selector, const asiolink::IOAddress& pool_start_address, @@ -356,6 +380,7 @@ public: /// @param server_selector Server selector. /// @param name Name of the global parameter to be deleted. /// @return Number of deleted global parameters. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteGlobalParameter4(const db::ServerSelector& server_selector, const std::string& name); @@ -364,6 +389,7 @@ public: /// /// @param server_selector Server selector. /// @return Number of deleted global parameters. + /// @throw NotImplemented if server selector is "unassigned". virtual uint64_t deleteAllGlobalParameters4(const db::ServerSelector& server_selector); diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 6c446fd25e..01ced7ad9f 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -85,6 +85,12 @@ uint64_t MySqlConfigBackendImpl::deleteFromTable(const int index, const ServerSelector& server_selector, const std::string& operation) { + + if (server_selector.amUnassigned()) { + isc_throw(NotImplemented, "managing configuration for no particular server" + " (unassigned) is unsupported at the moment"); + } + auto tag = getServerTag(server_selector, operation); MySqlBindingCollection in_bindings = { diff --git a/src/lib/database/server_selector.h b/src/lib/database/server_selector.h index ed05ce9811..4d1e07191f 100644 --- a/src/lib/database/server_selector.h +++ b/src/lib/database/server_selector.h @@ -88,6 +88,13 @@ public: return (tags_); } + /// @brief Convenience method checking if the server selector is "unassigned". + /// + /// @return true if the selector is "unassigned", false otherwise. + bool amUnassigned() const { + return (getType() == Type::UNASSIGNED); + } + private: /// @brief Constructor used for "unassigned" and "all" slection types. diff --git a/src/lib/database/tests/server_selector_unittest.cc b/src/lib/database/tests/server_selector_unittest.cc index 1f2ab09c03..28ee65925b 100644 --- a/src/lib/database/tests/server_selector_unittest.cc +++ b/src/lib/database/tests/server_selector_unittest.cc @@ -16,6 +16,7 @@ namespace { TEST(ServerSelectorTest, unassigned) { ServerSelector selector = ServerSelector::UNASSIGNED(); EXPECT_EQ(ServerSelector::Type::UNASSIGNED, selector.getType()); + EXPECT_TRUE(selector.amUnassigned()); EXPECT_TRUE(selector.getTags().empty()); } @@ -23,6 +24,7 @@ TEST(ServerSelectorTest, unassigned) { TEST(ServerSelectorTest, all) { ServerSelector selector = ServerSelector::ALL(); EXPECT_EQ(ServerSelector::Type::ALL, selector.getType()); + EXPECT_FALSE(selector.amUnassigned()); EXPECT_TRUE(selector.getTags().empty()); } @@ -30,6 +32,7 @@ TEST(ServerSelectorTest, all) { TEST(ServerSelectorTest, one) { ServerSelector selector = ServerSelector::ONE("some-tag"); EXPECT_EQ(ServerSelector::Type::SUBSET, selector.getType()); + EXPECT_FALSE(selector.amUnassigned()); std::set<std::string> tags = selector.getTags(); ASSERT_EQ(1, tags.size()); @@ -40,6 +43,7 @@ TEST(ServerSelectorTest, one) { TEST(ServerSelectorTest, multiple) { ServerSelector selector = ServerSelector::MULTIPLE({ "tag1", "tag2", "tag3" }); EXPECT_EQ(ServerSelector::Type::SUBSET, selector.getType()); + EXPECT_FALSE(selector.amUnassigned()); std::set<std::string> tags = selector.getTags(); ASSERT_EQ(3, tags.size()); |