// This test checks if the lease6_select callout is executed and expected
// parameters as passed.
-TEST_F(HookAllocEngine6Test, lease6_select) {
+TEST_F(HookAllocEngine6Test, lease6Select) {
// Note: The following order is working as expected:
// 1. create AllocEngine (that register hook points)
// This test checks if lease6_select callout is able to override the values
// in a lease6.
-TEST_F(HookAllocEngine6Test, change_lease6_select) {
+TEST_F(HookAllocEngine6Test, changeLease6Select) {
// Make sure that the overridden values are different than the ones from
// subnet originally used to create the lease
// This test checks if lease6_select callout can set the status to next
// step skip without the engine to retry.
-TEST_F(HookAllocEngine6Test, skip_lease6_select) {
+TEST_F(HookAllocEngine6Test, skipLease6Select) {
// Create allocation engine (hook names are registered in its ctor)
boost::scoped_ptr<AllocEngine> engine;
// This test checks if lease6_select callout can set the status to next
// step skip with retry allocation from dynamic pool.
-TEST_F(HookAllocEngine6Test, skip_lease6_select_subnet_global_host) {
+TEST_F(HookAllocEngine6Test, skipLease6SelectGlobalHost) {
// Create allocation engine (hook names are registered in its ctor)
boost::scoped_ptr<AllocEngine> engine;
// This test checks if lease6_select callout can set the status to next
// step skip with retry allocation from dynamic pool.
-TEST_F(HookAllocEngine6Test, skip_lease6_select_subnet_subnet_host) {
+TEST_F(HookAllocEngine6Test, skipLease6SelectSubnetHost) {
// Create allocation engine (hook names are registered in its ctor)
boost::scoped_ptr<AllocEngine> engine;
// This test checks if the lease4_select callout is executed and expected
// parameters as passed.
-TEST_F(HookAllocEngine4Test, lease4_select) {
+TEST_F(HookAllocEngine4Test, lease4Select) {
// Note: The following order is working as expected:
// 1. create AllocEngine (that register hook points)
// This test checks if lease4_select callout is able to override the values
// in a lease4.
-TEST_F(HookAllocEngine4Test, change_lease4_select) {
+TEST_F(HookAllocEngine4Test, changeLease4Select) {
// Make sure that the overridden values are different than the ones from
// subnet originally used to create the lease
// but in tests we need to create it on our own.
CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
-
AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_, IOAddress("0.0.0.0"),
false, true, "somehost.example.com.", false);
ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
// This test checks if lease4_select callout can set the status to next
// step skip without the engine to retry.
-TEST_F(HookAllocEngine4Test, skip_lease4_select) {
+TEST_F(HookAllocEngine4Test, skipLease4Select) {
+
+ // Create allocation engine (hook names are registered in its ctor)
+ boost::scoped_ptr<AllocEngine> engine;
+ ASSERT_NO_THROW(engine.reset(new AllocEngine(100)));
+ ASSERT_TRUE(engine);
+
+ // Initialize Hooks Manager
+ HookLibsCollection libraries; // no libraries at this time
+ ASSERT_NO_THROW(HooksManager::loadLibraries(libraries));
+
+ // Install a callout
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
+ "lease4_select", lease4_select_skip_callout));
+
+ CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
+
+ AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
+ IOAddress("0.0.0.0"),
+ false, false, "", false);
+ ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
+ ctx.callout_handle_ = callout_handle;
+
+ Lease4Ptr lease = engine->allocateLease4(ctx);
+
+ // Check that we got no lease
+ EXPECT_FALSE(lease);
+
+ // Check no retry was attempted
+ EXPECT_EQ(1, callback_skip_);
+
+ // Check if the callout handle state was reset after the callout.
+ checkCalloutHandleReset(ctx.query_);
+}
+
+// This test checks if lease4_select callout can set the status to next
+// step skip without the engine to retry.
+TEST_F(HookAllocEngine4Test, skipLease4SelectGlobalHost) {
// Create allocation engine (hook names are registered in its ctor)
boost::scoped_ptr<AllocEngine> engine;
ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
ctx.callout_handle_ = callout_handle;
+ HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
+ Host::IDENT_HWADDR, SUBNET_ID_GLOBAL,
+ SUBNET_ID_UNUSED, IOAddress("192.0.2.105")));
+ host->setHostname("ghost1");
+
+ CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
+ CfgMgr::instance().commit();
+
+ subnet_->setReservationsGlobal(true);
+
+ // Look up the reservation.
+ engine->findReservation(ctx);
+ // Make sure we found our host.
+ ConstHostPtr current = ctx.currentHost();
+ ASSERT_TRUE(current);
+ ASSERT_EQ("ghost1", current->getHostname());
+
+ Lease4Ptr lease = engine->allocateLease4(ctx);
+
+ // Check that we got no lease
+ EXPECT_FALSE(lease);
+
+ // Check no retry was attempted
+ EXPECT_EQ(1, callback_skip_);
+
+ // Check if the callout handle state was reset after the callout.
+ checkCalloutHandleReset(ctx.query_);
+}
+
+// This test checks if lease4_select callout can set the status to next
+// step skip without the engine to retry.
+TEST_F(HookAllocEngine4Test, skipLease4SelectSubnetHost) {
+
+ // Create allocation engine (hook names are registered in its ctor)
+ boost::scoped_ptr<AllocEngine> engine;
+ ASSERT_NO_THROW(engine.reset(new AllocEngine(100)));
+ ASSERT_TRUE(engine);
+
+ // Initialize Hooks Manager
+ HookLibsCollection libraries; // no libraries at this time
+ ASSERT_NO_THROW(HooksManager::loadLibraries(libraries));
+
+ // Install a callout
+ EXPECT_NO_THROW(HooksManager::preCalloutsLibraryHandle().registerCallout(
+ "lease4_select", lease4_select_skip_callout));
+
+ CalloutHandlePtr callout_handle = HooksManager::createCalloutHandle();
+
+ AllocEngine::ClientContext4 ctx(subnet_, clientid_, hwaddr_,
+ IOAddress("0.0.0.0"),
+ false, false, "", false);
+ ctx.query_.reset(new Pkt4(DHCPREQUEST, 1234));
+ ctx.callout_handle_ = callout_handle;
+
+ HostPtr host(new Host(&hwaddr_->hwaddr_[0], hwaddr_->hwaddr_.size(),
+ Host::IDENT_HWADDR, subnet_->getID(),
+ SUBNET_ID_UNUSED, IOAddress("192.0.2.105")));
+ host->setHostname("ghost1");
+
+ CfgMgr::instance().getStagingCfg()->getCfgHosts()->add(host);
+ CfgMgr::instance().commit();
+
+ subnet_->setReservationsGlobal(true);
+
+ // Look up the reservation.
+ engine->findReservation(ctx);
+ // Make sure we found our host.
+ ConstHostPtr current = ctx.currentHost();
+ ASSERT_TRUE(current);
+ ASSERT_EQ("ghost1", current->getHostname());
+
Lease4Ptr lease = engine->allocateLease4(ctx);
// Check that we got no lease