Пример #1
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"
        hostpath = "/var/lib/docker"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.path = hostpath

        mount_name = vol_name
        mount_path = '/test-hostpath'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container_nginx.add_volume_mount(mount)
        container_redis.add_volume_mount(mount)

        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.desired_replicas = 1

        if _utils.is_reachable(rc.config):
            rc.create()
            volnames = [x.name for x in rc.volumes]
            self.assertIn(vol_name, volnames)
Пример #2
0
    def test_pod_nfs(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = _utils.create_container(name=container_name, image=container_image)

        vol_name = "nfs"
        vol_type = "nfs"
        server = "howard.mtl.mnubo.com"
        nfs_path = "/fs1/test-nfs"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.nfs_server = server
        volume.nfs_path = nfs_path

        mount_name = vol_name
        mount_path = '/test-nfs'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

        pod_name = "nginx-{0}".format(str(uuid.uuid4()))
        pod = _utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if _utils.is_reachable(pod.config):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #3
0
    def test_pod_git_repo(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = _utils.create_container(name=container_name, image=container_image)

        vol_name = "git-repo"
        vol_type = "gitRepo"
        repo = "https://*****:*****@somewhere/repo.git"
        revision = "e42d3dca1541ba085f34ce282feda1109a707c7b"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.git_repository = repo
        volume.git_revision = revision

        mount_name = vol_name
        mount_path = '/test-git'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

        pod_name = "nginx-{0}".format(str(uuid.uuid4()))
        pod = _utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if _utils.is_reachable(pod.config):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #4
0
    def test_pod_aws_ebs(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = _utils.create_container(name=container_name, image=container_image)

        volume_id = "vol-0e3056a2"
        vol_name = "ebs"
        vol_type = "awsElasticBlockStore"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.volume_id = volume_id

        mount_name = vol_name
        mount_path = '/test-aws'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

        pod_name = "nginx-{0}".format(str(uuid.uuid4()))
        pod = _utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if _utils.is_reachable(pod.config):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #5
0
    def test_pod_gce_pd(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = _utils.create_container(name=container_name, image=container_image)

        pd_name = "kubernetes_py-py-test-pd"
        vol_name = "persistent"
        vol_type = "gcePersistentDisk"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.pd_name = pd_name

        mount_name = vol_name
        mount_path = '/test-gce'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

        pod_name = "nginx-{0}".format(str(uuid.uuid4()))
        pod = _utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if _utils.is_reachable(pod.config):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #6
0
    def test_pod_hostpath(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = _utils.create_container(name=container_name, image=container_image)

        vol_name = "hostpath"
        vol_type = "hostPath"
        host_path = "/var/lib/docker"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.path = host_path

        mount_name = vol_name
        mount_path = '/test-hostpath'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

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

        if _utils.is_reachable(pod.config):
            pod.create()
            volnames = [x.name for x in pod.volumes]
            self.assertIn(vol_name, volnames)
Пример #7
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.data = {k: v}

        vol_name = "secret"
        vol_type = "secret"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.secret_name = secret_name

        mount_name = vol_name
        mount_path = '/test-secret'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

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

        if _utils.is_reachable(pod.config):
            secret.create()
            pod.create()
            volnames = [x.name for x in pod.volumes]
            self.assertIn(vol_name, volnames)
    def test_api_create_nfs(self):
        pvname = "yopv"
        pvcname = "yopvc"
        volname = "yovolume"
        podname = "yopod"
        contname = "yocontainer"

        pvtype = "nfs"
        pv = _utils.create_pv(name=pvname, type=pvtype)
        pv.nfs_server = "nfs.company.com"
        pv.nfs_path = "/fs1/test-nfs"

        pvc = _utils.create_pvc(name=pvcname)

        vol = _utils.create_volume(name=volname, type='persistentVolumeClaim')
        vol.claim_name = pvcname

        container = _utils.create_container(name=contname, image="nginx:latest")
        volmount = _utils.create_volume_mount(name=volname, mount_path='/test-persistent')
        container.add_volume_mount(volmount)

        pod = _utils.create_pod(name=podname)
        pod.add_volume(vol)
        pod.add_container(container)

        if _utils.is_reachable(pvc.config):
            try:
                pv.create()
                pvc.create()
                pod.create()
                self.assertIsInstance(pv, K8sPersistentVolume)
                self.assertIsInstance(pvc, K8sPersistentVolumeClaim)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
    def test_api_create_gce_pd(self):
        pvname = "yopv"
        pvcname = "yopvc"
        volname = "yovolume"
        podname = "yopod"
        contname = "yocontainer"

        pvtype = "gcePersistentDisk"
        pv = _utils.create_pv(name=pvname, type=pvtype)
        pv.pd_name = "mnubo-disk1"
        pv.fs_type = "xfs"

        pvc = _utils.create_pvc(name=pvcname)

        vol = _utils.create_volume(name=volname, type="persistentVolumeClaim")
        vol.claim_name = pvcname

        container = _utils.create_container(name=contname, image="nginx:latest")
        volmount = _utils.create_volume_mount(name=volname, mount_path="/test-persistent")
        container.add_volume_mount(volmount)

        pod = _utils.create_pod(name=podname)
        pod.add_volume(vol)
        pod.add_container(container)

        if _utils.is_reachable(pvc.config):
            try:
                pv.create()
                pvc.create()
                pod.create()
                self.assertIsInstance(pv, K8sPersistentVolume)
                self.assertIsInstance(pvc, K8sPersistentVolumeClaim)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
    def test_api_create_aws_ebs(self):
        pvname = "yopv"
        pvcname = "yopvc"
        volname = "yovolume"
        podname = "yopod"
        contname = "yocontainer"

        pvtype = "awsElasticBlockStore"
        pv = _utils.create_pv(name=pvname, type=pvtype)
        pv.volume_id = "vol-0e3056a2"
        pv.fs_type = "xfs"

        pvc = _utils.create_pvc(name=pvcname)

        vol = _utils.create_volume(name=volname, type='persistentVolumeClaim')
        vol.claim_name = pvcname

        container = _utils.create_container(name=contname, image="nginx:latest")
        volmount = _utils.create_volume_mount(name=volname, mount_path='/test-persistent')
        container.add_volume_mount(volmount)

        pod = _utils.create_pod(name=podname)
        pod.add_volume(vol)
        pod.add_container(container)

        if _utils.is_reachable(pvc.config):
            try:
                pv.create()
                pvc.create()
                pod.create()
                self.assertIsInstance(pv, K8sPersistentVolume)
                self.assertIsInstance(pvc, K8sPersistentVolumeClaim)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #11
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 = "mnubo-disk1"
        vol_name = "persistent"
        vol_type = "gcePersistentDisk"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.pd_name = pd_name
        volume.read_only = True  # HTTP 422: GCE PD can only be mounted on multiple machines if it is read-only

        mount_name = vol_name
        mount_path = '/test-gce'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container_nginx.add_volume_mount(mount)
        container_redis.add_volume_mount(mount)

        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.desired_replicas = 3

        if _utils.is_reachable(rc.config):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #12
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"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.volume_id = volume_id

        mount_name = vol_name
        mount_path = '/test-aws'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container_nginx.add_volume_mount(mount)
        container_redis.add_volume_mount(mount)

        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.desired_replicas = 3

        if _utils.is_reachable(rc.config):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #13
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.data = {k: v}

        vol_name = "secret"
        vol_type = "secret"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.secret_name = secret_name

        mount_name = vol_name
        mount_path = '/test-secret'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container_nginx.add_volume_mount(mount)
        container_redis.add_volume_mount(mount)

        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.desired_replicas = 1

        if _utils.is_reachable(rc.config):
            secret.create()
            rc.create()
            volnames = [x.name for x in rc.volumes]
            self.assertIn(vol_name, volnames)
Пример #14
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"
        repo = "https://*****:*****@somewhere/repo.git"
        revision = "e42d3dca1541ba085f34ce282feda1109a707c7b"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.git_repository = repo
        volume.git_revision = revision

        mount_name = vol_name
        mount_path = '/test-git'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container_nginx.add_volume_mount(mount)
        container_redis.add_volume_mount(mount)

        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.desired_replicas = 3

        if _utils.is_reachable(rc.config):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #15
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"
        server = "howard.mtl.mnubo.com"
        path = "/fs1/test-nfs"
        volume = _utils.create_volume(name=vol_name, type=vol_type)
        volume.nfs_server = server
        volume.nfs_path = path

        mount_name = vol_name
        mount_path = '/test-nfs'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container_nginx.add_volume_mount(mount)
        container_redis.add_volume_mount(mount)

        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.desired_replicas = 3

        if _utils.is_reachable(rc.config):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Пример #16
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"
        volume = _utils.create_volume(name=vol_name, type=vol_type)

        mount_name = vol_name
        mount_path = '/test-emptydir'
        mount = K8sVolumeMount(name=mount_name, mount_path=mount_path)
        container.add_volume_mount(mount)

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

        if _utils.is_reachable(pod.config):
            pod.create()
            volnames = [x.name for x in pod.volumes]
            self.assertIn(vol_name, volnames)