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)
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
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()
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)
def test_init_no_args(self): config = _utils.create_config() with self.assertRaises(SyntaxError): K8sPersistentVolume(config=config)