def test_read_only_many_can_read_from_different_pods_and_nodes(self): pvc_name = 'pvc-rox' KubeUtils.create_pvc_and_wait_to_bound(self, pvc_name, TestAccessModes.StorageClass, access_modes=['ReadOnlyMany'], volumeMode='Block') # First Pod Should Succeed pod = KubeUtils.get_block_consumer_pod_template('pod-1-node-1', pvc_name) self.set_pod_node(pod, node_index=1) self.create_pod_with_cleanup(pod) KubeUtils.wait_for_pod_to_be_running(pod['metadata']['name']) # Second Pod on the same Node should Succeed pod = KubeUtils.get_block_consumer_pod_template('pod-2-node-1', pvc_name) self.set_pod_node(pod, node_index=1) self.create_pod_with_cleanup(pod) KubeUtils.wait_for_pod_to_be_running(pod['metadata']['name']) # Third Pod on a different Node should Succeed pod = KubeUtils.get_block_consumer_pod_template('pod-3-node-2', pvc_name) self.set_pod_node(pod, node_index=2) self.create_pod_with_cleanup(pod) KubeUtils.wait_for_pod_to_be_running(pod['metadata']['name'])
def test_block_volume(self): # create the PVC pvc_name = 'test-block-volume' KubeUtils.create_pvc_and_wait_to_bound(self, pvc_name, 'nvmesh-raid10', volumeMode='Block') # Create Consumer pod pod_name = 'block-volume-consumer' pod = KubeUtils.get_block_consumer_pod_template(pod_name, pvc_name) KubeUtils.create_pod(pod) KubeUtils.wait_for_pod_to_be_running(pod_name) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name))
def test_block_volume_extend(self): # Create PVC pvc_name = 'pvc-extend-block' KubeUtils.create_pvc_and_wait_to_bound(self, pvc_name, 'nvmesh-raid10', volumeMode='Block', access_modes=['ReadWriteMany']) # Create Pod pod_name = 'extend-block-consumer' pod = KubeUtils.get_block_consumer_pod_template(pod_name, pvc_name) KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name)) KubeUtils.wait_for_pod_to_be_running(pod_name) # Edit the PVC to increase the volume capacity new_size = '5Gi' pvc_patch = { 'spec': { 'resources': { 'requests': { 'storage': new_size } }, } } logger.info("Extending Volume {}".format(pvc_name)) KubeUtils.patch_pvc(pvc_name, pvc_patch) # verify kuberentes object updated KubeUtils.wait_for_pvc_to_extend(pvc_name, new_size) # wait for NVMesh Volume to show the updated size nvmesh_vol_name = KubeUtils.get_nvmesh_vol_name_from_pvc_name(pvc_name) size_5_gib_in_bytes = 5368709120 NVMeshUtils.wait_for_nvmesh_vol_properties( nvmesh_vol_name, {'capacity': size_5_gib_in_bytes}, self, attempts=15) # check block device size in container (using lsblk) KubeUtils.wait_for_block_device_resize(self, pod_name, nvmesh_vol_name, '5G')
def _check_pods_using_same_pvc_are_on_same_zone(self, storage_class_name): pod_names = set() for i in range(5): pod_names.add('pod-' + str(i)) # create PVC pvc_name = 'topology-single-pvc-' + storage_class_name KubeUtils.create_pvc_with_cleanup(self, pvc_name, storage_class_name, volumeMode='Block') # Create Pods for pod_name in pod_names: pod = KubeUtils.get_block_consumer_pod_template(pod_name, pvc_name) KubeUtils.create_pod(pod) # cleanup def pods_cleanup(): for pod_name in pod_names: KubeUtils.delete_pod(pod_name) for pod_name in pod_names: KubeUtils.wait_for_pod_to_delete(pod_name) self.addCleanup(pods_cleanup) for pod_name in pod_names: KubeUtils.wait_for_pod_to_be_running(pod_name, attempts=15) # collect Pod, Node and Zone data info = self._collect_pods_info(pod_names) # at least 2 different zones all_zones = set() for pod_name, pod_info in info.iteritems(): all_zones.add(pod_info['zone']) print('all_zones = %s' % all_zones) self.assertEqual(len(all_zones), 1)
def _create_multiple_pods_each_with_own_pvc(self, storage_class_name, num_of_pods=6): pod_names = set() pvc_names = set() for i in range(num_of_pods): pod_names.add('pod-' + str(i)) pvc_names.add('pvc-' + str(i)) # create PVCs for pvc_name in pvc_names: KubeUtils.create_pvc_with_cleanup(self, pvc_name, storage_class_name, volumeMode='Block') # Create Pods for i in range(num_of_pods): pod_name = 'pod-' + str(i) pvc_name = 'pvc-' + str(i) pod = KubeUtils.get_block_consumer_pod_template(pod_name, pvc_name) KubeUtils.create_pod(pod) # pods cleanups def cleanup(): for pod_name in pod_names: KubeUtils.delete_pod(pod_name) for pod_name in pod_names: KubeUtils.wait_for_pod_to_delete(pod_name) self.addCleanup(cleanup) for pod_name in pod_names: KubeUtils.wait_for_pod_to_be_running(pod_name, attempts=30) return pod_names
def _create_pod_on_specific_node(self, pod_name, pvc_name, node_index): pod = KubeUtils.get_block_consumer_pod_template(pod_name, pvc_name) pod['spec']['nodeSelector'] = {'worker-index': str(node_index)} KubeUtils.create_pod(pod) self.addCleanup(lambda: KubeUtils.delete_pod_and_wait(pod_name))