def test_if_webui_url_by_fwrk_id_has_prio_over_webui_url_by_fwrk_name( self, master_ar_process_pertest, mocker, valid_user_header): # This one is tricky, we need to create a state-summary entry that has # a framework entry with "name" field equal to the "id" field of a # different entry # Remove the data from Marathon mock mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) # Remove the data from MesosDNS mock mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Fabricate state-summary data needed for the tests fwrk_a = framework_from_template(SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "http://127.0.0.15:16001") fwrk_b = framework_from_template( "0535dd9a-2644-4945-a365-6fe0145f103f-0000", SCHEDULER_FWRK_ALWAYSTHERE_ID, "http://127.0.0.1:16000") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk_a, fwrk_b]) # Check that svcapps resolve to different port generic_correct_upstream_dest_test( master_ar_process_pertest, valid_user_header, '/service/{}/foo/bar/'.format(SCHEDULER_FWRK_ALWAYSTHERE_ID), "http://127.0.0.15:16001")
def test_if_webui_url_path_is_normalized( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from Marathon mock mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) # Remove the data from MesosDNS mock mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Test webui_url entry withouth trailing slash: fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "http://127.0.0.15:16001") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) generic_correct_upstream_dest_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', "http://127.0.0.15:16001" ) generic_correct_upstream_request_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', '/foo/bar/', http_ver='websockets' ) # Test webui_url entry with trailing slash: fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "http://127.0.0.15:16001/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) generic_correct_upstream_dest_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', "http://127.0.0.15:16001" ) generic_correct_upstream_request_test( master_ar_process_pertest, valid_user_header, '/service/scheduler-alwaysthere/foo/bar/', '/foo/bar/', http_ver='websockets' )
def test_if_broken_marathon_does_not_prevent_resolving_root_marathon( self, mocker, nginx_class, valid_user_header): # Bork Marathon Mock, DO NOT touch Mesos Mock: mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='always_bork', aux_data=True) # Change the Root Marathon's endpoint address as reported by Mesos mock, # so that we do not get the reply from the original endpoint (i.e. # http://127.0.0.1:8080 as it will always respond with broken responses # (see `mocker.send_command` call above). fwrk = framework_from_template(SCHEDULER_FWRK_ALWAYSTHERE_ID, "marathon", "http://127.0.0.2:8080/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) # Make period cache refreshes so rare that they do not get into # picture: ar = nginx_class( cache_first_poll_delay=1200, cache_poll_period=1200, cache_expiration=1200, cache_max_age_soft_limit=1200, cache_max_age_hard_limit=1800, ) url = ar.make_url_from_path("/service/marathon/v2/reflect/me") with GuardedSubprocess(ar): resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 data = resp.json() assert data['endpoint_id'] == 'http://127.0.0.2:8080'
def test_if_scheme_is_honoured_in_mesos_scheduler_entry( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from MesosDNS and Marathon mocks w.r.t. resolved service mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Mock TLS-enabled framework fwrk = framework_from_template(SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "https://127.0.0.4:443/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) url = master_ar_process_pertest.make_url_from_path( "/service/scheduler-alwaysthere/") resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 req_data = resp.json() assert req_data['endpoint_id'] == "https://127.0.0.4:443"
def test_if_scheme_is_honoured_in_mesos_scheduler_entry( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from MesosDNS and Marathon mocks w.r.t. resolved service mocker.send_command( endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) mocker.send_command( endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Mock TLS-enabled framework fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "https://127.0.0.4:443/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) url = master_ar_process_pertest.make_url_from_path("/service/scheduler-alwaysthere/") resp = requests.get(url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 req_data = resp.json() assert req_data['endpoint_id'] == "https://127.0.0.4:443"
def test_if_webui_url_by_fwrk_id_has_prio_over_webui_url_by_fwrk_name( self, master_ar_process_pertest, mocker, valid_user_header): # This one is tricky, we need to create a state-summary entry that has # a framework entry with "name" field equal to the "id" field of a # different entry # Remove the data from Marathon mock mocker.send_command(endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) # Remove the data from MesosDNS mock mocker.send_command(endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Fabricate state-summary data needed for the tests fwrk_a = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "http://127.0.0.15:16001") fwrk_b = framework_from_template( "0535dd9a-2644-4945-a365-6fe0145f103f-0000", SCHEDULER_FWRK_ALWAYSTHERE_ID, "http://127.0.0.1:16000") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk_a, fwrk_b]) # Check that svcapps resolve to different port generic_correct_upstream_dest_test( master_ar_process_pertest, valid_user_header, '/service/{}/foo/bar/'.format(SCHEDULER_FWRK_ALWAYSTHERE_ID), "http://127.0.0.15:16001" )
def test_if_only_matching_scheme_redirects_are_adjusted_for_mesos_frameworks( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from MesosDNS and Marathon mocks w.r.t. resolved service mocker.send_command( endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) mocker.send_command( endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Mock TLS-enabled framework fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "https://127.0.0.4:443/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) # Non-matching: mocker.send_command( endpoint_id="https://127.0.0.4:443", func_name='always_redirect', aux_data="http://127.0.0.1/") url = master_ar_process_pertest.make_url_from_path( "/service/scheduler-alwaysthere/foo/bar") r = requests.get(url, allow_redirects=False, headers=valid_user_header) assert r.status_code == 307 assert r.headers['Location'] == "http://127.0.0.1/" # Matching: mocker.send_command( endpoint_id="https://127.0.0.4:443", func_name='always_redirect', aux_data="https://127.0.0.1/") url = master_ar_process_pertest.make_url_from_path( "/service/scheduler-alwaysthere/foo/bar") r = requests.get(url, allow_redirects=False, headers=valid_user_header) assert r.status_code == 307 absolute = urljoin(url, r.headers['Location']) assert absolute == "http://127.0.0.1/service/scheduler-alwaysthere/"
def test_if_only_matching_scheme_redirects_are_adjusted_for_mesos_frameworks( self, master_ar_process_pertest, mocker, valid_user_header): # Remove the data from MesosDNS and Marathon mocks w.r.t. resolved service mocker.send_command( endpoint_id='http://127.0.0.1:8080', func_name='set_apps_response', aux_data={"apps": []}) mocker.send_command( endpoint_id='http://127.0.0.1:8123', func_name='set_srv_response', aux_data=EMPTY_SRV) # Mock TLS-enabled framework fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "scheduler-alwaysthere", "https://127.0.0.4:443/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) # Non-matching: mocker.send_command( endpoint_id="https://127.0.0.4:443", func_name='always_redirect', aux_data="http://127.0.0.1/") url = master_ar_process_pertest.make_url_from_path( "/service/scheduler-alwaysthere/foo/bar") r = requests.get(url, allow_redirects=False, headers=valid_user_header) assert r.status_code == 307 assert r.headers['Location'] == "http://127.0.0.1/" # Matching: mocker.send_command( endpoint_id="https://127.0.0.4:443", func_name='always_redirect', aux_data="https://127.0.0.1/") url = master_ar_process_pertest.make_url_from_path( "/service/scheduler-alwaysthere/foo/bar") r = requests.get(url, allow_redirects=False, headers=valid_user_header) assert r.status_code == 307 assert r.headers['Location'] == "http://127.0.0.1/service/scheduler-alwaysthere/"
def test_if_broken_marathon_does_not_prevent_resolving_root_marathon( self, mocker, nginx_class, valid_user_header): # Bork Marathon Mock, DO NOT touch Mesos Mock: mocker.send_command( endpoint_id='http://127.0.0.1:8080', func_name='always_bork', aux_data=True) # Change the Root Marathon's endpoint address as reported by Mesos mock, # so that we do not get the reply from the original endpoint (i.e. # http://127.0.0.1:8080 as it will always respond with broken responses # (see `mocker.send_command` call above). fwrk = framework_from_template( SCHEDULER_FWRK_ALWAYSTHERE_ID, "marathon", "http://127.0.0.2:8080/") mocker.send_command(endpoint_id='http://127.0.0.2:5050', func_name='set_frameworks_response', aux_data=[fwrk]) # Make period cache refreshes so rare that they do not get into # picture: ar = nginx_class(cache_first_poll_delay=1200, cache_poll_period=1200, cache_expiration=1200, cache_max_age_soft_limit=1200, cache_max_age_hard_limit=1800, ) url = ar.make_url_from_path("/service/marathon/v2/reflect/me") with GuardedSubprocess(ar): resp = requests.get( url, allow_redirects=False, headers=valid_user_header) assert resp.status_code == 200 data = resp.json() assert data['endpoint_id'] == 'http://127.0.0.2:8080'