Skip to content

Commit

Permalink
refactored setup/cleanup methods for hello-world example
Browse files Browse the repository at this point in the history
  • Loading branch information
omgoswami committed Aug 10, 2024
1 parent acc7c89 commit 8b6baea
Showing 1 changed file with 37 additions and 31 deletions.
68 changes: 37 additions & 31 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,40 @@ def _is_kyverno_running(self):
if 'kyverno' in line and 'Running' in line:
return True
return False


def setup_example_hello_world(self, provider):

if not TestKubePlus._is_kubeplus_running():
print("KubePlus is not running. Deploy KubePlus and then run tests")
sys.exit(0)

if os.getenv("KUBEPLUS_HOME") == '':
print("Skipping test as KUBEPLUS_HOME is not set.")
return

# register HelloWorldService API
cmd = "kubectl create -f ../examples/multitenancy/hello-world/hello-world-service-composition-localchart.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)

# check CRD installation
crd = "helloworldservices.platformapi.kubeplus"
crd_installed = self._check_crd_installed(crd)
if not crd_installed:
print("CRD " + crd + " not installed. Exiting this test.")
return

# create app instance
cmd = "kubectl create -f ../examples/multitenancy/hello-world/hs1.yaml --kubeconfig=%s" % provider
out, err = TestKubePlus.run_command(cmd)
time.sleep(10)


def cleanup_example_hello_world(self, provider):
cmd = "kubectl delete -f ../examples/multitenancy/hello-world/hs1.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)
cmd = "kubectl delete -f ../examples/multitenancy/hello-world/hello-world-service-composition-localchart.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)

def test_create_res_comp_for_chart_with_ns(self):
if not TestKubePlus._is_kubeplus_running():
Expand Down Expand Up @@ -526,53 +560,25 @@ def test_res_comp_with_no_podpolicies(self):
def test_appstatus_plugin(self):
kubeplus_home = os.getenv("KUBEPLUS_HOME")
provider = kubeplus_home + '/kubeplus-saas-provider.json'

def cleanup():
cmd = "kubectl delete -f ../examples/multitenancy/hello-world/hs1.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)
cmd = "kubectl delete -f ../examples/multitenancy/hello-world/hello-world-service-composition-localchart.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)

if not TestKubePlus._is_kubeplus_running():
print("KubePlus is not running. Deploy KubePlus and then run tests")
sys.exit(0)

if os.getenv("KUBEPLUS_HOME") == '':
print("Skipping test as KUBEPLUS_HOME is not set.")
return

# register HelloWorldService API
cmd = "kubectl create -f ../examples/multitenancy/hello-world/hello-world-service-composition-localchart.yaml --kubeconfig=%s" % provider
TestKubePlus.run_command(cmd)
self.setup_example_hello_world(provider=provider)

# check CRD installation
crd = "helloworldservices.platformapi.kubeplus"
crd_installed = self._check_crd_installed(crd)
if not crd_installed:
print("CRD " + crd + " not installed. Exiting this test.")
return

# create app instance
cmd = "kubectl create -f ../examples/multitenancy/hello-world/hs1.yaml --kubeconfig=%s" % provider
out, err = TestKubePlus.run_command(cmd)

time.sleep(10)
# test plugin
cmd = "kubectl appstatus HelloWorldService hs1 -k %s" % provider
out, err = TestKubePlus.run_command(cmd)

if err != '':
print("Something went wrong with the plugin.")
print(err)
cleanup()
self.cleanup_example_hello_world(provider=provider)
sys.exit(1)

# asserts
lines = out.split('\n')
self.assertTrue('Deployed' in lines[1])
self.assertTrue('Running' in lines[2] or 'Pending' in lines[2] or 'ContainerCreating' in lines[2])

cleanup()
self.cleanup_example_hello_world(provider=provider)
# TODO: Add tests for
# kubectl connections
# kubectl appresources
Expand Down

0 comments on commit 8b6baea

Please sign in to comment.