def test_api_create_hostpath_minikube(self):
        cfg = _utils.create_config()

        if _utils.is_reachable(cfg):
            pv = K8sPersistentVolume(
                name="pv-mysql",
                type="hostPath")
            try:
                pv.get()
            except NotFoundException:
                pv.capacity = {"storage": "512Mi"}
                pv.access_modes = ["ReadWriteOnce"]
                pv.reclaim_policy = "Delete"
                pv.path = "/tmp/mysql/data"
                pv.storage_class_name = "manual"
                pv.add_label('type', 'local')
                print("** creating mysql persistent volume...")
                pv.create()

            pvc = K8sPersistentVolumeClaim(
                config=cfg,
                name="pvc-mysql")
            try:
                pvc.get()
            except NotFoundException:
                pvc.storage_class_name = "manual"
                pvc.access_modes = ['ReadWriteOnce']
                pvc.resources = {'requests': {'storage': '512Mi'}}
                print("** creating mysql persistent volume claim...")
                pvc.create()

            self.assertIsInstance(pv, K8sPersistentVolume)
            self.assertIsInstance(pvc, K8sPersistentVolumeClaim)
示例#2
0
def create_pv(config=None, name=None, type=None):
    if config is None:
        config = create_config()
    obj = K8sPersistentVolume(
        config=config,
        name=name,
        type=type,
    )
    return obj
示例#3
0
def cleanup_pv():
    ref = create_pv(name="throwaway", type="hostPath")
    if is_reachable(ref.config.api_host):
        _list = ref.list()
        while len(_list) > 0:
            for v in _list:
                try:
                    vol = K8sPersistentVolume(config=ref.config, name=v['metadata']['name'], type=ref.type).get()
                    vol.delete()
                except NotFoundException:
                    continue
            _list = ref.list()
示例#4
0
 def test_init_invalid_type(self):
     name = "yoname"
     _type = object()
     config = _utils.create_config()
     with self.assertRaises(SyntaxError):
         K8sPersistentVolume(config=config, name=name, type=_type)
示例#5
0
 def test_init_no_args(self):
     config = _utils.create_config()
     with self.assertRaises(SyntaxError):
         K8sPersistentVolume(config=config)