diff --git a/.dockerignore b/.dockerignore index ba6605510..07d3a0d35 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ ./data-dir ./dist ./.trash-cache +./test/.pytest_cache diff --git a/Dockerfile.dapper b/Dockerfile.dapper index 67c9f633d..9ceaf42c6 100644 --- a/Dockerfile.dapper +++ b/Dockerfile.dapper @@ -2,8 +2,11 @@ FROM golang:1.12.6-alpine3.9 ARG DAPPER_HOST_ARCH ENV ARCH $DAPPER_HOST_ARCH +ENV K3S_VERSION v0.5.0 +ENV KUBECTL_VERSION v1.15.0 -RUN apk -U add bash git gcc musl-dev docker vim less file curl wget ca-certificates +RUN apk -U add bash git gcc musl-dev docker vim less file curl wget ca-certificates python3 py3-pip python3-dev openssl-dev libffi-dev jq +RUN pip3 install 'tox==3.6.0' RUN go get -d golang.org/x/lint/golint && \ git -C /go/src/golang.org/x/lint/golint checkout -b current 06c8688daad7faa9da5a0c2f163a3d14aac986ca && \ go install golang.org/x/lint/golint && \ @@ -16,13 +19,21 @@ RUN rm -rf /go/src /go/pkg RUN if [ "${ARCH}" == "amd64" ]; then \ curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s v1.15.0; \ fi +RUN curl -sL https://github.com/rancher/k3s/releases/download/${K3S_VERSION}/k3s > /usr/bin/k3s && \ + chmod +x /usr/bin/k3s +RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/${KUBECTL_VERSION}/bin/linux/amd64/kubectl > /usr/bin/kubectl && \ + chmod +x /usr/bin/kubectl ENV DAPPER_ENV REPO TAG DRONE_TAG CROSS ENV DAPPER_SOURCE /go/src/github.com/rancher/rio/ ENV DAPPER_OUTPUT ./bin ./dist ENV DAPPER_DOCKER_SOCKET true +ENV DAPPER_RUN_ARGS --privileged ENV HOME ${DAPPER_SOURCE} WORKDIR ${DAPPER_SOURCE} +VOLUME /var/lib/rancher/k3s +VOLUME /var/lib/cni +VOLUME /var/log ENTRYPOINT ["./scripts/entry"] CMD ["ci"] diff --git a/cli/cmd/install/install.go b/cli/cmd/install/install.go index 83c848bce..21a5bb2c8 100644 --- a/cli/cmd/install/install.go +++ b/cli/cmd/install/install.go @@ -77,6 +77,7 @@ type Install struct { ServiceCidr string `desc:"Manually specify service CIDR for service mesh to intercept"` DisableFeatures []string `desc:"Manually specify features to disable, supports CSV"` Yaml bool `desc:"Only print out k8s yaml manifest"` + Check bool `desc:"Only check status, don't deploy controller'"` Lite bool `desc:"Only install lite version of Rio(monitoring will be disabled, will be ignored if --disable-features is set)"` } @@ -177,21 +178,26 @@ func (i *Install) Run(ctx *clicontext.CLIContext) error { return nil } - if err := controllerStack.Deploy(answers); err != nil { - return err + if !i.Check { + fmt.Println("Deploying Rio control plane....") + if err := controllerStack.Deploy(answers); err != nil { + return err + } } - fmt.Println("Deploying Rio control plane....") + start := time.Now() for { time.Sleep(time.Second * 2) - dep, err := ctx.K8s.AppsV1().Deployments(namespace).Get("rio-controller", metav1.GetOptions{}) - if err != nil { - return err - } - if !serviceset.IsReady(&dep.Status) { - fmt.Printf("\r%v Waiting for deployment %s/%s to become ready", string(statusChar[statusIndex]), dep.Namespace, dep.Name) - statusIndex = modIndex(statusIndex) - continue + if !i.Check { + dep, err := ctx.K8s.AppsV1().Deployments(namespace).Get("rio-controller", metav1.GetOptions{}) + if err != nil { + return err + } + if !serviceset.IsReady(&dep.Status) { + fmt.Printf("\r%v Waiting for deployment %s/%s to become ready", string(statusChar[statusIndex]), dep.Namespace, dep.Name) + statusIndex = modIndex(statusIndex) + continue + } } info, err := ctx.Project.RioInfos().Get("rio", metav1.GetOptions{}) if err != nil { diff --git a/go.sum b/go.sum index 5a85dcce4..26119d61c 100644 --- a/go.sum +++ b/go.sum @@ -320,6 +320,7 @@ github.com/rancher/cert-manager v0.7.0-rio.1 h1:o7XDzUpKg2X1fSFpy/B4uU0IIQEUzT7E github.com/rancher/cert-manager v0.7.0-rio.1/go.mod h1:3cwEbVBo4BRNJ29j2MFyvX4Uno2lAQquejDtUXtE0YY= github.com/rancher/gitwatcher v0.0.0-20190612060519-6eee8fc7a202 h1:ID3ndmm5OMdJdjd7EFfXJoPm9QA/0BlSmLtf8sJZLRQ= github.com/rancher/gitwatcher v0.0.0-20190612060519-6eee8fc7a202/go.mod h1:8Ky3j8+TgcevUb7u6x7jSUDQf5amzYKYSv1mzn0zivQ= +github.com/rancher/k3s v1.14.3-k3s.2/go.mod h1:tMIUbj+a40AQcAd6RRazV5hcf7YWjhas4rNxidgJXms= github.com/rancher/mapper v0.0.0-20190426050457-84da984f3146 h1:rdM/qnaTd2pnQLlF1TYdyGSd7/ssVuu/a0YituJxxjI= github.com/rancher/mapper v0.0.0-20190426050457-84da984f3146/go.mod h1:zU4cm21k7ZBFVQhUu2aSH7NwouY317rLYxruOn+wdOQ= github.com/rancher/moq v0.0.0-20190404221404-ee5226d43009 h1:Xsxh7fX3+2wAUJtPy8g2lZh0cYuyifqhBL0vxCIYojs= diff --git a/modules/istio/controllers/istio/controller.go b/modules/istio/controllers/istio/controller.go index 1dce56080..0340c4eff 100644 --- a/modules/istio/controllers/istio/controller.go +++ b/modules/istio/controllers/istio/controller.go @@ -46,6 +46,36 @@ var ( evalTrigger trigger.Trigger ) +func RegisterNodeEndpointIndexer(ctx context.Context, rContext *types.Context) error { + i := indexer{ + namespace: rContext.Namespace, + } + rContext.Core.Core().V1().Endpoints().Cache().AddIndexer(indexName, i.indexEPByNode) + return nil +} + +type indexer struct { + namespace string +} + +func (i indexer) indexEPByNode(ep *corev1.Endpoints) ([]string, error) { + if ep.Namespace != i.namespace || ep.Name != constants.IstioGateway { + return nil, nil + } + + var result []string + + for _, subset := range ep.Subsets { + for _, addr := range subset.Addresses { + if addr.NodeName != nil { + result = append(result, *addr.NodeName) + } + } + } + + return result, nil +} + func Register(ctx context.Context, rContext *types.Context) error { if err := ensureClusterDomain(rContext.Namespace, rContext.Global.Admin().V1().ClusterDomain()); err != nil { return err @@ -79,12 +109,6 @@ func Register(ctx context.Context, rContext *types.Context) error { rContext.Global.Admin().V1().ClusterDomain(), rContext.Global.Admin().V1().PublicDomain()) - relatedresource.Watch(ctx, "node-enpoint", s.resolveEndpoint, - rContext.Core.Core().V1().Endpoints(), - rContext.Core.Core().V1().Node()) - - rContext.Core.Core().V1().Endpoints().Cache().AddIndexer(indexName, s.indexEPByNode) - switch { case constants.UseIPAddress != "": addresses := strings.Split(constants.UseIPAddress, ",") @@ -313,24 +337,6 @@ func (i istioDeployController) updateClusterDomain(addresses []string) error { return err } -func (i *istioDeployController) indexEPByNode(ep *corev1.Endpoints) ([]string, error) { - if ep.Namespace != i.namespace || ep.Name != constants.IstioGateway { - return nil, nil - } - - var result []string - - for _, subset := range ep.Subsets { - for _, addr := range subset.Addresses { - if addr.NodeName != nil { - result = append(result, *addr.NodeName) - } - } - } - - return result, nil -} - func (i *istioDeployController) syncSubdomain(key string, service *corev1.Service) (*corev1.Service, error) { if service == nil { return service, nil diff --git a/pkg/server/startup.go b/pkg/server/startup.go index 292ebaf04..ab5bf3487 100644 --- a/pkg/server/startup.go +++ b/pkg/server/startup.go @@ -3,6 +3,8 @@ package server import ( "context" + "github.com/rancher/rio/modules/istio/controllers/istio" + "github.com/rancher/rio/modules" "github.com/rancher/rio/pkg/constructors" "github.com/rancher/rio/pkg/controllers" @@ -96,6 +98,7 @@ func Startup(ctx context.Context, systemNamespace, kubeConfig string) error { } leader.RunOrDie(ctx, systemNamespace, "rio", rioContext.K8s, func(ctx context.Context) { + runtime.Must(istio.RegisterNodeEndpointIndexer(ctx, rioContext)) runtime.Must(controllers.Register(ctx, rioContext)) runtime.Must(modules.Register(ctx, rioContext)) runtime.Must(rioContext.Start(ctx)) diff --git a/scripts/test b/scripts/test index 08662432a..aeccdc7d5 100755 --- a/scripts/test +++ b/scripts/test @@ -3,5 +3,27 @@ set -e cd $(dirname $0)/.. -echo Running tests -go test -cover -tags=test ./... +if [[ ${ARCH} == amd64 ]]; then + echo Running tests + + k3s server & + sleep 10 + + export KUBECONFIG=/etc/rancher/k3s/k3s.yaml + export PATH=$(pwd)/bin:$PATH + + rio-controller & + rio install --check + + cd ./tests + PROC=$(nproc) + if [ "$PROC" > 8 ]; then + PROC=8 + fi + # todo: set $PROC=1, figure out how to run test in parallel + PROC=1 + tox -- -n $PROC + cd .. +fi + + diff --git a/tests/conftest.py b/tests/conftest.py index ef3cf9434..d4c18f095 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -15,7 +15,7 @@ def nspc(): @pytest.fixture def service(nspc): - srv = "tsrv" + str(random.randint(1000, 5000)) + srv = "tsrv" + str(random.randint(1000000, 9999999)) fullName = (f"{nspc}/{srv}") os.system(f"rio run -n {fullName} nginx") diff --git a/tests/init-nfs.bash b/tests/init-nfs.bash deleted file mode 100755 index b3c6262d6..000000000 --- a/tests/init-nfs.bash +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -x - -setup() { - nfs_server_stack=nfs-server-${RANDOM} - rio up $nfs_server_stack ./tests/nfs-stack/nfs-server-stack.yaml - rio wait ${nfs_server_stack}/nfs-server - ip=$(rio kubectl get po --all-namespaces -o wide | grep nfs-server | grep -v Terminating | awk '{print $(NF-2)}') - printf "NFS_SERVER_HOSTNAME: $ip\nNFS_SERVER_EXPORT_PATH: /" > answers.yaml - rio feature enable -a answers.yaml nfs - rm answers.yaml -} - -setup diff --git a/tests/new-validation/test_run.py b/tests/new-validation/test_run.py deleted file mode 100644 index 1aba7cf7b..000000000 --- a/tests/new-validation/test_run.py +++ /dev/null @@ -1,30 +0,0 @@ -# Run Validation test. Use functions to test run and get output - -import util - - -def test_rio_scale(service): - fullName = (f"{service}:v0") - scalefield = "spec.scale" - print(f"{fullName}") - - inspect = util.rioInspect(fullName, scalefield) - assert inspect == '1' - - -def test_rio_image(service): - fullName = (f"{service}:v0") - scalefield = "spec.image" - print(f"{fullName}") - - inspect = util.rioInspect(fullName, scalefield) - assert inspect == 'nginx' - - -def test_rio_weight(service): - fullName = (f"{service}:v0") - scalefield = "spec.weight" - print(f"{fullName}") - - inspect = util.rioInspect(fullName, scalefield) - assert inspect == '100' diff --git a/tests/new-validation/test_service_mesh.py b/tests/new-validation/test_service_mesh.py deleted file mode 100644 index c1e222c28..000000000 --- a/tests/new-validation/test_service_mesh.py +++ /dev/null @@ -1,66 +0,0 @@ -# Run Validation test. Use functions to test run and get output - -import util -import time - - -def create_service(nspc, image): - port = "-p 80/http" - fullName = util.rioRun(nspc, port, image) - - return fullName - - -def stage_service(image, fullName, version): - - util.rioStage(image, fullName, version) - - return - - -def get_app_info(fullName, field): - - inspect = util.rioInspect(fullName, field) - - return inspect - - -def change_weight(fullName, version, percent): - - cmd = (f"rio weight {fullName}:{version}={percent}") - util.run(cmd) - - return - - -def test_rio_svc_weight(nspc): - image = "ibuildthecloud/demo:v1" - image2 = "ibuildthecloud/demo:v3" - - fullName = create_service(nspc, image) - stage_service(image2, fullName, "v3") - - results1 = get_app_info(fullName, "status.revisionWeight.v0.weight") - results2 = get_app_info(fullName, "status.revisionWeight.v3.weight") - - assert results1 == '100' - assert results2 == 'null' - - -def test_rio_svc_weight2(nspc): - image = "ibuildthecloud/demo:v1" - image2 = "ibuildthecloud/demo:v3" - - fullName = create_service(nspc, image) - stage_service(image2, fullName, "v3") - time.sleep(5) - - change_weight(fullName, "v3", "5%") - - time.sleep(5) - - results1 = get_app_info(fullName, "status.revisionWeight.v0.weight") - results2 = get_app_info(fullName, "status.revisionWeight.v3.weight") - - assert results1 == '95' - assert results2 == '5' diff --git a/tests/nfs-stack/nfs-client-stack.yaml b/tests/nfs-stack/nfs-client-stack.yaml deleted file mode 100644 index b4eedeee5..000000000 --- a/tests/nfs-stack/nfs-client-stack.yaml +++ /dev/null @@ -1,37 +0,0 @@ -services: - nfs-provisioner: - image: quay.io/external_storage/nfs-client-provisioner:latest - env: - - PROVISIONER_NAME=nfs - - NFS_SERVER=${NFS_SERVER_HOSTNAME} - - NFS_PATH=${NFS_SERVER_EXPORT_PATH} - volumes: - - data:/persistentvolumes - global_permissions: - - get,list,watch,create,delete persistentvolumes - - get,list,watch,update persistentvolumeclaims - - get,list,watch storage.k8s.io/storageclasses - - create,update,patch events - permissions: - - get,list,watch,create,update,patch endpoints - restart: always - - sidekicks: - init-volumes: - image: daishan1992/nfs-client:latest - command: - - "sh" - - "-c" - - "mount -t nfs4 ${NFS_SERVER_HOSTNAME}:${NFS_SERVER_EXPORT_PATH} /persistentvolumes" - volumes: - - data:/persistentvolumes:shared - privileged: true - initContainer: true - imagePullPolicy: always - - -questions: -- variable: NFS_SERVER_HOSTNAME - description: "Hostname of NFS server" -- variable: NFS_SERVER_EXPORT_PATH - description: "Export path of NFS server" \ No newline at end of file diff --git a/tests/nfs-stack/nfs-server-stack.yaml b/tests/nfs-stack/nfs-server-stack.yaml deleted file mode 100644 index 0ce14e23f..000000000 --- a/tests/nfs-stack/nfs-server-stack.yaml +++ /dev/null @@ -1,9 +0,0 @@ -services: - nfs-server: - image: itsthenetwork/nfs-server-alpine:latest - imagePullPolicy: Always - environment: - - SHARED_DIRECTORY=/var/nfs - privileged: true - volumes: - - nfs:/var/nfs \ No newline at end of file diff --git a/tests/nfs-stack/volume-template-stack.yaml b/tests/nfs-stack/volume-template-stack.yaml deleted file mode 100644 index 206cf822b..000000000 --- a/tests/nfs-stack/volume-template-stack.yaml +++ /dev/null @@ -1,17 +0,0 @@ -services: - test1: - image: nginx:latest - volumes: - - data:/persistentvolumes - deploymentStrategy: ordered - test2: - image: nginx:latest - volumes: - - data:/persistentvolumes - deploymentStrategy: ordered - -volumes: - data: - driver: nfs - sizeInGb: 1 - template: true \ No newline at end of file diff --git a/tests/run/test_add-host.py b/tests/run/test_add-host.py deleted file mode 100644 index b2b0713ba..000000000 --- a/tests/run/test_add-host.py +++ /dev/null @@ -1,57 +0,0 @@ -import util - - -def run_addhost(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_addhost(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["extraHosts"] - - -def kube_chk_addhost(stack, sname): - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", sname) - cnt = obj['spec']['template']['spec'] - - out = [] - for item in cnt['hostAliases']: - out.append(item['hostnames']) - out.append(item['ip']) - -# hostname = [0] -# ip = cnt['ip'] -# results = (f"{ip}:{hostname}") - - return out - - -def test_addhost1(stack): - service_name = run_addhost(stack, '--add-host', '1.2.3.4:example.com') - - rio_addhost = rio_chk_addhost(stack, service_name) - assert rio_addhost == ['1.2.3.4:example.com'] - - kube_addhost = kube_chk_addhost(stack, service_name) - assert kube_addhost == [['example.com'], '1.2.3.4'] - - -def test_addhost2(stack): - service_name = run_addhost(stack, '--add-host', '1.2.3.4:example.com', - '--add-host', '2.3.4.5:bexample.com') - - rio_addhost = rio_chk_addhost(stack, service_name) - assert rio_addhost == ['1.2.3.4:example.com', '2.3.4.5:bexample.com'] - - kube_addhost = kube_chk_addhost(stack, service_name) - result = [['example.com'], '1.2.3.4', ['bexample.com'], '2.3.4.5'] - assert kube_addhost == result diff --git a/tests/run/test_autoscale.py b/tests/run/test_autoscale.py deleted file mode 100644 index a67c8c641..000000000 --- a/tests/run/test_autoscale.py +++ /dev/null @@ -1,37 +0,0 @@ -import util - - -def run_autoscale(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_autoscale(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["workingDir"] - - -def kube_chk_autoscale(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - results = cnt['workingDir'] - - return results - - -def test_autoscale1(stack): - service_name = run_autoscale(stack, '--scale', '1-10') - - rio_autoscale = rio_chk_autoscale(stack, service_name) - assert rio_autoscale == "/foo" - - kube_autoscale = kube_chk_autoscale(stack, service_name) - assert kube_autoscale == "/foo" diff --git a/tests/run/test_cap-add.py b/tests/run/test_cap-add.py deleted file mode 100644 index 9a48a6e53..000000000 --- a/tests/run/test_cap-add.py +++ /dev/null @@ -1,49 +0,0 @@ -import util -from os import system -from random import randint - - -def run_capadd(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_capadd_chk(stack, service_name): - fullName = "%s/%s" % (stack, service_name) - got = util.rioInspect(fullName, "capAdd") - print(got) - - return got - - -def kube_capadd_chk(stack, service_name, *capabilities): - fullName = "%s/%s" % (stack, service_name) - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", service_name) - - container = obj['spec']['template']['spec']['containers'][0] - return container['securityContext']['capabilities']['add'] - - -def test_cap_1(stack): - service_name = run_capadd(stack, "--cap-add", "ALL") - - r = rio_capadd_chk(stack, service_name) - assert r == "[ALL]" - - k = kube_capadd_chk(stack, service_name, "ALL") - assert k == ['ALL'] - - -def test_cap_2(stack): - service_name = run_capadd(stack, "--cap-add", "ALL", "--cap-add", "SYSLOG") - - r = rio_capadd_chk(stack, service_name) - assert r == "[ALL SYSLOG]" - - k = kube_capadd_chk(stack, service_name, "ALL", "SYSLOG") - assert k == ['ALL', 'SYSLOG'] diff --git a/tests/run/test_cap-drop.py b/tests/run/test_cap-drop.py deleted file mode 100644 index bfb07f1ca..000000000 --- a/tests/run/test_cap-drop.py +++ /dev/null @@ -1,50 +0,0 @@ -import util -from os import system -from random import randint - - -def run_capdrop(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_capdrop_chk(stack, service_name): - fullName = "%s/%s" % (stack, service_name) - got = util.rioInspect(fullName, "capDrop") - print(got) - - return got - - -def kube_capdrop_chk(stack, service_name, *capabilities): - fullName = "%s/%s" % (stack, service_name) - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", service_name) - - container = obj['spec']['template']['spec']['containers'][0] - return container['securityContext']['capabilities']['drop'] - - -def test_cap_1(stack): - service_name = run_capdrop(stack, "--cap-drop", "AUDIT_CONTROL") - - r = rio_capdrop_chk(stack, service_name) - assert r == "[AUDIT_CONTROL]" - - k = kube_capdrop_chk(stack, service_name, "AUDIT_CONTROL") - assert k == ['AUDIT_CONTROL'] - - -def test_cap_2(stack): - service_name = run_capdrop(stack, "--cap-drop", "AUDIT_CONTROL", - "--cap-drop", "SYSLOG") - - r = rio_capdrop_chk(stack, service_name) - assert r == "[AUDIT_CONTROL SYSLOG]" - - k = kube_capdrop_chk(stack, service_name, "AUDIT_CONTROL", "SYSLOG") - assert k == ['AUDIT_CONTROL', 'SYSLOG'] diff --git a/tests/run/test_config_file.py b/tests/run/test_config_file.py deleted file mode 100644 index fcf5a9b70..000000000 --- a/tests/run/test_config_file.py +++ /dev/null @@ -1,71 +0,0 @@ -import util -import random - - -def config_setup(stack, *text): - - config = util.rioConfigCreate(stack, *text) - fullname = (f"{stack}/{config}") - - return config - - -def run_config(stack, config_name): - name = "tsrv" + str(random.randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - tempdir = ":/temp" + str(random.randint(100, 999)) - - cmd = (f'rio run -n {fullName}') - cmd += (f' --config {config_name}{tempdir}') - cmd += " nginx" - - print(cmd) - util.run(cmd) - util.run(f"rio wait {fullName}") - print(name) - - return name - - -def rio_chk(stack, sname): - fullName = "%s/%s" % (stack, sname) - - inspect = util.rioInspect(fullName) - - out = [] - for item in inspect["configs"]: - out.append(item["source"]) - - out.sort() - - return out - - -def kube_chk(stack, service_name): - fullName = "%s/%s" % (stack, service_name) - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", service_name) - - out = [] - for item in obj['spec']['template']['spec']['volumes']: - if 'configMap' in item: - out.append(str(item['configMap']['name']).split("-")[0]) - - out.sort() - print(out) - - return out - - -def test_config_name(stack): - config_name1 = config_setup(stack, "2foo=2bar", "2foo1=2bar2") - servicename = run_config(stack, config_name1) - - gotrio = rio_chk(stack, servicename) - assert gotrio == [config_name1] - - gotk8s = kube_chk(stack, servicename) - assert gotk8s == [config_name1] diff --git a/tests/run/test_cpus.py b/tests/run/test_cpus.py deleted file mode 100644 index ffef3c7a2..000000000 --- a/tests/run/test_cpus.py +++ /dev/null @@ -1,75 +0,0 @@ -# from os import unlink -from random import randint -import util -from time import sleep -# import tempfile - - -def run_cpus(stack, value): - - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - value = str(value) - - cmd += " --cpus " + value + " nginx" - - print(cmd) - util.run(cmd) -# util.run(f"rio wait {fullName}") - sleep(5) - print(name) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['nanoCpus'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - container = obj['spec']['template']['spec']['containers'][0] - return container['resources']['requests']['cpu'] - - -def test_cpus(stack): - cpus = 0 - service_name = run_cpus(stack, cpus) - - rio_got = rio_chk(stack, service_name) - assert rio_got == (f"{cpus}") - -# k8s_got = kube_chk(stack, service_name) -# assert k8s_got == (f"{cpus}") - - -def test_cpus2(stack): - cpus = 1 - service_name = run_cpus(stack, cpus) - - rio_got = rio_chk(stack, service_name) - assert rio_got == (f"{cpus}") - -# k8s_got = kube_chk(stack, service_name) -# assert k8s_got == (f"{cpus}") - - -def test_cpus3(stack): - cpus = 10 - service_name = run_cpus(stack, cpus) - - rio_got = rio_chk(stack, service_name) - assert rio_got == (f"{cpus}") - -# k8s_got = kube_chk(stack, service_name) -# assert k8s_got == (f"{cpus}") diff --git a/tests/run/test_dns-option.py b/tests/run/test_dns-option.py deleted file mode 100644 index 52b0b2946..000000000 --- a/tests/run/test_dns-option.py +++ /dev/null @@ -1,61 +0,0 @@ -from random import randint -import util - - -def run_dns(stack, *dns_options): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - - for c in dns_options: - cmd += " --dns-option " + c - - cmd += " nginx" - - print(cmd) - util.runwait(cmd, fullName) - print(name) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['dnsOptions'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - out = [] - for item in obj['spec']['template']['spec']['dnsConfig']['options']: - out.append(item['name']) - - return out - - -def test_content(stack): - service_name = run_dns(stack, "debug") - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['debug'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['debug'] - - -def test_content2(stack): - service_name = run_dns(stack, "debug", "attempts:2") - - got = rio_chk(stack, service_name) - assert got == ['debug', 'attempts:2'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['debug', 'attempts:2'] diff --git a/tests/run/test_dns-search.py b/tests/run/test_dns-search.py deleted file mode 100644 index e9bee57a3..000000000 --- a/tests/run/test_dns-search.py +++ /dev/null @@ -1,57 +0,0 @@ -from random import randint -import util - - -def run_dns(stack, *dns_search): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - - for c in dns_search: - cmd += " --dns-search " + c - - cmd += " nginx" - - print(cmd) - util.runwait(cmd, fullName) - print(name) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['dnsSearch'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - return obj['spec']['template']['spec']['dnsConfig']['searches'] - - -def test_content(stack): - service_name = run_dns(stack, "example.com") - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['example.com'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['example.com'] - - -def test_content2(stack): - service_name = run_dns(stack, "example.com", "example2.com") - - got = rio_chk(stack, service_name) - assert got == ['example.com', 'example2.com'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['example.com', 'example2.com'] diff --git a/tests/run/test_dns.py b/tests/run/test_dns.py deleted file mode 100644 index 17097a054..000000000 --- a/tests/run/test_dns.py +++ /dev/null @@ -1,57 +0,0 @@ -from random import randint -import util - - -def run_dns(stack, *dns): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - - for c in dns: - cmd += " --dns " + c - - cmd += " nginx" - - print(cmd) - util.runwait(cmd, fullName) - print(name) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['dns'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - return obj['spec']['template']['spec']['dnsConfig']['nameservers'] - - -def test_content(stack): - service_name = run_dns(stack, '1.1.1.1') - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['1.1.1.1'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['1.1.1.1'] - - -def test_content2(stack): - service_name = run_dns(stack, "1.1.1.1", "2.2.2.2") - - got = rio_chk(stack, service_name) - assert got == ['1.1.1.1', '2.2.2.2'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['1.1.1.1', '2.2.2.2'] diff --git a/tests/run/test_entrypoint.py b/tests/run/test_entrypoint.py deleted file mode 100644 index 529f867e0..000000000 --- a/tests/run/test_entrypoint.py +++ /dev/null @@ -1,57 +0,0 @@ -from random import randint -import util - - -def run_entrypoint(stack, *entrypoint): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - - for c in entrypoint: - cmd += " -t -i --entrypoint " + c - - cmd += " nginx" - - print(cmd) - util.runwait(cmd, fullName) - print(name) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['entrypoint'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - return obj['spec']['template']['spec']['containers'][0]['command'] - - -def test_content(stack): - service_name = run_entrypoint(stack, 'sh') - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['sh'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['sh'] - - -# def test_content2(stack): -# service_name = run_entrypoint(stack, "echo", "hello") - -# got = rio_chk(stack, service_name) -# assert got == ['echo', 'hello'] - -# gotk8s = kube_chk(stack, service_name) -# assert gotk8s == ['echo', '$HOME'] diff --git a/tests/run/test_env-file.py b/tests/run/test_env-file.py deleted file mode 100644 index 90fab53a1..000000000 --- a/tests/run/test_env-file.py +++ /dev/null @@ -1,77 +0,0 @@ -from os import unlink -from random import randint -import util -import tempfile - - -def env_file_setup(stack, *envs): - - fp = tempfile.NamedTemporaryFile(delete=False) - - for c in envs: - fp.write(bytes(c+"\n", 'utf8')) - - fp.close() - - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - - cmd += " --env-file " + fp.name + " nginx" - - util.runwait(cmd, fullName) - - unlink(fp.name) - - return name - - -def rio_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['environment'] - - -def kube_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - container = obj['spec']['template']['spec']['containers'][0] - - out = [] - for item in container['env']: - out.append(item['name']) - out.append(item['value']) - - print(out) - - return out - - -def test_content(stack): - service_name = env_file_setup(stack, 'foo=bar') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['foo=bar'] - - print(service_name) - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['foo', 'bar'] - - -def test_content2(stack): - service_name = env_file_setup(stack, 'foo=bar', 'foo2=bar2') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['foo=bar', 'foo2=bar2'] - - print(service_name) - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['foo', 'bar', 'foo2', 'bar2'] diff --git a/tests/run/test_env-value.py b/tests/run/test_env-value.py deleted file mode 100644 index d3b8ccc94..000000000 --- a/tests/run/test_env-value.py +++ /dev/null @@ -1,69 +0,0 @@ -from random import randint -import util - - -def run_environment_var(stack, *envs): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - command = (f'rio run -n {fullName}') - - for c in envs: - command += " -e " + c - - command += " nginx" - print(command) - util.runwait(command, fullName) - - return name - - -def rio_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['environment'] - - -def kube_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - container = obj['spec']['template']['spec']['containers'][0] - - out = [] - for item in container['env']: - out.append(item['name']) - out.append(item['value']) - - print(out) - - return out - - -def test_content(stack): - service_name = run_environment_var(stack, 'foo=bar') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['foo=bar'] - - print(service_name) - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['foo', 'bar'] - - -def test_content2(stack): - service_name = run_environment_var(stack, 'foo=bar', 'foo2=bar2') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == ['foo=bar', 'foo2=bar2'] - - print(service_name) - gotk8s = kube_chk(stack, service_name) - assert gotk8s == ['foo', 'bar', 'foo2', 'bar2'] diff --git a/tests/run/test_expose.py b/tests/run/test_expose.py deleted file mode 100644 index 032dd433f..000000000 --- a/tests/run/test_expose.py +++ /dev/null @@ -1,74 +0,0 @@ -from random import randint -import util - - -def run_expose(stack, *prt): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - command = (f'rio run -n {fullName}') - - for c in prt: - command += " --expose " + c - - command += " nginx" - util.runwait(command, fullName) - - print(command) - - return name - - -def rio_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - out = [] - for item in inspect["expose"]: - out.append(item["targetPort"]) - out.append(item["protocol"]) - - return out - - -def kube_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - container = obj['spec']['template']['spec']['containers'][0] - - out = [] - for item in container['ports']: - out.append(item['containerPort']) - out.append(item['protocol']) - - print(out) - - return out - - -def test_content(stack): - service_name = run_expose(stack, '22/tcp') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == [22, 'tcp'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == [22, 'TCP'] - - -def test_content2(stack): - service_name = run_expose(stack, '22/tcp', '80/udp') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == [22, 'tcp', 80, 'udp'] - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == [22, 'TCP', 80, 'UDP'] diff --git a/tests/run/test_global_permission.py b/tests/run/test_global_permission.py deleted file mode 100644 index 7848e0fbf..000000000 --- a/tests/run/test_global_permission.py +++ /dev/null @@ -1,80 +0,0 @@ -from random import randint -import util - - -def rio_permission_setup(stack, *rpermission): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - cmd = (f'rio run -n {fullName}') - - for p in rpermission: - cmd += " --global-permission " + p - - cmd += " nginx" - util.runwait(cmd, fullName) - print(cmd) - - return name - - -def riotest(stack, sname): - - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['globalPermissions'][0]['verbs'] - - -def kubesatest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "sa", sname) - replicas = obj['metadata']['name'] - - return replicas - - -def kubeclusterrolebindingtest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0].split("-")[1] - - cmd = (f'rio kubectl get -o=json clusterrolebinding') - obj = util.runToJson(cmd) - - for item in obj['items']: - if item['metadata']['name'] == (f'{sname}-{namespace}'): - return item['subjects'][0]['name'] - - return None - - -def kubeclusterroletest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0].split("-")[1] - - cmd = (f'rio kubectl get -o=json clusterrole') - obj = util.runToJson(cmd) - - for item in obj['items']: - if item['metadata']['name'] == (f'{sname}-{namespace}'): - return item['rules'][0]['verbs'] - - return None - - -def test_name1(stack): - serviceName = rio_permission_setup(stack, "'update cluster'") - - assert riotest(stack, serviceName) == ['update'] - - assert serviceName in kubesatest(stack, serviceName) - assert kubeclusterroletest(stack, serviceName) == ['update'] - assert serviceName in kubeclusterrolebindingtest(stack, serviceName) diff --git a/tests/run/test_health-cmd.py b/tests/run/test_health-cmd.py deleted file mode 100644 index 86c548252..000000000 --- a/tests/run/test_health-cmd.py +++ /dev/null @@ -1,146 +0,0 @@ -from random import randint -import util - - -def run_healthcmd_setup(stack, cmd, interval='', - retries='', start='', timeout=''): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - options = (f'{interval}{retries}{start}{timeout}') - - rcmd = (f'rio run -n {fullName} --health-cmd {cmd} {options}nginx') - - util.runwait(rcmd, fullName) - - return name - - -def riocmd(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['test'] - - -def riointerval(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['intervalSeconds'] - - -def rioretries(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['healthyThreshold'] - - -def riosperiod(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['initialDelaySeconds'] - - -def riotimeout(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['timeoutSeconds'] - - -def kubecmd(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['exec']['command'] - - return results - - -def kubeinterval(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['periodSeconds'] - - return results - - -def kuberetries(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['successThreshold'] - - return results - - -def kubesperiod(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['initialDelaySeconds'] - - return results - - -def kubetimeout(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['timeoutSeconds'] - - return results - - -def test_healthcmd(stack): - cmd = "'echo hello'" - serviceName = run_healthcmd_setup(stack, cmd) - - assert riocmd(stack, serviceName) == ['CMD-SHELL', 'echo hello'] - - assert kubecmd(stack, serviceName) == ['sh', '-c', 'echo hello'] - - -def test_healthcmd2(stack): - cmd = "'echo hello'" - rintvl = '--health-interval 6s ' - rrtries = '--health-retries 1 ' - rsp = '--health-start-period 8s ' - rto = '--health-timeout 9s ' - serviceName = run_healthcmd_setup(stack, cmd, rintvl, rrtries, rsp, rto) - - assert riocmd(stack, serviceName) == ['CMD-SHELL', 'echo hello'] - assert riointerval(stack, serviceName) == 6 - assert rioretries(stack, serviceName) == 1 - assert riosperiod(stack, serviceName) == 8 - assert riotimeout(stack, serviceName) == 9 - - assert kubecmd(stack, serviceName) == ['sh', '-c', 'echo hello'] - assert kubeinterval(stack, serviceName) == 6 - assert kuberetries(stack, serviceName) == 1 - assert kubesperiod(stack, serviceName) == 8 - assert kubetimeout(stack, serviceName) == 9 diff --git a/tests/run/test_health-url.py b/tests/run/test_health-url.py deleted file mode 100644 index bf6b486a3..000000000 --- a/tests/run/test_health-url.py +++ /dev/null @@ -1,146 +0,0 @@ -from random import randint -import util - - -def run_healthurl_setup(stack, url, interval='', - retries='', start='', timeout=''): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - options = (f'{interval}{retries}{start}{timeout}') - - rcmd = (f'rio run -n {fullName} --health-url {url} {options}nginx') - - util.runwait(rcmd, fullName) - - return name - - -def riourl(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['test'] - - -def riointerval(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['intervalSeconds'] - - -def rioretries(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['healthyThreshold'] - - -def riosperiod(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['initialDelaySeconds'] - - -def riotimeout(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['healthcheck']['timeoutSeconds'] - - -def kubeurl(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['httpGet']['httpHeaders'][0]['value'] - - return results - - -def kubeinterval(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['periodSeconds'] - - return results - - -def kuberetries(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['successThreshold'] - - return results - - -def kubesperiod(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['initialDelaySeconds'] - - return results - - -def kubetimeout(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['livenessProbe'] - results = cnt['timeoutSeconds'] - - return results - - -def test_healthurl(stack): - url = "http://localhost:80" - serviceName = run_healthurl_setup(stack, url) - - assert riourl(stack, serviceName) == ['http://localhost:80'] - - assert kubeurl(stack, serviceName) == 'localhost:80' - - -def test_healthurl2(stack): - url = "http://localhost:80" - rintvl = '--health-interval 6s ' - rrtries = '--health-retries 1 ' - rsp = '--health-start-period 8s ' - rto = '--health-timeout 9s ' - serviceName = run_healthurl_setup(stack, url, rintvl, rrtries, rsp, rto) - - assert riourl(stack, serviceName) == ['http://localhost:80'] - assert riointerval(stack, serviceName) == 6 - assert rioretries(stack, serviceName) == 1 - assert riosperiod(stack, serviceName) == 8 - assert riotimeout(stack, serviceName) == 9 - - assert kubeurl(stack, serviceName) == 'localhost:80' - assert kubeinterval(stack, serviceName) == 6 - assert kuberetries(stack, serviceName) == 1 - assert kubesperiod(stack, serviceName) == 8 - assert kubetimeout(stack, serviceName) == 9 diff --git a/tests/run/test_hostname.py b/tests/run/test_hostname.py deleted file mode 100644 index f7385ab74..000000000 --- a/tests/run/test_hostname.py +++ /dev/null @@ -1,40 +0,0 @@ -import util - - -def run_hostname(stack, value, value2): - name = util.rioRun(stack, value, value2, 'nginx') - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['hostname'] - - -def kube_chk(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec'] - results = cnt['hostname'] - - return results - - -def test_hostname1(stack): - value = "--hostname" - value2 = "chost" - - service_name = run_hostname(stack, value, value2) - - rio_got = rio_chk(stack, service_name) - assert rio_got == "chost" - - kube_got = kube_chk(stack, service_name) - assert kube_got == "chost" diff --git a/tests/run/test_image-pull.py b/tests/run/test_image-pull.py deleted file mode 100644 index 6c9cae42a..000000000 --- a/tests/run/test_image-pull.py +++ /dev/null @@ -1,70 +0,0 @@ -from random import randint -import util - - -def run_image_pull(stack, img): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - command = (f'rio run -n {fullName}') - command += " --image-pull-policy " + img - - command += " nginx" - util.runwait(command, fullName) - - print(command) - - return name - - -def rio_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['imagePullPolicy'] - - -def kube_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - return obj['spec']['template']['spec']['containers'][0]['imagePullPolicy'] - - -def test_content(stack): - service_name = run_image_pull(stack, 'always') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == 'always' - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == 'Always' - - -def test_content2(stack): - service_name = run_image_pull(stack, 'never') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == 'never' - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == 'Never' - - -def test_content3(stack): - service_name = run_image_pull(stack, 'not-present') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == 'not-present' - - gotk8s = kube_chk(stack, service_name) - assert gotk8s == 'IfNotPresent' diff --git a/tests/run/test_init.py b/tests/run/test_init.py deleted file mode 100644 index abdde3ed9..000000000 --- a/tests/run/test_init.py +++ /dev/null @@ -1,46 +0,0 @@ -import util - - -def run_init(stack, value): - name = util.rioRun(stack, value, 'nginx') - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['init'] - - -def kube_chk(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['initContainers'][1] - results = cnt['image'] - - return results - - -def test_init1(stack): - value = "--init" - service_name = run_init(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got is True - -# kube_got = kube_chk(stack, service_name) -# assert kube_got == "nginx" - - -def test_init2(stack): - value = "" - service_name = run_init(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got is False diff --git a/tests/run/test_interactive.py b/tests/run/test_interactive.py deleted file mode 100644 index daa2e9004..000000000 --- a/tests/run/test_interactive.py +++ /dev/null @@ -1,46 +0,0 @@ -import util - - -def run_interactive(stack, value): - name = util.rioRun(stack, value, 'nginx') - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['stdinOpen'] - - -def kube_chk(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - results = cnt['stdin'] - - return results - - -def test_interactive1(stack): - value = "--interactive" - service_name = run_interactive(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got is True - - kube_got = kube_chk(stack, service_name) - assert kube_got is True - - -def test_interactive2(stack): - value = "" - service_name = run_interactive(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got is False diff --git a/tests/run/test_ipc.py b/tests/run/test_ipc.py deleted file mode 100644 index 28555fdca..000000000 --- a/tests/run/test_ipc.py +++ /dev/null @@ -1,48 +0,0 @@ -import util - - -def run_ipc(stack, value, value2): - name = util.rioRun(stack, value, value2, 'nginx') - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['ipc'] - - -def kube_chk(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec'] - results = cnt['hostIPC'] - - return results - - -def test_ipc1(stack): - value = "--ipc" - value2 = "host" - service_name = run_ipc(stack, value, value2) - - rio_got = rio_chk(stack, service_name) - assert rio_got == "host" - - kube_got = kube_chk(stack, service_name) - assert kube_got is True - - -def test_ipc2(stack): - value = "" - value2 = "" - service_name = run_ipc(stack, value, value2) - - rio_got = rio_chk(stack, service_name) - assert rio_got == "default" diff --git a/tests/run/test_label-file.py b/tests/run/test_label-file.py deleted file mode 100644 index 27b6dd1f1..000000000 --- a/tests/run/test_label-file.py +++ /dev/null @@ -1,67 +0,0 @@ -from os import unlink -from random import randint -import util -import tempfile - - -def lbl_file_setup(stack, *lbl): - - fp = tempfile.NamedTemporaryFile(delete=False) - - for c in lbl: - fp.write(bytes(c+"\n", 'utf8')) - - fp.close() - - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName}') - - cmd += " --label-file " + fp.name + " nginx" - - util.runwait(cmd, fullName) - - unlink(fp.name) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['labels'] - - -def kube_chk(stack, sname, *lbl): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - results = "" - for c in lbl: - results += obj['spec']['template']['metadata']['labels'][f"{lbl}"] - - return results - - -def test_content(stack): - service_name = lbl_file_setup(stack, 'foo=bar') - - gotrio = rio_chk(stack, service_name) - assert gotrio == {'foo': 'bar'} - -# gotk8s = kube_chk(stack, service_name, "foo") -# assert gotk8s == 'bar' - - -def test_content2(stack): - service_name = lbl_file_setup(stack, 'foo=bar', 'foo2=bar2') - - gotrio = rio_chk(stack, service_name) - assert gotrio == {'foo': 'bar', 'foo2': 'bar2'} - -# gotk8s = kube_chk(stack, service_name, "foo2") -# assert gotk8s == ['foo', 'bar', 'foo2', 'bar2'] diff --git a/tests/run/test_memory-limit.py b/tests/run/test_memory-limit.py deleted file mode 100644 index 6dcdacae6..000000000 --- a/tests/run/test_memory-limit.py +++ /dev/null @@ -1,91 +0,0 @@ -from random import randint -import util - - -def run_memlimit(stack, size, unit): - - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName} --memory-limit {size}{unit} nginx') - util.runwait(cmd, fullName) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['memoryLimitBytes'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - container = obj['spec']['template']['spec']['containers'][0] - return container['resources']['limits']['memory'] - - -def test_memlimit(stack): - size = "100000000" - unit = "" - service_name = run_memlimit(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 100000000 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "100M" - - -def test_memlimit2(stack): - size = "100000000" - unit = "b" - service_name = run_memlimit(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 100000000 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "100M" - - -def test_memlimit3(stack): - size = "100000" - unit = "k" - service_name = run_memlimit(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 102400000 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "102400k" - - -def test_memlimit4(stack): - size = "10" - unit = "m" - service_name = run_memlimit(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 10485760 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "10485760" - - -def test_memlimit5(stack): - size = "1" - unit = "g" - service_name = run_memlimit(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 1073741824 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "1073741824" diff --git a/tests/run/test_memory.py b/tests/run/test_memory.py deleted file mode 100644 index 207dcd4e5..000000000 --- a/tests/run/test_memory.py +++ /dev/null @@ -1,91 +0,0 @@ -from random import randint -import util - - -def run_mem(stack, size, unit): - - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - cmd = (f'rio run -n {fullName} --memory {size}{unit} nginx') - util.runwait(cmd, fullName) - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['memoryReservationBytes'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - container = obj['spec']['template']['spec']['containers'][0] - return container['resources']['requests']['memory'] - - -def test_mem(stack): - size = "100000000" - unit = "" - service_name = run_mem(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 100000000 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "100M" - - -def test_mem2(stack): - size = "100000000" - unit = "b" - service_name = run_mem(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 100000000 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "100M" - - -def test_mem3(stack): - size = "100000" - unit = "k" - service_name = run_mem(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 102400000 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "102400k" - - -def test_mem4(stack): - size = "10" - unit = "m" - service_name = run_mem(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 10485760 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "10485760" - - -def test_mem5(stack): - size = "1" - unit = "g" - service_name = run_mem(stack, size, unit) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 1073741824 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == "1073741824" diff --git a/tests/run/test_metadata.py b/tests/run/test_metadata.py deleted file mode 100644 index 7fcf3ea62..000000000 --- a/tests/run/test_metadata.py +++ /dev/null @@ -1,60 +0,0 @@ -from random import randint -import util - - -def run_metadata(stack, *mdata): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - command = (f'rio run -n {fullName}') - - for d in mdata: - command += " --metadata " + d - - command += " nginx" - util.runwait(command, fullName) - - return name - - -def rio_chk(stack, sname): - print(sname) - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['metadata'] - - -def kube_chk(stack, sname, mdata): - print(sname) - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - container = obj['spec']['template']['metadata']['annotations'][f"{mdata}"] - - return container - - -def test_content(stack): - service_name = run_metadata(stack, 'foo=bar') - - gotrio = rio_chk(stack, service_name) - assert gotrio == {'foo': 'bar'} - - print(service_name) - gotk8s = kube_chk(stack, service_name, "foo") - assert gotk8s == 'bar' - - -def test_content2(stack): - service_name = run_metadata(stack, 'foo=bar', 'foo2=bar2') - print(service_name) - - gotrio = rio_chk(stack, service_name) - assert gotrio == {'foo': 'bar', 'foo2': 'bar2'} - -# print(service_name) -# gotk8s = kube_chk(stack, service_name) -# assert gotk8s == ['foo', 'bar', 'foo2', 'bar2'] diff --git a/tests/run/test_name.py b/tests/run/test_name.py deleted file mode 100644 index dc7af9488..000000000 --- a/tests/run/test_name.py +++ /dev/null @@ -1,57 +0,0 @@ - -import util - - -def rio_name_setup(stack, sname): - - fullName = (f"{stack}/{sname}") - cmd = (f"rio run --name {fullName} nginx") - util.runwait(cmd, fullName) - - return sname - - -def riotest(stack, sname): - - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['name'] - - -def kubetest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", sname) - replicas = obj['metadata']['name'] - - return replicas - - -def test_name1(stack): - serviceName = "testname" - rio_name_setup(stack, serviceName) - assert serviceName in riotest(stack, serviceName) - - assert serviceName in kubetest(stack, serviceName) - - -def test_name2(stack): - serviceName = "a" - rio_name_setup(stack, serviceName) - - assert serviceName in riotest(stack, serviceName) - - assert serviceName in kubetest(stack, serviceName) - - -def test_name3(stack): - serviceName = "areallylongnamethatcanbelonger" - rio_name_setup(stack, serviceName) - - assert serviceName in riotest(stack, serviceName) - - assert serviceName in kubetest(stack, serviceName) diff --git a/tests/run/test_network.py b/tests/run/test_network.py deleted file mode 100644 index a081bea39..000000000 --- a/tests/run/test_network.py +++ /dev/null @@ -1,48 +0,0 @@ -from random import randint -import util - - -def run_network_setup(stack, value): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - cmd = (f'rio run -n {fullName} --network {value} nginx') - - util.runwait(cmd, fullName) - - return name - - -def riotest(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['net'] - - -def kubetest(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - results = obj['spec']['template']['spec']['hostNetwork'] - - return results - - -def test_network(stack): - networkValue = "host" - serviceName = run_network_setup(stack, networkValue) - - assert riotest(stack, serviceName) == networkValue - - assert kubetest(stack, serviceName) is True - - -def test_network2(stack): - networkValue = "default" - serviceName = run_network_setup(stack, networkValue) - - assert riotest(stack, serviceName) == networkValue diff --git a/tests/run/test_permission.py b/tests/run/test_permission.py deleted file mode 100644 index 7a64ff256..000000000 --- a/tests/run/test_permission.py +++ /dev/null @@ -1,73 +0,0 @@ -from random import randint -import util - - -def rio_permission_setup(stack, *rpermission): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - cmd = (f'rio run -n {fullName}') - - for p in rpermission: - cmd += " --permission " + p - - cmd += " nginx" - util.runwait(cmd, fullName) - - return name - - -def riotest(stack, sname): - - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['permissions'][0]['verbs'] - - -def kubesatest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "sa", sname) - replicas = obj['metadata']['name'] - - return replicas - - -def kuberolebindingtest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - realname = sname + "-" + id.split(":")[0].split("-")[1] - - cmd = (f'rio kubectl get -n rio-cloud -o=json rolebinding {realname}') - obj = util.runToJson(cmd) - replicas = obj['roleRef']['name'] - - return replicas - - -def kuberoletest(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - realname = sname + "-" + id.split(":")[0].split("-")[1] - - cmd = (f'rio kubectl get -n rio-cloud -o=json role {realname}') - obj = util.runToJson(cmd) - replicas = obj['rules'][0]['verbs'] - - return replicas - - -def test_name1(stack): - serviceName = rio_permission_setup(stack, "'update service'") - - assert riotest(stack, serviceName) == ['update'] - - assert serviceName in kubesatest(stack, serviceName) - assert kuberoletest(stack, serviceName) == ['update'] - assert serviceName in kuberolebindingtest(stack, serviceName) diff --git a/tests/run/test_pid.py b/tests/run/test_pid.py deleted file mode 100644 index 3444960f4..000000000 --- a/tests/run/test_pid.py +++ /dev/null @@ -1,50 +0,0 @@ -from random import randint -import util - - -def run_pid_setup(stack, value): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - cmd = (f'rio run -n {fullName} --pid={value} nginx') - - util.run(cmd) - util.run(f"rio wait {fullName}") - - return name - - -def riotest(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['pid'] - - -def kubetest(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - results = obj['spec']['template']['spec']['pid'] - - return results - - -def test_pid(stack): - pidValue = "host" - serviceName = run_pid_setup(stack, pidValue) - - assert riotest(stack, serviceName) == pidValue - -# assert kubetest(stack, serviceName) is True -# bug #137 in rio issues, pid is not being set - - -def test_pid2(stack): - pidValue = "default" - serviceName = run_pid_setup(stack, pidValue) - - assert riotest(stack, serviceName) == pidValue diff --git a/tests/run/test_privileged.py b/tests/run/test_privileged.py deleted file mode 100644 index 5b2f2374a..000000000 --- a/tests/run/test_privileged.py +++ /dev/null @@ -1,51 +0,0 @@ -from random import randint -import util - - -def run_privileged_setup(stack, option=''): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - cmd = (f'rio run -n {fullName} {option}nginx') - - util.run(cmd) - util.run(f"rio wait {fullName}") - - return name - - -def riotest(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['privileged'] - - -def kubetest(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - container = obj['spec']['template']['spec']['containers'][0] - results = container['securityContext']['privileged'] - - return results - - -def test_privileged(stack): - value = "--privileged " - serviceName = run_privileged_setup(stack, value) - - assert riotest(stack, serviceName) is True - - assert kubetest(stack, serviceName) is True - - -def test_privileged2(stack): - serviceName = run_privileged_setup(stack) - - assert riotest(stack, serviceName) is False - - assert kubetest(stack, serviceName) is False diff --git a/tests/run/test_publish.py b/tests/run/test_publish.py deleted file mode 100644 index b4199855a..000000000 --- a/tests/run/test_publish.py +++ /dev/null @@ -1,70 +0,0 @@ -from random import randint -import util - - -def rio_publish_setup(stack, pvalue, tvalue): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - cmd = (f'rio run -n {fullName} --publish {pvalue}:{tvalue} nginx') - - util.run(cmd) - print(cmd) - util.run(f"rio wait {fullName}") - - return name - - -def rio_return_port(stack, sname): - - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['ports'][0]['port'] - - -def rio_return_target(stack, sname): - - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect['ports'][0]['targetPort'] - - -def kube_return_port(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", sname) - container = obj['spec']['template']['spec']['containers'][0] - results = container['ports'][0]['hostPort'] - - return results - - -def kube_return_target(stack, sname): - - fullName = (f"{stack}/{sname}") - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", sname) - container = obj['spec']['template']['spec']['containers'][0] - results = container['ports'][0]['containerPort'] - - return results - - -def test_publish1(stack): - portValue = 8080 - targetValue = 80 - - serviceName = rio_publish_setup(stack, portValue, targetValue) - - assert rio_return_port(stack, serviceName) == portValue - assert rio_return_target(stack, serviceName) == targetValue - - assert kube_return_port(stack, serviceName) == portValue - assert kube_return_target(stack, serviceName) == targetValue diff --git a/tests/run/test_read-only.py b/tests/run/test_read-only.py deleted file mode 100644 index fbe583301..000000000 --- a/tests/run/test_read-only.py +++ /dev/null @@ -1,52 +0,0 @@ -from random import randint -import util - - -def run_readonly_setup(stack, option=''): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - cmd = (f'rio run -n {fullName} {option}ubuntu') - - util.run(cmd) - util.run(f"rio wait {fullName}") - - return name - - -def riotest(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readOnly'] - - -def kubetest(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - container = obj['spec']['template']['spec']['containers'][0] - results = container['securityContext']['readOnlyRootFilesystem'] - - return results - - -def test_privileged(stack): - value = "--read-only -i " - serviceName = run_readonly_setup(stack, value) - - assert riotest(stack, serviceName) is True - - assert kubetest(stack, serviceName) is True - - -def test_privileged2(stack): - value = "-i " - serviceName = run_readonly_setup(stack, value) - - assert riotest(stack, serviceName) is False - - assert kubetest(stack, serviceName) is False diff --git a/tests/run/test_ready-cmd.py b/tests/run/test_ready-cmd.py deleted file mode 100644 index 1158877ea..000000000 --- a/tests/run/test_ready-cmd.py +++ /dev/null @@ -1,147 +0,0 @@ -from random import randint -import util - - -def run_readycmd_setup(stack, cmd, interval='', - retries='', start='', timeout=''): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - options = (f'{interval}{retries}{start}{timeout}') - - rcmd = (f'rio run -n {fullName} --ready-cmd {cmd} {options}nginx') - - util.run(rcmd) - util.run(f"rio wait {fullName}") - - return name - - -def riocmd(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['test'] - - -def riointerval(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['intervalSeconds'] - - -def rioretries(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['healthyThreshold'] - - -def riosperiod(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['initialDelaySeconds'] - - -def riotimeout(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['timeoutSeconds'] - - -def kubecmd(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['exec']['command'] - - return results - - -def kubeinterval(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['periodSeconds'] - - return results - - -def kuberetries(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['successThreshold'] - - return results - - -def kubesperiod(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['initialDelaySeconds'] - - return results - - -def kubetimeout(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['timeoutSeconds'] - - return results - - -def test_readycmd(stack): - cmd = "'echo hello'" - serviceName = run_readycmd_setup(stack, cmd) - - assert riocmd(stack, serviceName) == ['CMD-SHELL', 'echo hello'] - - assert kubecmd(stack, serviceName) == ['sh', '-c', 'echo hello'] - - -def test_readycmd2(stack): - cmd = "'echo hello'" - rintvl = '--ready-interval 6s ' - rrtries = '--ready-retries 7 ' - rsp = '--ready-start-period 8s ' - rto = '--ready-timeout 9s ' - serviceName = run_readycmd_setup(stack, cmd, rintvl, rrtries, rsp, rto) - - assert riocmd(stack, serviceName) == ['CMD-SHELL', 'echo hello'] - assert riointerval(stack, serviceName) == 6 - assert rioretries(stack, serviceName) == 7 - assert riosperiod(stack, serviceName) == 8 - assert riotimeout(stack, serviceName) == 9 - - assert kubecmd(stack, serviceName) == ['sh', '-c', 'echo hello'] - assert kubeinterval(stack, serviceName) == 6 - assert kuberetries(stack, serviceName) == 7 - assert kubesperiod(stack, serviceName) == 8 - assert kubetimeout(stack, serviceName) == 9 diff --git a/tests/run/test_ready-url.py b/tests/run/test_ready-url.py deleted file mode 100644 index 27a01670a..000000000 --- a/tests/run/test_ready-url.py +++ /dev/null @@ -1,147 +0,0 @@ -from random import randint -import util - - -def run_readyurl_setup(stack, url, interval='', - retries='', start='', timeout=''): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - options = (f'{interval}{retries}{start}{timeout}') - - rcmd = (f'rio run -n {fullName} --ready-url {url} {options}nginx') - - util.run(rcmd) - util.run(f"rio wait {fullName}") - - return name - - -def riourl(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['test'] - - -def riointerval(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['intervalSeconds'] - - -def rioretries(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['healthyThreshold'] - - -def riosperiod(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['initialDelaySeconds'] - - -def riotimeout(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['readycheck']['timeoutSeconds'] - - -def kubeurl(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['httpGet']['httpHeaders'][0]['value'] - - return results - - -def kubeinterval(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['periodSeconds'] - - return results - - -def kuberetries(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['successThreshold'] - - return results - - -def kubesperiod(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['initialDelaySeconds'] - - return results - - -def kubetimeout(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0]['readinessProbe'] - results = cnt['timeoutSeconds'] - - return results - - -def test_readyurl(stack): - url = "http://localhost:80" - serviceName = run_readyurl_setup(stack, url) - - assert riourl(stack, serviceName) == ['http://localhost:80'] - - assert kubeurl(stack, serviceName) == 'localhost:80' - - -def test_readyurl2(stack): - url = "http://localhost:80" - rintvl = '--ready-interval 6s ' - rrtries = '--ready-retries 7 ' - rsp = '--ready-start-period 8s ' - rto = '--ready-timeout 9s ' - serviceName = run_readyurl_setup(stack, url, rintvl, rrtries, rsp, rto) - - assert riourl(stack, serviceName) == ['http://localhost:80'] - assert riointerval(stack, serviceName) == 6 - assert rioretries(stack, serviceName) == 7 - assert riosperiod(stack, serviceName) == 8 - assert riotimeout(stack, serviceName) == 9 - - assert kubeurl(stack, serviceName) == 'localhost:80' - assert kubeinterval(stack, serviceName) == 6 - assert kuberetries(stack, serviceName) == 7 - assert kubesperiod(stack, serviceName) == 8 - assert kubetimeout(stack, serviceName) == 9 diff --git a/tests/run/test_run-run.py b/tests/run/test_run-run.py deleted file mode 100644 index b45d19e96..000000000 --- a/tests/run/test_run-run.py +++ /dev/null @@ -1,30 +0,0 @@ -# Run Validation test. Use functions to test run and get outpu - -import util - - -def riotest(stack, service): - fullName = (f"{stack}/{service}") - - inspect = util.rioInspect(fullName) - - return inspect['state'] - - -def kubetest(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - replicas = obj['status']['replicas'] - - return replicas - - -def test_rio_status(stack, service): - assert riotest(stack, service) == "active" - - -def test_kube_replicas(stack, service): - assert kubetest(stack, service) == 1 diff --git a/tests/run/test_scale_run.py b/tests/run/test_scale_run.py deleted file mode 100644 index 17efed593..000000000 --- a/tests/run/test_scale_run.py +++ /dev/null @@ -1,59 +0,0 @@ -import util - - -def run_scale(stack, value): - name = util.rioRun(stack, '--scale', value, 'nginx') - - return name - - -def rio_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['scale'] - - -def kube_chk(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - - container = obj['spec']['replicas'] - return container - - -def test_scale(stack): - value = "1" - service_name = run_scale(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 1 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == 1 - - -def test_scale2(stack): - value = "3" - service_name = run_scale(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 3 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == 3 - - -def test_scale3(stack): - value = "10" - service_name = run_scale(stack, value) - - rio_got = rio_chk(stack, service_name) - assert rio_got == 10 - - k8s_got = kube_chk(stack, service_name) - assert k8s_got == 10 diff --git a/tests/run/test_secret.py b/tests/run/test_secret.py deleted file mode 100644 index 888d5712a..000000000 --- a/tests/run/test_secret.py +++ /dev/null @@ -1,102 +0,0 @@ -import util - - -def run_secret(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_source(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - out = [] - for item in inspect["secrets"]: - out.append(item["source"]) - - out.sort() - - return out - - -def rio_chk_target(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - out = [] - for item in inspect["secrets"]: - out.append(item["target"]) - - out.sort() - - return out - - -def kube_chk_mountName(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - - out = [] - for item in cnt['volumeMounts']: - out.append(item['name']) - - out.sort() - - return out - - -def kube_chk_mountPath(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - - out = [] - for item in cnt['volumeMounts']: - out.append(item['mountPath']) - - out.sort() - - return out - - -def test_ipc1(stack): - service_name = run_secret(stack, '--secret', 'foo:bar') - - rio_source = rio_chk_source(stack, service_name) - rio_target = rio_chk_target(stack, service_name) - - assert rio_source == ['foo'] - assert rio_target == ['bar'] - - kube_mountName = kube_chk_mountName(stack, service_name) - kube_mountPath = kube_chk_mountPath(stack, service_name) - - assert kube_mountName == ['secret-foo'] - assert kube_mountPath == ['bar'] - - -def test_ipc2(stack): - value1 = 'foo:bar' - value2 = 'foo2:bar2' - service_name = run_secret(stack, '--secret', value1, '--secret', value2) - - rio_source = rio_chk_source(stack, service_name) - rio_target = rio_chk_target(stack, service_name) - - assert rio_source == ['foo', 'foo2'] - assert rio_target == ['bar', 'bar2'] - - kube_mountName = kube_chk_mountName(stack, service_name) - kube_got = kube_chk_mountPath(stack, service_name) - - assert kube_mountName == ['secret-foo', 'secret-foo2'] - assert kube_got == ['bar', 'bar2'] diff --git a/tests/run/test_tmpfs.py b/tests/run/test_tmpfs.py deleted file mode 100644 index 5ff4985c5..000000000 --- a/tests/run/test_tmpfs.py +++ /dev/null @@ -1,38 +0,0 @@ -import util - - -def run_tmpfs(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_tmpfs(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["tmpfs"][0]["path"] - - -def kube_chk_tmpfs(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - results = cnt['volumeMounts'][0]['mountPath'] - - return results - - -def test_tty1(stack): - service_name = run_tmpfs(stack, '--tmpfs /tmp') - - rio_tty = rio_chk_tmpfs(stack, service_name) - assert rio_tty == "/tmp" - -# Bug #159 -# kube_tty = kube_chk_tmpfs(stack, service_name) -# assert kube_tty is True diff --git a/tests/run/test_tty.py b/tests/run/test_tty.py deleted file mode 100644 index 9584c06b1..000000000 --- a/tests/run/test_tty.py +++ /dev/null @@ -1,47 +0,0 @@ -import util - - -def run_tty(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_tty(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["tty"] - - -def kube_chk_tty(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - results = cnt['tty'] - - return results - - -def test_tty1(stack): - service_name = run_tty(stack, '--tty=true') - - rio_tty = rio_chk_tty(stack, service_name) - assert rio_tty is True - - kube_tty = kube_chk_tty(stack, service_name) - assert kube_tty is True - - -def test_tty2(stack): - service_name = run_tty(stack, '--tty=false') - - rio_tty = rio_chk_tty(stack, service_name) - assert rio_tty is False - -# kube_tty = kube_chk_tty(stack, service_name) -# assert kube_tty is False diff --git a/tests/run/test_update-order.py b/tests/run/test_update-order.py deleted file mode 100644 index c6c536980..000000000 --- a/tests/run/test_update-order.py +++ /dev/null @@ -1,65 +0,0 @@ -import util - - -def run_update_order(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_update_order(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["updateOrder"] - - -def kube_chk_maxSurge(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['strategy']['rollingUpdate'] - results = cnt['maxSurge'] - - return results - - -def kube_chk_maxUnavailable(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['strategy']['rollingUpdate'] - results = cnt['maxUnavailable'] - - return results - - -def test_updateOrder1(stack): - service_name = run_update_order(stack, '--update-order', 'start-first') - - rio_update_order = rio_chk_update_order(stack, service_name) - assert rio_update_order == "start-first" - - kube_maxSurge = kube_chk_maxSurge(stack, service_name) - assert kube_maxSurge == 1 - - kube_maxUnavailable = kube_chk_maxUnavailable(stack, service_name) - assert kube_maxUnavailable == 0 - - -def test_updateOrder2(stack): - service_name = run_update_order(stack, '--update-order', 'stop-first') - - rio_update_order = rio_chk_update_order(stack, service_name) - assert rio_update_order == "stop-first" - - kube_maxSurge = kube_chk_maxSurge(stack, service_name) - assert kube_maxSurge == 0 - - kube_maxUnavailable = kube_chk_maxUnavailable(stack, service_name) - assert kube_maxUnavailable == 1 diff --git a/tests/run/test_update-strategy.py b/tests/run/test_update-strategy.py deleted file mode 100644 index 827fecf2d..000000000 --- a/tests/run/test_update-strategy.py +++ /dev/null @@ -1,48 +0,0 @@ -import util - - -def run_updateStrategy(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_updateStrategy(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["updateStrategy"] - - -def kube_chk_updateStrategy(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['strategy'] - results = cnt['type'] - - return results - - -def test_updateStrategy1(stack): - service_name = run_updateStrategy(stack, '--update-strategy', 'rolling') - - rio_updateStrategy = rio_chk_updateStrategy(stack, service_name) - assert rio_updateStrategy == "rolling" - - kube_updateStrategy = kube_chk_updateStrategy(stack, service_name) - assert kube_updateStrategy == "RollingUpdate" - - -# bug 162 -# def test_updateStrategy2(stack): -# service_name = run_updateStrategy(stack, '--update-strategy', 'on-delete') -# -# rio_updateStrategy = rio_chk_updateStrategy(stack, service_name) -# assert rio_updateStrategy == "on-delete" -# -# kube_updateStrategy = kube_chk_updateStrategy(stack, service_name) -# assert kube_updateStrategy == "on-delete" diff --git a/tests/run/test_volume-driver.py b/tests/run/test_volume-driver.py deleted file mode 100644 index 1e9992bda..000000000 --- a/tests/run/test_volume-driver.py +++ /dev/null @@ -1,37 +0,0 @@ -import util - - -def run_voldriver(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_voldriver(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["defaultVolumeDriver"] - - -def kube_chk_voldriver(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - results = cnt['defaultVolumeDriver'] - - return results - - -def test_voldriver1(stack): - service_name = run_voldriver(stack, '--volume-driver', 'local') - - rio_voldriver = rio_chk_voldriver(stack, service_name) - assert rio_voldriver == "local" - - kube_voldriver = kube_chk_voldriver(stack, service_name) - assert kube_voldriver == "local" diff --git a/tests/run/test_workdir.py b/tests/run/test_workdir.py deleted file mode 100644 index bae2f665c..000000000 --- a/tests/run/test_workdir.py +++ /dev/null @@ -1,37 +0,0 @@ -import util - - -def run_workdir(stack, *value): - - name = util.rioRun(stack, ' '.join(value), 'nginx') - - return name - - -def rio_chk_workdir(stack, sname): - fullName = (f"{stack}/{sname}") - inspect = util.rioInspect(fullName) - - return inspect["workingDir"] - - -def kube_chk_workdir(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - obj = util.kubectl(namespace, "deployment", service) - cnt = obj['spec']['template']['spec']['containers'][0] - results = cnt['workingDir'] - - return results - - -def test_workdir1(stack): - service_name = run_workdir(stack, '--workdir', '/foo') - - rio_workdir = rio_chk_workdir(stack, service_name) - assert rio_workdir == "/foo" - - kube_workdir = kube_chk_workdir(stack, service_name) - assert kube_workdir == "/foo" diff --git a/tests/tox.ini b/tests/tox.ini index 1fc4fad8b..5f73ba2f9 100644 --- a/tests/tox.ini +++ b/tests/tox.ini @@ -2,7 +2,7 @@ envlist=flake8, py36 [testenv] -passenv=RUN_NFS_TEST +passenv = KUBECONFIG deps=-rrequirements.txt commands=py.test --durations=20 {posargs} diff --git a/tests/util.py b/tests/util.py index cabd2a8e7..4245d67a3 100644 --- a/tests/util.py +++ b/tests/util.py @@ -45,7 +45,7 @@ def rioRun(nspc, *args): run(cmd) time.sleep(5) - return fullName + return srv def rioStage(image, srv, version): @@ -56,7 +56,7 @@ def rioStage(image, srv, version): return -def rioConfigCreate(stack, *configs): +def rioConfigCreate(nspc, *configs): config_name = "tconfig" + str(random.randint(1000, 5000)) fp = tempfile.NamedTemporaryFile(delete=False) @@ -66,7 +66,7 @@ def rioConfigCreate(stack, *configs): fp.close() - run(f"rio config create {stack}/{config_name} {fp.name}") + run(f"rio config create {nspc}/{config_name} {fp.name}") os.unlink(fp.name) return config_name @@ -74,13 +74,15 @@ def rioConfigCreate(stack, *configs): def rioInspect(resource, field=None): if field: + print(resource) + print(field) return run(f"rio inspect --format json {resource} | jq -r .{field}") else: return runToJson(f"rio inspect {resource}") def kubectl(namespace, ktype, resource): - cmd = (f"rio kubectl get -n {namespace} -o=json {ktype}/{resource}") + cmd = (f"kubectl get -n {namespace} -o=json {ktype}/{resource}") return runToJson(cmd) diff --git a/tests/validation/test_config.py b/tests/validation/test_config.py index 0c6e99805..8dd8463e5 100644 --- a/tests/validation/test_config.py +++ b/tests/validation/test_config.py @@ -2,53 +2,35 @@ import util -def config_setup(stack, *text): +def config_setup(nspc, *text): - config = util.rioConfigCreate(stack, *text) - fullname = (f"{stack}/{config}") + config = util.rioConfigCreate(nspc, *text) return config def rio_config_content(fullname): - rio_content = "rio inspect --format '{{.content}}' %s" % fullname - rio_content = util.run(rio_content) + rio_cont = (f"rio inspect --format json {fullname} | jq -r .data.content") + rio_cont = util.run(rio_cont) - return rio_content - - -def kube_config_content(fullname, config_name): - - nsp = "rio inspect --format '{{.id}}' %s | cut -f1 -d:" % fullname - nsp = util.run(nsp) - k_cmd = "rio kubectl get config -n %s -o=json %s" % (nsp, config_name) - kube_content = k_cmd + "| jq -r .spec.content" - kube_content = util.run(kube_content) - - return kube_content + return rio_cont # Validation tests -def test_create_config1(stack): +def test_create_config1(nspc): text = "foo=bar" - config_name = config_setup(stack, text) - fullname = (f"{stack}/{config_name}") + config_name = config_setup(nspc, text) + fullname = (f"{nspc}/{config_name}") rio_content = rio_config_content(fullname) assert rio_content == "foo=bar" - kube_content = kube_config_content(fullname, config_name) - assert kube_content == "foo=bar" - -def test_create_config2(stack): +def test_create_config2(nspc): text1 = "foo=bar" text2 = "foo2=bar2" - config_name = config_setup(stack, text1, text2) - fullname = (f"{stack}/{config_name}") + config_name = config_setup(nspc, text1, text2) + fullname = (f"{nspc}/{config_name}") rio_content = rio_config_content(fullname) assert rio_content == "foo=bar foo2=bar2" - - kube_content = kube_config_content(fullname, config_name) - assert kube_content == "foo=bar foo2=bar2" diff --git a/tests/validation/test_create.py b/tests/validation/test_create.py deleted file mode 100644 index 0a72e3473..000000000 --- a/tests/validation/test_create.py +++ /dev/null @@ -1,27 +0,0 @@ -# Setup -from random import randint -import util - - -def create_service(stack): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - rio_create = "rio create -n %s nginx" % fullName - rio_create = util.run(rio_create) - util.run("rio --wait-state inactive wait %s" % fullName) - - return fullName - - -def test_create_status(stack): - fullName = create_service(stack) - create_status = util.rioInspect(fullName, "state") - - assert create_status == "inactive" - - -def test_create_scale(stack): - fullName = create_service(stack) - create_scale = util.rioInspect(fullName, "scale") - - assert create_scale == '0' diff --git a/tests/new-validation/test_domain.py b/tests/validation/test_domain.py similarity index 80% rename from tests/new-validation/test_domain.py rename to tests/validation/test_domain.py index eb5363bbe..cc8262222 100644 --- a/tests/new-validation/test_domain.py +++ b/tests/validation/test_domain.py @@ -4,14 +4,15 @@ def create_service(nspc, image): - fullName = util.rioRun(nspc, image) + srv = util.rioRun(nspc, image) + fullName = (f"{nspc}/{srv}") return fullName def create_domain(dname, fname): - cmd = (f"rio domain add {dname} {fname}") + cmd = (f"rio domain register {dname} {fname}") print(cmd) util.run(cmd) diff --git a/tests/new-validation/test_endpoint.py b/tests/validation/test_endpoint.py similarity index 85% rename from tests/new-validation/test_endpoint.py rename to tests/validation/test_endpoint.py index 1a41b92e0..20ee8aa99 100644 --- a/tests/new-validation/test_endpoint.py +++ b/tests/validation/test_endpoint.py @@ -43,12 +43,15 @@ def test_rio_app_endpoint(nspc): image = "ibuildthecloud/demo:v1" image2 = "ibuildthecloud/demo:v3" - fullName = create_service(nspc, image) + srv = create_service(nspc, image) + fullName = (f"{nspc}/{srv}") + print(fullName) stage_service(image2, fullName, "v3") appEndpoint = get_app_info(fullName, "status.endpoints[0]") + print(f"{appEndpoint}") - results = util.run(f"curl {appEndpoint}") + results = util.run(f"curl -s {appEndpoint}") print(f"{results}") assert results == 'Hello World' @@ -58,7 +61,9 @@ def test_rio_svc_endpoint1(nspc): image = "ibuildthecloud/demo:v1" image2 = "ibuildthecloud/demo:v3" - fullName = create_service(nspc, image) + srv = create_service(nspc, image) + fullName = (f"{nspc}/{srv}") + stage_service(image2, fullName, "v3") svcEndpoint = get_version_endpoint(fullName, "v0") diff --git a/tests/validation/test_export.py b/tests/validation/test_export.py index 407094c94..d29cd0c76 100644 --- a/tests/validation/test_export.py +++ b/tests/validation/test_export.py @@ -1,37 +1,24 @@ # Setup -import pytest import util -@pytest.fixture -def serviceJson(stack, service): - fullName = "%s/%s" % (stack, service) - obj = util.runToJson("rio export -o json -t service %s" % fullName) - return obj +def pullimage(nspc, service): + cmd = (f"rio export -t service {service} | grep 'image:' | cut -d' ' -f 4") + image = util.run(cmd) + return image -@pytest.fixture -def stackJson(stack, service): - # service is passed in so that there will be one in the stack export - obj = util.runToJson("rio export -o json %s" % stack) - return obj +def pullscale(nspc, service): + cmd = (f"rio export -t service {service} | grep 'scale:' | cut -d' ' -f 4") + image = util.run(cmd) + return image -def test_service_export_image(serviceJson): - assert serviceJson['image'] == "nginx" +def test_service_export_image(nspc, service): + results = pullimage(nspc, service) + assert results == "nginx" -def test_service_export_name(service, serviceJson): - assert serviceJson['name'] == ("%s" % service) - - -def test_service_export_scale(serviceJson): - assert serviceJson['scale'] == 1 - - -def test_stack_export_service_image(stackJson, service): - assert stackJson['services'][service]['image'] == "nginx" - - -def test_stack_export_service_scale(stackJson, service): - assert stackJson['services'][service]['scale'] == 1 +def test_service_export_scale(nspc, service): + results = pullscale(nspc, service) + assert results == '1' diff --git a/tests/new-validation/test_externalservice.py b/tests/validation/test_externalservice.py similarity index 100% rename from tests/new-validation/test_externalservice.py rename to tests/validation/test_externalservice.py diff --git a/tests/validation/test_publicdomain.py b/tests/validation/test_publicdomain.py deleted file mode 100644 index cabd8e640..000000000 --- a/tests/validation/test_publicdomain.py +++ /dev/null @@ -1,57 +0,0 @@ -# Run Validation test. Use functions to test run and get outpu -import util -from random import randint - - -def riorun(stack): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - - cmd = (f'rio run -p 80/http -n {fullName} nginx:latest') - - util.runwait(cmd, fullName) -# util.run(f"rio wait {fullName}") - - return name - - -def riocreatedomain(stack, s_name): - cmd = (f'rio domain add test.foo.bar2 {stack}/{s_name}') - util.run(cmd) - - -def riotest(): - domainId = "rio domain --format '{{.ID}}'" - domainId = util.run(domainId) - - inspect = util.rioInspect(domainId) - - return inspect['domainName'] - - -def kubetest(stack, service): - - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - - contents = util.kubectl(namespace, 'virtualservice', service) - print(contents) - - domainName = contents['spec']['hosts'][2] - print(domainName) - - return domainName - - -def test_domain_name(stack): - sname = riorun(stack) - riocreatedomain(stack, sname) - riodname = riotest() - assert riodname == "test.foo.bar2" - -# k8sdname = kubetest(stack, sname) -# assert k8sdname == "test.foo.bar2" - - cmd = (f'rio domain rm test.foo.bar2 ') - util.run(cmd) diff --git a/tests/new-validation/test_route.py b/tests/validation/test_route.py similarity index 90% rename from tests/new-validation/test_route.py rename to tests/validation/test_route.py index 1f96a5656..819e1f3dc 100644 --- a/tests/new-validation/test_route.py +++ b/tests/validation/test_route.py @@ -6,7 +6,8 @@ def create_service(nspc, image): port = "-p 80/http" - fullName = util.rioRun(nspc, port, image) + srv = util.rioRun(nspc, port, image) + fullName = (f"{nspc}/{srv}") return fullName @@ -28,7 +29,7 @@ def get_app_info(fullName, field): def route_service(nspc, rName, sname, fName, vs): - cmd = (f"rio route append {rName}.{nspc}/to-{sname}-{vs} to {fName}:{vs}") + cmd = (f"rio route add {rName}.{nspc}/to-{sname}-{vs} to {fName}:{vs}") print(f"{cmd}") util.run(cmd) diff --git a/tests/validation/test_run.py b/tests/validation/test_run.py index b45d19e96..1aba7cf7b 100644 --- a/tests/validation/test_run.py +++ b/tests/validation/test_run.py @@ -1,30 +1,30 @@ -# Run Validation test. Use functions to test run and get outpu +# Run Validation test. Use functions to test run and get output import util -def riotest(stack, service): - fullName = (f"{stack}/{service}") +def test_rio_scale(service): + fullName = (f"{service}:v0") + scalefield = "spec.scale" + print(f"{fullName}") - inspect = util.rioInspect(fullName) + inspect = util.rioInspect(fullName, scalefield) + assert inspect == '1' - return inspect['state'] +def test_rio_image(service): + fullName = (f"{service}:v0") + scalefield = "spec.image" + print(f"{fullName}") -def kubetest(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] + inspect = util.rioInspect(fullName, scalefield) + assert inspect == 'nginx' - obj = util.kubectl(namespace, "deployment", service) - replicas = obj['status']['replicas'] - return replicas +def test_rio_weight(service): + fullName = (f"{service}:v0") + scalefield = "spec.weight" + print(f"{fullName}") - -def test_rio_status(stack, service): - assert riotest(stack, service) == "active" - - -def test_kube_replicas(stack, service): - assert kubetest(stack, service) == 1 + inspect = util.rioInspect(fullName, scalefield) + assert inspect == '100' diff --git a/tests/validation/test_scale.py b/tests/validation/test_scale.py index 9333e50cd..0b108169f 100644 --- a/tests/validation/test_scale.py +++ b/tests/validation/test_scale.py @@ -1,52 +1,35 @@ import util -import time -def set_scale(stack, service, scale): - fullName = "%s/%s" % (stack, service) - cmd = (f"rio scale {fullName}={scale}") - util.runwait(cmd, fullName) +def set_scale(service, scale): + cmd = (f"rio scale {service}={scale}") + util.run(cmd) -def rio_return_scale(stack, service): - fullName = "%s/%s" % (stack, service) - scale_amount = util.rioInspect(fullName, "scale") - return scale_amount +def rio_return_scale(service): + scalefield = "spec.scale" + inspect = util.rioInspect(service, scalefield) + return inspect -def kube_return_scale(stack, service): - fullName = "%s/%s" % (stack, service) - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", service) - replicas = obj['status']['replicas'] +def test_scale3(service): + set_scale(service, 3) - return replicas - - -def test_scale3(stack, service): - set_scale(stack, service, 3) - - scale_amount = rio_return_scale(stack, service) + scale_amount = rio_return_scale(service) assert scale_amount == '3' - time.sleep(5) - - replicas = kube_return_scale(stack, service) - assert replicas == 3 - -def test_rio_scale5(stack, service): - set_scale(stack, service, 5) +def test_rio_scale5(service): + set_scale(service, 5) - scale_amount = rio_return_scale(stack, service) + scale_amount = rio_return_scale(service) assert scale_amount == '5' -def test_rio_scale10(stack, service): - set_scale(stack, service, 10) +def test_rio_scale10(service): + set_scale(service, 10) - scale_amount = rio_return_scale(stack, service) + scale_amount = rio_return_scale(service) assert scale_amount == '10' diff --git a/tests/validation/test_service_mesh.py b/tests/validation/test_service_mesh.py index 0656c7db8..c5d3ea480 100644 --- a/tests/validation/test_service_mesh.py +++ b/tests/validation/test_service_mesh.py @@ -1,95 +1,75 @@ +# Run Validation test. Use functions to test run and get output + import util -from random import randint -import tempfile +import time + + +def create_service(nspc, image): + port = "-p 80/http" + srv = util.rioRun(nspc, port, image) + fullName = (f"{nspc}/{srv}") + + return fullName + + +def stage_service(image, fullName, version): + + util.rioStage(image, fullName, version) + return -def config_version(stack, version): - config = "tconfig" + str(randint(1000, 5000)) - fp = tempfile.NamedTemporaryFile(delete=False) - version_as_bytes = str.encode(version) - fp.write(b'%s' % version_as_bytes) - fp.close() - print(stack) - config_name = stack + "/" + config - print(config_name) +def get_app_info(fullName, field): - util.run("rio config create %s %s" % (config_name, fp.name)) + inspect = util.rioInspect(fullName, field) - return config + return inspect -def create_service(stack, config): - name = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, name) - path = "/usr/share/nginx/html/index.html" - print(fullName) - print(config) - run_command = "rio run -n %s -p 80/http --config %s:%s nginx" % ( - fullName, config, path - ) - print(run_command) - util.runwait(run_command, fullName) +def change_weight(fullName, version, percent): - return name + cmd = (f"rio weight {fullName}:{version}={percent}") + util.run(cmd) + return -def stage_service(stack, name, version, second_config): - fullName = "%s/%s" % (stack, name) - path = "/usr/share/nginx/html/index.html" - command = "rio stage --image=nginx --config %s:%s %s:%s" % ( - second_config, path, fullName, version - ) - print(command) - util.runwait(command, fullName) - stackJson = util.runToJson("rio export -o json %s" % stack) - got = stackJson['services'][name]['revisions']['v2']['scale'] - return got +def test_rio_svc_weight(nspc): + image = "ibuildthecloud/demo:v1" + image2 = "ibuildthecloud/demo:v3" + fullName = create_service(nspc, image) + stage_service(image2, fullName, "v3") + fullName1 = (f"{fullName}:v0") + fullName2 = (f"{fullName}:v3") -def weight_service(stack, name, version, weight): - fullName = "%s/%s" % (stack, name) - command = "rio weight %s:%s=%s" % (fullName, version, weight) - util.run(command) - stackJson = util.runToJson("rio export -o json %s" % stack) - got = stackJson['services'][name]['revisions']['v2']['weight'] + results1 = get_app_info(fullName1, "spec.weight") + results2 = get_app_info(fullName2, "spec.weight") - return got + print(f"{results1}") + print(f"{results2}") + assert results1 == '100' + assert results2 == 'null' -def promote_service(stack, name, version): - fullName = "%s/%s" % (stack, name) - command = "rio promote %s:%s" % (fullName, version) - util.run(command) - stackJson = util.runToJson("rio export -o json %s" % stack) - got = stackJson['services'][name]['version'] - return got +def test_rio_svc_weight2(nspc): + image = "ibuildthecloud/demo:v1" + image2 = "ibuildthecloud/demo:v3" + fullName = create_service(nspc, image) + stage_service(image2, fullName, "v3") + fullName1 = (f"{fullName}:v0") + fullName2 = (f"{fullName}:v3") -def test_stage_service(stack): - config_name = config_version(stack, "1") - name = create_service(stack, config_name) - second_config = config_version(stack, "2") - got = stage_service(stack, name, "v2", second_config) - assert got == 1 + time.sleep(5) + change_weight(fullName, "v3", "5%") -def test_weight_service(stack): - config_name = config_version(stack, "1") - name = create_service(stack, config_name) - second_config = config_version(stack, "2") - stage_service(stack, name, "v2", second_config) - got = weight_service(stack, name, "v2", "50") - assert got == 50 + time.sleep(5) + results1 = get_app_info(fullName1, "spec.weight") + results2 = get_app_info(fullName2, "spec.weight") -def test_promote_service(stack): - config_name = config_version(stack, "1") - name = create_service(stack, config_name) - second_config = config_version(stack, "2") - stage_service(stack, name, "v2", second_config) - weight_service(stack, name, "v2", "50") - got = promote_service(stack, name, "v2") - assert got == "v2" + assert results1 == '95' + assert results2 == '5' diff --git a/tests/validation/test_stack.py b/tests/validation/test_stack.py deleted file mode 100644 index b77ccf0c3..000000000 --- a/tests/validation/test_stack.py +++ /dev/null @@ -1,12 +0,0 @@ -import util - - -def test_stack_create(stack): - stack_status = util.rioInspect(stack, "state") - assert stack_status == "active" - - -def test_add_service(stack, service): - fullName = stack + "/" + service - service_status = util.rioInspect(fullName, "state") - assert service_status == "active" diff --git a/tests/validation/test_volume-emptydir.py b/tests/validation/test_volume-emptydir.py deleted file mode 100644 index dbe597c53..000000000 --- a/tests/validation/test_volume-emptydir.py +++ /dev/null @@ -1,70 +0,0 @@ -# Run Validation test. Use functions to test run and get outpu - -import util -from random import randint - - -def riorun(stack, vname): - sname = "tsrv" + str(randint(1000, 5000)) - fullName = "%s/%s" % (stack, sname) - - cmd = (f'rio run -n {fullName} -v {vname} nginx') - util.runwait(cmd, fullName) - - return sname - - -def rio_vol_target(stack, sname): - fullName = (f"{stack}/{sname}") - - inspect = util.rioInspect(fullName) - - return inspect['volumes'][0]['target'] - - -def kube_vol_target(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - obj = obj['spec']['template']['spec']['containers'][0] - - return obj['volumeMounts'][0]['mountPath'] - - -def kube_vol_name(stack, sname): - fullName = (f"{stack}/{sname}") - - id = util.rioInspect(fullName, "id") - namespace = id.split(":")[0] - obj = util.kubectl(namespace, "deployment", sname) - obj = obj['spec']['template']['spec']['containers'][0] - - return obj['volumeMounts'][0]['name'] - - -def test_anon(stack): - srv_name = riorun(stack, '/data') - - target = rio_vol_target(stack, srv_name) - assert target == '/data' - - mpath = kube_vol_target(stack, srv_name) - assert mpath == '/data' - - vol_name = kube_vol_name(stack, srv_name) - assert vol_name == 'anon-data' - - -def test_named(stack): - srv_name = riorun(stack, 'test:/data') - - target = rio_vol_target(stack, srv_name) - assert target == '/data' - - mpath = kube_vol_target(stack, srv_name) - assert mpath == '/data' - - vol_name = kube_vol_name(stack, srv_name) - assert vol_name == 'test' diff --git a/tests/validation/test_volume.py b/tests/validation/test_volume.py deleted file mode 100644 index 7ffcb748d..000000000 --- a/tests/validation/test_volume.py +++ /dev/null @@ -1,40 +0,0 @@ -# Run Validation test. Use functions to test run and get output - -from random import randint -import util - - -def riovolume(stack, size): - vname = "tvol" + str(randint(1000, 5000)) - fullName = (f"{stack}/{vname}") - - cmd = (f'rio volume create {fullName} {size}') - - util.run(cmd) - - return fullName - - -def riotest(vname): - inspect = util.rioInspect(vname) - - return inspect['sizeInGb'] - - -def kubetest(vname): - - id = util.rioInspect(vname, "id") - nspace = id.split(":")[0] - - obj = util.kubectl(nspace, "pvc", vname) - volsize = obj['spec']['resources']['requests']['storage'] - - return volsize - - -def test_vol_size(stack): - volname = riovolume(stack, 1) - - assert riotest(volname) == 1 - -# assert kubetest(volname) == '1Gi' diff --git a/tests/validation/test_volume_nfs.py b/tests/validation/test_volume_nfs.py deleted file mode 100644 index 4e4535e66..000000000 --- a/tests/validation/test_volume_nfs.py +++ /dev/null @@ -1,83 +0,0 @@ -# Run Validation test. Use functions to test run and get output - -from random import randint -import util -import os - - -def riovolume(stack, size): - vname = "tvol" + str(randint(1000, 5000)) - fullName = (f"{stack}/{vname}") - print(fullName) - - cmd = (f'rio volume create -d nfs {fullName} {size}') - - util.run(cmd) - - return vname - - -def rio_bound(stack, vname): - fullVolName = (f"{stack}/{vname}") - state = 'bound' - - util.wait_for_state(fullVolName, state) - inspect = util.rioInspect(fullVolName) - - return inspect['state'] - - -def rio_bind_workload(stack, vname): - name = "tsrv" + str(randint(1000, 5000)) - fullName = (f"{stack}/{name}") - - cmd = (f'rio run -n {fullName} -v {vname}:/data nginx') - util.runwait(cmd, fullName) - util.run(f"rio exec {fullName} touch /data/helloworld") - output = util.run(f"rio exec {fullName} ls /data") - - return output - - -def riotest(stack, vname): - fullVolName = (f"{stack}/{vname}") - - inspect = util.rioInspect(fullVolName) - - return inspect['sizeInGb'] - - -def kubetest(stack, vname): - fullVolName = (f"{stack}/{vname}") - - id = util.rioInspect(fullVolName, "id") - namespace = id.split(":")[0] - print(namespace) - - obj = util.kubectl(namespace, "pvc", vname) - volsize = obj['spec']['resources']['requests']['storage'] - - return volsize - - -def test_nfs_vol_bound(stack): - volname = riovolume(stack, 1) - if os.getenv('RUN_NFS_TEST') != "true": - print('WARNING! nfs_not_enabled skipping test') - return - - assert rio_bound(stack, volname) == 'bound' - assert riotest(stack, volname) == 1 - assert kubetest(stack, volname) == '1Gi' - - -def test_nfs_bind_workload(stack): - volname = riovolume(stack, 1) - if os.getenv('RUN_NFS_TEST') != "true": - print('WARNING! nfs_not_enabled skipping test') - return - - rio_bound(stack, volname) - results = rio_bind_workload(stack, volname) - - assert results == 'helloworld' diff --git a/tests/validation/test_volume_templates.py b/tests/validation/test_volume_templates.py deleted file mode 100644 index 65edd282c..000000000 --- a/tests/validation/test_volume_templates.py +++ /dev/null @@ -1,54 +0,0 @@ -import util -import os - - -def riovolume(stack, path): - cmd = (f'rio up {stack} {path}') - - util.run(cmd) - - -def rio_check_bound(stack, vname): - fullVolName = (f"{stack}/{vname}") - state = 'bound' - - util.wait_for_state(fullVolName, state) - inspect = util.rioInspect(fullVolName) - - return inspect['state'] - - -def rio_bind_workload(stack, vname, wrklname): - fullVolName = (f"{stack}/{vname}") - fullWklName = (f"{stack}/{wrklname}") - - util.wait_for_state(fullVolName, "active") - util.run(f"rio exec {fullVolName} touch /persistentvolumes/helloworld") - cmd = (f"rio run -n {fullWklName} -v data-{vname}-0:/data nginx") - util.runwait(cmd, fullWklName) - output = util.run(f"rio exec {fullWklName} ls /data") - - print(f'OUTPUT = {output}') - - return output - - -def test_vol_template(stack): - if os.getenv('RUN_NFS_TEST') != "true": - print('WARNING! nfs_not_enabled skipping test') - return - - riovolume(stack, './nfs-stack/volume-template-stack.yaml') - # to run locally you have to change url to - # ./tests/nfs-stack/volume-template-stack.yaml - - cmd = (f"rio inspect {stack}/data --format json | jq '.template'") - template_results = util.run(cmd) - - assert template_results == "true" - - assert rio_check_bound(stack, 'data-test1-0') == 'bound' - assert rio_check_bound(stack, 'data-test2-0') == 'bound' - - assert rio_bind_workload(stack, 'test1', 'inspect-v1') == 'helloworld' - assert rio_bind_workload(stack, 'test2', 'inspect-v2') == 'helloworld' diff --git a/tests/validation/volume-common.bash b/tests/validation/volume-common.bash deleted file mode 100644 index a380653b7..000000000 --- a/tests/validation/volume-common.bash +++ /dev/null @@ -1,22 +0,0 @@ -wait_for_state() { - for i in {1..30} - do - sleep 2 - if [[ $(rio inspect $1 | jq -r '.state') == $2 ]]; then - pass="true" - break - fi - done - [ $pass == "true" ] -} - -wait_for_ip() { - export ip="" - for i in {1..30} - do - if ! [[ $ip =~ ^10.42.* ]]; then - ip=$(rio kubectl get po --all-namespaces -o wide | grep $1 | awk '{print $(NF-2)}') - sleep 2 - fi - done -} \ No newline at end of file