-
Notifications
You must be signed in to change notification settings - Fork 166
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
Verify the NooBaa DB PostreSQL version at upgrade #10440
base: master
Are you sure you want to change the base?
Changes from 2 commits
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 |
---|---|---|
|
@@ -754,6 +754,10 @@ def run_ocs_upgrade( | |
upgrade_ocs.version_before_upgrade, | ||
) | ||
|
||
from ocs_ci.helpers.helpers import verify_nb_db_psql_version | ||
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. move the imports to the top |
||
|
||
verify_nb_db_psql_version() | ||
|
||
# update external secrets | ||
if config.DEPLOYMENT["external_mode"]: | ||
upgrade_version = version.get_semantic_version(upgrade_version, True) | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -24,8 +24,13 @@ | |||||
from ocs_ci.ocs import constants | ||||||
from ocs_ci.ocs.external_ceph import RolesContainer, Ceph, CephNode | ||||||
from ocs_ci.ocs.clients import WinNode | ||||||
from ocs_ci.ocs.exceptions import CommandFailed, ExternalClusterDetailsException | ||||||
from ocs_ci.ocs.ocp import OCP | ||||||
from ocs_ci.ocs.exceptions import ( | ||||||
CommandFailed, | ||||||
ExternalClusterDetailsException, | ||||||
ResourceNotFoundError, | ||||||
UnexpectedBehaviour, | ||||||
) | ||||||
from ocs_ci.ocs.ocp import OCP, get_images | ||||||
from ocs_ci.ocs.openstack import CephVMNode | ||||||
from ocs_ci.ocs.parallel import parallel | ||||||
from ocs_ci.ocs.resources.ocs import OCS | ||||||
|
@@ -34,6 +39,7 @@ | |||||
from ocs_ci.utility.retry import retry | ||||||
from ocs_ci.utility.utils import ( | ||||||
create_directory_path, | ||||||
exec_nb_db_query, | ||||||
mirror_image, | ||||||
run_cmd, | ||||||
get_oadp_version, | ||||||
|
@@ -1890,3 +1896,88 @@ def get_dr_operator_versions(): | |||||
if submariner_operator_version: | ||||||
versions_dic["submariner_version"] = submariner_operator_version | ||||||
return versions_dic | ||||||
|
||||||
|
||||||
def get_nb_db_psql_version_from_image(): | ||||||
""" | ||||||
Get the NooBaa DB PostgreSQL version from the image name in the NooBaa DB statefulset | ||||||
|
||||||
Returns: | ||||||
str: The NooBaa DB PostgreSQL version | ||||||
|
||||||
Raises: | ||||||
ResourceNotFoundError: If the NooBaa DB statefulset is not available | ||||||
UnexpectedBehaviour: If the NooBaa DB version could not be extracted from the | ||||||
NooBaa DB statefulset image | ||||||
|
||||||
""" | ||||||
nb_db_sts_obj = OCP( | ||||||
kind=constants.STATEFULSET, | ||||||
namespace=ocsci_config.ENV_DATA["cluster_namespace"], | ||||||
resource_name=constants.NOOBAA_DB_STATEFULSET, | ||||||
) | ||||||
if not nb_db_sts_obj.data: | ||||||
raise ResourceNotFoundError( | ||||||
f"NooBaa DB statefulset {constants.NOOBAA_DB_STATEFULSET} not found" | ||||||
) | ||||||
|
||||||
try: | ||||||
images = get_images(nb_db_sts_obj.data) | ||||||
psql_img = next(iter(images.values())) # Only one image is expected | ||||||
re_match = re.search(r"postgresql-(\d+(\.\d+)*)", psql_img) | ||||||
return re_match.group(1) | ||||||
except Exception as e: | ||||||
raise UnexpectedBehaviour( | ||||||
f"Failed to extract the NooBaa DB version from its stateful set: {e}" | ||||||
) | ||||||
|
||||||
|
||||||
def query_nb_db_psql_version(): | ||||||
""" | ||||||
Query the NooBaa DB for its PostgreSQL version | ||||||
|
||||||
Returns: | ||||||
str: The NooBaa DB version | ||||||
|
||||||
Raises: | ||||||
ResourceNotFoundError: If the NooBaa DB pod was not found | ||||||
UnexpectedBehaviour: If the NooBaa DB version could not be extracted from the | ||||||
NooBaa DB pod | ||||||
""" | ||||||
try: | ||||||
raw_output = exec_nb_db_query("SELECT version();")[0] | ||||||
except IndexError: | ||||||
raise UnexpectedBehaviour("Failed to query the NooBaa DB for its version") | ||||||
return re.search(r"PostgreSQL (\S+)", raw_output).group(1) | ||||||
|
||||||
|
||||||
def get_expected_nb_db_psql_version(): | ||||||
""" | ||||||
Get the expected NooBaa DB version from the NooBaa CR | ||||||
|
||||||
Returns: | ||||||
str: The expected NooBaa DB version | ||||||
|
||||||
Raises: | ||||||
ResourceNotFoundError: If the NooBaa CR was not found | ||||||
UnexpectedBehaviour: If the NooBaa DB version could not be extracted from the | ||||||
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.
Suggested change
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. leave empty line |
||||||
""" | ||||||
|
||||||
nb_cr_obj = OCP( | ||||||
kind=constants.NOOBAA_RESOURCE_NAME, | ||||||
namespace=ocsci_config.ENV_DATA["cluster_namespace"], | ||||||
resource_name=constants.NOOBAA_RESOURCE_NAME, | ||||||
) | ||||||
if not nb_cr_obj: | ||||||
raise ResourceNotFoundError( | ||||||
f"NooBaa CR {constants.NOOBAA_RESOURCE_NAME} not found" | ||||||
) | ||||||
|
||||||
try: | ||||||
psql_image = nb_cr_obj.data["spec"]["dbImage"] | ||||||
re_match = re.search(r"postgresql-(\d+(\.\d+)*)", psql_image) | ||||||
return re_match.group(1) | ||||||
except Exception as e: | ||||||
raise UnexpectedBehaviour( | ||||||
f"Failed to extract the NooBaa DB version from the NooBaa CR: {e}" | ||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
from ocs_ci.framework.testlib import libtest | ||
from ocs_ci.helpers.helpers import verify_nb_db_psql_version | ||
|
||
|
||
@libtest | ||
@pytest.mark.parametrize( | ||
"check_image", | ||
[ | ||
False, | ||
True, | ||
], | ||
) | ||
def test_nb_db_psql_version(check_image): | ||
verify_nb_db_psql_version(check_image_name_version=check_image) |
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.
could you combine these two import to one