def check_env_var_count_set_on_container(context, envVar, app_name=None): openshift = Openshift() if app_name is None: app_name = context.application.name app_name = Template(app_name).substitute(scenario_id=scenario_id(context)) env = openshift.get_deployment_env_info(app_name, context.namespace.name) assert str(env).count(envVar) == 1
def check_file_value(context, file_path): value = Template( context.text.strip()).substitute(NAMESPACE=context.namespace.name) resource = Template(file_path).substitute(scenario_id=scenario_id(context)) polling2.poll( lambda: context.application.get_file_value(resource) == value, step=5, timeout=400)
def sbo_secret_name_has_been_set(context, sbr_name=None): if sbr_name is None: sbr_name = list(context.bindings.values())[0].name else: sbr_name = Template(sbr_name).substitute( scenario_id=scenario_id(context)) polling2.poll(lambda: context.bindings[sbr_name].get_secret_name() != "", step=5, timeout=800, ignore_exceptions=(json.JSONDecodeError, ))
def check_resource_readable(context, user, resource, namespace=None): openshift = Openshift() data = resource.split("/") res_type = data[0] res_name = Template(data[1]).substitute(scenario_id=scenario_id(context)) ns = namespace if namespace is not None else context.namespace.name res = openshift.get_resource_info_by_jsonpath(resource_type=res_type, name=res_name, namespace=ns, user=user) assert res is not None, f"User {user} should be able to read {resource} in {ns} namespace"
def is_running(context, application_name=None, bindingRoot=None, asDeploymentConfig=False): if application_name is None: application_name = scenario_id(context) application = GenericTestApp(application_name, context.namespace.name) if asDeploymentConfig: application.resource = "deploymentconfig" if not application.is_running(): print("application is not running, trying to import it") application.install(bindingRoot=bindingRoot) context.application = application # save the generation number context.original_application_generation = application.get_generation() context.latest_application_generation = application.get_generation()
def apply_yaml(context, user=None): openshift = Openshift() resource = Template( context.text).substitute(scenario_id=scenario_id(context)) metadata = yaml.full_load(resource)["metadata"] metadata_name = metadata["name"] if "namespace" in metadata: ns = metadata["namespace"] else: if "namespace" in context: ns = context.namespace.name else: ns = None output = openshift.apply(resource, ns, user) result = re.search(rf'.*{metadata_name}.*(created|unchanged|configured)', output) assert result is not None, f"Unable to apply YAML for CR '{metadata_name}': {output}" return metadata
def sbr_is_applied(context, user=None): if "application" in context and "application_type" in context: application = context.application if context.application_type == "nodejs": context.application_original_generation = application.get_observed_generation( ) context.application_original_pod_name = application.get_running_pod_name( ) elif context.application_type == "knative": context.application_original_generation = context.application.get_generation( ) else: assert False, f"Invalid application type in context.application_type={context.application_type}, valid are 'nodejs', 'knative'" if "namespace" in context: ns = context.namespace.name else: ns = None resource = Template( context.text).substitute(scenario_id=scenario_id(context)) binding = ServiceBinding(resource, ns) assert binding.create(user) is not None, "Service binding not created" context.bindings[binding.name] = binding context.sb_secret = ""
def check_file_exists(context, file_path): resource = Template(file_path).substitute(scenario_id=scenario_id(context)) polling2.poll(lambda: context.application.get_file_value(resource) != "", step=5, timeout=400)