Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: refactoring methods in tests and adding tests for plugins #1346

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need 'provider=provider', since provider is not a keyword argument in line 50.
Just pass 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
Loading