def migration_confirm_test(clients, volume_name, base_image=""): # NOQA client = get_random_client(clients) hosts = clients.keys() host1 = hosts[0] host2 = hosts[1] volume = client.create_volume(name=volume_name, size=SIZE, numberOfReplicas=REPLICA_COUNT, baseImage=base_image) volume = common.wait_for_volume_detached(client, volume_name) volume.attach(hostId=host1) volume = common.wait_for_volume_healthy(client, volume_name) volume = volume.migrationStart(nodeId=host2) attached_nodes = get_volume_attached_nodes(volume) assert host1 in attached_nodes assert volume["migrationNodeID"] == host2 with pytest.raises(Exception) as e: volume.migrationConfirm() assert "migration is not ready" in str(e.value) volume = common.wait_for_volume_migration_ready(client, volume_name) volume = volume.migrationConfirm() volume = common.wait_for_volume_migration_node(client, volume_name, host2) assert volume["migrationNodeID"] == "" volume = volume.detach() volume = common.wait_for_volume_detached(client, volume_name) client.delete(volume) wait_for_volume_delete(client, volume_name)
def migration_rollback_test(clients, volume_name, base_image=""): # NOQA client = get_random_client(clients) hosts = clients.keys() host1 = hosts[0] host2 = hosts[1] volume = client.create_volume(name=volume_name, size=SIZE, numberOfReplicas=REPLICA_COUNT, baseImage=base_image) volume = common.wait_for_volume_detached(client, volume_name) volume.attach(hostId=host1) volume = common.wait_for_volume_healthy(client, volume_name) volume = volume.migrationStart(nodeId=host2) attached_nodes = get_volume_attached_nodes(volume) assert host1 in attached_nodes assert volume["migrationNodeID"] == host2 volume = common.wait_for_volume_migration_ready(client, volume_name) volume = volume.migrationRollback() volume = common.wait_for_volume_migration_node(client, volume_name, host1) assert volume["migrationNodeID"] == "" volume = volume.detach() volume = common.wait_for_volume_detached(client, volume_name) client.delete(volume) wait_for_volume_delete(client, volume_name)
def test_setting_default_replica_count(clients, volume_name): # NOQA client = get_random_client(clients) setting = client.by_id_setting(common.SETTING_DEFAULT_REPLICA_COUNT) old_value = setting["value"] setting = client.update(setting, value="5") volume = client.create_volume(name=volume_name, size=SIZE) volume = common.wait_for_volume_detached(client, volume_name) assert len(volume["replicas"]) == int(setting.value) client.delete(volume) wait_for_volume_delete(client, volume_name) setting = client.update(setting, value=old_value)
def test_volume_scheduling_failure(clients, volume_name): # NOQA ''' Test fail to schedule by disable scheduling for all the nodes Also test cannot attach a scheduling failed volume ''' client = get_random_client(clients) nodes = client.list_node() assert len(nodes) > 0 for node in nodes: node = client.update(node, allowScheduling=False) node = common.wait_for_node_update(client, node["id"], "allowScheduling", False) volume = client.create_volume(name=volume_name, size=SIZE, numberOfReplicas=3) volume = common.wait_for_volume_condition_scheduled(client, volume_name, "status", CONDITION_STATUS_FALSE) volume = common.wait_for_volume_detached(client, volume_name) self_node = get_self_host_id() with pytest.raises(Exception) as e: volume.attach(hostId=self_node) assert "not scheduled" in str(e.value) for node in nodes: node = client.update(node, allowScheduling=True) node = common.wait_for_node_update(client, node["id"], "allowScheduling", True) volume = common.wait_for_volume_condition_scheduled(client, volume_name, "status", CONDITION_STATUS_TRUE) volume = common.wait_for_volume_detached(client, volume_name) volume = volume.attach(hostId=self_node) volume = common.wait_for_volume_healthy(client, volume_name) endpoint = get_volume_endpoint(volume) assert endpoint != "" volume_rw_test(endpoint) volume = volume.detach() volume = common.wait_for_volume_detached(client, volume_name) client.delete(volume) wait_for_volume_delete(client, volume_name)
def setup_migration_test(clients, volume_name, backing_image=""): # NOQA """ Creates a new migratable volume then attaches it to the current node to write some test data on it. """ client = get_random_client(clients) volume = client.create_volume(name=volume_name, size=SIZE, numberOfReplicas=REPLICA_COUNT, backingImage=backing_image, accessMode="rwx", migratable=True) volume = common.wait_for_volume_detached(client, volume_name) volume.attach(hostId=common.get_self_host_id()) volume = common.wait_for_volume_healthy(client, volume_name) # write test data data = common.write_volume_random_data(volume) common.check_volume_data(volume, data) volume.detach(hostId="") volume = common.wait_for_volume_detached(client, volume_name) return client, volume, data
def test_volume_multinode(clients, volume_name): # NOQA hosts = clients.keys() volume = get_random_client(clients).create_volume(name=volume_name, size=SIZE, numberOfReplicas=2) volume = common.wait_for_volume_detached(get_random_client(clients), volume_name) for host_id in hosts: volume = volume.attach(hostId=host_id) volume = common.wait_for_volume_healthy(get_random_client(clients), volume_name) engine = get_volume_engine(volume) assert engine["hostId"] == host_id volume = volume.detach() volume = common.wait_for_volume_detached(get_random_client(clients), volume_name) get_random_client(clients).delete(volume) wait_for_volume_delete(get_random_client(clients), volume_name) volumes = get_random_client(clients).list_volume() assert len(volumes) == 0
def test_settings(clients): # NOQA client = get_random_client(clients) setting_names = [ common.SETTING_BACKUP_TARGET, common.SETTING_BACKUP_TARGET_CREDENTIAL_SECRET, common.SETTING_STORAGE_OVER_PROVISIONING_PERCENTAGE, common.SETTING_STORAGE_MINIMAL_AVAILABLE_PERCENTAGE, common.SETTING_DEFAULT_REPLICA_COUNT ] settings = client.list_setting() settingMap = {} for setting in settings: settingMap[setting["name"]] = setting for name in setting_names: assert settingMap[name] is not None assert settingMap[name]["definition"]["description"] is not None for name in setting_names: setting = client.by_id_setting(name) assert settingMap[name]["value"] == setting["value"] old_value = setting["value"] if name == common.SETTING_STORAGE_OVER_PROVISIONING_PERCENTAGE: with pytest.raises(Exception) as e: client.update(setting, value="-100") assert "with invalid "+name in \ str(e.value) with pytest.raises(Exception) as e: client.update(setting, value="testvalue") assert "with invalid "+name in \ str(e.value) setting = client.update(setting, value="200") assert setting["value"] == "200" setting = client.by_id_setting(name) assert setting["value"] == "200" elif name == common.SETTING_STORAGE_MINIMAL_AVAILABLE_PERCENTAGE: with pytest.raises(Exception) as e: client.update(setting, value="300") assert "with invalid "+name in \ str(e.value) with pytest.raises(Exception) as e: client.update(setting, value="-30") assert "with invalid "+name in \ str(e.value) with pytest.raises(Exception) as e: client.update(setting, value="testvalue") assert "with invalid "+name in \ str(e.value) setting = client.update(setting, value="30") assert setting["value"] == "30" setting = client.by_id_setting(name) assert setting["value"] == "30" elif name == common.SETTING_BACKUP_TARGET: with pytest.raises(Exception) as e: client.update(setting, value="testvalue$test") assert "with invalid "+name in \ str(e.value) setting = client.update(setting, value="nfs://test") assert setting["value"] == "nfs://test" setting = client.by_id_setting(name) assert setting["value"] == "nfs://test" elif name == common.SETTING_BACKUP_TARGET_CREDENTIAL_SECRET: setting = client.update(setting, value="testvalue") assert setting["value"] == "testvalue" setting = client.by_id_setting(name) assert setting["value"] == "testvalue" elif name == common.SETTING_DEFAULT_REPLICA_COUNT: with pytest.raises(Exception) as e: client.update(setting, value="-1") assert "with invalid "+name in \ str(e.value) with pytest.raises(Exception) as e: client.update(setting, value="testvalue") assert "with invalid "+name in \ str(e.value) with pytest.raises(Exception) as e: client.update(setting, value="21") assert "with invalid "+name in \ str(e.value) setting = client.update(setting, value="2") assert setting["value"] == "2" setting = client.by_id_setting(name) assert setting["value"] == "2" setting = client.update(setting, value=old_value) assert setting["value"] == old_value