def test_rollback_no_args(self):
     name = "nginx"
     image1 = "nginx:1.7.9"
     image2 = "nginx:1.9.1"
     container = utils.create_container(name=name, image=image1)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.desired_replicas = 3
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         self.assertEqual(image1, dep.containers[0].image)
         dep.container_image = (name, image2)
         dep.update()
         self.assertIn('deployment.kubernetes.io/revision', dep.annotations)
         rev_before = dep.get_annotation(
             'deployment.kubernetes.io/revision')
         self.assertNotEqual(image1, dep.containers[0].image)
         self.assertEqual(image2, dep.containers[0].image)
         dep.rollback()
         self.assertIn('deployment.kubernetes.io/revision', dep.annotations)
         rev_after = dep.get_annotation('deployment.kubernetes.io/revision')
         self.assertNotEqual(rev_before, rev_after)
         self.assertGreater(rev_after, rev_before)
         self.assertEqual(image1, dep.containers[0].image)
         self.assertNotEqual(image2, dep.containers[0].image)
 def test_get_by_name_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
Ejemplo n.º 3
0
    def test_pod_emptydir(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = utils.create_container(name=container_name, image=container_image)

        vol_name = "emptydir"
        vol_type = "emptyDir"
        vol_mount = "/test-emptydir"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        container.add_volume_mount(volume)

        pod_name = "nginx"
        pod = utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if utils.is_reachable(pod.config.api_host):
            pod.create()
            vols = pod.model.model['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = pod.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(1, len(pod.model.model['spec']['containers']))

            mounts = pod.model.model['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(1, len(pod.model.pod_spec.model['containers']))

            mounts = pod.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
Ejemplo n.º 4
0
 def test_list_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         objs = dep.list()
         self.assertIsInstance(objs, list)
         self.assertEqual(0, len(objs))
Ejemplo n.º 5
0
 def test_get_by_name_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
 def test_api_create(self):
     ds = DaemonSet(utils.fluentd_daemonset())
     k8s_ds = utils.create_daemonset(name=ds.name)
     k8s_ds.model = ds
     if utils.is_reachable(k8s_ds.config.api_host):
         k8s_ds.create()
         self.assertIsInstance(k8s_ds, K8sDaemonSet)
 def test_list_nonexistent(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         objs = dep.list()
         self.assertIsInstance(objs, list)
         self.assertEqual(0, len(objs))
Ejemplo n.º 8
0
 def test_create(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().get_hex()[:5]))
     acct = utils.create_service_account(name=name)
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         from_get = acct.get()
         self.assertEqual(acct, from_get)
Ejemplo n.º 9
0
 def test_delete(self):
     name = "yoname"
     rs = utils.create_rs(name=name)
     config = utils.create_config()
     if utils.is_reachable(config.api_host):
         utils.cleanup_rs()
         result = rs.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
Ejemplo n.º 10
0
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         try:
             dep.delete()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, NotFoundException)
Ejemplo n.º 11
0
 def test_add_api_token(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().get_hex()[:5]))
     acct = utils.create_service_account(name=name)
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         acct.add_api_token()
         secrets = K8sSecret.api_tokens_for_service_account(
             config=acct.config, name=acct.name)
         self.assertEqual(2, len(secrets))
 def test_delete(self):
     name = "yoname"
     rs = utils.create_rs(name=name)
     config = utils.create_config()
     if utils.is_reachable(config.api_host):
         utils.cleanup_rs()
         result = rs.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         try:
             dep.delete()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, NotFoundException)
