-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DPE-4114] Test: Scale to zero units #347
base: main
Are you sure you want to change the base?
Changes from 1 commit
9d7bfed
938035f
7dc328b
b762ec8
0ca9740
04bc51c
171b53f
27c97f4
8382d0d
d467d8c
526357b
4b64ce9
927ad24
a18b1d3
18211ed
d917d88
0a0486f
ab160f3
263a1ef
a1b24dd
19574bd
6873326
6716eaf
41bfc2f
2b7db14
ef84bf6
e670781
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
import logging | ||
|
||
import pytest | ||
from pip._vendor import requests | ||
from pytest_operator.plugin import OpsTest | ||
from tenacity import Retrying, stop_after_delay, wait_fixed | ||
|
||
|
@@ -14,7 +15,7 @@ | |
get_machine_from_unit, | ||
get_password, | ||
get_unit_address, | ||
run_command_on_unit, | ||
run_command_on_unit, scale_application, | ||
) | ||
from .conftest import APPLICATION_NAME | ||
from .helpers import ( | ||
|
@@ -540,3 +541,78 @@ async def test_network_cut_without_ip_change( | |
), "Connection is not possible after network restore" | ||
|
||
await is_cluster_updated(ops_test, primary_name) | ||
|
||
@pytest.mark.group(1) | ||
async def test_deploy_zero_units(ops_test: OpsTest): | ||
"""Scale the database to zero units and scale up again.""" | ||
wait_for_apps = False | ||
if not await app_name(ops_test): | ||
wait_for_apps = True | ||
async with ops_test.fast_forward(): | ||
await ops_test.model.deploy( | ||
APP_NAME, | ||
application_name=APP_NAME, | ||
num_units=3, | ||
storage={"pgdata": {"pool": "lxd-btrfs", "size": 2048}}, | ||
series=CHARM_SERIES, | ||
channel="edge", | ||
) | ||
|
||
# Deploy the continuous writes application charm if it wasn't already deployed. | ||
if not await app_name(ops_test, APPLICATION_NAME): | ||
wait_for_apps = True | ||
async with ops_test.fast_forward(): | ||
await ops_test.model.deploy( | ||
APPLICATION_NAME, | ||
application_name=APPLICATION_NAME, | ||
series=CHARM_SERIES, | ||
channel="edge", | ||
) | ||
|
||
if wait_for_apps: | ||
await ops_test.model.wait_for_idle(status="active", timeout=3000) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the above comment is handled, this line can be moved close to the deployment of the PostgreSQL application. |
||
|
||
# Start an application that continuously writes data to the database. | ||
await start_continuous_writes(ops_test, APP_NAME) | ||
|
||
logger.info("checking whether writes are increasing") | ||
await are_writes_increasing(ops_test) | ||
|
||
unit_ip_addresses = [] | ||
storage_id_list = [] | ||
primary_name = await get_primary(ops_test, APP_NAME) | ||
primary_storage = "" | ||
for unit in ops_test.model.applications[APP_NAME].units: | ||
# Save IP addresses of units | ||
unit_ip_addresses.append(await get_unit_ip(ops_test, unit.name)) | ||
|
||
# Save detached storage ID | ||
if primary_name != unit.name: | ||
storage_id_list.append(storage_id(ops_test, unit.name)) | ||
else: | ||
primary_storage = storage_id(ops_test, unit.name) | ||
|
||
# Scale the database to zero units. | ||
logger.info("scaling database to zero units") | ||
await scale_application(ops_test, APP_NAME, 0) | ||
|
||
# Checking shutdown units | ||
for unit_ip in unit_ip_addresses: | ||
try: | ||
resp = requests.get(f"http://{unit_ip}:8008") | ||
assert resp.status_code != 200, f"status code = {resp.status_code}, message = {resp.text}" | ||
except requests.exceptions.ConnectionError as e: | ||
assert True, f"unit host = http://{unit_ip}:8008, all units shutdown" | ||
except Exception as e: | ||
assert False, f"{e} unit host = http://{unit_ip}:8008, something went wrong" | ||
|
||
# Scale the database to one unit. | ||
logger.info("scaling database to one unit") | ||
await add_unit_with_storage(ops_test, storage=primary_storage, app=APP_NAME) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After the unit starts, we should check if the data on the storage has been actually restored. |
||
logger.info("checking whether writes are increasing") | ||
await are_writes_increasing(ops_test) | ||
|
||
# Scale the database to three units. | ||
for store_id in storage_id_list: | ||
await add_unit_with_storage(ops_test, storage=store_id, app=APP_NAME) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JFMI, should re use ops lib directly as in helper it refers to this which is resolved:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. We should remove the workaround and use the methods provided by the lib. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC this is only available in libjuju 3 |
||
await check_writes(ops_test) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After 2nd and 3rd units start, it is needed to check that data on them is restored from WAL (not via backup/restore). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ha_test.helpers.reused_replica_storage() and ha_test.helpers.reused_full_cluster_recovery_storage() should do the trick. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part can be removed, as the continuous writes application is already deployed by
test_build_and_deploy
.