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

Function TEST_P

src/tests/container_logger_tests.cpp:648–827  ·  view source on GitHub ↗

Tests that the packaged logrotate container logger will rotate files when the agent is root, but the executor is launched as a non-root user. 1. When `--switch_user` is true on the agent, the logger module should launch subprocesses with the same user as the executor. 2. When `--switch_user` is false on the agent, the logger module should inherit the user of the agent.

Source from the content-addressed store, hash-verified

646// 2. When `--switch_user` is false on the agent, the logger module should
647// inherit the user of the agent.
648TEST_P(UserContainerLoggerTest,
649 ROOT_LOGROTATE_UNPRIVILEGED_USER_RotateWithSwitchUserTrueOrFalse)
650{
651 // Create a master, agent, and framework.
652 Try<Owned<cluster::Master>> master = StartMaster();
653 ASSERT_SOME(master);
654
655 Future<SlaveRegisteredMessage> slaveRegisteredMessage =
656 FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _);
657
658 // We'll need access to these flags later.
659 slave::Flags flags = CreateSlaveFlags();
660
661 // Use the non-default container logger that rotates logs.
662 flags.container_logger = LOGROTATE_CONTAINER_LOGGER_NAME;
663
664 // Parameterize the `--switch_user` flag to test both options.
665 flags.switch_user = GetParam();
666
667 // In order for the unprivileged user to successfully chdir, the
668 // agent's work directory needs to have execute permissions.
669 Try<Nothing> chmod = os::chmod(
670 flags.work_dir, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
671 ASSERT_SOME(chmod);
672
673 Fetcher fetcher(flags);
674
675 // We use an actual containerizer + executor since we want something to run.
676 Try<MesosContainerizer*> _containerizer =
677 MesosContainerizer::create(flags, false, &fetcher);
678
679 ASSERT_SOME(_containerizer);
680 Owned<MesosContainerizer> containerizer(_containerizer.get());
681
682 Owned<MasterDetector> detector = master.get()->createDetector();
683
684 Try<Owned<cluster::Slave>> slave =
685 StartSlave(detector.get(), containerizer.get(), flags);
686 ASSERT_SOME(slave);
687
688 AWAIT_READY(slaveRegisteredMessage);
689 SlaveID slaveId = slaveRegisteredMessage->slave_id();
690
691 MockScheduler sched;
692 MesosSchedulerDriver driver(
693 &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
694
695 Future<FrameworkID> frameworkId;
696 EXPECT_CALL(sched, registered(&driver, _, _))
697 .WillOnce(FutureArg<1>(&frameworkId));
698
699 // Wait for an offer, and start a task.
700 Future<vector<Offer>> offers;
701 EXPECT_CALL(sched, resourceOffers(&driver, _))
702 .WillOnce(FutureArg<1>(&offers))
703 .WillRepeatedly(Return()); // Ignore subsequent offers.
704
705 driver.start();

Callers

nothing calls this directly

Calls 15

chmodFunction · 0.85
pstreeFunction · 0.85
getExecutorPathFunction · 0.85
createDetectorMethod · 0.80
createTaskFunction · 0.70
statClass · 0.70
startMethod · 0.65
launchTasksMethod · 0.65
stopMethod · 0.65
joinMethod · 0.65
createFunction · 0.50
getenvFunction · 0.50

Tested by

no test coverage detected