Example #1
0
    def test_list_deployments(self):
        api_key = get_oc_api_token()
        with K8sBackend(api_key=api_key) as k8s_backend:

            namespace = k8s_backend.create_namespace()

            with DockerBackend() as backend:
                postgres_image = backend.ImageClass("centos/postgresql-10-centos7")

                postgres_image_metadata = postgres_image.get_metadata()

                # set up env variables
                db_env_variables = {"POSTGRESQL_USER": "******",
                                    "POSTGRESQL_PASSWORD": "******",
                                    "POSTGRESQL_DATABASE": "db"}

                postgres_image_metadata.env_variables.update(db_env_variables)

                db_labels = {"app": "postgres"}

                db_deployment = Deployment(name="database", selector=db_labels, labels=db_labels,
                                           image_metadata=postgres_image_metadata,
                                           namespace=namespace,
                                           create_in_cluster=True)

                try:
                    db_deployment.wait(200)
                    assert db_deployment.all_pods_ready()
                    assert any(db_deployment.name == d.name for d in k8s_backend.list_deployments())
                finally:
                    db_deployment.delete()
                    k8s_backend.delete_namespace(namespace)
Example #2
0
def test_database_deployment():
    with K8sBackend() as k8s_backend:

        namespace = k8s_backend.create_namespace()

        with DockerBackend() as backend:
            postgres_image = backend.ImageClass("centos/postgresql-10-centos7")

            postgres_image_metadata = postgres_image.get_metadata()

            # set up env variables
            db_env_variables = {"POSTGRESQL_USER": "******",
                                "POSTGRESQL_PASSWORD": "******",
                                "POSTGRESQL_DATABASE": "db"}

            postgres_image_metadata.env_variables.update(db_env_variables)

            db_labels = {"app": "postgres"}

            db_service = Service(name="database", ports=["5432"], selector=db_labels,
                                 namespace=namespace,
                                 create_in_cluster=True)

            db_deployment = Deployment(name="database", selector=db_labels, labels=db_labels,
                                       image_metadata=postgres_image_metadata, namespace=namespace,
                                       create_in_cluster=True)

            try:
                db_deployment.wait(200)
                assert db_deployment.all_pods_ready()
            finally:
                db_deployment.delete()
                db_service.delete()
                k8s_backend.delete_namespace(namespace)
Example #3
0
def test_deployment_from_template():
    with K8sBackend() as k8s_backend:

        namespace = k8s_backend.create_namespace()

        template = """
        apiVersion: apps/v1
        kind: Deployment
        metadata:
          name: nginx-deployment
          labels:
            app: nginx
        spec:
          replicas: 3
          selector:
            matchLabels:
              app: nginx
          template:
            metadata:
              labels:
                app: nginx
            spec:
              containers:
              - name: nginx
                image: nginx:1.7.9
                ports:
                - containerPort: 80
        """

        test_deployment = Deployment(namespace=namespace,
                                     from_template=template,
                                     create_in_cluster=True)

        try:
            test_deployment.wait(200)
            assert test_deployment.all_pods_ready()
        finally:
            test_deployment.delete()
            k8s_backend.delete_namespace(namespace)
Example #4
0
    def test_deployment_from_template(self):
        api_key = get_oc_api_token()
        with K8sBackend(api_key=api_key) as k8s_backend:

            namespace = k8s_backend.create_namespace()

            template = """
            apiVersion: apps/v1
            kind: Deployment
            metadata:
              name: hello-world
              labels:
                app: hello-world
            spec:
              replicas: 3
              selector:
                matchLabels:
                  app: hello-world
              template:
                metadata:
                  labels:
                    app: hello-world
                spec:
                  containers:
                  - name: hello-openshift
                    image: openshift/hello-openshift
            """

            test_deployment = Deployment(namespace=namespace,
                                         from_template=template,
                                         create_in_cluster=True)

            try:
                test_deployment.wait(200)
                assert test_deployment.all_pods_ready()
            finally:
                test_deployment.delete()
                k8s_backend.delete_namespace(namespace)
Example #5
0
    kind: Deployment
    metadata:
      name: hello-world
      labels:
        app: hello-world
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: hello-world
      template:
        metadata:
          labels:
            app: hello-world
        spec:
          containers:
          - name: hello-openshift
            image: openshift/hello-openshift
    """

    test_deployment = Deployment(namespace=namespace,
                                 from_template=template,
                                 create_in_cluster=True)

    try:
        test_deployment.wait(200)
        assert test_deployment.all_pods_ready()
    finally:
        test_deployment.delete()
        k8s_backend.delete_namespace(namespace)