Skip to content

Commit

Permalink
Merge pull request #55 from mrrajan/provision_dev
Browse files Browse the repository at this point in the history
Added scripts to provision new mongo DB instances from CLI
  • Loading branch information
mergify[bot] authored Aug 11, 2022
2 parents b38f0c4 + cc41722 commit 74bb437
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 2 deletions.
26 changes: 26 additions & 0 deletions resources/keywords/provision_dbinstance.resource
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,29 @@ DBSC Instance Retrieval Failed On Dev View
Element Should Be Visible ${btnTryAgain}
Element Should Be Visible ${btnClose}
Click Button ${btnClose}

User Provisions New ${databaseProvider} Instance On ${ns_type} Namespace Using OC CLI
Provision DB Instance ${databaseProvider} ${ns_type}

DB Instance Provisioned Successfully On ${ns_type} Namespace Using OC CLI
${targetNS} Set Variable ${newProject}
IF '${ns_type}' == 'Default'
${targetNS} Set Variable redhat-dbaas-operator
END
${cmd} Set Variable oc get DBaaSInstance/${instanceName} -n ${targetNS} -o custom-columns=:.status
Wait Until Keyword Succeeds 10x 2s Instance Available Without Error ${cmd}
${cmd_instance} Set Variable oc get DBaaSInstance/${instanceName} -n ${targetNS} -o custom-columns=:.status.instanceID | grep -v '^$'
Retrieve Instance ID ${cmd_instance}

Instance Available Without Error ${cmd}
${stdout} = Execute Command ${cmd} True
${stdout_str} = Convert To String ${stdout}
${stdout_str} = Convert To Lower Case ${stdout_str}
Should Contain ${stdout_str} type:provisionready
Should Not Contain Any ${stdout_str} error notfound

Retrieve Instance ID ${cmd_instance}
${stdout} = Execute Command ${cmd_instance} True
${stdout_str} = Convert To String ${stdout}[0]
Should Not Contain Any ${stdout_str} None
Set Suite Variable ${instanceID} ${stdout_str}
22 changes: 22 additions & 0 deletions tests/mongodb_provision_cli.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*** Settings ***
Documentation Provision and Deploy MongoDB Database Instance from Developer View
Metadata Version 0.0.1

Resource ../resources/keywords/provision_dbinstance.resource

Suite Setup Set Library Search Order SeleniumLibrary
Suite Teardown Tear Down The Test Suite
Test Setup Given Login To OpenShift CLI
Test Teardown Logout Of OpenShift CLI


*** Test Cases ***
Scenario: Provision MongoDB Database Instance On Default Namespace Using OC CLI
[Tags] smoke RHOD-61-adm
When User Provisions New MongoDB Instance On Default Namespace Using OC CLI
Then DB Instance Provisioned Successfully On Default Namespace Using OC CLI

Scenario: Provision MongoDB Database Instance On User Defined Namespace Using OC CLI
[Tags] smoke RHOD-61-dev
When User Provisions New MongoDB Instance On User Defined Namespace Using OC CLI
Then DB Instance Provisioned Successfully On User Defined Namespace Using OC CLI
12 changes: 12 additions & 0 deletions utils/data/oc_dbaas_instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: dbaas.redhat.com/v1alpha1
kind: DBaaSInstance
metadata:
name: instance_name
namespace: deploy_instance_ns
spec:
name: instance_name
inventoryRef:
name: provider_account
namespace: prov_acc_ns
otherInstanceParams:
{}
44 changes: 42 additions & 2 deletions utils/scripts/dbaas_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

ROBOT_LIBRARY_VERSION = "0.6"
ROBOT_LIBRARY_VERSION = "0.7"


def select_database_instance(
Expand Down Expand Up @@ -202,7 +202,7 @@ def retrieve_instances(isv, namespace):
provider_account = BuiltIn().get_variable_value(r"\${provaccname}")
if provider_account == "":
create_secret_cli(isv, "true")
import_provider_account_cli(isv)
import_provider_account_cli(isv, namespace)
provider_account = BuiltIn().get_variable_value(r"\${provaccname}")
cmd = "oc describe DBaaSInventory/{} -n {}".format(provider_account, namespace)
while True:
Expand Down Expand Up @@ -301,3 +301,43 @@ def check_dbsc_connection(project, instance_id):
)
else:
BuiltIn().fail("DBSC Connections are not present for the project: " + project)


def provision_db_instance(isv, deploy_view, default_pa_ns="Yes"):
"""To Provision New DB Instance Under Provider Account.
Arguments deploy_view and default_pa_ns defines the target namespaces to
deploy database instance and import provider account respectively"""
prov_acc_ns = "redhat-dbaas-operator"
deploy_instance_ns = "redhat-dbaas-operator"
create_new_project(BuiltIn().get_variable_value(r"\${TEST TAGS}"))
if default_pa_ns != "Yes":
prov_acc_ns = BuiltIn().get_variable_value(r"\${newProject}")
retrieve_instances(isv, prov_acc_ns)
if "user" in deploy_view.lower():
deploy_instance_ns = BuiltIn().get_variable_value(r"\${newProject}")
src = create_provision_instance_yaml(isv, prov_acc_ns, deploy_instance_ns)
oc_cli = BuiltIn().get_library_instance("OpenshiftLibrary")
kind = "DBaaSInstance"
api_version = "dbaas.redhat.com/v1alpha1"
oc_cli.oc_apply(kind, src, api_version)
log.info("DB Instance " + BuiltIn().get_variable_value(r"\${instanceName}")
+ "provisioned successfully!")


def create_provision_instance_yaml(isv, prov_acc_ns, deploy_instance_ns):
"""To create provision instance yaml"""
instance = util.get_instance_name("cli")
BuiltIn().set_suite_variable(r"\${instanceName}", instance)
yaml_deploy_instance = "./utils/data/oc_dbaas_instance.yaml"
with open(yaml_deploy_instance, "r") as provision:
data = yaml.safe_load(provision)
data["metadata"]["name"] = instance
data["metadata"]["namespace"] = deploy_instance_ns
data["spec"]["name"] = instance
data["spec"]["inventoryRef"]["name"] = BuiltIn().get_variable_value(r"\${provaccname}")
data["spec"]["inventoryRef"]["namespace"] = prov_acc_ns
if "mongo" in isv.lower():
data["spec"]["otherInstanceParams"]["projectName"] = instance
print(data)
return yaml.dump(data, sort_keys=False)

0 comments on commit 74bb437

Please sign in to comment.