Skip to content

Commit

Permalink
Change validate and get_answer method as per requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
khushboo-rancher authored and sangeethah committed Feb 7, 2020
1 parent f8e784b commit 02e3eec
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 30 deletions.
14 changes: 0 additions & 14 deletions tests/validation/tests/v3_api/cataloglib_appversion.json

This file was deleted.

54 changes: 44 additions & 10 deletions tests/validation/tests/v3_api/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1547,9 +1547,16 @@ def get_answer(quest):
# only for type string . For other types error out
if "required" in quest.keys():
if quest["required"]:
assert quest["type"] == "string", \
"Cannot set default for types other than string"
answer = "fake"
if quest["type"] == "enum" and "options" in quest.keys():
answer = quest["options"][0]
elif quest["type"] == "password":
answer = "R@ncher135"
elif quest["type"] == "string":
answer = "fake"
else:
assert False, \
"Cannot set default for types {}" \
"".format(quest["type"])
return answer

def check_if_question_needed(questions_and_answers, ques):
Expand Down Expand Up @@ -1613,6 +1620,15 @@ def validate_app_deletion(client, app_id,


def validate_catalog_app(proj_client, app, external_id, answer=None):
"""
This method validates all the workloads deployed are in active state,
have correct version and validates the answers.
@param proj_client: Project client object of a existing project.
@param app: Deployed app object.
@param external_id: URl of app API.
@param answer: answer, app seek while deploying, body of the post call.
@return: Deployed app object.
"""
if answer is None:
answers = get_defaut_question_answers(get_user_client(), external_id)
else:
Expand All @@ -1623,23 +1639,41 @@ def validate_catalog_app(proj_client, app, external_id, answer=None):
"the version of the app is not correct"
# check if associated workloads are active
ns = app.targetNamespace
pramaters = external_id.split('&')
assert len(pramaters) > 1, \
"Incorrect list of paramaters from catalog external ID"
chart = pramaters[len(pramaters)-2].split("=")[1] + "-" + \
pramaters[len(pramaters)-1].split("=")[1]
parameters = external_id.split('&')
assert len(parameters) > 1, \
"Incorrect list of parameters from catalog external ID"
chart = parameters[len(parameters)-2].split("=")[1] + "-" + \
parameters[len(parameters)-1].split("=")[1]
app_name = parameters[len(parameters)-2].split("=")[1]
workloads = proj_client.list_workload(namespaceId=ns).data
for wl in workloads:
assert wl.state == "active"
assert wl.workloadLabels.chart == chart, \
"the chart version is wrong"
chart_deployed = get_chart_info(wl.workloadLabels)
# '-' check is to make sure chart has both app name and version.
if app_name in chart_deployed and '-' in chart_deployed:
assert chart_deployed == chart, "the chart version is wrong"

# Validate_app_answers
assert len(answers.items() - app["answers"].items()) == 0, \
"Answers are not same as the original catalog answers"
return app


def get_chart_info(workloadlabels):
"""
This method finds either 'chart' tag or
'helm.sh/chart' tag from workload API
@param workloadlabels: workloadslabel object
@return: chart value of workload e.g. 'app_name-version'
"""
if "chart" in workloadlabels.keys():
return workloadlabels.chart
elif "helm.sh/chart" in workloadlabels.keys():
return workloadlabels["helm.sh/chart"]
else:
return ''


def create_user(client, cattle_auth_url=CATTLE_AUTH_URL):
user_name = random_name()
user = client.create_user(username=user_name,
Expand Down
29 changes: 29 additions & 0 deletions tests/validation/tests/v3_api/resource/cataloglib_appversion.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"artifactory-jcr": "0.1.0",
"chartmuseum": "2.3.1",
"citrix-k8s-cpx-ingress-controller": "1.6.1",
"citrix-k8s-ingress-controller": "1.6.1",
"datadog": "1.33.0",
"docker-registry": "1.8.1",
"drone": "2.0.7",
"efk": "7.3.0",
"etcd-operator": "0.9.0",
"fluentd-aggregator": "0.3.1",
"grafana": "3.8.6",
"hadoop": "1.1.1",
"harbor": "1.2.0",
"instana-agent": "1.0.16",
"magento": "5.1.4",
"mariadb": "6.7.4",
"memcached" : "2.9.0",
"mongodb-replicaset" : "3.9.6",
"mongodb": "7.2.6",
"mysql": "1.3.1",
"openebs": "1.6.0",
"prometheus": "9.1.0",
"redis": "9.0.2",
"redskyops": "0.1.2",
"traefik": "1.0.0",
"vault-operator": "0.1.3",
"wordpress": "7.3.8"
}
28 changes: 22 additions & 6 deletions tests/validation/tests/v3_api/test_catalog_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@
from .common import pytest
from .common import create_ns
from .common import create_catalog_external_id
from .common import get_defaut_question_answers
from .common import validate_catalog_app
from .common import validate_app_deletion
from .common import get_user_client_and_cluster
from .common import create_kubeconfig
from .common import get_cluster_client_for_token
from .common import create_project
from .common import random_test_name
from .common import get_defaut_question_answers
from .common import validate_catalog_app
from .common import get_project_client_for_token
from .common import USER_TOKEN
from .common import get_user_client


cluster_info = {"cluster": None, "cluster_client": None,
"project": None, "project_client": None,
"user_client": None}
catalog_filename = os.path.join(os.path.dirname(os.path.realpath(__file__)),
"cataloglib_appversion.json")
"./resource/cataloglib_appversion.json")
with open(catalog_filename, "r") as app_v:
app_data = json.load(app_v)

Expand All @@ -39,6 +40,8 @@ def test_catalog_app_deploy(app_name, app_version):
Runs for app from 'cataloglib_appversion.json',
creates relevant namespace and deploy them.
Validates status of the app, version and answer.
try block is to make sure apps are deleted even
after they fail to validate.
"""
user_client = cluster_info["user_client"]
project_client = cluster_info["project_client"]
Expand All @@ -50,19 +53,26 @@ def test_catalog_app_deploy(app_name, app_version):
app_ext_id = create_catalog_external_id('library',
app_name, app_version)
answer = get_defaut_question_answers(user_client, app_ext_id)
app = project_client.create_app(
try:
app = project_client.create_app(
name=random_test_name(),
externalId=app_ext_id,
targetNamespace=ns.name,
projectId=ns.projectId,
answers=answer)
validate_catalog_app(project_client, app, app_ext_id, answer)
validate_catalog_app(project_client, app, app_ext_id, answer)
except (AssertionError, RuntimeError):
project_client.delete(app)
validate_app_deletion(project_client, app.id)
user_client.delete(ns)
assert False, "App deployment/Validation failed."
project_client.delete(app)
validate_app_deletion(project_client, app.id)
user_client.delete(ns)


@pytest.fixture(scope='module', autouse="True")
def create_project_client():
def create_project_client(request):
"""
Creates project in a cluster and collects details of
user, project and cluster
Expand All @@ -79,3 +89,9 @@ def create_project_client():
cluster_info["project"] = project
cluster_info["project_client"] = project_client
cluster_info["user_client"] = user_client

def fin():
client = get_user_client()
client.delete(cluster_info["project"])

request.addfinalizer(fin)

0 comments on commit 02e3eec

Please sign in to comment.