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)
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): k8s_service.create() k8s_rc.create() self.assertIsInstance(k8s_service, K8sService) self.assertIsInstance(k8s_rc, K8sReplicationController)
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)
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)
def test_rc_hostpath_list(self): volumes = [ {"hostPath": {"path": "/root/.dockercfg"}, "name": "dockercred"}, {"hostPath": {"path": "/usr/bin/docker"}, "name": "dockerbin"}, {"hostPath": {"path": "/var/run/docker.sock"}, "name": "dockersock"}, {"hostPath": {"path": "/root/.docker"}, "name": "dockerconfig"}, ] rc = _utils.create_rc(name="admintool") for vol in volumes: keys = list(filter(lambda x: x != "name", vol.keys())) v = K8sVolume(name=vol["name"], type=keys[0],) dico = vol[keys[0]] if dico is not None: v.path = dico["path"] rc.add_volume(v) self.assertEqual(len(volumes), len(rc.volumes)) for i in range(0, len(volumes)): self.assertEqual(volumes[i]["name"], rc.volumes[i].name) self.assertEqual(volumes[i]["hostPath"]["path"], rc.volumes[i].hostPath.path)
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)
def test_rc_hostpath_list(self): volumes = [{ 'hostPath': { 'path': '/root/.dockercfg' }, 'name': 'dockercred' }, { 'hostPath': { 'path': '/usr/bin/docker' }, 'name': 'dockerbin' }, { 'hostPath': { 'path': '/var/run/docker.sock' }, 'name': 'dockersock' }, { 'hostPath': { 'path': '/root/.docker' }, 'name': 'dockerconfig' }] rc = _utils.create_rc(name="admintool") for vol in volumes: keys = list(filter(lambda x: x != 'name', vol.keys())) v = K8sVolume( name=vol['name'], type=keys[0], ) dico = vol[keys[0]] if dico is not None: v.path = dico['path'] rc.add_volume(v) self.assertEqual(len(volumes), len(rc.volumes)) for i in range(0, len(volumes)): self.assertEqual(volumes[i]['name'], rc.volumes[i].name) self.assertEqual(volumes[i]['hostPath']['path'], rc.volumes[i].hostPath.path)
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)
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)