mesos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From al...@apache.org
Subject [1/4] mesos git commit: Added a test to ensure MESOS-6142 is fixed.
Date Wed, 16 Nov 2016 15:35:12 GMT
Repository: mesos
Updated Branches:
  refs/heads/master c333f4bef -> a568bcdf5


Added a test to ensure MESOS-6142 is fixed.

This test ensures that frameworks can't reserve resources using a role
different from the one they registered with.

Review: https://reviews.apache.org/r/53470/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/a1780704
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/a1780704
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/a1780704

Branch: refs/heads/master
Commit: a1780704308838d89eac75149cf2ba71da464b46
Parents: c333f4b
Author: Gastón Kleiman <gaston@mesosphere.com>
Authored: Wed Nov 16 16:11:37 2016 +0100
Committer: Alexander Rukletsov <alexr@apache.org>
Committed: Wed Nov 16 16:31:34 2016 +0100

----------------------------------------------------------------------
 src/tests/reservation_tests.cpp | 92 ++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a1780704/src/tests/reservation_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/reservation_tests.cpp b/src/tests/reservation_tests.cpp
index 6c28ab4..b589e91 100644
--- a/src/tests/reservation_tests.cpp
+++ b/src/tests/reservation_tests.cpp
@@ -2087,6 +2087,98 @@ TEST_F(ReservationTest, WithoutAuthenticationWithPrincipal)
   driver.join();
 }
 
+
+// This tests that a framework can't reserve resources using a role different
+// from the one it registered with.
+TEST_F(ReservationTest, DropReserveWithInvalidRole)
+{
+  const string frameworkRole = "role";
+  const string invalidRole = "invalid-role";
+
+  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
+  frameworkInfo.set_role(frameworkRole);
+
+  master::Flags masterFlags = CreateMasterFlags();
+  masterFlags.allocation_interval = Milliseconds(5);
+
+  TestAllocator<> allocator;
+  EXPECT_CALL(allocator, initialize(_, _, _, _, _));
+
+  Try<Owned<cluster::Master>> master = StartMaster(&allocator, masterFlags);
+  ASSERT_SOME(master);
+
+  slave::Flags agentFlags = CreateSlaveFlags();
+  agentFlags.resources = "cpus:1;mem:512";
+
+  EXPECT_CALL(allocator, addSlave(_, _, _, _, _));
+
+  Owned<MasterDetector> detector = master.get()->createDetector();
+  Try<Owned<cluster::Slave>> agent = StartSlave(detector.get(), agentFlags);
+  ASSERT_SOME(agent);
+
+  MockScheduler sched;
+  MesosSchedulerDriver driver(
+      &sched, frameworkInfo, master.get()->pid, DEFAULT_CREDENTIAL);
+
+  // We use this to capture offers from 'resourceOffers'.
+  Future<vector<Offer>> offers;
+
+  EXPECT_CALL(sched, registered(&driver, _, _));
+
+  // The expectation for the first offer.
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers));
+
+  EXPECT_CALL(allocator, addFramework(_, _, _));
+
+  driver.start();
+
+  // In the first offer, expect an offer with unreserved resources.
+  AWAIT_READY(offers);
+
+  ASSERT_EQ(1u, offers.get().size());
+  Offer offer = offers->front();
+
+  Resources unreserved = Resources::parse("cpus:1;mem:512").get();
+  EXPECT_TRUE(Resources(offer.resources()).contains(unreserved));
+
+  // The expectation for the next offer.
+  EXPECT_CALL(sched, resourceOffers(&driver, _))
+    .WillOnce(FutureArg<1>(&offers))
+    .WillRepeatedly(Return()); // Ignore subsequent offers.
+
+  // Expect that the reserve offer operation will be dropped.
+  EXPECT_CALL(allocator, updateAllocation(_, _, _, _))
+    .Times(0);
+
+  // We use the filter explicitly here so that the resources will not
+  // be filtered for 5 seconds (the default).
+  Filters filters;
+  filters.set_refuse_seconds(0);
+
+  // Attempt to reserve resources using a different role than the one the
+  // framework is registered with.
+  Resources dynamicallyReservedInvalidRole = unreserved.flatten(
+      invalidRole,
+      createReservationInfo(frameworkInfo.principal())).get();
+
+  driver.acceptOffers(
+      {offer.id()},
+      {RESERVE(dynamicallyReservedInvalidRole)},
+      filters);
+
+  // In the next offer, still expect an offer with the unreserved resources.
+  AWAIT_READY(offers);
+
+  ASSERT_EQ(1u, offers.get().size());
+  offer = offers->front();
+
+  EXPECT_TRUE(Resources(offer.resources()).contains(unreserved));
+
+  driver.stop();
+  driver.join();
+}
+
 }  // namespace tests {
 }  // namespace internal {
 }  // namespace mesos {


Mime
View raw message