Ejemplo n.º 14
0
    def test_rc_aws_ebs(self):
        # http://kubernetes.io/docs/user-guide/volumes/#awselasticblockstore
        # - the nodes on which pods are running must be AWS EC2 instances
        # - those instances need to be in the same region and availability-zone as the EBS volume
        # - EBS only supports a single EC2 instance mounting a volume

        # Pod creation will timeout waiting for readiness if not on AWS; unschedulable.

        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        volume_id = "vol-0e3056a2"
        vol_name = "ebs"
        vol_type = "awsElasticBlockStore"
        vol_mount = "/test-aws-ebs"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_volume_id(volume_id)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['template']['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(2, len(rc.model.model['spec']['template']['spec']['containers']))

                mounts = rc.model.model['spec']['template']['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(2, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Ejemplo n.º 15
0
 def test_stateful_nginx(self):
     svc = Service(headless_service())
     sset = StatefulSet(stateful_set())
     k8s_svc = K8sService(name='headless')
     k8s_sset = K8sStatefulSet(name='sset')
     k8s_svc.model = svc
     k8s_sset.model = sset
     if utils.is_reachable(k8s_svc.config.api_host):
         k8s_svc.create()
         k8s_sset.create()
Ejemplo n.º 16
0
    def test_rc_gce_pd(self):
        # http://kubernetes.io/docs/user-guide/volumes/#gcepersistentdisk
        # - the nodes on which pods are running must be GCE VMs
        # - those VMs need to be in the same GCE project and zone as the PD

        # Pod creation will timeout waiting for readiness if not on GCE; unschedulable.

        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        pd_name = "kubernetes-py-test-pd"
        vol_name = "persistent"
        vol_type = "gcePersistentDisk"
        vol_mount = "/test-gce-pd"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount, read_only=True)
        volume.set_pd_name(pd_name)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(1, len(rc.model.model['spec']['containers']))

                mounts = rc.model.model['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(1, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Ejemplo n.º 17
0
 def test_update_namespace_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yorc-{0}".format(str(uuid.uuid4()))
     nspace = "yonamespace"
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.set_namespace(nspace)
         with self.assertRaises(BadRequestException):
             dep.update()
 def test_update_namespace_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yorc-{0}".format(str(uuid.uuid4()))
     nspace = "yonamespace"
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.namespace = nspace
         with self.assertRaises(BadRequestException):
             dep.update()
 def test_update_name_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name1 = "yodep1"
     name2 = "yodep2"
     dep = utils.create_deployment(name=name1)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.name = name2
         with self.assertRaises(NotFoundException):
             dep.update()
 def test_create_already_exists(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.desired_replicas = 1
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         with self.assertRaises(AlreadyExistsException):
             dep.create()
 def test_delete(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         utils.cleanup_deployments()
         result = dep.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
Ejemplo n.º 22
0
 def test_delete(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         utils.cleanup_deployments()
         result = dep.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
Ejemplo n.º 23
0
 def test_create_already_exists(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.set_replicas(1)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         with self.assertRaises(AlreadyExistsException):
             dep.create()
Ejemplo n.º 24
0
 def test_update_name_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name1 = "yodep1"
     name2 = "yodep2"
     dep = utils.create_deployment(name=name1)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         dep.name = name2
         with self.assertRaises(BadRequestException):
             dep.update()
Ejemplo n.º 25
0
 def test_get_by_name(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(1, len(result))
         self.assertIsInstance(result[0], K8sDeployment)
         self.assertEqual(dep, result[0])
 def test_get_by_name(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         result = K8sDeployment.get_by_name(config=dep.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(1, len(result))
         self.assertIsInstance(result[0], K8sDeployment)
         self.assertEqual(dep, result[0])
Ejemplo n.º 27
0
    def test_rc_nfs(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        vol_name = "nfs"
        vol_type = "nfs"
        vol_mount = "/test-nfs"
        server = "howard.mtl.mnubo.com"
        path = "/fs1/test-nfs"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_server(server)
        volume.set_path(path)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(1, len(rc.model.model['spec']['containers']))

                mounts = rc.model.model['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(1, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Ejemplo n.º 28
0
    def test_rc_git_repo(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        vol_name = "git-repo"
        vol_type = "gitRepo"
        vol_mount = "/test-git-repo"
        repo = "https://*****:*****@git-lab1.mtl.mnubo.com/ops/traffic-analyzer.git"
        revision = "e42d3dca1541ba085f34ce282feda1109a707c7b"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_git_repository(repo)
        volume.set_git_revision(revision)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(1, len(rc.model.model['spec']['containers']))

                mounts = rc.model.model['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(1, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Ejemplo n.º 29
0
    def fetch_certificates(self) -> bool:
        """Fetch the certificate files from AWS S3 service."""
        # First test to see if we have an internet connection
        if not is_reachable("https://aws.amazon.com/", True):
            return False
        cert_file_list = ("cert.pem", "chain.pem", "fullchain.pem",
                          "privkey.pem")

        self.cert_dir.mkdir(0o755, parents=True, exist_ok=True)
        for cert_file in cert_file_list:
            if not aws_s3_get(f"{self.server_name}/{cert_file}",
                              Path(f"{self.cert_dir}/{cert_file}")):
                return False
        return True
Ejemplo n.º 30
0
    def test_rc_secret(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        secret_name = "yosecret"
        secret = utils.create_secret(name=secret_name)
        k = ".secret-file"
        v = "dmFsdWUtMg0KDQo="
        secret.set_data(k, v)

        vol_name = "secret"
        vol_type = "secret"
        vol_mount = "/test-secret"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_secret_name(secret)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "app"
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(1)

        if utils.is_reachable(rc.config.api_host):
            secret.create()
            rc.create()
            vols = rc.model.model['spec']['template']['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = rc.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(2, len(rc.model.model['spec']['template']['spec']['containers']))

            mounts = rc.model.model['spec']['template']['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(2, len(rc.model.pod_spec.model['containers']))

            mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
Ejemplo n.º 31
0
 def test_update_pod_labels(self):
     name = "nginx"
     image = "nginx:1.7.9"
     container = utils.create_container(name=name, image=image)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         labels = dep.get_pod_labels()
         labels['newkey'] = 'newvalue'
         dep.set_pod_labels(labels)
         updated = dep.update()
         self.assertEqual(labels, updated.get_pod_labels())
 def test_update_pod_labels(self):
     name = "nginx"
     image = "nginx:1.7.9"
     container = utils.create_container(name=name, image=image)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.desired_replicas = 3
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         labels = dep.pod_labels
         labels['newkey'] = 'newvalue'
         dep.pod_labels = labels
         updated = dep.update()
         self.assertEqual(labels, updated.pod_labels)
Ejemplo n.º 33
0
 def test_create_three_replicas(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(3, d.model.model['status']['replicas'])
         self.assertEqual(3, d.model.model['status']['availableReplicas'])
         self.assertEqual(3, d.model.model['status']['updatedReplicas'])
Ejemplo n.º 34
0
 def test_create_zero_replicas(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "redis"
     cont_image = "redis:3.2.3"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(0, d.model.model['spec']['replicas'])
         self.assertNotIn('replicas', d.model.model['status'])
         self.assertNotIn('availableReplicas', d.model.model['status'])
         self.assertNotIn('updatedReplicas', d.model.model['status'])
Ejemplo n.º 35
0
 def test_scale(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         replicas = dep.get_replicas()
         for k in replicas:
             self.assertEqual(3, replicas[k])
         dep.scale(5)
         replicas = dep.get_replicas()
         for k in replicas:
             self.assertEqual(5, replicas[k])
 def test_create_one_replica(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     dep.desired_replicas = 1
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(1, d.desired_replicas)
         self.assertEqual(1, d.available_replicas)
         self.assertEqual(1, d.updated_replicas)
 def test_scale(self):
     cont_name = "yocontainer"
     container = utils.create_container(name=cont_name)
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     dep.add_container(container)
     dep.desired_replicas = 3
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         self.assertEqual(3, dep.desired_replicas)
         self.assertEqual(3, dep.updated_replicas)
         self.assertEqual(3, dep.available_replicas)
         dep.scale(5)
         self.assertEqual(5, dep.desired_replicas)
         self.assertEqual(5, dep.updated_replicas)
         self.assertEqual(5, dep.available_replicas)
Ejemplo n.º 38
0
    def wait_for_webserver(self) -> bool:
        """
        Wait until Nginx webserver is up.

        wait_for_webserver will wait until the Nginx webserver has started.  This
        is done by periodically sending an http request to our URL and waiting for
        a response of 200 (OK) or 301 (Redirected).  We do not allow redirects nor
        do we send an https request because the webserver is started up with a
        self-signed certificate which will cause an error in these cases.
        """
        attempt_count = 0
        while attempt_count < self.max_connect_tries:
            if is_reachable(f"http://{self.server_name}", False):
                return True
            attempt_count += 1
            time.sleep(10)
        return False
 def test_create_zero_replicas(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "redis"
     cont_image = "redis:3.2.3"
     cont = utils.create_container(name=cont_name, image=cont_image)
     dep.add_container(container=cont)
     if utils.is_reachable(dep.config.api_host):
         d = dep.create()
         self.assertIsNotNone(d)
         self.assertIsInstance(d, K8sDeployment)
         self.assertEqual(d, dep)
         self.assertEqual(0, d.desired_replicas)
         self.assertIsNone(d.available_replicas)
         self.assertIsNone(d.current_replicas)
         self.assertIsNone(d.unavailable_replicas)
         self.assertIsNone(d.updated_replicas)
Ejemplo n.º 40
0
 def test_update_container_image(self):
     name = "nginx"
     image1 = "nginx:1.7.9"
     image2 = "nginx:1.9.1"
     container = utils.create_container(name=name, image=image1)
     dep_name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=dep_name)
     dep.add_container(container)
     dep.set_replicas(3)
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         self.assertEqual(image1, dep.model.model['spec']['template']['spec']['containers'][0]['image'])
         dep.set_container_image(name=name, image=image2)
         dep.update()
         self.assertIn('annotations', dep.model.deployment_metadata.model)
         self.assertIn('deployment.kubernetes.io/revision', dep.model.deployment_metadata.model['annotations'])
         self.assertNotEqual(image1, dep.model.model['spec']['template']['spec']['containers'][0]['image'])
         self.assertEqual(image2, dep.model.model['spec']['template']['spec']['containers'][0]['image'])
    def test_cassandra_setup(self):
        svc = Service(utils.cassandra_service())
        k8s_service = utils.create_service(name="cassandra")
        k8s_service.model = svc

        rc = ReplicationController(utils.cassandra_rc())
        k8s_rc = utils.create_rc(name="cassandra")
        k8s_rc.model = rc

        ds = DaemonSet(utils.cassandra_daemonset())
        k8s_ds = utils.create_daemonset(name="cassandra")
        k8s_ds.model = ds

        if utils.is_reachable(k8s_rc.config.api_host):
            k8s_service.create()
            k8s_rc.create()
            self.assertIsInstance(k8s_service, K8sService)
            self.assertIsInstance(k8s_rc, K8sReplicationController)
Ejemplo n.º 42
0
    def test_rc_hostpath(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        vol_name = "hostpath"
        vol_type = "hostPath"
        vol_mount = "/test-hostpath"
        hostpath = "/var/lib/docker"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_path(hostpath)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "app"
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(1)

        if utils.is_reachable(rc.config.api_host):
            rc.create()
            vols = rc.model.model['spec']['template']['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = rc.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(2, len(rc.model.model['spec']['template']['spec']['containers']))

            mounts = rc.model.model['spec']['template']['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(2, len(rc.model.pod_spec.model['containers']))

            mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
 def test_list_multiple(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     config = K8sConfig(kubeconfig=utils.kubeconfig_fallback)
     deployments = []
     count = 3
     objs = []
     if utils.is_reachable(config.api_host):
         for i in range(0, count):
             name = "yodep-{0}".format(str(uuid.uuid4()))
             dep = utils.create_deployment(config, name)
             dep.add_container(container)
             result = dep.create()
             self.assertIsInstance(result, K8sDeployment)
             self.assertEqual(dep, result)
             deployments.append(dep)
             objs = dep.list()
         self.assertEqual(count, len(deployments))
         self.assertEqual(count, len(objs))
Ejemplo n.º 44
0
    def test_pod_secret(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = utils.create_container(name=container_name, image=container_image)

        secret_name = "yosecret"
        secret = utils.create_secret(name=secret_name)
        k = ".secret-file"
        v = "dmFsdWUtMg0KDQo="
        secret.set_data(k, v)

        vol_name = "secret"
        vol_type = "secret"
        vol_mount = "/test-secret"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_secret_name(secret)
        container.add_volume_mount(volume)

        pod_name = "nginx"
        pod = utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if utils.is_reachable(pod.config.api_host):
            secret.create()
            pod.create()
            vols = pod.model.model['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = pod.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(1, len(pod.model.model['spec']['containers']))

            mounts = pod.model.model['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(1, len(pod.model.pod_spec.model['containers']))

            mounts = pod.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
Ejemplo n.º 45
0
 def test_add_image_pull_secret(self):
     name = "mnubo.com-sa-{0}".format(str(uuid.uuid4().get_hex()[:5]))
     acct = utils.create_service_account(name=name)
     data = {
         "auths": {
             "repo:port": {
                 "auth": "authstring",
                 "email": "*****@*****.**"
             }
         }
     }
     if utils.is_reachable(acct.config.api_host):
         acct.create()
         secret = K8sSecret.create_image_pull_secret(config=acct.config,
                                                     name=acct.name,
                                                     data=data)
         acct.add_image_pull_secret(secret)
         secrets = K8sSecret.list_image_pull_secrets()
         self.assertEqual(1, len(secrets))
Ejemplo n.º 46
0
 def test_list_multiple(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     config = K8sConfig(kubeconfig=utils.kubeconfig_fallback)
     deployments = []
     count = 3
     objs = []
     if utils.is_reachable(config.api_host):
         for i in range(0, count):
             name = "yodep-{0}".format(str(uuid.uuid4()))
             dep = utils.create_deployment(config, name)
             dep.add_container(container)
             result = dep.create()
             self.assertIsInstance(result, K8sDeployment)
             self.assertEqual(dep, result)
             deployments.append(dep)
             objs = dep.list()
         self.assertEqual(count, len(deployments))
         self.assertEqual(count, len(objs))
Ejemplo n.º 47
0
    def test_gce_pd(self):
        json = {
            "kind": "StorageClass",
            "apiVersion": "storage.k8s.io/v1beta1",
            "metadata": {
                "name": "slow"
            },
            "provisioner": "kubernetes.io/gce-pd",
            "parameters": {
                "type": "pd-standard",
            }
        }

        sc = StorageClass(json)
        k8s_sc = utils.create_storage_class(name='sc')
        k8s_sc.model = sc

        if utils.is_reachable(k8s_sc.config.api_host):
            k8s_sc.create()
            from_get = k8s_sc.get()
            self.assertIsInstance(from_get, K8sStorageClass)
 def test_create_no_args(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(UnprocessableEntityException):
             dep.create()
Ejemplo n.º 49
0
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(NotFoundException):
             dep.delete()
 def test_delete_nonexistent(self):
     name = "yorc-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(NotFoundException):
             dep.delete()
Ejemplo n.º 51
0
 def test_create_no_args(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     if utils.is_reachable(dep.config.api_host):
         with self.assertRaises(UnprocessableEntityException):
             dep.create()