MCPcopy Create free account
hub / github.com/apache/mesos / TEST_F

Function TEST_F

src/tests/master_authorization_tests.cpp:139–207  ·  view source on GitHub ↗

This test verifies that an authorized task launch is successful.

Source from the content-addressed store, hash-verified

137
138// This test verifies that an authorized task launch is successful.
139TEST_F(MasterAuthorizationTest, AuthorizedTask)
140{
141 // Setup ACLs so that the framework can launch tasks as "foo".
142 ACLs acls;
143 mesos::ACL::RunTask* acl = acls.add_run_tasks();
144 acl->mutable_principals()->add_values(DEFAULT_FRAMEWORK_INFO.principal());
145 acl->mutable_users()->add_values("foo");
146
147 master::Flags flags = CreateMasterFlags();
148 flags.acls = acls;
149
150 Try<Owned<cluster::Master>> master = StartMaster(flags);
151 ASSERT_SOME(master);
152
153 // Create an authorized executor.
154 ExecutorInfo executor = createExecutorInfo("test-executor", "exit 1");
155 executor.mutable_command()->set_user("foo");
156
157 MockExecutor exec(executor.executor_id());
158 TestContainerizer containerizer(&exec);
159
160 Owned<MasterDetector> detector = master.get()->createDetector();
161 Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer);
162 ASSERT_SOME(slave);
163
164 MockScheduler sched;
165 MesosSchedulerDriver driver(
166 &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
167
168 EXPECT_CALL(sched, registered(&driver, _, _));
169
170 Future<vector<Offer>> offers;
171 EXPECT_CALL(sched, resourceOffers(&driver, _))
172 .WillOnce(FutureArg<1>(&offers))
173 .WillRepeatedly(Return()); // Ignore subsequent offers.
174
175 driver.start();
176
177 AWAIT_READY(offers);
178 ASSERT_FALSE(offers->empty());
179
180 // Create an authorized task.
181 TaskInfo task;
182 task.set_name("test");
183 task.mutable_task_id()->set_value("1");
184 task.mutable_slave_id()->MergeFrom(offers.get()[0].slave_id());
185 task.mutable_resources()->MergeFrom(offers.get()[0].resources());
186 task.mutable_executor()->MergeFrom(executor);
187
188 EXPECT_CALL(exec, registered(_, _, _, _));
189
190 EXPECT_CALL(exec, launchTask(_, _))
191 .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING));
192
193 Future<TaskStatus> status;
194 EXPECT_CALL(sched, statusUpdate(&driver, _))
195 .WillOnce(FutureArg<1>(&status));
196

Callers

nothing calls this directly

Calls 15

createExecutorInfoFunction · 0.85
shutdownFunction · 0.85
FutureSatisfyFunction · 0.85
errorFunction · 0.85
WeeksClass · 0.85
createBasicAuthHeadersFunction · 0.85
protobufFunction · 0.85
AcceptedClass · 0.85
principalMethod · 0.80
createDetectorMethod · 0.80

Tested by

no test coverage detected