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)
Example #2
0
def create_pvc(config=None, name=None):
    if config is None:
        config = create_config()
    obj = K8sPersistentVolumeClaim(
        config=config,
        name=name
    )
    return obj
Example #3
0
def cleanup_pvc():
    ref = create_pvc(name="throwaway")
    if is_reachable(ref.config.api_host):
        _list = ref.list()
        while len(_list) > 0:
            for c in _list:
                try:
                    claim = K8sPersistentVolumeClaim(config=ref.config, name=c['metadata']['name']).get()
                    claim.delete()
                except NotFoundException:
                    continue
            _list = ref.list()
Example #4
0
 def test_init_invalid_name(self):
     name = object()
     config = utils.create_config()
     with self.assertRaises(SyntaxError):
         K8sPersistentVolumeClaim(config=config, name=name)
Example #5
0
 def test_init_no_args(self):
     config = utils.create_config()
     with self.assertRaises(SyntaxError):
         K8sPersistentVolumeClaim(config=config)