Skip to content

Commit

Permalink
tests: update for using location_conf from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jcsp committed Jun 23, 2024
1 parent 801bffe commit 0ecb9a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 38 deletions.
46 changes: 15 additions & 31 deletions test_runner/regress/test_attach_tenant_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
NeonEnv,
NeonEnvBuilder,
)
from fixtures.pageserver.http import PageserverApiException, TenantConfig
from fixtures.pageserver.http import TenantConfig
from fixtures.remote_storage import LocalFsStorage, RemoteStorageKind
from fixtures.utils import wait_until

Expand Down Expand Up @@ -82,8 +82,8 @@ def test_null_body(negative_env: NegativeTests):
tenant_id = negative_env.tenant_id
ps_http = env.pageserver.http_client()

res = ps_http.post(
f"{ps_http.base_url}/v1/tenant/{tenant_id}/attach",
res = ps_http.put(
f"{ps_http.base_url}/v1/location_config/{tenant_id}",
data=b"null",
headers={"Content-Type": "application/json"},
)
Expand All @@ -99,35 +99,16 @@ def test_null_config(negative_env: NegativeTests):
tenant_id = negative_env.tenant_id
ps_http = env.pageserver.http_client()

res = ps_http.post(
f"{ps_http.base_url}/v1/tenant/{tenant_id}/attach",
data=b'{"config": null}',
res = ps_http.put(
f"{ps_http.base_url}/v1/location_config/{tenant_id}",
json={"mode": "AttachedSingle", "generation": 1, "tenant_conf": None, "secondary_conf": {}},
headers={"Content-Type": "application/json"},
)
assert res.status_code == 400


def test_config_with_unknown_keys_is_bad_request(negative_env: NegativeTests):
"""
If we send a config with unknown keys, the request should be rejected with status 400.
"""

env = negative_env.neon_env
tenant_id = negative_env.tenant_id

config_with_unknown_keys = {
"compaction_period": "1h",
"this_key_does_not_exist": "some value",
}

with pytest.raises(PageserverApiException) as e:
env.pageserver.tenant_attach(tenant_id, config=config_with_unknown_keys)
assert e.type == PageserverApiException
assert e.value.status_code == 400


@pytest.mark.parametrize("content_type", [None, "application/json"])
def test_no_config(positive_env: NeonEnv, content_type: Optional[str]):
def test_empty_config(positive_env: NeonEnv, content_type: Optional[str]):
"""
When the 'config' body attribute is omitted, the request should be accepted
and the tenant should use the default configuration
Expand All @@ -141,11 +122,14 @@ def test_no_config(positive_env: NeonEnv, content_type: Optional[str]):
ps_http.tenant_detach(tenant_id)
assert tenant_id not in [TenantId(t["id"]) for t in ps_http.tenant_list()]

body = {"generation": env.storage_controller.attach_hook_issue(tenant_id, env.pageserver.id)}

ps_http.post(
f"{ps_http.base_url}/v1/tenant/{tenant_id}/attach",
json=body,
ps_http.put(
f"{ps_http.base_url}/v1/location_conf/{tenant_id}",
json={
"mode": "AttachedSingle",
"generation": env.storage_controller.attach_hook_issue(tenant_id, env.pageserver.id),
"tenant_conf": {},
"secondary_conf": {},
},
headers=None if content_type else {"Content-Type": "application/json"},
).raise_for_status()

Expand Down
13 changes: 7 additions & 6 deletions test_runner/regress/test_remote_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,14 @@ def test_remote_storage_backup_and_restore(
"data": {"reason": "storage-sync-list-remote-timelines"},
}

# Even though the tenant is broken, subsequent calls to location_conf API will succeed, but
# the tenant will always end up in a broken state as a result of the failpoint.
# Ensure that even though the tenant is broken, retrying the attachment fails
with pytest.raises(Exception, match="Tenant state is Broken"):
# Use same generation as in previous attempt
gen_state = env.storage_controller.inspect(tenant_id)
assert gen_state is not None
generation = gen_state[0]
env.pageserver.tenant_attach(tenant_id, generation=generation)
tenant_info = wait_until_tenant_state(pageserver_http, tenant_id, "Broken", 15)
gen_state = env.storage_controller.inspect(tenant_id)
assert gen_state is not None
generation = gen_state[0]
env.pageserver.tenant_attach(tenant_id, generation=generation)

# Restart again, this implicitly clears the failpoint.
# test_remote_failures=1 remains active, though, as it's in the pageserver config.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_walredo_not_left_behind_on_detach(neon_env_builder: NeonEnvBuilder):
expected_exception=PageserverApiException,
match=f"NotFound: tenant {tenant_id}",
):
pageserver_http.tenant_detach(tenant_id)
pageserver_http.tenant_status(tenant_id)

# create new nenant
tenant_id, _ = env.neon_cli.create_tenant()
Expand Down

0 comments on commit 0ecb9a3

Please sign in to comment.