コード例 #1
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_update_add_container_fails(self):
     cont_names = ["yocontainer", "yocontainer2"]
     container = utils.create_container(name=cont_names[0])
     pod_name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=pod_name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         container = utils.create_container(name=cont_names[1])
         pod.add_container(container)
         try:
             pod.update()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, UnprocessableEntityException)
コード例 #2
0
 def test_update_container_image_keep_env_vars(self):
     name = "yodep-{0}".format(str(uuid.uuid4()))
     dep = utils.create_deployment(name=name)
     cont_name = "nginx"
     cont_image = "nginx:1.7.9"
     new_image = "nginx:1.10.3"
     env_var_name = "YoVariable"
     cont = utils.create_container(name=cont_name, image=cont_image)
     cont.add_env(name=env_var_name, value=name)
     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()
         # Change the container image
         dep.container_image = (cont_name, new_image)
         # Update the deployment
         dep.update()
         # Refresh whatever we have.
         dep.get()
         for c in dep.containers:
             self.assertIsInstance(c, K8sContainer)
             if c.name == cont_name:
                 self.assertEqual(c.image, new_image)
                 self.assertEqual(c.env[0].name, env_var_name)
                 self.assertEqual(c.env[0].value, name)
コード例 #3
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.api_host):
            pod.create()
            volnames = [x.name for x in pod.volumes]
            self.assertIn(vol_name, volnames)
コード例 #4
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.api_host):
            secret.create()
            pod.create()
            volnames = [x.name for x in pod.volumes]
            self.assertIn(vol_name, volnames)
コード例 #5
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.api_host):
            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_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.api_host):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #7
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-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.api_host):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #8
0
    def test_myweb_start(self):

        # create a myweb service
        svc = utils.create_service(name="myweb")
        self.assertIsInstance(svc, K8sService)
        svc.selector = {'name': 'myweb'}
        svc.type = 'NodePort'
        svc.add_port(
            name="tcp31030",
            port=31030,
            target_port="tcp31030",
            protocol="tcp",
            node_port=8030
        )

        # create a myweb replication controller
        container = utils.create_container(name="myweb", image="nginx:latest")
        container.add_port(
            container_port=80,
            host_port=31030,
            name="tcp31030",
            protocol="tcp"
        )
        rc = utils.create_rc(name="myweb", replicas=2)
        rc.add_container(container)

        # create the API resources
        if utils.is_reachable(rc.config.api_host):
            svc.create()
            rc.create()
            pass
コード例 #9
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.api_host):
            try:
                pod.create()
                volnames = [x.name for x in pod.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #10
0
    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.api_host):
            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_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.api_host):
            try:
                pv.create()
                pvc.create()
                pod.create()
                self.assertIsInstance(pv, K8sPersistentVolume)
                self.assertIsInstance(pvc, K8sPersistentVolumeClaim)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #12
0
 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)
コード例 #13
0
    def test_containers(self):
        c_name = "redis"
        c_image = "redis:latest"
        c_image_2 = "redis:3.2.3"
        container = utils.create_container(name=c_name, image=c_image)
        name = "job-{}".format(uuid.uuid4())

        cj = utils.create_cronjob(name=name)
        cj.add_container(container)
        self.assertEqual(1, len(cj.containers))
        self.assertIn(c_name, cj.container_image)
        self.assertEqual(c_image, cj.container_image[c_name])

        container = utils.create_container(name=c_name, image=c_image_2)
        cj.add_container(container)
        self.assertEqual(1, len(cj.containers))
        self.assertEqual(c_image_2, cj.container_image[c_name])
コード例 #14
0
 def test_add_env(self):
     cont = Container(utils.myweb_container())
     k8s_container = utils.create_container(name=cont.name)
     k8s_container.model = cont
     envs = utils.myweb_envs()
     for k, v in envs.items():
         k8s_container.add_env(k, v)
     self.assertEqual(4, len(k8s_container.env))
