Beispiel #1
0
// This test ensures we don't break the API when it comes to JSON
// representation of NetworkInfo.
TEST(HTTP, SerializeNetworkInfo)
{
  NetworkInfo networkInfo;
  NetworkInfo::IPAddress* address = networkInfo.add_ip_addresses();
  address->set_protocol(NetworkInfo::IPv4);
  address->set_ip_address("10.0.0.1");
  networkInfo.set_protocol(NetworkInfo::IPv6);
  networkInfo.set_ip_address("10.0.0.2");
  networkInfo.add_groups("foo");
  networkInfo.add_groups("bar");

  JSON::Value object = JSON::protobuf(networkInfo);

  Try<JSON::Value> expected = JSON::parse(
      "{"
      "  \"ip_addresses\":"
      "  ["
      "    {"
      "      \"protocol\": \"IPv4\","
      "      \"ip_address\": \"10.0.0.1\""
      "    }"
      "  ],"
      "  \"protocol\": \"IPv6\","
      "  \"ip_address\": \"10.0.0.2\","
      "  \"groups\": ["
      "    \"foo\","
      "    \"bar\""
      "  ]"
      "}");

  ASSERT_SOME(expected);
  EXPECT_EQ(expected.get(), object);
}
Beispiel #2
0
  virtual Result<TaskStatus> slaveTaskStatusDecorator(
      const FrameworkID& frameworkId,
      const TaskStatus& status)
  {
    LOG(INFO) << "Executing 'slaveTaskStatusDecorator' hook";

    Labels labels;

    // Set one known label.
    Label* newLabel = labels.add_labels();
    newLabel->set_key("bar");
    newLabel->set_value("qux");

    // Remove label which was set by test.
    foreach (const Label& oldLabel, status.labels().labels()) {
      if (oldLabel.key() != "foo") {
        labels.add_labels()->CopyFrom(oldLabel);
      }
    }

    TaskStatus result;
    result.mutable_labels()->CopyFrom(labels);

    // Set an IP address, a network isolation group, and a known label
    // in network info. This data is later validated by the
    // 'HookTest.VerifySlaveTaskStatusDecorator' test.
    NetworkInfo* networkInfo =
      result.mutable_container_status()->add_network_infos();
    // TODO(CD): Deprecated -- remove after 0.27.0.
    networkInfo->set_ip_address("4.3.2.1");
    NetworkInfo::IPAddress* ipAddress =
      networkInfo->add_ip_addresses();
    ipAddress->set_ip_address("4.3.2.1");
    networkInfo->add_groups("public");

    Label* networkInfoLabel = networkInfo->mutable_labels()->add_labels();
    networkInfoLabel->set_key("net_foo");
    networkInfoLabel->set_value("net_bar");

    return result;
  }