Skip to content

Commit

Permalink
feat(tests): add python tests for lvm volume
Browse files Browse the repository at this point in the history
- add python tests for replica operations backed by lvm

Signed-off-by: Tiago Castro <[email protected]>
Co-authored-by: Akhil Mohan <[email protected]>
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro and akhilerm committed Feb 16, 2024
1 parent fba64f9 commit 43eecf0
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 15 deletions.
6 changes: 6 additions & 0 deletions io-engine/src/bin/io-engine-client/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use byte_unit::Byte;
use snafu::{Backtrace, Snafu};
use strum::ParseError;
use tonic::transport::Channel;

use io_engine_api::v0::{
Expand All @@ -23,6 +24,11 @@ pub enum ClientError {
source: tonic::Status,
backtrace: Backtrace,
},
#[snafu(display("gRPC status: {}", source))]
GrpcParseStatus {
source: ParseError,
backtrace: Backtrace,
},
#[snafu(display("Context building error: {}", source))]
ContextCreate {
source: context::Error,
Expand Down
9 changes: 5 additions & 4 deletions io-engine/src/bin/io-engine-client/v1/replica_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{
context::{Context, OutputFormat},
parse_size,
ClientError,
GrpcParseStatus,
GrpcStatus,
};
use byte_unit::Byte;
Expand Down Expand Up @@ -345,11 +346,11 @@ async fn replica_list(
matches: &ArgMatches,
) -> crate::Result<()> {
let pooltype = matches
.get_one::<String>("type")
.get_many::<String>("type")
.unwrap_or_default()
.map(|s| pool_cli::PoolType::from_str(s.as_str()))
.transpose()
.map_err(|e| Status::invalid_argument(e.to_string()))
.context(GrpcStatus)?;
.collect::<Result<Vec<_>, _>>()
.context(GrpcParseStatus)?;
let pooltypes = pooltype
.into_iter()
.map(|t| v1_rpc::pool::PoolType::from(t) as i32)
Expand Down
4 changes: 3 additions & 1 deletion io-engine/src/grpc/v1/replica.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,9 @@ impl ReplicaRpc for ReplicaService {

let mut replicas = vec![];

if args.pooltypes.iter().any(|t| *t == PoolType::Lvs as i32) {
if args.pooltypes.is_empty()
|| args.pooltypes.iter().any(|t| *t == PoolType::Lvs as i32)
{
replicas.extend(Self::list_lvs_replicas().await?);
}
if args.pooltypes.iter().any(|t| *t == PoolType::Lvm as i32) {
Expand Down
7 changes: 5 additions & 2 deletions scripts/pytest-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function run_tests()
(
set -x
report=$(echo "${name}-xunit-report.xml" | tr '/' '-')
python -m pytest --tc-file='test_config.ini' --docker-compose="$name" "$name" --junit-xml="$ROOTDIR/$report"
python -m pytest --tc-file='test_config.ini' --docker-compose="$name" "$name" --junit-xml="$ROOTDIR/$report" $TEST_ARGS
)
elif [ -f "$name" ] || [ -f "${name%::*}" ]
then
Expand All @@ -56,7 +56,7 @@ function run_tests()
base=$(dirname "$name")
( cd "$base"; docker-compose down 2>/dev/null || true )
report=$(echo "$base/${name%.py}-xunit-report.xml" | tr '/' '-')
python -m pytest --tc-file='test_config.ini' --docker-compose="$base" "$name" --junit-xml="$ROOTDIR/$report"
python -m pytest --tc-file='test_config.ini' --docker-compose="$base" "$name" --junit-xml="$ROOTDIR/$report" $TEST_ARGS
)
fi
done
Expand All @@ -71,6 +71,7 @@ fi
pushd "$SRCDIR/test/python" >/dev/null && source ./venv/bin/activate && popd >/dev/null

TEST_LIST=
TEST_ARGS=
while [ "$#" -gt 0 ]; do
case "$1" in
--clean-all)
Expand All @@ -87,6 +88,8 @@ while [ "$#" -gt 0 ]; do
param="$1"
if [ -d "$real_1" ] || [ -f "$real_1" ] || [ -f "${real_1%::*}" ]; then
param="$real_1"
else
TEST_ARGS="${TEST_ARGS:-}$1"
fi
TEST_LIST="$TEST_LIST \n$param"
;;
Expand Down
2 changes: 1 addition & 1 deletion test/python/v1/pool/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ services:
- NEXUS_NVMF_RESV_ENABLE=1
- PATH=${LLVM_SYMBOLIZER_DIR:-}:${LVM_BINS:-}
- ASAN_OPTIONS=detect_leaks=0
- LVM_ENABLE=1
- LVM=true
command: ${SRCDIR}/${IO_ENGINE_DIR}/io-engine -g 0.0.0.0 -l 1,2 -r /tmp/ms0.sock
networks:
mayastor_net:
Expand Down
10 changes: 6 additions & 4 deletions test/python/v1/pool/test_bdd_lvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def create(name, disks, pooltype):
def find_pool(get_mayastor_instance):
def find(name):
for pool in get_mayastor_instance.pool_rpc.ListPools(
pb.ListPoolOptions()
pb.ListPoolOptions()
).pools:
if pool.name == name:
return pool
Expand All @@ -120,14 +120,14 @@ def get_lvm_feature(get_mayastor_instance, get_mayastor_info):

@then("the instance shall report if it supports the LVM feature")
def the_instance_shall_report_if_it_supports_the_lvm_feature(
get_mayastor_instance, get_mayastor_info, get_lvm_feature
get_mayastor_instance, get_mayastor_info, get_lvm_feature
):
assert get_lvm_feature


@when("the user creates a pool specifying a URI representing an loop disk")
def the_user_creates_a_pool_specifying_a_uri_representing_an_loop_disk(
get_mayastor_instance, volgrp_with_losetup_disk, create_pool
get_mayastor_instance, volgrp_with_losetup_disk, create_pool
):
create_pool(f"{volgrp_with_losetup_disk}", [], pb.Lvm)

Expand All @@ -139,7 +139,9 @@ def the_lvm_pool_should_be_created(find_pool):

@when("the user destroys a pool specifying type as lvm")
def the_user_destroys_a_pool_specifying_type_as_lvm(get_mayastor_instance):
get_mayastor_instance.pool_rpc.DestroyPool(pb.DestroyPoolRequest(name="lvmpool", pooltype=pb.Lvm))
get_mayastor_instance.pool_rpc.DestroyPool(
pb.DestroyPoolRequest(name="lvmpool", pooltype=pb.Lvm)
)


@then("the lvm pool should be removed")
Expand Down
4 changes: 3 additions & 1 deletion test/python/v1/pool/test_bdd_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ def pool_creation_should_fail(find_pool):

@then("the pool create command should fail")
def the_pool_create_command_should_fail(create_pool_that_already_exists):
assert create_pool_that_already_exists.value.code() == grpc.StatusCode.ALREADY_EXISTS
assert (
create_pool_that_already_exists.value.code() == grpc.StatusCode.ALREADY_EXISTS
)


@then("the pool destroy command should fail")
Expand Down
14 changes: 12 additions & 2 deletions test/python/v1/replica/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ services:
- MY_POD_IP=10.0.0.2
- NEXUS_NVMF_ANA_ENABLE=1
- NEXUS_NVMF_RESV_ENABLE=1
- PATH=${LLVM_SYMBOLIZER_DIR:-}
- PATH=${LLVM_SYMBOLIZER_DIR:-}:${LVM_BINS:-}
- ASAN_OPTIONS=detect_leaks=0
command: ${SRCDIR}/${IO_ENGINE_DIR}/io-engine -g 0.0.0.0 -l 1 -r /tmp/ms0.sock
- LVM=true
- RUST_LOG=debug
command: ${SRCDIR}/${IO_ENGINE_DIR}/io-engine -g 0.0.0.0 -l 1 -r /tmp/ms0.sock --reactor-freeze-detection
networks:
mayastor_net:
ipv4_address: 10.0.0.2
Expand All @@ -32,6 +34,14 @@ services:
- /dev/hugepages:/dev/hugepages
- /tmp:/tmp
- /var/tmp:/var/tmp
- /dev:/dev
- /run/udev:/run/udev
privileged: true
devices:
- /dev/loop0
- /dev/loop1
- /dev/loop2
ipc: "host"
networks:
mayastor_net:
name: mayastor_net
Expand Down
20 changes: 20 additions & 0 deletions test/python/v1/replica/features/lvm_replica.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: LVM replica support

Background:
Given a mayastor instance "ms0"
And an LVM VG backed pool called "lvmpool"

Scenario: Creating an lvm volume on an imported lvm volume group
When a user calls the createreplica on pool "lvmpool"
Then an lv should be created on the lvmpool

Scenario: Destroying a replica backed by lvm pool
Given an LVM backed replica
When a user calls destroy replica
Then the replica gets destroyed

Scenario: Listing replicas from either an LVS or LVM pool
Given an LVS pool with a replica
And an LVM backed replica
When a user calls list replicas
Then all replicas should be listed
Loading

0 comments on commit 43eecf0

Please sign in to comment.