Skip to content

Commit 26e2f05

Browse files
committed
Automated nbdkit data plugin supports base64 in format strings
Signed-off-by: Ganesh Hubale <ghubale@redhat.com>
1 parent 9562eb2 commit 26e2f05

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

v2v/tests/cfg/nbdkit/nbdkit.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@
165165
- constraints:
166166
checkpoint = "blocksize_constraints"
167167
expected_fields = "block_size_preferred block_size_maximum block_size_minimum"
168+
- data:
169+
only source_none..dest_none
170+
version_required = "[nbdkit-1.46,)"
171+
checkpoint = "test_data_plugin_supports_base64_in_format_string"
172+
variants:
173+
- positive_test:
174+
test_state= 'positive'
175+
- negative_test:
176+
test_state= 'negative'
177+
expected_err_msg= 'Base64 decoding error.'
168178
- run:
169179
checkpoint = 'has_run_againt_vddk'
170180
vpx_passwd_file = "/tmp/v2v_vpx_passwd"

v2v/tests/src/nbdkit/nbdkit.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,33 @@ def test_nbdkit_instance_name():
809809
# Force kill if it's being stubborn
810810
p.kill()
811811

812+
def test_data_plugin_supports_base64_in_format_string():
813+
import base64
814+
test_state = params_get(params, "test_state")
815+
if test_state == "positive":
816+
# Prepare the data
817+
original_text = b"nbdkit-test123"
818+
# Encode bytes to a base64 string
819+
b64_input = base64.b64encode(original_text).decode()
820+
cmd_str = f"nbdkit -U - data \'base64:{b64_input}\' --run 'nbdcopy $uri -'"
821+
# Execute command
822+
result = process.run(cmd_str, shell=True, ignore_status=True)
823+
# Result.stdout contains the raw binary output from nbdcopy
824+
cmd_output = result.stdout
825+
if original_text not in cmd_output:
826+
test.fail(f"Base64 decoding failed. Expected {original_text!r}, got {cmd_output!r}")
827+
elif test_state == "negative":
828+
# Negative scenario - Check with invalid value
829+
invalid_b64 = "base64:SGVsbG8@@@"
830+
cmd_str = f"nbdkit -U - data \'{invalid_b64}\' --run 'nbdcopy $uri -'"
831+
# Execute command
832+
result = process.run(cmd_str, shell=True, ignore_status=True)
833+
# Verify the error message
834+
cmd_output = result.stderr_text
835+
err_msg = params_get(params, "expected_err_msg")
836+
if err_msg not in cmd_output:
837+
test.fail(f"Error message - \'{err_msg}\' not appeared.")
838+
812839
if version_required and not multiple_versions_compare(
813840
version_required):
814841
test.cancel("Testing requires version: %s" % version_required)
@@ -889,5 +916,7 @@ def test_nbdkit_instance_name():
889916
check_blocksize_constraints()
890917
elif checkpoint == 'test_nbdkit_instance_name':
891918
test_nbdkit_instance_name()
919+
elif checkpoint == 'test_data_plugin_supports_base64_in_format_string':
920+
test_data_plugin_supports_base64_in_format_string()
892921
else:
893922
test.error('Not found testcase: %s' % checkpoint)

0 commit comments

Comments
 (0)