src/tests/slave_tests.cpp
TEST_F(SlaveTest, TaskStatusContainerStatus)
{
  Try<Owned<cluster::Master>> master = StartMaster();
  ASSERT_SOME(master);

  MockExecutor exec(DEFAULT_EXECUTOR_ID);
  TestContainerizer containerizer(&exec);

  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer);
  ASSERT_SOME(slave);

  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);

  EXPECT_CALL(sched, registered(&driver, _, _))
    .Times(1);

  Future<vector<Offer>> offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); // Ignore subsequent offers.

  driver.start();

  AWAIT_READY(offers);
  EXPECT_NE(0u, offers.get().size());

  TaskInfo task = createTask(offers.get()[0], "sleep 100", DEFAULT_EXECUTOR_ID);

  ExecutorDriver* execDriver;
  EXPECT_CALL(exec, registered(_, _, _, _))
    .WillOnce(SaveArg<0>(&execDriver));

  EXPECT_CALL(exec, launchTask(_, _))
    .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING));

  Future<TaskStatus> status;
  EXPECT_CALL(sched, statusUpdate(&driver, _))
    .WillOnce(FutureArg<1>(&status));

  driver.launchTasks(offers.get()[0].id(), {task});

  AWAIT_READY(status);

  const string slaveIPAddress = stringify(slave.get()->pid.address.ip);

  // Validate that the Slave has passed in its IP address in
  // TaskStatus.container_status.network_infos[0].ip_address.
  EXPECT_TRUE(status.get().has_container_status());
  EXPECT_EQ(1, status.get().container_status().network_infos().size());
  EXPECT_TRUE(
      status.get().container_status().network_infos(0).has_ip_address());
  EXPECT_EQ(
      slaveIPAddress,
      status.get().container_status().network_infos(0).ip_address());

  // Now do the same validation with state endpoint.
  Future<Response> response = process::http::get(
      slave.get()->pid,
      "state",
      None(),
      createBasicAuthHeaders(DEFAULT_CREDENTIAL));

  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  AWAIT_EXPECT_RESPONSE_HEADER_EQ(APPLICATION_JSON, "Content-Type", response);

  Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
  ASSERT_SOME(parse);

  // Validate that the IP address passed in by the Slave is available at the
  // state endpoint.
  ASSERT_SOME_EQ(
      slaveIPAddress,
      parse.get().find<JSON::String>(
          "frameworks[0].executors[0].tasks[0].statuses[0]"
          ".container_status.network_infos[0].ip_address"));

  EXPECT_CALL(exec, shutdown(_))
    .Times(AtMost(1));

  driver.stop();
  driver.join();
}
// This test verifies that TaskStatus::container_status an is exposed over
// the slave state endpoint.
This test verifies that TaskStatus::container_status an is exposed over
the slave state endpoint.
This test verifies that TaskStatus :: container_status an is exposed over the slave state endpoint .
TEST_F(SlaveTest, TaskStatusContainerStatus)
{
  Try<Owned<cluster::Master>> master = StartMaster();
  ASSERT_SOME(master);
  MockExecutor exec(DEFAULT_EXECUTOR_ID);
  TestContainerizer containerizer(&exec);
  Owned<MasterDetector> detector = master.get()->createDetector();
  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer);
  ASSERT_SOME(slave);
  MockScheduler sched;
  MesosSchedulerDriver driver(
      &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL);
  EXPECT_CALL(sched, registered(&driver, _, _))
    .Times(1);
  Future<vector<Offer>> offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); 
  driver.start();
  AWAIT_READY(offers);
  EXPECT_NE(0u, offers.get().size());
  TaskInfo task = createTask(offers.get()[0], "sleep 100", DEFAULT_EXECUTOR_ID);
  ExecutorDriver* execDriver;
  EXPECT_CALL(exec, registered(_, _, _, _))
    .WillOnce(SaveArg<0>(&execDriver));
  EXPECT_CALL(exec, launchTask(_, _))
    .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING));
  Future<TaskStatus> status;
  EXPECT_CALL(sched, statusUpdate(&driver, _))
    .WillOnce(FutureArg<1>(&status));
  driver.launchTasks(offers.get()[0].id(), {task});
  AWAIT_READY(status);
  const string slaveIPAddress = stringify(slave.get()->pid.address.ip);
  EXPECT_TRUE(status.get().has_container_status());
  EXPECT_EQ(1, status.get().container_status().network_infos().size());
  EXPECT_TRUE(
      status.get().container_status().network_infos(0).has_ip_address());
  EXPECT_EQ(
      slaveIPAddress,
      status.get().container_status().network_infos(0).ip_address());
  Future<Response> response = process::http::get(
      slave.get()->pid,
      "state",
      None(),
      createBasicAuthHeaders(DEFAULT_CREDENTIAL));
  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
  AWAIT_EXPECT_RESPONSE_HEADER_EQ(APPLICATION_JSON, "Content-Type", response);
  Try<JSON::Object> parse = JSON::parse<JSON::Object>(response.get().body);
  ASSERT_SOME(parse);
  ASSERT_SOME_EQ(
      slaveIPAddress,
      parse.get().find<JSON::String>(
          "frameworks[0].executors[0].tasks[0].statuses[0]"
          ".container_status.network_infos[0].ip_address"));
  EXPECT_CALL(exec, shutdown(_))
    .Times(AtMost(1));
  driver.stop();
  driver.join();
}
TEST_F ( SlaveTest , TaskStatusContainerStatus ) { Try < Owned < cluster :: Master > > master = StartMaster ( ) ; ASSERT_SOME ( master ) ; MockExecutor exec ( DEFAULT_EXECUTOR_ID ) ; TestContainerizer containerizer ( & exec ) ; Owned < MasterDetector > detector = master . get ( ) -> createDetector ( ) ; Try < Owned < cluster :: Slave > > slave = StartSlave ( detector . get ( ) , & containerizer ) ; ASSERT_SOME ( slave ) ; MockScheduler sched ; MesosSchedulerDriver driver ( & sched , DEFAULT_FRAMEWORK_INFO , master . get ( ) -> pid , DEFAULT_CREDENTIAL ) ; EXPECT_CALL ( sched , registered ( & driver , _ , _ ) ) . Times ( 1 ) ; Future < vector < Offer > > offers ; EXPECT_CALL ( sched , resourceOffers ( & driver , _ ) ) . WillOnce ( FutureArg < 1 > ( & offers ) ) . WillRepeatedly ( Return ( ) ) ; driver . start ( ) ; AWAIT_READY ( offers ) ; EXPECT_NE ( 0u , offers . get ( ) . size ( ) ) ; TaskInfo task = createTask ( offers . get ( ) [ 0 ] , " " , DEFAULT_EXECUTOR_ID ) ; ExecutorDriver * execDriver ; EXPECT_CALL ( exec , registered ( _ , _ , _ , _ ) ) . WillOnce ( SaveArg < 0 > ( & execDriver ) ) ; EXPECT_CALL ( exec , launchTask ( _ , _ ) ) . WillOnce ( SendStatusUpdateFromTask ( TASK_RUNNING ) ) ; Future < TaskStatus > status ; EXPECT_CALL ( sched , statusUpdate ( & driver , _ ) ) . WillOnce ( FutureArg < 1 > ( & status ) ) ; driver . launchTasks ( offers . get ( ) [ 0 ] . id ( ) , { task } ) ; AWAIT_READY ( status ) ; const string slaveIPAddress = stringify ( slave . get ( ) -> pid . address . ip ) ; EXPECT_TRUE ( status . get ( ) . has_container_status ( ) ) ; EXPECT_EQ ( 1 , status . get ( ) . container_status ( ) . network_infos ( ) . size ( ) ) ; EXPECT_TRUE ( status . get ( ) . container_status ( ) . network_infos ( 0 ) . has_ip_address ( ) ) ; EXPECT_EQ ( slaveIPAddress , status . get ( ) . container_status ( ) . network_infos ( 0 ) . ip_address ( ) ) ; Future < Response > response = process :: http :: get ( slave . get ( ) -> pid , " " , None ( ) , createBasicAuthHeaders ( DEFAULT_CREDENTIAL ) ) ; AWAIT_EXPECT_RESPONSE_STATUS_EQ ( OK ( ) . status , response ) ; AWAIT_EXPECT_RESPONSE_HEADER_EQ ( APPLICATION_JSON , " " , response ) ; Try < JSON :: Object > parse = JSON :: parse < JSON :: Object > ( response . get ( ) . body ) ; ASSERT_SOME ( parse ) ; ASSERT_SOME_EQ ( slaveIPAddress , parse . get ( ) . find < JSON :: String > ( " " " " ) ) ; EXPECT_CALL ( exec , shutdown ( _ ) ) . Times ( AtMost ( 1 ) ) ; driver . stop ( ) ; driver . join ( ) ; }
This test verifies that TaskStatus::container_status an is exposed over
the slave state endpoint.
This test verifies that TaskStatus :: container_status an is exposed over the slave state endpoint .
// Ignore subsequent offers. // Validate that the Slave has passed in its IP address in // TaskStatus.container_status.network_infos[0].ip_address. // Now do the same validation with state endpoint. // Validate that the IP address passed in by the Slave is available at the // state endpoint.