|
|
|
@ -202,6 +202,9 @@ argp.add_argument( |
|
|
|
|
help= |
|
|
|
|
'Leave GCP VMs and configuration running after test. Default behavior is ' |
|
|
|
|
'to delete when tests complete.') |
|
|
|
|
argp.add_argument('--halt_after_fail', |
|
|
|
|
action='store_true', |
|
|
|
|
help='Halt and save the resources when test failed.') |
|
|
|
|
argp.add_argument( |
|
|
|
|
'--compute_discovery_document', |
|
|
|
|
default=None, |
|
|
|
@ -655,11 +658,16 @@ def test_change_backend_service(gcp, original_backend_service, instance_group, |
|
|
|
|
same_zone_instance_group) |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends(original_backend_instances, |
|
|
|
|
_WAIT_FOR_STATS_SEC) |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
patch_url_map_backend_service(gcp, alternate_backend_service) |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends(alternate_backend_instances, |
|
|
|
|
_WAIT_FOR_URL_MAP_PATCH_SEC) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
patch_backend_service(gcp, alternate_backend_service, []) |
|
|
|
|
|
|
|
|
@ -672,6 +680,7 @@ def test_gentle_failover(gcp, |
|
|
|
|
logger.info('Running test_gentle_failover') |
|
|
|
|
num_primary_instances = len(get_instance_names(gcp, primary_instance_group)) |
|
|
|
|
min_instances_for_gentle_failover = 3 # Need >50% failure to start failover |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
if num_primary_instances < min_instances_for_gentle_failover: |
|
|
|
|
resize_instance_group(gcp, primary_instance_group, |
|
|
|
@ -710,9 +719,15 @@ def test_gentle_failover(gcp, |
|
|
|
|
primary_instance_group, |
|
|
|
|
swapped_primary_and_secondary=True) |
|
|
|
|
else: |
|
|
|
|
passed = False |
|
|
|
|
raise e |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
patch_backend_service(gcp, backend_service, [primary_instance_group]) |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_backend_service(gcp, backend_service, |
|
|
|
|
[primary_instance_group]) |
|
|
|
|
resize_instance_group(gcp, primary_instance_group, |
|
|
|
|
num_primary_instances) |
|
|
|
|
instance_names = get_instance_names(gcp, primary_instance_group) |
|
|
|
@ -724,6 +739,7 @@ def test_load_report_based_failover(gcp, backend_service, |
|
|
|
|
primary_instance_group, |
|
|
|
|
secondary_instance_group): |
|
|
|
|
logger.info('Running test_load_report_based_failover') |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
patch_backend_service( |
|
|
|
|
gcp, backend_service, |
|
|
|
@ -763,8 +779,13 @@ def test_load_report_based_failover(gcp, backend_service, |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends(primary_instance_names, |
|
|
|
|
_WAIT_FOR_BACKEND_SEC) |
|
|
|
|
logger.info("success") |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
patch_backend_service(gcp, backend_service, [primary_instance_group]) |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_backend_service(gcp, backend_service, |
|
|
|
|
[primary_instance_group]) |
|
|
|
|
instance_names = get_instance_names(gcp, primary_instance_group) |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends(instance_names, |
|
|
|
|
_WAIT_FOR_BACKEND_SEC) |
|
|
|
@ -781,6 +802,7 @@ def test_ping_pong(gcp, backend_service, instance_group): |
|
|
|
|
def test_remove_instance_group(gcp, backend_service, instance_group, |
|
|
|
|
same_zone_instance_group): |
|
|
|
|
logger.info('Running test_remove_instance_group') |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
patch_backend_service(gcp, |
|
|
|
|
backend_service, |
|
|
|
@ -817,7 +839,11 @@ def test_remove_instance_group(gcp, backend_service, instance_group, |
|
|
|
|
balancing_mode='RATE') |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends(remaining_instance_names, |
|
|
|
|
_WAIT_FOR_BACKEND_SEC) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_backend_service(gcp, backend_service, [instance_group]) |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends(instance_names, |
|
|
|
|
_WAIT_FOR_BACKEND_SEC) |
|
|
|
@ -864,6 +890,7 @@ def test_secondary_locality_gets_no_requests_on_partial_primary_failure( |
|
|
|
|
logger.info( |
|
|
|
|
'Running secondary_locality_gets_no_requests_on_partial_primary_failure' |
|
|
|
|
) |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
patch_backend_service( |
|
|
|
|
gcp, backend_service, |
|
|
|
@ -897,9 +924,12 @@ def test_secondary_locality_gets_no_requests_on_partial_primary_failure( |
|
|
|
|
primary_instance_group, |
|
|
|
|
swapped_primary_and_secondary=True) |
|
|
|
|
else: |
|
|
|
|
passed = False |
|
|
|
|
raise e |
|
|
|
|
finally: |
|
|
|
|
patch_backend_service(gcp, backend_service, [primary_instance_group]) |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_backend_service(gcp, backend_service, |
|
|
|
|
[primary_instance_group]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_secondary_locality_gets_requests_on_primary_failure( |
|
|
|
@ -909,6 +939,7 @@ def test_secondary_locality_gets_requests_on_primary_failure( |
|
|
|
|
secondary_instance_group, |
|
|
|
|
swapped_primary_and_secondary=False): |
|
|
|
|
logger.info('Running secondary_locality_gets_requests_on_primary_failure') |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
patch_backend_service( |
|
|
|
|
gcp, backend_service, |
|
|
|
@ -942,9 +973,12 @@ def test_secondary_locality_gets_requests_on_primary_failure( |
|
|
|
|
primary_instance_group, |
|
|
|
|
swapped_primary_and_secondary=True) |
|
|
|
|
else: |
|
|
|
|
passed = False |
|
|
|
|
raise e |
|
|
|
|
finally: |
|
|
|
|
patch_backend_service(gcp, backend_service, [primary_instance_group]) |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_backend_service(gcp, backend_service, |
|
|
|
|
[primary_instance_group]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_services_for_urlmap_tests(gcp, original_backend_service, |
|
|
|
@ -991,6 +1025,7 @@ def test_metadata_filter(gcp, original_backend_service, instance_group, |
|
|
|
|
[same_zone_instance_group]) |
|
|
|
|
wait_for_healthy_backends(gcp, alternate_backend_service, |
|
|
|
|
same_zone_instance_group) |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
with open(bootstrap_path) as f: |
|
|
|
|
md = json.load(f)['node']['metadata'] |
|
|
|
@ -1122,13 +1157,18 @@ def test_metadata_filter(gcp, original_backend_service, instance_group, |
|
|
|
|
wait_until_all_rpcs_go_to_given_backends( |
|
|
|
|
alternate_backend_instances, _WAIT_FOR_STATS_SEC) |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_backend_service(gcp, alternate_backend_service, []) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_api_listener(gcp, backend_service, instance_group, |
|
|
|
|
alternate_backend_service): |
|
|
|
|
logger.info("Running api_listener") |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
wait_for_healthy_backends(gcp, backend_service, instance_group) |
|
|
|
|
backend_instances = get_instance_names(gcp, instance_group) |
|
|
|
@ -1175,12 +1215,17 @@ def test_api_listener(gcp, backend_service, instance_group, |
|
|
|
|
wait_until_no_rpcs_go_to_given_backends(backend_instances, |
|
|
|
|
_WAIT_FOR_STATS_SEC) |
|
|
|
|
|
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
delete_global_forwarding_rule(gcp, |
|
|
|
|
forwarding_rule_name + new_config_suffix) |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
delete_global_forwarding_rule( |
|
|
|
|
gcp, forwarding_rule_name + new_config_suffix) |
|
|
|
|
delete_target_proxy(gcp, target_proxy_name + new_config_suffix) |
|
|
|
|
delete_url_map(gcp, url_map_name + new_config_suffix) |
|
|
|
|
create_url_map(gcp, url_map_name, backend_service, service_host_name) |
|
|
|
|
create_url_map(gcp, url_map_name, backend_service, |
|
|
|
|
service_host_name) |
|
|
|
|
create_target_proxy(gcp, target_proxy_name) |
|
|
|
|
create_global_forwarding_rule(gcp, forwarding_rule_name, |
|
|
|
|
potential_service_ports) |
|
|
|
@ -1196,6 +1241,7 @@ def test_api_listener(gcp, backend_service, instance_group, |
|
|
|
|
|
|
|
|
|
def test_forwarding_rule_port_match(gcp, backend_service, instance_group): |
|
|
|
|
logger.info("Running test_forwarding_rule_port_match") |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
wait_for_healthy_backends(gcp, backend_service, instance_group) |
|
|
|
|
backend_instances = get_instance_names(gcp, instance_group) |
|
|
|
@ -1208,7 +1254,11 @@ def test_forwarding_rule_port_match(gcp, backend_service, instance_group): |
|
|
|
|
]) |
|
|
|
|
wait_until_no_rpcs_go_to_given_backends(backend_instances, |
|
|
|
|
_WAIT_FOR_STATS_SEC) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
delete_global_forwarding_rule(gcp) |
|
|
|
|
create_global_forwarding_rule(gcp, forwarding_rule_name, |
|
|
|
|
potential_service_ports) |
|
|
|
@ -1224,6 +1274,7 @@ def test_forwarding_rule_port_match(gcp, backend_service, instance_group): |
|
|
|
|
|
|
|
|
|
def test_forwarding_rule_default_port(gcp, backend_service, instance_group): |
|
|
|
|
logger.info("Running test_forwarding_rule_default_port") |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
wait_for_healthy_backends(gcp, backend_service, instance_group) |
|
|
|
|
backend_instances = get_instance_names(gcp, instance_group) |
|
|
|
@ -1259,11 +1310,16 @@ def test_forwarding_rule_default_port(gcp, backend_service, instance_group): |
|
|
|
|
service_host_name) |
|
|
|
|
wait_until_no_rpcs_go_to_given_backends(backend_instances, |
|
|
|
|
_WAIT_FOR_STATS_SEC) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
delete_global_forwarding_rule(gcp) |
|
|
|
|
delete_target_proxy(gcp) |
|
|
|
|
delete_url_map(gcp) |
|
|
|
|
create_url_map(gcp, url_map_name, backend_service, service_host_name) |
|
|
|
|
create_url_map(gcp, url_map_name, backend_service, |
|
|
|
|
service_host_name) |
|
|
|
|
create_target_proxy(gcp, target_proxy_name) |
|
|
|
|
create_global_forwarding_rule(gcp, forwarding_rule_name, |
|
|
|
|
potential_service_ports) |
|
|
|
@ -1289,6 +1345,7 @@ def test_traffic_splitting(gcp, original_backend_service, instance_group, |
|
|
|
|
gcp, original_backend_service, instance_group, |
|
|
|
|
alternate_backend_service, same_zone_instance_group) |
|
|
|
|
|
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
# Patch urlmap, change route action to traffic splitting between |
|
|
|
|
# original and alternate. |
|
|
|
@ -1345,7 +1402,11 @@ def test_traffic_splitting(gcp, original_backend_service, instance_group, |
|
|
|
|
else: |
|
|
|
|
logger.info("success") |
|
|
|
|
break |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
patch_backend_service(gcp, alternate_backend_service, []) |
|
|
|
|
|
|
|
|
@ -1365,6 +1426,7 @@ def test_path_matching(gcp, original_backend_service, instance_group, |
|
|
|
|
gcp, original_backend_service, instance_group, |
|
|
|
|
alternate_backend_service, same_zone_instance_group) |
|
|
|
|
|
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
# A list of tuples (route_rules, expected_instances). |
|
|
|
|
test_cases = [ |
|
|
|
@ -1485,7 +1547,11 @@ def test_path_matching(gcp, original_backend_service, instance_group, |
|
|
|
|
raise Exception( |
|
|
|
|
'timeout waiting for RPCs to the expected instances: %s' |
|
|
|
|
% expected_instances) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
patch_backend_service(gcp, alternate_backend_service, []) |
|
|
|
|
|
|
|
|
@ -1505,6 +1571,7 @@ def test_header_matching(gcp, original_backend_service, instance_group, |
|
|
|
|
gcp, original_backend_service, instance_group, |
|
|
|
|
alternate_backend_service, same_zone_instance_group) |
|
|
|
|
|
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
# A list of tuples (route_rules, expected_instances). |
|
|
|
|
test_cases = [ |
|
|
|
@ -1683,7 +1750,11 @@ def test_header_matching(gcp, original_backend_service, instance_group, |
|
|
|
|
raise Exception( |
|
|
|
|
'timeout waiting for RPCs to the expected instances: %s' |
|
|
|
|
% expected_instances) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
patch_backend_service(gcp, alternate_backend_service, []) |
|
|
|
|
|
|
|
|
@ -1718,6 +1789,7 @@ def test_circuit_breaking(gcp, original_backend_service, instance_group, |
|
|
|
|
''' |
|
|
|
|
logger.info('Running test_circuit_breaking') |
|
|
|
|
additional_backend_services = [] |
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
# TODO(chengyuanzhang): Dedicated backend services created for circuit |
|
|
|
|
# breaking test. Once the issue for unsetting backend service circuit |
|
|
|
@ -1835,9 +1907,14 @@ def test_circuit_breaking(gcp, original_backend_service, instance_group, |
|
|
|
|
# for sending RPCs) after restoring backend services. |
|
|
|
|
configure_client( |
|
|
|
|
[messages_pb2.ClientConfigureRequest.RpcType.UNARY_CALL]) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
patch_backend_service(gcp, original_backend_service, [instance_group]) |
|
|
|
|
patch_backend_service(gcp, original_backend_service, |
|
|
|
|
[instance_group]) |
|
|
|
|
for backend_service in additional_backend_services: |
|
|
|
|
delete_backend_service(gcp, backend_service) |
|
|
|
|
set_validate_for_proxyless(gcp, True) |
|
|
|
@ -1919,6 +1996,7 @@ def test_timeout(gcp, original_backend_service, instance_group): |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
first_case = True |
|
|
|
|
for (testcase_name, client_config, expected_results) in test_cases: |
|
|
|
@ -1967,7 +2045,11 @@ def test_timeout(gcp, original_backend_service, instance_group): |
|
|
|
|
'%s: timeout waiting for expected results: %s; got %s' % |
|
|
|
|
(testcase_name, expected_results, |
|
|
|
|
after_stats.stats_per_method)) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -2088,6 +2170,7 @@ def test_fault_injection(gcp, original_backend_service, instance_group): |
|
|
|
|
) |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
passed = True |
|
|
|
|
try: |
|
|
|
|
first_case = True |
|
|
|
|
for (testcase_name, client_config, expected_results) in test_cases: |
|
|
|
@ -2146,7 +2229,11 @@ def test_fault_injection(gcp, original_backend_service, instance_group): |
|
|
|
|
'%s: timeout waiting for expected results: %s; got %s' % |
|
|
|
|
(testcase_name, expected_results, |
|
|
|
|
after_stats.stats_per_method)) |
|
|
|
|
except Exception: |
|
|
|
|
passed = False |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if passed or not args.halt_after_fail: |
|
|
|
|
patch_url_map_backend_service(gcp, original_backend_service) |
|
|
|
|
set_validate_for_proxyless(gcp, True) |
|
|
|
|
|
|
|
|
@ -3293,6 +3380,9 @@ try: |
|
|
|
|
failed_tests.append(test_case) |
|
|
|
|
result.state = 'FAILED' |
|
|
|
|
result.message = str(e) |
|
|
|
|
if args.halt_after_fail: |
|
|
|
|
# Stop the test suite if one case failed. |
|
|
|
|
raise |
|
|
|
|
finally: |
|
|
|
|
if client_process: |
|
|
|
|
if client_process.returncode: |
|
|
|
@ -3321,6 +3411,11 @@ try: |
|
|
|
|
logger.error('Test case(s) %s failed', failed_tests) |
|
|
|
|
sys.exit(1) |
|
|
|
|
finally: |
|
|
|
|
if not args.keep_gcp_resources: |
|
|
|
|
keep_resources = args.keep_gcp_resources |
|
|
|
|
if args.halt_after_fail and failed_tests: |
|
|
|
|
logger.info( |
|
|
|
|
'Halt after fail triggered, exiting without cleaning up resources') |
|
|
|
|
keep_resources = True |
|
|
|
|
if not keep_resources: |
|
|
|
|
logger.info('Cleaning up GCP resources. This may take some time.') |
|
|
|
|
clean_up(gcp) |
|
|
|
|