Skip to content

Commit

Permalink
fix error in test 0.2 (red-hat-storage#10910)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Osypenko <[email protected]>
  • Loading branch information
DanielOsypenko authored Dec 11, 2024
1 parent 71fee55 commit 6ca8996
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
54 changes: 42 additions & 12 deletions ocs_ci/utility/deployment_openshift_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@
logger = logging.getLogger(__name__)


def create_namespace(yaml_file):
def create_namespace(yaml_file, skip_resource_exists=False):
"""
Creation of namespace "openshift-operators-redhat"
for Elasticsearch-operator and "openshift-logging"
for ClusterLogging-operator
Args:
yaml_file (str): Path to yaml file to create namespace
skip_resource_exists: Skip the namespace creation if it already exists
Example:
create_namespace(yaml_file=constants.EO_NAMESPACE_YAML)
Expand All @@ -38,11 +39,20 @@ def create_namespace(yaml_file):
namespaces = ocp.OCP(kind=constants.NAMESPACES)

logger.info("Creating Namespace.........")
assert namespaces.create(yaml_file=yaml_file), "Failed to create namespace"
try:
assert namespaces.create(yaml_file=yaml_file), "Failed to create namespace"
except CommandFailed as e:
if "AlreadyExists" in str(e) and skip_resource_exists:
# on Rosa HCP the ns created from the deployment
logger.warning("Namespace already exists")
else:
raise
logger.info("Successfully created Namespace")


def create_elasticsearch_operator_group(yaml_file, resource_name):
def create_elasticsearch_operator_group(
yaml_file, resource_name, skip_resource_exists=False
):
"""
Creation of operator-group for Elastic-search operator
Expand All @@ -51,6 +61,7 @@ def create_elasticsearch_operator_group(yaml_file, resource_name):
elastic-search
resource_name (str): Name of the operator group to create for
elastic-search
skip_resource_exists: Skip the resource creation if it already exists
Returns:
bool: True if operator group for elastic search is created
Expand All @@ -69,7 +80,14 @@ def create_elasticsearch_operator_group(yaml_file, resource_name):
namespace=constants.OPENSHIFT_OPERATORS_REDHAT_NAMESPACE,
)

es_operator_group.create(yaml_file=yaml_file)
try:
es_operator_group.create(yaml_file=yaml_file)
except CommandFailed as e:
if "AlreadyExists" in str(e) and skip_resource_exists:
logger.warning("Operator group already exists")
return True
else:
raise
try:
es_operator_group.get(resource_name, out_yaml_format=True)
logger.info("The Operator group is created successfully")
Expand All @@ -79,7 +97,7 @@ def create_elasticsearch_operator_group(yaml_file, resource_name):
return True


def set_rbac(yaml_file, resource_name):
def set_rbac(yaml_file, resource_name, skip_resource_exists=False):
"""
Setting Role Based Access Control to grant Prometheus
permission to access the openshift-operators-redhat namespace
Expand All @@ -89,7 +107,7 @@ def set_rbac(yaml_file, resource_name):
(ROLE BASED ACCESS CONTROL)
resource_name (str): Name of the resource for which we give RBAC
permissions
skip_resource_exists: Skip the resource creation if it already exists
Returns:
bool: True if RBAC is set successfully,
false otherwise
Expand All @@ -107,7 +125,14 @@ def set_rbac(yaml_file, resource_name):
namespace=constants.OPENSHIFT_OPERATORS_REDHAT_NAMESPACE,
)

rbac_role.create(yaml_file=yaml_file, out_yaml_format=False)
try:
rbac_role.create(yaml_file=yaml_file, out_yaml_format=False)
except CommandFailed as e:
if "AlreadyExists" in str(e) and skip_resource_exists:
logger.warning("RBAC role already exists")
return True
else:
raise
try:
rbac_role.get(resource_name, out_yaml_format=True)
rbac_rolebinding.get(resource_name, out_yaml_format=True)
Expand Down Expand Up @@ -151,16 +176,15 @@ def get_elasticsearch_subscription():
return bool(es_sub)


def create_clusterlogging_operator_group(yaml_file):
def create_clusterlogging_operator_group(yaml_file, skip_resource_exists=False):
"""
Creation of operator-group for clusterlogging
operator.
Args:
yaml_file (str): Path to yaml file to create operator group for
cluster-logging operator
resource_name (str): Name of the operator group to create for
cluster-logging operator
skip_resource_exists: Skip the resource creation if it already exists
Returns:
bool: True if operator group for cluster-logging is created
Expand All @@ -174,8 +198,14 @@ def create_clusterlogging_operator_group(yaml_file):
operator_group = ocp.OCP(
kind=constants.OPERATOR_GROUP, namespace=constants.OPENSHIFT_LOGGING_NAMESPACE
)

operator_group.create(yaml_file=yaml_file)
try:
operator_group.create(yaml_file=yaml_file)
except CommandFailed as e:
if "AlreadyExists" in str(e) and skip_resource_exists:
logger.warning("Operator group already exists")
return True
else:
raise
try:
operator_group.get(out_yaml_format=True)
logger.info("The Operator group is created successfully")
Expand Down
22 changes: 11 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3268,6 +3268,7 @@ def install_logging(request):
* The teardown will uninstall cluster-logging from the cluster
"""
rosa_hcp_depl = config.ENV_DATA.get("platform") == constants.ROSA_HCP_PLATFORM

def finalizer():
uninstall_cluster_logging()
Expand All @@ -3291,18 +3292,15 @@ def finalizer():
logging_channel = "stable" if ocp_version >= version.VERSION_4_7 else ocp_version

# Creates namespace openshift-operators-redhat
try:
ocp_logging_obj.create_namespace(yaml_file=constants.EO_NAMESPACE_YAML)
except CommandFailed as e:
if "AlreadyExists" in str(e):
# on Rosa HCP the ns created from the deployment
log.info("Namespace openshift-operators-redhat already exists")
else:
raise
ocp_logging_obj.create_namespace(
yaml_file=constants.EO_NAMESPACE_YAML, skip_resource_exists=rosa_hcp_depl
)

# Creates an operator-group for elasticsearch
assert ocp_logging_obj.create_elasticsearch_operator_group(
yaml_file=constants.EO_OG_YAML, resource_name="openshift-operators-redhat"
yaml_file=constants.EO_OG_YAML,
resource_name="openshift-operators-redhat",
skip_resource_exists=rosa_hcp_depl,
)

# Set RBAC policy on the project
Expand All @@ -3325,11 +3323,13 @@ def finalizer():
)

# Creates a namespace openshift-logging
ocp_logging_obj.create_namespace(yaml_file=constants.CL_NAMESPACE_YAML)
ocp_logging_obj.create_namespace(
yaml_file=constants.CL_NAMESPACE_YAML, skip_resource_exists=rosa_hcp_depl
)

# Creates an operator-group for cluster-logging
assert ocp_logging_obj.create_clusterlogging_operator_group(
yaml_file=constants.CL_OG_YAML
yaml_file=constants.CL_OG_YAML, skip_resource_exists=rosa_hcp_depl
)

# Creates subscription for cluster-logging
Expand Down

0 comments on commit 6ca8996

Please sign in to comment.