示例#1
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)
示例#2
0
    def test_pod_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 = 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.add_volume_mount(volume)

        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.api_host):
            try:
                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)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
示例#3
0
    def test_pod_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 = 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)
        volume.set_pd_name(pd_name)
        container.add_volume_mount(volume)

        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.api_host):
            try:
                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)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
示例#4
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"
        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.add_volume_mount(volume)

        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.api_host):
            try:
                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)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
示例#5
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"
        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.add_volume_mount(volume)

        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.api_host):
            try:
                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)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
示例#6
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)