diff --git a/.github/workflows/kubernetes_engine_test.yaml b/.github/workflows/kubernetes_engine_test.yaml new file mode 100644 index 0000000000..8b27d34726 --- /dev/null +++ b/.github/workflows/kubernetes_engine_test.yaml @@ -0,0 +1,32 @@ +name: Kubernetes Engine Test +on: + push: + path: + - acto/kubernetes_engine/** +jobs: + KubernetesEngineTest: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-go@v4 + with: + go-version: '1.20.5' + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + make + - name: Install Kind + run: | + go install sigs.k8s.io/kind@v0.20.0 + - name: Install minikube + run: | + curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 + sudo install minikube-linux-amd64 /usr/local/bin/minikube + - name: Run KubernetesEngineTest + run: | + pytest -m "kubernetes_engine" \ No newline at end of file diff --git a/acto/kubernetes_engine/test_kubernetes_engines.py b/acto/kubernetes_engine/test_kubernetes_engines.py new file mode 100644 index 0000000000..76cce88c23 --- /dev/null +++ b/acto/kubernetes_engine/test_kubernetes_engines.py @@ -0,0 +1,47 @@ +import os + +import pytest + +from acto.kubernetes_engine.base import KubernetesEngine +from acto.kubernetes_engine.kind import Kind + +from . import minikube as minikube + +# class TestKubernetesEngines(): +# kind_cluster = kind.Kind(acto_namespace=0) + +kind_cluster = Kind(acto_namespace=0) +minikube_cluster = minikube.Minikube(acto_namespace=0) + +testcases = [(kind_cluster,3, "v1.27.3"), (minikube_cluster, 3, "v1.27.4")] + +@pytest.mark.kubernetes_engine +@pytest.mark.parametrize('cluster_instance,num_nodes,version', testcases) +def test_kubernetes_engines(cluster_instance: KubernetesEngine, num_nodes, version): + configPath = os.path.join(os.path.expanduser('~'), '.kube/test-config') + name = "test-cluster" + # num_nodes = 3 + # version = "v1.27.4" + + cluster_instance.configure_cluster(num_nodes, version) + print( + f"Creating cluster {name} with {num_nodes} nodes, version {version}, configPath {configPath}") + cluster_instance.create_cluster(name, configPath) + + node_list = cluster_instance.get_node_list(name) + assert len(node_list) == num_nodes + + cluster_instance.delete_cluster(name, configPath) + with pytest.raises(RuntimeError): + # expect to raise RuntimeError + # get_node_list should raise RuntimeError when cluster is not found + cluster_instance.get_node_list(name) + + + # def test_minikube_load_image(): + # num_nodes = 3 + # name = "hz" + # version = "v1.27.4" + # cluster = minikube.Minikube(acto_namespace = 0, num_nodes=num_nodes, version=version) + # # cluster.create_cluster(name, "/users/hzeng21/.kube/config2") + # cluster.load_images("/users/hzeng21/.kube/sleepy.tar", name=name) \ No newline at end of file diff --git a/pytest.ini b/pytest.ini index 3e5d97ec6c..b2cb5e6444 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,3 +2,4 @@ markers = local: mark a test to run on a local machine singleBugReproduction: mark a test to run e2e regressions on a pull request + kubernetes_engine: mark a test for cluster set up