Skip to content

Commit

Permalink
V2 v3 changes for parse foo from v2 json (#12113)
Browse files Browse the repository at this point in the history
V2 to V3 changes for parseFoofromV2json
:
Risk Level: NA
Testing: unit and format
Docs Changes: NA

Part of #10843

Signed-off-by: Abhay Narayan Katare <[email protected]>
  • Loading branch information
ankatare authored Jul 16, 2020
1 parent 15d212c commit 9af3796
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 91 deletions.
164 changes: 100 additions & 64 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ TEST_F(ClusterManagerImplTest, OutlierEventLog) {
)EOF";

EXPECT_CALL(log_manager_, createAccessLog("foo"));
create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));
}

TEST_F(ClusterManagerImplTest, NoSdsConfig) {
Expand Down Expand Up @@ -262,7 +262,7 @@ TEST_F(ClusterManagerImplTest, UnknownClusterType) {
}
)EOF";

EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV2Json(json)), EnvoyException,
EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV3Json(json)), EnvoyException,
"invalid value \"foo\" for type TYPE_ENUM");
}

Expand All @@ -280,7 +280,7 @@ TEST_F(ClusterManagerImplTest, LocalClusterNotDefined) {
)EOF",
clustersJson({defaultStaticClusterJson("cluster_1"), defaultStaticClusterJson("cluster_2")}));

EXPECT_THROW(create(parseBootstrapFromV2Json(json)), EnvoyException);
EXPECT_THROW(create(parseBootstrapFromV3Json(json)), EnvoyException);
}

TEST_F(ClusterManagerImplTest, BadClusterManagerConfig) {
Expand All @@ -298,7 +298,7 @@ TEST_F(ClusterManagerImplTest, BadClusterManagerConfig) {
}
)EOF";

EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV2Json(json)), EnvoyException,
EXPECT_THROW_WITH_REGEX(create(parseBootstrapFromV3Json(json)), EnvoyException,
"fake_property: Cannot find field");
}

Expand All @@ -317,7 +317,7 @@ TEST_F(ClusterManagerImplTest, LocalClusterDefined) {
clustersJson({defaultStaticClusterJson("cluster_1"), defaultStaticClusterJson("cluster_2"),
defaultStaticClusterJson("new_cluster")}));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));
checkStats(3 /*added*/, 0 /*modified*/, 0 /*removed*/, 3 /*active*/, 0 /*warming*/);

factory_.tls_.shutdownThread();
Expand All @@ -327,7 +327,7 @@ TEST_F(ClusterManagerImplTest, DuplicateCluster) {
const std::string json = fmt::sprintf(
"{\"static_resources\":{%s}}",
clustersJson({defaultStaticClusterJson("cluster_1"), defaultStaticClusterJson("cluster_1")}));
const auto config = parseBootstrapFromV2Json(json);
const auto config = parseBootstrapFromV3Json(json);
EXPECT_THROW(create(config), EnvoyException);
}

Expand Down Expand Up @@ -697,7 +697,7 @@ TEST_F(ClusterManagerImplTest, ClusterProvidedLbNoLb) {
cluster1->info_->lb_type_ = LoadBalancerType::ClusterProvided;
EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _))
.WillOnce(Return(std::make_pair(cluster1, nullptr)));
EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV2Json(json)), EnvoyException,
EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Json(json)), EnvoyException,
"cluster manager: cluster provided LB specified but cluster "
"'cluster_0' did not provide one. Check cluster documentation.");
}
Expand All @@ -711,7 +711,7 @@ TEST_F(ClusterManagerImplTest, ClusterProvidedLbNotConfigured) {
cluster1->info_->name_ = "cluster_0";
EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _))
.WillOnce(Return(std::make_pair(cluster1, new MockThreadAwareLoadBalancer())));
EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV2Json(json)), EnvoyException,
EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Json(json)), EnvoyException,
"cluster manager: cluster provided LB not specified but cluster "
"'cluster_0' provided one. Check cluster documentation.");
}
Expand All @@ -731,7 +731,7 @@ class ClusterManagerImplThreadAwareLbTest : public ClusterManagerImplTest {
EXPECT_CALL(factory_, clusterFromProto_(_, _, _, _))
.WillOnce(Return(std::make_pair(cluster1, nullptr)));
ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary));
create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));

EXPECT_EQ(nullptr, cluster_manager_->get("cluster_0")->loadBalancer().chooseHost(nullptr));

