def test_static_provisioning(self): # Create NVMesh Volume nvmesh_volume_name = "csi-testing-static-prov" volume = Volume( name=nvmesh_volume_name, RAIDLevel=RAIDLevels.STRIPED_AND_MIRRORED_RAID_10, VPG='DEFAULT_RAID_10_VPG', capacity=5 * GiB, description="Volume for CSI Driver Static Provisioning") err, out = NVMeshUtils.getVolumeAPI().save([volume]) self.assertIsNone(err, 'Error Creating NVMesh Volume. %s' % err) create_res = out[0] self.assertTrue( create_res['success'], 'Error Creating NVMesh Volume. %s' % create_res['error']) self.addCleanup(lambda: NVMeshUtils.getVolumeAPI().delete([volume])) # Create PV pv_name = 'pv-name-in-k8s' accessModes = ['ReadWriteOnce'] volume_size = '5Gi' sc_name = 'nvmesh-raid10' pv = KubeUtils.get_pv_for_static_provisioning(pv_name, nvmesh_volume_name, accessModes, sc_name, volume_size) core_api.create_persistent_volume(pv) self.addCleanup(lambda: core_api.delete_persistent_volume(pv_name)) pv_list = core_api.list_persistent_volume( field_selector='metadata.name={}'.format(pv_name)) self.assertIsNotNone(pv_list) self.assertTrue(len(pv_list.items)) self.assertEqual(pv_list.items[0].metadata.name, pv_name) # Create PVC pvc_name = 'pvc-static-prov' KubeUtils.create_pvc_and_wait_to_bound(self, pvc_name, sc_name, access_modes=accessModes, storage=volume_size, volumeMode='Block') self.addCleanup(lambda: KubeUtils.delete_pvc(pvc_name)) # Create Consumer pod pod_name = 'pod-static-prov' cmd = 'echo hello ; while true ; do sleep 60; done' pod = KubeUtils.get_shell_pod_template(pod_name, pvc_name, cmd, volume_mode_block=True) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name)) KubeUtils.wait_for_pod_to_be_running(pod_name)
def test_mixed_access_modes(self): # This test creates a PV with reclaimPolicy: Retain (making sure it is not deleted when the bounded PVC is deleted) # Then will create PVC's with different AccessModes to use the same PV. in between some PV clean needs to be done. # Create Storage Class with reclaimPolicy: Retain sc_name = 'sc-nvmesh-retain' KubeUtils.create_storage_class(sc_name, {'vpg': 'DEFAULT_RAID_10_VPG'}, reclaimPolicy='Retain') self.addCleanup(lambda: KubeUtils.delete_storage_class(sc_name)) # Create NVMesh Volume nvmesh_volume_name = "vol1" volume = Volume( name=nvmesh_volume_name, RAIDLevel=RAIDLevels.STRIPED_AND_MIRRORED_RAID_10, VPG='DEFAULT_RAID_10_VPG', capacity=5 * GiB, description="Volume for CSI Driver Static Provisioning") err, out = NVMeshUtils.getVolumeAPI().save([volume]) self.assertIsNone(err, 'Error Creating NVMesh Volume. %s' % err) create_res = out[0] self.assertTrue( create_res['success'], 'Error Creating NVMesh Volume. %s' % create_res['error']) self.addCleanup(lambda: NVMeshUtils.getVolumeAPI().delete([volume])) # Create PV pv_name = 'csi-testing-pv-vol1' volume_size = '5Gi' self.create_pv_for_static_prov(nvmesh_volume_name, pv_name, sc_name, volume_size) # Create PVC with accessMode ReadWriteOnce pvc_name = 'pvc-rwo' KubeUtils.create_pvc_and_wait_to_bound(self, pvc_name, sc_name, access_modes=['ReadWriteOnce'], storage=volume_size, volumeMode='Filesystem') self.addCleanup(lambda: KubeUtils.delete_pvc(pvc_name)) # Create Pod to create a file on the File System pod_name = 'pod-file-writer' cmd = 'echo hello > /vol/file1' pod = KubeUtils.get_shell_pod_template(pod_name, pvc_name, cmd) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name)) KubeUtils.wait_for_pod_to_complete(pod_name) KubeUtils.delete_pod_and_wait(pod_name) # Delete the PVC KubeUtils.delete_pvc(pvc_name) KubeUtils.wait_for_pv_to_be_released(pv_name) # Make PV Available for the next PVC (by removing claimRef field from the PV ==OR== deleting and recreating the PV) KubeUtils.delete_pv(pv_name) KubeUtils.wait_for_pv_to_delete(pv_name) self.create_pv_for_static_prov(nvmesh_volume_name, pv_name, sc_name, volume_size) # Create PVC With ReadOnlyMany pvc_name = 'pvc-rox' KubeUtils.create_pvc_and_wait_to_bound(self, pvc_name, sc_name, access_modes=['ReadOnlyMany'], storage=volume_size, volumeMode='Filesystem') self.addCleanup(lambda: KubeUtils.delete_pvc(pvc_name)) # 7. Create 2 Pods that will read the File System - Should Succeed pod1_name = 'pod-file-reader1' cmd = 'cat /vol/file1' pod = KubeUtils.get_shell_pod_template(pod1_name, pvc_name, cmd) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod1_name)) pod2_name = 'pod-file-reader2' pod = KubeUtils.get_shell_pod_template(pod2_name, pvc_name, cmd) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod2_name)) KubeUtils.wait_for_pod_to_complete(pod2_name) # 8. Create 1 Pod that will try to write to the FileSystem - Should Fail pod_name = 'pod-file-writer' cmd = 'echo hello > /vol/file1' pod = KubeUtils.get_shell_pod_template(pod_name, pvc_name, cmd) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name)) KubeUtils.wait_for_pod_to_fail(pod_name)
def _run_shell_pod(self, pod_name, pvc_name, cmd, attempts=60): pod = KubeUtils.get_shell_pod_template(pod_name, pvc_name, cmd) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name)) KubeUtils.wait_for_pod_to_complete(pod_name, attempts=attempts)