Skip to content

Commit

Permalink
V2 to v3 fragment (#11213)
Browse files Browse the repository at this point in the history
Risk Level:Low
Testing: integration and format testing

Part of #10843

Signed-off-by: Abhay Narayan Katare <[email protected]>
  • Loading branch information
ankatare authored Jul 6, 2020
1 parent f483845 commit e73738f
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 94 deletions.
5 changes: 3 additions & 2 deletions source/common/protobuf/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ class MessageUtil {

template <class MessageType>
static void loadFromYamlAndValidate(const std::string& yaml, MessageType& message,
ProtobufMessage::ValidationVisitor& validation_visitor) {
loadFromYaml(yaml, message, validation_visitor);
ProtobufMessage::ValidationVisitor& validation_visitor,
bool avoid_boosting = false) {
loadFromYaml(yaml, message, validation_visitor, !avoid_boosting);
validate(message, validation_visitor);
}

Expand Down
28 changes: 15 additions & 13 deletions test/common/tcp_proxy/tcp_proxy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ using ::Envoy::Network::UpstreamServerName;

namespace {
Config constructConfigFromYaml(const std::string& yaml,
Server::Configuration::FactoryContext& context) {
Server::Configuration::FactoryContext& context,
bool avoid_boosting = true) {
envoy::extensions::filters::network::tcp_proxy::v3::TcpProxy tcp_proxy;
TestUtility::loadFromYamlAndValidate(yaml, tcp_proxy);
TestUtility::loadFromYamlAndValidate(yaml, tcp_proxy, false, avoid_boosting);
return Config(tcp_proxy, context);
}

Expand Down Expand Up @@ -122,7 +123,7 @@ TEST(ConfigTest, DEPRECATED_FEATURE_TEST(BadConfig)) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context;
EXPECT_THROW(constructConfigFromYaml(yaml_string, factory_context), EnvoyException);
EXPECT_THROW(constructConfigFromYaml(yaml_string, factory_context, false), EnvoyException);
}

TEST(ConfigTest, DEPRECATED_FEATURE_TEST(EmptyRouteConfig)) {
Expand All @@ -134,7 +135,7 @@ TEST(ConfigTest, DEPRECATED_FEATURE_TEST(EmptyRouteConfig)) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context_;
EXPECT_THROW(constructConfigFromYaml(yaml, factory_context_), EnvoyException);
EXPECT_THROW(constructConfigFromYaml(yaml, factory_context_, false), EnvoyException);
}

TEST(ConfigTest, DEPRECATED_FEATURE_TEST(Routes)) {
Expand Down Expand Up @@ -185,7 +186,7 @@ TEST(ConfigTest, DEPRECATED_FEATURE_TEST(Routes)) {
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context_;
Config config_obj(constructConfigFromYaml(yaml, factory_context_));
Config config_obj(constructConfigFromYaml(yaml, factory_context_, false));

{
// hit route with destination_ip (10.10.10.10/32)
Expand Down Expand Up @@ -364,7 +365,7 @@ TEST(ConfigTest, DEPRECATED_FEATURE_TEST(RouteWithTopLevelMetadataMatchConfig))
)EOF";

NiceMock<Server::Configuration::MockFactoryContext> factory_context_;
Config config_obj(constructConfigFromYaml(yaml, factory_context_));
Config config_obj(constructConfigFromYaml(yaml, factory_context_, false));

ProtobufWkt::Value v1, v2;
v1.set_string_value("v1");
Expand Down Expand Up @@ -1742,7 +1743,7 @@ class TcpProxyRoutingTest : public testing::Test {
public:
TcpProxyRoutingTest() = default;

void setup() {
void setup(bool avoid_boosting = true) {
const std::string yaml = R"EOF(
stat_prefix: name
cluster: fallback_cluster
Expand All @@ -1752,7 +1753,8 @@ class TcpProxyRoutingTest : public testing::Test {
cluster: fake_cluster
)EOF";

config_ = std::make_shared<Config>(constructConfigFromYaml(yaml, factory_context_));
config_ =
std::make_shared<Config>(constructConfigFromYaml(yaml, factory_context_, avoid_boosting));
}

void initializeFilter() {
Expand All @@ -1772,7 +1774,7 @@ class TcpProxyRoutingTest : public testing::Test {
};

TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(NonRoutableConnection)) {
setup();
setup(false);

const uint32_t total_cx = config_->stats().downstream_cx_total_.value();
const uint32_t non_routable_cx = config_->stats().downstream_cx_no_route_.value();
Expand All @@ -1793,7 +1795,7 @@ TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(NonRoutableConnection)) {
}

TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(RoutableConnection)) {
setup();
setup(false);

const uint32_t total_cx = config_->stats().downstream_cx_total_.value();
const uint32_t non_routable_cx = config_->stats().downstream_cx_no_route_.value();
Expand All @@ -1815,7 +1817,7 @@ TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(RoutableConnection)) {

// Test that the tcp proxy uses the cluster from FilterState if set
TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(UseClusterFromPerConnectionCluster)) {
setup();
setup(false);
initializeFilter();

connection_.streamInfo().filterState()->setData(
Expand All @@ -1832,7 +1834,7 @@ TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(UseClusterFromPerConnectionC

// Test that the tcp proxy forwards the requested server name from FilterState if set
TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(UpstreamServerName)) {
setup();
setup(false);
initializeFilter();

connection_.streamInfo().filterState()->setData(
Expand Down Expand Up @@ -1862,7 +1864,7 @@ TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(UpstreamServerName)) {

// Test that the tcp proxy override ALPN from FilterState if set
TEST_F(TcpProxyRoutingTest, DEPRECATED_FEATURE_TEST(ApplicationProtocols)) {
setup();
setup(false);
initializeFilter();

connection_.streamInfo().filterState()->setData(
Expand Down
19 changes: 10 additions & 9 deletions test/common/upstream/cluster_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ namespace Envoy {
namespace Upstream {
namespace {

envoy::config::bootstrap::v3::Bootstrap parseBootstrapFromV3Yaml(const std::string& yaml) {
envoy::config::bootstrap::v3::Bootstrap parseBootstrapFromV3Yaml(const std::string& yaml,
bool avoid_boosting = true) {
envoy::config::bootstrap::v3::Bootstrap bootstrap;
TestUtility::loadFromYaml(yaml, bootstrap, true);
TestUtility::loadFromYaml(yaml, bootstrap, true, avoid_boosting);
return bootstrap;
}

Expand Down Expand Up @@ -200,7 +201,7 @@ TEST_F(ClusterManagerImplTest, MultipleProtocolCluster) {
checkConfigDump(R"EOF(
static_clusters:
- cluster:
"@type": type.googleapis.com/envoy.api.v2.Cluster
"@type": type.googleapis.com/envoy.config.cluster.v3.Cluster
name: http12_cluster
connect_timeout: 0.250s
lb_policy: ROUND_ROBIN
Expand Down Expand Up @@ -442,7 +443,7 @@ TEST_F(ClusterManagerImplTest, OriginalDstLbRestriction2) {
port_value: 11001
)EOF";

EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Yaml(yaml, false)), EnvoyException,
"cluster: LB policy hidden_envoy_deprecated_ORIGINAL_DST_LB is not "
"valid for Cluster type STATIC. "
"'ORIGINAL_DST_LB' is allowed only with cluster type 'ORIGINAL_DST'");
Expand Down Expand Up @@ -559,7 +560,7 @@ TEST_F(ClusterManagerImplTest, SubsetLoadBalancerOriginalDstRestriction) {
- keys: [ "x" ]
)EOF";

EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_MESSAGE(create(parseBootstrapFromV3Yaml(yaml, false)), EnvoyException,
"cluster: LB policy hidden_envoy_deprecated_ORIGINAL_DST_LB cannot be "
"combined with lb_subset_config");
}
Expand Down Expand Up @@ -1226,8 +1227,8 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) {
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11001
address: "127.0.0.1"
port_value: 11001
last_updated:
seconds: 1234567891
nanos: 234000000
Expand Down Expand Up @@ -1259,8 +1260,8 @@ TEST_F(ClusterManagerImplTest, ModifyWarmingCluster) {
connect_timeout: 0.25s
hosts:
- socket_address:
address: "127.0.0.1"
port_value: 11002
address: "127.0.0.1"
port_value: 11002
last_updated:
seconds: 1234567891
nanos: 234000000
Expand Down
44 changes: 22 additions & 22 deletions test/common/upstream/health_checker_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class HttpHealthCheckerImplTest : public testing::Test, public HealthCheckerTest
std::unordered_map<std::string,
const envoy::config::endpoint::v3::Endpoint::HealthCheckConfig>;

void allocHealthChecker(const std::string& yaml) {
void allocHealthChecker(const std::string& yaml, bool avoid_boosting = true) {
health_checker_ = std::make_shared<TestHttpHealthCheckerImpl>(
*cluster_, parseHealthCheckFromV2Yaml(yaml), dispatcher_, runtime_, random_,
*cluster_, parseHealthCheckFromV3Yaml(yaml, avoid_boosting), dispatcher_, runtime_, random_,
HealthCheckEventLoggerPtr(event_logger_storage_.release()));
}

Expand Down Expand Up @@ -2569,9 +2569,9 @@ class TestProdHttpHealthChecker : public ProdHttpHealthCheckerImpl {

class ProdHttpHealthCheckerTest : public testing::Test, public HealthCheckerTestBase {
public:
void allocHealthChecker(const std::string& yaml) {
void allocHealthChecker(const std::string& yaml, bool avoid_boosting = true) {
health_checker_ = std::make_shared<TestProdHttpHealthChecker>(
*cluster_, parseHealthCheckFromV2Yaml(yaml), dispatcher_, runtime_, random_,
*cluster_, parseHealthCheckFromV3Yaml(yaml, avoid_boosting), dispatcher_, runtime_, random_,
HealthCheckEventLoggerPtr(event_logger_storage_.release()));
}

Expand Down Expand Up @@ -2646,7 +2646,7 @@ TEST_F(HttpHealthCheckerImplTest, DEPRECATED_FEATURE_TEST(Http1CodecClient)) {
use_http2: false
)EOF";

allocHealthChecker(yaml);
allocHealthChecker(yaml, false);
addCompletionCallback();
EXPECT_EQ(Http::CodecClient::Type::HTTP1, health_checker_->codecClientType());
}
Expand All @@ -2666,7 +2666,7 @@ TEST_F(HttpHealthCheckerImplTest, DEPRECATED_FEATURE_TEST(Http2CodecClient)) {
use_http2: true
)EOF";

allocHealthChecker(yaml);
allocHealthChecker(yaml, false);
addCompletionCallback();
EXPECT_EQ(Http::CodecClient::Type::HTTP2, health_checker_->codecClientType());
}
Expand Down Expand Up @@ -2755,7 +2755,7 @@ TEST(HttpStatusChecker, Default) {
)EOF";

HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200);
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200);

EXPECT_TRUE(http_status_checker.inRange(200));
EXPECT_FALSE(http_status_checker.inRange(204));
Expand All @@ -2777,7 +2777,7 @@ TEST(HttpStatusChecker, Single100) {
)EOF";

HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200);
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200);

EXPECT_FALSE(http_status_checker.inRange(200));

Expand All @@ -2802,7 +2802,7 @@ TEST(HttpStatusChecker, Single599) {
)EOF";

HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200);
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200);

EXPECT_FALSE(http_status_checker.inRange(200));

Expand All @@ -2829,7 +2829,7 @@ TEST(HttpStatusChecker, Ranges_204_304) {
)EOF";

HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200);
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200);

EXPECT_FALSE(http_status_checker.inRange(200));

Expand Down Expand Up @@ -2858,7 +2858,7 @@ TEST(HttpStatusChecker, Below100) {

EXPECT_THROW_WITH_MESSAGE(
HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200),
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200),
EnvoyException, "Invalid http status range: expecting start >= 100, but found start=99");
}

Expand All @@ -2879,7 +2879,7 @@ TEST(HttpStatusChecker, Above599) {

EXPECT_THROW_WITH_MESSAGE(
HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200),
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200),
EnvoyException, "Invalid http status range: expecting end <= 600, but found end=601");
}

Expand All @@ -2900,7 +2900,7 @@ TEST(HttpStatusChecker, InvalidRange) {

EXPECT_THROW_WITH_MESSAGE(
HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200),
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200),
EnvoyException,
"Invalid http status range: expecting start < end, but found start=200 and end=200");
}
Expand All @@ -2922,7 +2922,7 @@ TEST(HttpStatusChecker, InvalidRange2) {

EXPECT_THROW_WITH_MESSAGE(
HttpHealthCheckerImpl::HttpStatusChecker http_status_checker(
parseHealthCheckFromV2Yaml(yaml).http_health_check().expected_statuses(), 200),
parseHealthCheckFromV3Yaml(yaml).http_health_check().expected_statuses(), 200),
EnvoyException,
"Invalid http status range: expecting start < end, but found start=201 and end=200");
}
Expand Down Expand Up @@ -2988,9 +2988,9 @@ TEST(TcpHealthCheckMatcher, match) {

class TcpHealthCheckerImplTest : public testing::Test, public HealthCheckerTestBase {
public:
void allocHealthChecker(const std::string& yaml) {
void allocHealthChecker(const std::string& yaml, bool avoid_boosting = true) {
health_checker_ = std::make_shared<TcpHealthCheckerImpl>(
*cluster_, parseHealthCheckFromV2Yaml(yaml), dispatcher_, runtime_, random_,
*cluster_, parseHealthCheckFromV3Yaml(yaml, avoid_boosting), dispatcher_, runtime_, random_,
HealthCheckEventLoggerPtr(event_logger_storage_.release()));
}

Expand Down Expand Up @@ -5009,7 +5009,7 @@ TEST(HealthCheckProto, Validation) {
path: /healthcheck
)EOF";
envoy::config::core::v3::HealthCheck health_check_proto;
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV2Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed.*value must be greater than.*");
}
{
Expand All @@ -5025,7 +5025,7 @@ TEST(HealthCheckProto, Validation) {
path: /healthcheck
)EOF";
envoy::config::core::v3::HealthCheck health_check_proto;
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV2Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed.*value must be greater than.*");
}
{
Expand All @@ -5041,7 +5041,7 @@ TEST(HealthCheckProto, Validation) {
path: /healthcheck
)EOF";
envoy::config::core::v3::HealthCheck health_check_proto;
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV2Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed.*value must be greater than.*");
}
{
Expand All @@ -5057,7 +5057,7 @@ TEST(HealthCheckProto, Validation) {
path: /healthcheck
)EOF";
envoy::config::core::v3::HealthCheck health_check_proto;
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV2Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed.*value must be greater than.*");
}
{
Expand All @@ -5071,7 +5071,7 @@ TEST(HealthCheckProto, Validation) {
path: /healthcheck
)EOF";
envoy::config::core::v3::HealthCheck health_check_proto;
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV2Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed.*value is required.*");
}
{
Expand All @@ -5085,7 +5085,7 @@ TEST(HealthCheckProto, Validation) {
path: /healthcheck
)EOF";
envoy::config::core::v3::HealthCheck health_check_proto;
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV2Yaml(yaml)), EnvoyException,
EXPECT_THROW_WITH_REGEX(TestUtility::validate(parseHealthCheckFromV3Yaml(yaml)), EnvoyException,
"Proto constraint validation failed.*value is required.*");
}
}
Expand Down
8 changes: 8 additions & 0 deletions test/common/upstream/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ makeLocalityWeights(std::initializer_list<uint32_t> locality_weights) {
return std::make_shared<LocalityWeights>(locality_weights);
}

inline envoy::config::core::v3::HealthCheck
parseHealthCheckFromV3Yaml(const std::string& yaml_string, bool avoid_boosting = true) {
envoy::config::core::v3::HealthCheck health_check;
TestUtility::loadFromYamlAndValidate(yaml_string, health_check, false, avoid_boosting);
return health_check;
}

// For DEPRECATED TEST CASES
inline envoy::config::core::v3::HealthCheck
parseHealthCheckFromV2Yaml(const std::string& yaml_string) {
envoy::config::core::v3::HealthCheck health_check;
Expand Down
Loading

0 comments on commit e73738f

Please sign in to comment.