The RMR change to support routing based on the MEID (
190665fe)
broke the related unit tests. This change fixes the unit test.
This change also adds a check to the init wrapper function to
ensure that an error is generated if RMR is unable to initialise
the underlying transport.
Issue-ID: RICAPP-74
Signed-off-by: E. Scott Daniels <daniels@research.att.com>
Change-Id: I1f3ca3f8e821cd1356fb5247404b8cafd22a6119
Versioning <http://semver.org/>`__.
Versioning <http://semver.org/>`__.
+[2.2.1] - 3/3/2020
+--------------------
+
+::
+
+ * Correct the MEID unit test (broken by RMR commit 190665fe)
+ * Change rmr_init to catch init failure reported by RMR
+
+
[2.2.0] - 12/5/2019
--------------------
[2.2.0] - 12/5/2019
--------------------
# CI script installs RMR from PackageCloud using this version
---
# CI script installs RMR from PackageCloud using this version
---
# ==================================================================================
# ==================================================================================
-# Copyright (c) 2019 Nokia
-# Copyright (c) 2018-2019 AT&T Intellectual Property.
+# Copyright (c) 2019-2020 Nokia
+# Copyright (c) 2018-2020 AT&T Intellectual Property.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
class BadBufferAllocation(BaseException):
"""a bad buffer was allocated, check the rmr context"""
class BadBufferAllocation(BaseException):
"""a bad buffer was allocated, check the rmr context"""
+
+
+class MeidSizeOutOfRange(BaseException):
+ """an attempt to set the MEID with a buffer that was too large"""
+
+
+class InitFailed(BaseException):
+ """rmr init failure, the context is unusable"""
# vim: expandtab ts=4 sw=4:
# ==================================================================================
# vim: expandtab ts=4 sw=4:
# ==================================================================================
-# Copyright (c) 2019 Nokia
-# Copyright (c) 2018-2019 AT&T Intellectual Property.
+# Copyright (c) 2019-2020 Nokia
+# Copyright (c) 2018-2020 AT&T Intellectual Property.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
from ctypes import RTLD_GLOBAL, Structure, c_int, POINTER, c_char, c_char_p, c_void_p, memmove, cast
from ctypes import CDLL
from ctypes import create_string_buffer
from ctypes import RTLD_GLOBAL, Structure, c_int, POINTER, c_char, c_char_p, c_void_p, memmove, cast
from ctypes import CDLL
from ctypes import create_string_buffer
-from rmr.exceptions import BadBufferAllocation
+from rmr.exceptions import BadBufferAllocation, MeidSizeOutOfRange, InitFailed
# https://docs.python.org/3.7/library/ctypes.html
# https://stackoverflow.com/questions/2327344/ctypes-loading-a-c-shared-library-that-has-dependencies/30845750#30845750
# https://docs.python.org/3.7/library/ctypes.html
# https://stackoverflow.com/questions/2327344/ctypes-loading-a-c-shared-library-that-has-dependencies/30845750#30845750
"""
Refer to rmr C documentation for rmr_init
extern void* rmr_init(char* uproto_port, int max_msg_size, int flags)
"""
Refer to rmr C documentation for rmr_init
extern void* rmr_init(char* uproto_port, int max_msg_size, int flags)
+
+ This python function checks that the context is not None and raises
+ an excption if it is.
- return _rmr_init(uproto_port, max_msg_size, flags)
+ mrc = _rmr_init(uproto_port, max_msg_size, flags)
+ if mrc is None:
+ raise InitFailed()
+ return mrc
_rmr_ready = rmr_c_lib.rmr_ready
_rmr_ready = rmr_c_lib.rmr_ready
"""
Refer to the rmr C documentation for rmr_bytes2meid
extern int rmr_bytes2meid(rmr_mbuf_t* mbuf, unsigned char const* src, int len);
"""
Refer to the rmr C documentation for rmr_bytes2meid
extern int rmr_bytes2meid(rmr_mbuf_t* mbuf, unsigned char const* src, int len);
+
+ Caution: the meid length supported in an RMR message is 32 bytes, but C applications
+ expect this to be a nil terminated string and thus only 31 bytes are actually available.
+
+ Raises: exceptions.MeidSizeOutOfRang
+ max = _get_constants().get("RMR_MAX_MEID", 32)
+ if len(byte_str) >= max:
+ raise MeidSizeOutOfRange
+
return _rmr_bytes2meid(ptr_mbuf, byte_str, len(byte_str))
return _rmr_bytes2meid(ptr_mbuf, byte_str, len(byte_str))
- sz = _get_constants().get("RMR_MAX_MEID", 64) # size for buffer to fill
+ sz = _get_constants().get("RMR_MAX_MEID", 32) # size for buffer to fill
buf = create_string_buffer(sz)
_rmr_get_meid(ptr_mbuf, buf)
return buf.value
buf = create_string_buffer(sz)
_rmr_get_meid(ptr_mbuf, buf)
return buf.value
packages=find_packages(),
author="Tommy Carpenter, E. Scott Daniels",
description="Python wrapper for RIC RMR",
packages=find_packages(),
author="Tommy Carpenter, E. Scott Daniels",
description="Python wrapper for RIC RMR",
# vim: ts=4 sw=4 expandtab:
# =================================================================================2
# vim: ts=4 sw=4 expandtab:
# =================================================================================2
-# Copyright (c) 2019 Nokia
-# Copyright (c) 2018-2019 AT&T Intellectual Property.
+# Copyright (c) 2019-2020 Nokia
+# Copyright (c) 2018-2020 AT&T Intellectual Property.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"\x01\x02"
assert len(rmr.rmr_get_meid(sbuf)) == 2
assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"\x01\x02"
assert len(rmr.rmr_get_meid(sbuf)) == 2
- rmr.rmr_set_meid(sbuf, b"\x00" * 32)
+ rmr.rmr_set_meid(sbuf, b"\x00" * 31)
assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"" # NULL bytes get truncated
assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"" # NULL bytes get truncated
- rmr.rmr_set_meid(sbuf, b"6" * 32)
- assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"6" * 32 # string in string out
+ rmr.rmr_set_meid(sbuf, b"6" * 31)
+ assert rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"6" * 31 # string in string out
rmr.rmr_set_meid(sbuf, b"\x01\x02")
assert (
rmr.rmr_set_meid(sbuf, b"\x01\x02")
assert (
- rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"\x01\x02" + b"6" * 30
- ) # bytes in string out, 6s left over
- assert len(rmr.rmr_get_meid(sbuf)) == 32
+ rmr.rmr_get_meid(sbuf) == rmr.message_summary(sbuf)["meid"] == b"\x01\x02"
+ ) # Ctypes will chop at first nil, so expect only 2 bytes back
+
+ assert len(rmr.rmr_get_meid(sbuf)) == 2
+
+ # test that an exception is raised for buffers which are too long
+ with pytest.raises(exceptions.MeidSizeOutOfRange):
+ rmr.rmr_set_meid(sbuf, b"8" * 32)
+