コード例 #15
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_is_ready(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         p = pod.create()
         self.assertTrue(p.is_ready())
コード例 #16
0
 def test_server_version_no_kubeconfig(self):
     api_host = "127.0.0.1:8001"
     cfg = K8sConfig(kubeconfig=None, api_host=api_host)
     if utils.is_reachable(cfg.api_host):
         container = utils.create_container(name="nginx", image="nginx:latest")
         cj = utils.create_cronjob(config=cfg, name="test")
         cj.add_container(container)
         cj.create()
         self.assertIsInstance(cj, K8sCronJob)
コード例 #17
0
 def test_is_ready(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         p = pod.create()
         self.assertTrue(p.is_ready())
コード例 #18
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.api_host):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #19
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.api_host):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #20
0
 def test_list(self):
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     container = utils.create_container(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         _list = pod.list()
         for x in _list:
             self.assertIsInstance(x, K8sPod)
コード例 #21
0
 def test_get_by_name(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         pods = K8sPod.get_by_name(config=pod.config, name=name)
         self.assertIsInstance(pods, list)
         self.assertEqual(1, len(pods))
コード例 #22
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_get_by_labels(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         pods = K8sPod.get_by_labels(config=pod.config, labels={'name': name})
         self.assertIsInstance(pods, list)
         self.assertEqual(1, len(pods))
コード例 #23
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_delete(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         utils.cleanup_pods()
         result = pod.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
コード例 #24
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.namespace = nspace
         with self.assertRaises(BadRequestException):
             dep.update()
コード例 #25
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_get(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         from_create = pod.create()
         from_get = pod.get()
         self.assertIsInstance(from_create, K8sPod)
         self.assertIsInstance(from_get, K8sPod)
         self.assertEqual(from_create, from_get)
コード例 #26
0
 def test_get(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         from_create = pod.create()
         from_get = pod.get()
         self.assertIsInstance(from_create, K8sPod)
         self.assertIsInstance(from_get, K8sPod)
         self.assertEqual(from_create, from_get)
コード例 #27
0
 def test_create_already_exists(self):
     name = "yocontainer"
     c = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(c)
     if utils.is_reachable(pod.config.api_host):
         with self.assertRaises(AlreadyExistsException):
             result = pod.create()
             self.assertIsInstance(result, K8sPod)
             self.assertEqual(pod, result)
             pod.create()
コード例 #28
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.desired_replicas = 1
     if utils.is_reachable(dep.config.api_host):
         dep.create()
         with self.assertRaises(AlreadyExistsException):
             dep.create()
コード例 #29
0
 def test_delete(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         utils.cleanup_pods()
         result = pod.list()
         self.assertIsInstance(result, list)
         self.assertEqual(0, len(result))
コード例 #30
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(NotFoundException):
             dep.update()
コード例 #31
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))
コード例 #32
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.api_host):
            secret.create()
            rc.create()
            volnames = [x.name for x in rc.volumes]
            self.assertIn(vol_name, volnames)
コード例 #33
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.api_host):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #34
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])
コード例 #35
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_get_pod_status(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         p = pod.create()
         time.sleep(3)  # let creation happen
         result = p.get_status()
         self.assertIsInstance(result, PodStatus)
         for i in ['conditions', 'containerStatuses', 'hostIP', 'phase', 'podIP', 'startTime']:
             self.assertIn(i, result.model)
コード例 #36
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.api_host):
            try:
                rc.create()
                volnames = [x.name for x in rc.volumes]
                self.assertIn(vol_name, volnames)
            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
コード例 #37
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_create_already_exists(self):
     name = "yocontainer"
     c = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod = utils.create_pod(name=name)
     pod.add_container(c)
     if utils.is_reachable(pod.config.api_host):
         try:
             result = pod.create()
             self.assertIsInstance(result, K8sPod)
             self.assertEqual(pod, result)
             pod.create()
         except Exception as err:
             self.assertIsInstance(err, AlreadyExistsException)
コード例 #38
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_list_multiple(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     config = K8sConfig(kubeconfig=utils.kubeconfig_fallback)
     pods = []
     count = 3
     if utils.is_reachable(config.api_host):
         for i in range(0, count):
             name = "yopod-{0}".format(str(uuid.uuid4()))
             pod = utils.create_pod(config, name)
             pod.add_container(container)
             result = pod.create()
             self.assertIsInstance(result, K8sPod)
             self.assertEqual(pod, result)
             pods.append(pod)
         self.assertEqual(count, len(pods))
コード例 #39
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_update_labels(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     pod1 = utils.create_pod(name=name)
     pod1.add_container(container)
     if utils.is_reachable(pod1.config.api_host):
         pod1.create()
         labels = pod1.get_labels()
         labels['yomama'] = 'sofat'
         pods = K8sPod.get_by_labels(config=pod1.config, labels=labels)
         self.assertIsInstance(pods, list)
         self.assertEqual(0, len(pods))
         pod1.set_labels(labels)
         pod1.update()
         pods = K8sPod.get_by_labels(config=pod1.config, labels=labels)
         self.assertIsInstance(pods, list)
         self.assertEqual(1, len(pods))
コード例 #40
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_update_name_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name1 = "yopod1"
     name2 = "yopod2"
     pod = utils.create_pod(name=name1)
     pod.add_container(container)
     if utils.is_reachable(pod.config.api_host):
         pod.create()
         result = K8sPod.get_by_name(config=pod.config, name=name1)
         self.assertIsInstance(result, list)
         self.assertEqual(1, len(result))
         self.assertIsInstance(result[0], K8sPod)
         result[0].name = name2
         try:
             result[0].update()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, BadRequestException)
コード例 #41
0
ファイル: test_k8s_pod.py プロジェクト: mnubo/kubernetes-py
 def test_update_namespace_fails(self):
     name = "yocontainer"
     container = utils.create_container(name=name)
     name = "yopod-{0}".format(str(uuid.uuid4()))
     nspace = "yonamespace"
     pod1 = utils.create_pod(name=name)
     pod1.add_container(container)
     if utils.is_reachable(pod1.config.api_host):
         pod1.create()
         result = K8sPod.get_by_name(config=pod1.config, name=name)
         self.assertIsInstance(result, list)
         self.assertEqual(1, len(result))
         pod2 = result[0]
         self.assertIsInstance(pod2, K8sPod)
         self.assertNotEqual(pod2.get_namespace(), nspace)
         self.assertEqual(pod1, pod2)
         pod2.set_namespace(nspace)
         try:
             pod2.update()
             self.fail("Should not fail.")
         except Exception as err:
             self.assertIsInstance(err, BadRequestException)