Expand Down Expand Up @@ -834,7 +834,7 @@ TEST_F(ClusterManagerImplTest, UnknownCluster) {
const std::string json = fmt::sprintf("{\"static_resources\":{%s}}",
clustersJson({defaultStaticClusterJson("cluster_1")}));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));
EXPECT_EQ(nullptr, cluster_manager_->get("hello"));
EXPECT_EQ(nullptr, cluster_manager_->httpConnPoolForCluster("hello", ResourcePriority::Default,
Http::Protocol::Http2, nullptr));
Expand Down Expand Up @@ -890,7 +890,7 @@ TEST_F(ClusterManagerImplTest, ShutdownOrder) {
const std::string json = fmt::sprintf("{\"static_resources\":{%s}}",
clustersJson({defaultStaticClusterJson("cluster_1")}));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));
Cluster& cluster = cluster_manager_->activeClusters().begin()->second;
EXPECT_EQ("cluster_1", cluster.info()->name());
EXPECT_EQ(cluster.info(), cluster_manager_->get("cluster_1")->info());
Expand Down Expand Up @@ -918,7 +918,7 @@ TEST_F(ClusterManagerImplTest, InitializeOrder) {
"dynamic_resources": {
"cds_config": {
"api_config_source": {
"api_type": "UNSUPPORTED_REST_LEGACY",
"api_type": "0",
"refresh_delay": "30s",
"cluster_names": ["cds_cluster"]
}
Expand Down Expand Up @@ -958,7 +958,7 @@ TEST_F(ClusterManagerImplTest, InitializeOrder) {
EXPECT_CALL(*cds_cluster, initialize(_));
EXPECT_CALL(*cluster1, initialize(_));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));

ReadyWatcher initialized;
cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); });
Expand Down Expand Up @@ -1000,78 +1000,102 @@ TEST_F(ClusterManagerImplTest, InitializeOrder) {
version_info: version3
static_clusters:
- cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "cds_cluster"
type: "STATIC"
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
- cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "fake_cluster"
type: "STATIC"
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
- cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "fake_cluster2"
type: "STATIC"
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
dynamic_active_clusters:
- version_info: "version1"
cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "cluster3"
type: "STATIC"
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
- version_info: "version2"
cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "cluster4"
type: "STATIC"
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
- version_info: "version3"
cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "cluster5"
type: "STATIC"
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
Expand Down Expand Up @@ -1120,7 +1144,7 @@ TEST_F(ClusterManagerImplTest, DynamicRemoveWithLocalCluster) {
ON_CALL(*foo, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary));
EXPECT_CALL(*foo, initialize(_));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));
foo->initialize_callback_();

// Now add a dynamic cluster. This cluster will have a member update callback from the local
Expand Down Expand Up @@ -1178,14 +1202,18 @@ TEST_F(ClusterManagerImplTest, RemoveWarmingCluster) {
dynamic_warming_clusters:
- version_info: "version3"
cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "fake_cluster"
type: STATIC
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
Expand Down Expand Up @@ -1221,14 +1249,18 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) {
dynamic_warming_clusters:
- version_info: "version3"
cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "fake_cluster"
type: STATIC
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
Expand All @@ -1242,7 +1274,7 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) {
EXPECT_CALL(*cluster2, initializePhase()).Times(0);
EXPECT_CALL(*cluster2, initialize(_));
EXPECT_TRUE(cluster_manager_->addOrUpdateCluster(
parseClusterFromV2Json(fmt::sprintf(kDefaultStaticClusterTmpl, "fake_cluster",
parseClusterFromV3Json(fmt::sprintf(kDefaultStaticClusterTmpl, "fake_cluster",
R"EOF(
"socket_address": {
"address": "127.0.0.1",
Expand All @@ -1254,14 +1286,18 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) {
dynamic_warming_clusters:
- version_info: "version3"
cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: "fake_cluster"
type: STATIC
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11002
load_assignment:
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 11002
last_updated:
seconds: 1234567891
nanos: 234000000
Expand Down Expand Up @@ -1404,7 +1440,7 @@ TEST_F(ClusterManagerImplTest, AddOrUpdateClusterStaticExists) {
ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary));
EXPECT_CALL(*cluster1, initialize(_));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));

ReadyWatcher initialized;
cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); });
Expand Down Expand Up @@ -1433,7 +1469,7 @@ TEST_F(ClusterManagerImplTest, HostsPostedToTlsCluster) {
ON_CALL(*cluster1, initializePhase()).WillByDefault(Return(Cluster::InitializePhase::Primary));
EXPECT_CALL(*cluster1, initialize(_));

create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));

ReadyWatcher initialized;
cluster_manager_->setInitializedCb([&]() -> void { initialized.ready(); });
Expand Down Expand Up @@ -1501,7 +1537,7 @@ TEST_F(ClusterManagerImplTest, CloseHttpConnectionsOnHealthFailure) {
// Test inline init.
initialize_callback();
}));
create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));

EXPECT_CALL(factory_, allocateConnPool_(_, _, _)).WillOnce(Return(cp1));
cluster_manager_->httpConnPoolForCluster("some_cluster", ResourcePriority::Default,
Expand Down Expand Up @@ -1564,7 +1600,7 @@ TEST_F(ClusterManagerImplTest, CloseTcpConnectionPoolsOnHealthFailure) {
// Test inline init.
initialize_callback();
}));
create(parseBootstrapFromV2Json(json));
create(parseBootstrapFromV3Json(json));

EXPECT_CALL(factory_, allocateTcpConnPool_(_)).WillOnce(Return(cp1));
cluster_manager_->tcpConnPoolForCluster("some_cluster", ResourcePriority::Default, nullptr);
Expand Down
Loading

0 comments on commit 9af3796

Please sign in to comment.