def init(create_pool_disk_images): # Shorten the reconcile periods and cache period to speed up the tests. Deployer.start_with_args( [ "-j", "-m=2", "-w=10s", "--reconcile-idle-period=500ms", "--reconcile-period=500ms", "--cache-period=1s", ] ) # Create pools ApiClient.pools_api().put_node_pool( MAYASTOR_1, POOL1_UUID, CreatePoolBody(["aio:///host/tmp/{}".format(POOL_DISK1)]), ) ApiClient.pools_api().put_node_pool( MAYASTOR_2, POOL2_UUID, CreatePoolBody(["aio:///host/tmp/{}".format(POOL_DISK2)]), ) # Create and publish a volume on node 1 request = CreateVolumeBody(VolumePolicy(False), NUM_VOLUME_REPLICAS, VOLUME_SIZE) ApiClient.volumes_api().put_volume(VOLUME_UUID, request) ApiClient.volumes_api().put_volume_target(VOLUME_UUID, MAYASTOR_1, Protocol("nvmf")) yield Deployer.stop()
def init(): Deployer.start(num_mayastors=NUM_MAYASTORS) ApiClient.pools_api().put_node_pool( NODE_1_NAME, POOL_1_UUID, CreatePoolBody( ["malloc:///disk?size_mb=50"], labels={ "pool1-specific-key": "pool1-specific-value", "openebs.io/created-by": "msp-operator", }, ), ) ApiClient.pools_api().put_node_pool( NODE_2_NAME, POOL_2_UUID, CreatePoolBody( ["malloc:///disk?size_mb=50"], labels={ "pool2-specific-key": "pool2-specific-value", "openebs.io/created-by": "msp-operator", }, ), ) yield Deployer.stop()
def init(): Deployer.start(1) ApiClient.pools_api().put_node_pool( NODE_NAME, POOL_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"])) ApiClient.volumes_api().put_volume( VOLUME_UUID, CreateVolumeBody(VolumePolicy(False), 1, VOLUME_SIZE)) yield Deployer.stop()
def pool_labels_must_contain_all_the_volume_topology_labels(): """pool labels must contain all the volume topology labels.""" volume = ApiClient.volumes_api().get_volume(VOLUME_UUID) assert (common_labels( volume["spec"]["topology"]["pool_topology"]["labelled"]["inclusion"], ApiClient.pools_api().get_pool(POOL_1_UUID), ) or common_labels( volume["spec"]["topology"]["pool_topology"]["labelled"]["inclusion"], ApiClient.pools_api().get_pool(POOL_2_UUID), )) == len( volume["spec"]["topology"]["pool_topology"]["labelled"]["inclusion"])
def pool_labels_must_contain_all_the_volume_request_topology_labels( create_request): """pool labels must contain all the volume request topology labels.""" assert (common_labels( create_request[CREATE_REQUEST_KEY]["topology"]["pool_topology"] ["labelled"]["inclusion"], ApiClient.pools_api().get_pool(POOL_1_UUID), ) or common_labels( create_request[CREATE_REQUEST_KEY]["topology"]["pool_topology"] ["labelled"]["inclusion"], ApiClient.pools_api().get_pool(POOL_2_UUID), )) == len(create_request[CREATE_REQUEST_KEY]["topology"]["pool_topology"] ["labelled"]["inclusion"])
def init(): Deployer.start(2) ApiClient.pools_api().put_node_pool( NODE1_NAME, POOL1_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"]) ) ApiClient.pools_api().put_node_pool( NODE2_NAME, POOL2_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"]) ) ApiClient.volumes_api().put_volume( VOLUME_UUID, CreateVolumeBody(VolumePolicy(False), 2, 10485761) ) yield Deployer.stop()
def no_of_suitable_pools(volume_pool_topology_labels): pool_labels = [ ApiClient.pools_api().get_pool(POOL_1_UUID)["spec"]["labels"], ApiClient.pools_api().get_pool(POOL_2_UUID)["spec"]["labels"], ] count = 0 for labels in pool_labels: f = True for key in volume_pool_topology_labels: if not (key in labels and volume_pool_topology_labels[key] == labels[key]): f = False if f: count += 1 return count
def check_get_node_capacity(get_nodes_capacity): pool_api = ApiClient.pools_api() for i, p in enumerate([POOL1_UUID, POOL2_UUID]): pool = pool_api.get_pool(p) assert (pool.state.capacity == get_nodes_capacity[i] ), "Node pool size does not match reported node capacity"
def background(): Deployer.start_with_args([ "-j", "-m=3", "-w=10s", "--cache-period=1s", "--mayastor-env=NEXUS_NVMF_ANA_ENABLE=1,NEXUS_NVMF_RESV_ENABLE=1", "--agents-env=TEST_NEXUS_NVMF_ANA_ENABLE=1", ]) ApiClient.pools_api().put_node_pool( POOL_NODE, POOL_UUID, CreatePoolBody(["malloc:///disk?size_mb=100"])) ApiClient.volumes_api().put_volume( VOLUME_UUID, CreateVolumeBody(VolumePolicy(False), 1, VOLUME_SIZE)) volume = ApiClient.volumes_api().put_volume_target(VOLUME_UUID, TARGET_NODE_1, Protocol("nvmf")) yield volume Deployer.stop()
def the_number_of_suitable_pools_is_less_than_the_number_of_desired_volume_replicas( create_request, ): """the number of suitable pools is less than the number of desired volume replicas.""" # Delete the pool so that there aren't enough pools_api = ApiClient.pools_api() pools_api.del_pool(POOL_UUID) num_pools = len(pools_api.get_pools()) num_volume_replicas = create_request[CREATE_REQUEST_KEY]["replicas"] assert num_pools < num_volume_replicas
def no_available_pools_for_replacement_replicas(): """no available pools for replacement replicas.""" pool_api = ApiClient.pools_api() pools = pool_api.get_pools() assert len(pools) == 3 # Delete the additional pool so that a replacement replica cannot be created. pool_api.del_pool(POOL_3_UUID) pools = pool_api.get_pools() assert len(pools) == 2
def init(create_pool_disk_images): # Shorten the reconcile periods and cache period to speed up the tests. Deployer.start_with_args([ "-j", "-m=2", "-w=10s", "--reconcile-idle-period=500ms", "--reconcile-period=500ms", "--cache-period=1s", ]) # Create pools ApiClient.pools_api().put_node_pool( MAYASTOR_2, POOL2_UUID, CreatePoolBody([f"aio:///host/tmp/{POOL_DISK2}"], labels={"node": MAYASTOR_2}), ) yield Deployer.stop()
def the_number_of_volume_replicas_is_less_than_or_equal_to_the_number_of_suitable_pools( create_request, ): """the number of volume replicas is less than or equal to the number of suitable pools.""" num_volume_replicas = create_request[CREATE_REQUEST_KEY]["replicas"] if (hasattr(create_request[CREATE_REQUEST_KEY], "topology") and "pool_topology" in create_request[CREATE_REQUEST_KEY]["topology"]): no_of_pools = no_of_suitable_pools( create_request[CREATE_REQUEST_KEY]["topology"]["pool_topology"] ["labelled"]["inclusion"]) else: # Here we are fetching all pools and comparing its length, because if we reach this part of code # it signifies the volume request has no pool topology labels, thus all pools are suitable no_of_pools = len(ApiClient.pools_api().get_pools()) assert num_volume_replicas <= no_of_pools
def a_control_plane_a_mayastor_instance_and_a_pool(): """a control plane, Mayastor instances and a pool.""" docker_client = docker.from_env() # The control plane comprises the core agents, rest server and etcd instance. for component in ["core", "rest", "etcd"]: Docker.check_container_running(component) # Check all Mayastor instances are running try: mayastors = docker_client.containers.list(all=True, filters={"name": "mayastor"}) except docker.errors.NotFound: raise Exception("No Mayastor instances") for mayastor in mayastors: Docker.check_container_running(mayastor.attrs["Name"]) # Check for a pool pool = ApiClient.pools_api().get_pool(POOL_UUID) assert pool.id == POOL_UUID
def setup(): Deployer.start(2) subprocess.run(["sudo", "chmod", "go+rw", "/var/tmp/csi.sock"], check=True) # Create 2 pools. pool_labels = {"openebs.io/created-by": "msp-operator"} pool_api = ApiClient.pools_api() pool_api.put_node_pool( NODE1, POOL1_UUID, CreatePoolBody(["malloc:///disk?size_mb=128"], labels=pool_labels), ) pool_api.put_node_pool( NODE2, POOL2_UUID, CreatePoolBody(["malloc:///disk?size_mb=128"], labels=pool_labels), ) yield try: pool_api.del_pool(POOL1_UUID) pool_api.del_pool(POOL2_UUID) except: pass Deployer().stop()
def init_resources(): ApiClient.pools_api().put_node_pool( NODE_1_NAME, POOL_1_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"])) ApiClient.pools_api().put_node_pool( NODE_2_NAME, POOL_2_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"])) ApiClient.volumes_api().put_volume( VOLUME_UUID, CreateVolumeBody(VolumePolicy(True), NUM_VOLUME_REPLICAS, VOLUME_SIZE), ) ApiClient.pools_api().put_node_pool( NODE_3_NAME, POOL_3_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"])) # Publish volume so that there is a nexus to add a replica to. volume = ApiClient.volumes_api().put_volume_target(VOLUME_UUID, NODE_1_NAME, Protocol("nvmf")) assert hasattr(volume.spec, "target") assert str(volume.spec.target.protocol) == str(Protocol("nvmf"))
def a_suitable_available_pool(): """a suitable available pool.""" pools = ApiClient.pools_api().get_pools() assert len(pools) == 3
def init(): Deployer.start(1) ApiClient.pools_api().put_node_pool( NODE_NAME, POOL_UUID, CreatePoolBody(["malloc:///disk?size_mb=50"])) yield Deployer.stop()
def csi_plugin_and_rest_api(): # Check REST APi accessibility by listing pools. ApiClient.pools_api().get_pools() return csi_rpc_handle()
def csi_plugin_without_rest_api(stop_start_rest): # Make sure REST API is not accessible anymore. with pytest.raises(Exception) as e: ApiClient.pools_api().get_pools() return csi_rpc_handle()
def two_nodes_with_one_pool_each(): pool_api = ApiClient.pools_api() pool1 = pool_api.get_pool(POOL1_UUID) pool2 = pool_api.get_pool(POOL2_UUID) return [pool1, pool2]
def the_number_of_volume_replicas_is_less_than_or_equal_to_the_number_of_suitable_pools( create_request, ): """the number of volume replicas is less than or equal to the number of suitable pools.""" num_pools = len(ApiClient.pools_api().get_pools()) num_volume_replicas = create_request[CREATE_REQUEST_KEY]["replicas"] assert num_volume_replicas <= num_pools
def suitable_available_pools_with_labels(): """suitable available pools with labels.""" # Since the volume does not contain any topology, # all the pools are suitable candidates for selection assert len(ApiClient.pools_api().get_pools()) != 0