Another python3 stuff. before: FAILED (errors=436, failures=94) after: FAILED (errors=313, failures=97)
= >From 72f2c70a16420ab4ada0c3df1d588b1ac148311d Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori <[email protected]> Date: Fri, 26 Jun 2015 09:42:11 +0900 Subject: [PATCH] python3: use bytearray rather than str for packet library Signed-off-by: FUJITA Tomonori <[email protected]> --- ryu/lib/packet/igmp.py | 6 +- ryu/lib/packet/sctp.py | 80 ++++++++++++------------ ryu/tests/unit/packet/test_cfm.py | 123 +++++++++++++++++++------------------ ryu/tests/unit/packet/test_dhcp.py | 4 +- ryu/tests/unit/packet/test_igmp.py | 7 ++- ryu/tests/unit/packet/test_ipv6.py | 86 +++++++++++++------------- ryu/tests/unit/packet/test_sctp.py | 7 ++- 7 files changed, 163 insertions(+), 150 deletions(-) diff --git a/ryu/lib/packet/igmp.py b/ryu/lib/packet/igmp.py index f819fa6..237f37e 100644 --- a/ryu/lib/packet/igmp.py +++ b/ryu/lib/packet/igmp.py @@ -301,7 +301,7 @@ class igmpv3_query(igmp): if 0 == self.csum: self.csum = packet_utils.checksum(buf) struct.pack_into('!H', buf, 2, self.csum) - return str(buf) + return buf def __len__(self): return self._MIN_LEN + len(self.srcs) * 4 @@ -374,7 +374,7 @@ class igmpv3_report(igmp): if 0 == self.csum: self.csum = packet_utils.checksum(buf) struct.pack_into('!H', buf, 2, self.csum) - return str(buf) + return buf def __len__(self): records_len = 0 @@ -462,7 +462,7 @@ class igmpv3_report_group(stringify.StringifyMixin): if 0 == self.aux_len: self.aux_len = len(self.aux) // 4 struct.pack_into('!B', buf, 1, self.aux_len) - return str(buf) + return buf def __len__(self): return self._MIN_LEN + len(self.srcs) * 4 + self.aux_len * 4 diff --git a/ryu/lib/packet/sctp.py b/ryu/lib/packet/sctp.py index 1806e37..0a4a978 100644 --- a/ryu/lib/packet/sctp.py +++ b/ryu/lib/packet/sctp.py @@ -134,11 +134,11 @@ class sctp(packet_base.PacketBase): self.csum)) if self.chunks: for one in self.chunks: - buf.extend(one.serialize()) + buf += one.serialize() if self.csum == 0: self.csum = self._checksum(buf) struct.pack_into('!I', buf, 8, self.csum) - return str(buf) + return buf def __len__(self): length = self._MIN_LEN @@ -296,11 +296,11 @@ class chunk_init_base(chunk): self.length, self.init_tag, self.a_rwnd, self.os, self.mis, self.i_tsn)) for one in self.params: - buf.extend(one.serialize()) + buf += one.serialize() if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @six.add_metaclass(abc.ABCMeta) @@ -329,11 +329,11 @@ class chunk_heartbeat_base(chunk): self._PACK_STR, self.chunk_type(), self.flags, self.length)) if self.info is not None: - buf.extend(self.info.serialize()) + buf += self.info.serialize() if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @six.add_metaclass(abc.ABCMeta) @@ -453,11 +453,11 @@ class chunk_data(chunk): buf = bytearray(struct.pack( self._PACK_STR, self.chunk_type(), flags, self.length, self.tsn, self.sid, self.seq, self.payload_id)) - buf.extend(self.payload_data) + buf += self.payload_data if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @sctp.register_chunk_type @@ -645,13 +645,13 @@ class chunk_sack(chunk): self.length, self.tsn_ack, self.a_rwnd, self.gapack_num, self.duptsn_num)) for one in self.gapacks: - buf.extend(struct.pack(chunk_sack._GAPACK_STR, one[0], one[1])) + buf += struct.pack(chunk_sack._GAPACK_STR, one[0], one[1]) for one in self.duptsns: - buf.extend(struct.pack(chunk_sack._DUPTSN_STR, one)) + buf += struct.pack(chunk_sack._DUPTSN_STR, one) if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @sctp.register_chunk_type @@ -809,11 +809,11 @@ class chunk_abort(chunk): buf = bytearray(struct.pack( self._PACK_STR, self.chunk_type(), flags, self.length)) for one in self.causes: - buf.extend(one.serialize()) + buf += one.serialize() if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @sctp.register_chunk_type @@ -962,11 +962,11 @@ class chunk_error(chunk): buf = bytearray(struct.pack( self._PACK_STR, self.chunk_type(), self.flags, self.length)) for one in self.causes: - buf.extend(one.serialize()) + buf += one.serialize() if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @sctp.register_chunk_type @@ -1019,14 +1019,14 @@ class chunk_cookie_echo(chunk): self._PACK_STR, self.chunk_type(), self.flags, self.length)) if self.cookie is not None: - buf.extend(self.cookie) + buf += self.cookie if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf @sctp.register_chunk_type @@ -1223,14 +1223,14 @@ class cause_with_value(cause): buf = bytearray(struct.pack( self._PACK_STR, self.cause_code(), self.length)) if self.value is not None: - buf.extend(self.value) + buf += self.value if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf @chunk_abort.register_cause_code @@ -1337,7 +1337,7 @@ class cause_missing_param(cause): buf = bytearray(struct.pack( self._PACK_STR, self.cause_code(), self.length, self.num)) for one in self.types: - buf.extend(struct.pack('!H', one)) + buf += struct.pack('!H', one) if 0 == self.num: self.num = len(self.types) struct.pack_into('!I', buf, 4, self.num) @@ -1346,8 +1346,8 @@ class cause_missing_param(cause): struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf @chunk_abort.register_cause_code @@ -1467,14 +1467,14 @@ class cause_unresolvable_addr(cause_with_value): def serialize(self): buf = bytearray(struct.pack( self._PACK_STR, self.cause_code(), self.length)) - buf.extend(self.value.serialize()) + buf += self.value.serialize() if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf @chunk_abort.register_cause_code @@ -1696,14 +1696,14 @@ class cause_restart_with_new_addr(cause_with_value): buf = bytearray(struct.pack( self._PACK_STR, self.cause_code(), self.length)) for one in self.value: - buf.extend(one.serialize()) + buf += one.serialize() if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf @chunk_abort.register_cause_code @@ -1796,14 +1796,14 @@ class param(stringify.StringifyMixin): buf = bytearray(struct.pack( self._PACK_STR, self.param_type(), self.length)) if self.value: - buf.extend(self.value) + buf += self.value if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf def __len__(self): length = self.length @@ -2057,14 +2057,14 @@ class param_supported_addr(param): buf = bytearray(struct.pack( self._PACK_STR, self.param_type(), self.length)) for one in self.value: - buf.extend(struct.pack(param_supported_addr._VALUE_STR, one)) + buf += struct.pack(param_supported_addr._VALUE_STR, one) if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) mod = len(buf) % 4 if mod: - buf.extend(bytearray(4 - mod)) - return str(buf) + buf += bytearray(4 - mod) + return buf @chunk_init.register_param_type @@ -2115,11 +2115,11 @@ class param_ipv4(param): buf = bytearray(struct.pack( self._PACK_STR, self.param_type(), self.length)) if self.value: - buf.extend(addrconv.ipv4.text_to_bin(self.value)) + buf += addrconv.ipv4.text_to_bin(self.value) if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf @chunk_init.register_param_type @@ -2170,8 +2170,8 @@ class param_ipv6(param): buf = bytearray(struct.pack( self._PACK_STR, self.param_type(), self.length)) if self.value: - buf.extend(addrconv.ipv6.text_to_bin(self.value)) + buf += addrconv.ipv6.text_to_bin(self.value) if 0 == self.length: self.length = len(buf) struct.pack_into('!H', buf, 2, self.length) - return str(buf) + return buf diff --git a/ryu/tests/unit/packet/test_cfm.py b/ryu/tests/unit/packet/test_cfm.py index 4120f87..a349430 100644 --- a/ryu/tests/unit/packet/test_cfm.py +++ b/ryu/tests/unit/packet/test_cfm.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. - +import six import unittest import logging import inspect @@ -227,7 +227,7 @@ class Test_cfm(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.ins.parser(str(self.buf)) + _res = self.ins.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] @@ -258,13 +258,16 @@ class Test_cfm(unittest.TestCase): def test_serialize(self): pass + def _ins_serialize(self, data, prev): + return six.binary_type(self.ins.serialize(data, prev)) + def test_serialize_with_cc_message(self): self.setUp_cc_message() self.test_serialize() data = bytearray() prev = None - buf = self.ins.serialize(data, prev) - cc_message = cfm.cc_message.parser(str(buf)) + buf = self._ins_serialize(data, prev) + cc_message = cfm.cc_message.parser(buf) eq_(repr(self.message), repr(cc_message)) def test_serialize_with_loopback_message(self): @@ -272,8 +275,8 @@ class Test_cfm(unittest.TestCase): self.test_serialize() data = bytearray() prev = None - buf = self.ins.serialize(data, prev) - loopback_message = cfm.loopback_message.parser(str(buf)) + buf = self._ins_serialize(data, prev) + loopback_message = cfm.loopback_message.parser(buf) eq_(repr(self.message), repr(loopback_message)) def test_serialize_with_loopback_reply(self): @@ -281,8 +284,8 @@ class Test_cfm(unittest.TestCase): self.test_serialize() data = bytearray() prev = None - buf = self.ins.serialize(data, prev) - loopback_reply = cfm.loopback_reply.parser(str(buf)) + buf = self._ins_serialize(data, prev) + loopback_reply = cfm.loopback_reply.parser(buf) eq_(repr(self.message), repr(loopback_reply)) def test_serialize_with_link_trace_message(self): @@ -290,8 +293,8 @@ class Test_cfm(unittest.TestCase): self.test_serialize() data = bytearray() prev = None - buf = self.ins.serialize(data, prev) - link_trace_message = cfm.link_trace_message.parser(str(buf)) + buf = self._ins_serialize(data, prev) + link_trace_message = cfm.link_trace_message.parser(buf) eq_(repr(self.message), repr(link_trace_message)) def test_serialize_with_link_trace_reply(self): @@ -299,8 +302,8 @@ class Test_cfm(unittest.TestCase): self.test_serialize() data = bytearray() prev = None - buf = self.ins.serialize(data, prev) - link_trace_reply = cfm.link_trace_reply.parser(str(buf)) + buf = self._ins_serialize(data, prev) + link_trace_reply = cfm.link_trace_reply.parser(buf) eq_(repr(self.message), repr(link_trace_reply)) def test_to_string(self): @@ -511,7 +514,7 @@ class Test_cc_message(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -545,7 +548,7 @@ class Test_cc_message(unittest.TestCase): self.tlvs ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -580,7 +583,7 @@ class Test_cc_message(unittest.TestCase): self.tlvs ) buf = ins.serialize() - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -602,7 +605,7 @@ class Test_cc_message(unittest.TestCase): def test_default_args(self): ins = cfm.cc_message() buf = ins.serialize() - res = struct.unpack_from(cfm.cc_message._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.cc_message._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 1) @@ -666,7 +669,7 @@ class Test_loopback_message(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -683,7 +686,7 @@ class Test_loopback_message(unittest.TestCase): ins = cfm.loopback_message() buf = ins.serialize() res = struct.unpack_from(cfm.loopback_message._PACK_STR, - str(buf)) + six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 3) @@ -743,7 +746,7 @@ class Test_loopback_reply(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -759,7 +762,7 @@ class Test_loopback_reply(unittest.TestCase): def test_default_args(self): ins = cfm.loopback_reply() buf = ins.serialize() - res = struct.unpack_from(cfm.loopback_reply._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.loopback_reply._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 2) @@ -838,7 +841,7 @@ class Test_link_trace_message(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -857,7 +860,7 @@ class Test_link_trace_message(unittest.TestCase): def test_default_args(self): ins = cfm.link_trace_message() buf = ins.serialize() - res = struct.unpack_from(cfm.link_trace_message._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.link_trace_message._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 5) @@ -944,7 +947,7 @@ class Test_link_trace_reply(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.md_lv, res[0] >> 5) eq_(self.version, res[0] & 0x1f) eq_(self.opcode, res[1]) @@ -964,7 +967,7 @@ class Test_link_trace_reply(unittest.TestCase): def test_default_args(self): ins = cfm.link_trace_reply() buf = ins.serialize() - res = struct.unpack_from(cfm.link_trace_reply._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.link_trace_reply._PACK_STR, six.binary_type(buf)) eq_(res[0] >> 5, 0) eq_(res[0] & 0x1f, 0) eq_(res[1], 4) @@ -1043,7 +1046,7 @@ class Test_sender_id_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1062,7 +1065,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB1sB2sB' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(7, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1079,7 +1082,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB2sB3s' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(8, res[1]) eq_(0, res[2]) @@ -1095,7 +1098,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB1sB' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(4, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1109,7 +1112,7 @@ class Test_sender_id_tlv(unittest.TestCase): ) buf = ins.serialize() form = '!BHBB2sB' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(5, res[1]) eq_(0, res[2]) @@ -1129,7 +1132,7 @@ class Test_sender_id_tlv(unittest.TestCase): self.ma, ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.chassis_id_length, res[2]) @@ -1147,7 +1150,7 @@ class Test_sender_id_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.sender_id_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.sender_id_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.sender_id_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_SENDER_ID_TLV) eq_(res[1], 1) eq_(res[2], 0) @@ -1189,7 +1192,7 @@ class Test_port_status_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.port_status, res[2]) @@ -1201,7 +1204,7 @@ class Test_port_status_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.port_status_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.port_status_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.port_status_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_PORT_STATUS_TLV) eq_(res[1], 1) eq_(res[2], 2) @@ -1243,7 +1246,7 @@ class Test_data_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.data_value, res[2]) @@ -1254,7 +1257,7 @@ class Test_data_tlv(unittest.TestCase): self.data_value ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.data_value, res[2]) @@ -1266,7 +1269,7 @@ class Test_data_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.data_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.data_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.data_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_DATA_TLV) eq_(res[1], 0) @@ -1307,7 +1310,7 @@ class Test_interface_status_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.interface_status, res[2]) @@ -1319,7 +1322,7 @@ class Test_interface_status_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.interface_status_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.interface_status_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.interface_status_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_INTERFACE_STATUS_TLV) eq_(res[1], 1) eq_(res[2], 1) @@ -1364,9 +1367,12 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase): eq_(self.egress_id_ui, res.egress_id_ui) eq_(self.egress_id_mac, res.egress_id_mac) + def _serialize(self): + return six.binary_type(self.ins.serialize()) + def test_serialize(self): - buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + buf = self._serialize() + res = struct.unpack_from(self.form, buf) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.egress_id_ui, res[2]) @@ -1378,8 +1384,8 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase): self.egress_id_ui, self.egress_id_mac ) - buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + buf = self._serialize() + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.egress_id_ui, res[2]) @@ -1393,7 +1399,7 @@ class Test_ltm_egress_identifier_tlv(unittest.TestCase): ins = cfm.ltm_egress_identifier_tlv() buf = ins.serialize() res = struct.unpack_from( - cfm.ltm_egress_identifier_tlv._PACK_STR, str(buf)) + cfm.ltm_egress_identifier_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_LTM_EGRESS_IDENTIFIER_TLV) eq_(res[1], 8) eq_(res[2], 0) @@ -1448,8 +1454,8 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase): eq_(self.next_egress_id_mac, res.next_egress_id_mac) def test_serialize(self): - buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + buf = six.binary_type(self.ins.serialize()) + res = struct.unpack_from(self.form, buf) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.last_egress_id_ui, res[2]) @@ -1464,8 +1470,8 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase): self.next_egress_id_ui, self.next_egress_id_mac ) - buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + buf = six.binary_type(self.ins.serialize()) + res = struct.unpack_from(self.form, buf) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.last_egress_id_ui, res[2]) @@ -1479,9 +1485,8 @@ class Test_ltr_egress_identifier_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.ltr_egress_identifier_tlv() - buf = ins.serialize() - res = struct.unpack_from(cfm.ltr_egress_identifier_tlv._PACK_STR, - str(buf)) + buf = six.binary_type(ins.serialize()) + res = struct.unpack_from(cfm.ltr_egress_identifier_tlv._PACK_STR, buf) eq_(res[0], cfm.CFM_LTR_EGRESS_IDENTIFIER_TLV) eq_(res[1], 16) eq_(res[2], 0) @@ -1534,7 +1539,7 @@ class Test_organization_specific_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.oui, res[2]) @@ -1548,7 +1553,7 @@ class Test_organization_specific_tlv(unittest.TestCase): self.value ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.oui, res[2]) @@ -1563,7 +1568,7 @@ class Test_organization_specific_tlv(unittest.TestCase): ins = cfm.organization_specific_tlv() buf = ins.serialize() res = struct.unpack_from(cfm.organization_specific_tlv._PACK_STR, - str(buf)) + six.binary_type(buf)) eq_(res[0], cfm.CFM_ORGANIZATION_SPECIFIC_TLV) eq_(res[1], 4) eq_(res[2], b"\x00\x00\x00") @@ -1623,7 +1628,7 @@ class Test_reply_ingress_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1641,7 +1646,7 @@ class Test_reply_ingress_tlv(unittest.TestCase): self.port_id ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1657,7 +1662,7 @@ class Test_reply_ingress_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.reply_ingress_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.reply_ingress_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.reply_ingress_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_REPLY_INGRESS_TLV) eq_(res[1], 7) eq_(res[2], 1) @@ -1718,7 +1723,7 @@ class Test_reply_egress_tlv(unittest.TestCase): def test_serialize(self): buf = self.ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1736,7 +1741,7 @@ class Test_reply_egress_tlv(unittest.TestCase): self.port_id ) buf = ins.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self._type, res[0]) eq_(self.length, res[1]) eq_(self.action, res[2]) @@ -1752,7 +1757,7 @@ class Test_reply_egress_tlv(unittest.TestCase): def test_default_args(self): ins = cfm.reply_egress_tlv() buf = ins.serialize() - res = struct.unpack_from(cfm.reply_egress_tlv._PACK_STR, str(buf)) + res = struct.unpack_from(cfm.reply_egress_tlv._PACK_STR, six.binary_type(buf)) eq_(res[0], cfm.CFM_REPLY_EGRESS_TLV) eq_(res[1], 7) eq_(res[2], 1) diff --git a/ryu/tests/unit/packet/test_dhcp.py b/ryu/tests/unit/packet/test_dhcp.py index d6f4aae..dd85921 100644 --- a/ryu/tests/unit/packet/test_dhcp.py +++ b/ryu/tests/unit/packet/test_dhcp.py @@ -14,6 +14,7 @@ # limitations under the License. +import six import inspect import logging import struct @@ -137,7 +138,8 @@ class Test_dhcp_offer(unittest.TestCase): prev = None buf = self.dh.serialize(data, prev) - res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR, str(buf)) + res = struct.unpack_from(dhcp.dhcp._DHCP_PACK_STR, + six.binary_type(buf)) eq_(self.op, res[0]) eq_(self.htype, res[1]) diff --git a/ryu/tests/unit/packet/test_igmp.py b/ryu/tests/unit/packet/test_igmp.py index b691356..8f1d786 100644 --- a/ryu/tests/unit/packet/test_igmp.py +++ b/ryu/tests/unit/packet/test_igmp.py @@ -496,7 +496,7 @@ class Test_igmpv3_report(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.g.parser(str(self.buf)) + _res = self.g.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] else: @@ -963,7 +963,7 @@ class Test_igmpv3_report_group(unittest.TestCase): def test_default_args(self): rep = igmpv3_report_group() buf = rep.serialize() - res = unpack_from(igmpv3_report_group._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report_group._PACK_STR, six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 0) @@ -991,7 +991,8 @@ class Test_igmpv3_report_group(unittest.TestCase): aux = 'abcde' rep = igmpv3_report_group(aux=aux) buf = rep.serialize() - res = unpack_from(igmpv3_report_group._PACK_STR, str(buf)) + res = unpack_from(igmpv3_report_group._PACK_STR, + six.binary_type(buf)) eq_(res[0], 0) eq_(res[1], 2) diff --git a/ryu/tests/unit/packet/test_ipv6.py b/ryu/tests/unit/packet/test_ipv6.py index 914d314..c9d57d9 100644 --- a/ryu/tests/unit/packet/test_ipv6.py +++ b/ryu/tests/unit/packet/test_ipv6.py @@ -14,6 +14,7 @@ # limitations under the License. +import six import unittest import logging import inspect @@ -262,7 +263,7 @@ class Test_ipv6(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.ip.parser(str(self.buf)) + _res = self.ip.parser(six.binary_type(self.buf)) if type(_res) is tuple: res = _res[0] else: @@ -302,12 +303,14 @@ class Test_ipv6(unittest.TestCase): self.setUp_with_multi_headers() self.test_parser() + def _ip_serialize(self, data, prev): + return six.binary_type(self.ip.serialize(data, prev)) + def test_serialize(self): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) - - res = struct.unpack_from(ipv6.ipv6._PACK_STR, str(buf)) + buf = self._ip_serialize(data, prev) + res = struct.unpack_from(ipv6.ipv6._PACK_STR, buf) eq_(self.v_tc_flow, res[0]) eq_(self.payload_length, res[1]) @@ -322,8 +325,8 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) - hop_opts = ipv6.hop_opts.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + buf = self._ip_serialize(data, prev) + hop_opts = ipv6.hop_opts.parser(buf[ipv6.ipv6._MIN_LEN:]) eq_(repr(self.hop_opts), repr(hop_opts)) def test_serialize_with_dst_opts(self): @@ -332,8 +335,8 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) - dst_opts = ipv6.dst_opts.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + buf = self._ip_serialize(data, prev) + dst_opts = ipv6.dst_opts.parser(buf[ipv6.ipv6._MIN_LEN:]) eq_(repr(self.dst_opts), repr(dst_opts)) def test_serialize_with_routing_type3(self): @@ -342,8 +345,8 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) - routing = ipv6.routing.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + buf = self._ip_serialize(data, prev) + routing = ipv6.routing.parser(buf[ipv6.ipv6._MIN_LEN:]) eq_(repr(self.routing), repr(routing)) def test_serialize_with_fragment(self): @@ -352,8 +355,8 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) - fragment = ipv6.fragment.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + buf = self._ip_serialize(data, prev) + fragment = ipv6.fragment.parser(buf[ipv6.ipv6._MIN_LEN:]) eq_(repr(self.fragment), repr(fragment)) def test_serialize_with_auth(self): @@ -362,8 +365,8 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) - auth = ipv6.auth.parser(str(buf[ipv6.ipv6._MIN_LEN:])) + buf = self._ip_serialize(data, prev) + auth = ipv6.auth.parser(buf[ipv6.ipv6._MIN_LEN:]) eq_(repr(self.auth), repr(auth)) def test_serialize_with_multi_headers(self): @@ -372,11 +375,11 @@ class Test_ipv6(unittest.TestCase): data = bytearray() prev = None - buf = self.ip.serialize(data, prev) + buf = self._ip_serialize(data, prev) offset = ipv6.ipv6._MIN_LEN - hop_opts = ipv6.hop_opts.parser(str(buf[offset:])) + hop_opts = ipv6.hop_opts.parser(buf[offset:]) offset += len(hop_opts) - auth = ipv6.auth.parser(str(buf[offset:])) + auth = ipv6.auth.parser(buf[offset:]) eq_(repr(self.hop_opts), repr(hop_opts)) eq_(repr(self.auth), repr(auth)) @@ -448,7 +451,7 @@ class Test_ipv6(unittest.TestCase): def test_default_args(self): ip = ipv6.ipv6() buf = ip.serialize(bytearray(), None) - res = struct.unpack(ipv6.ipv6._PACK_STR, str(buf)) + res = struct.unpack(ipv6.ipv6._PACK_STR, six.binary_type(buf)) eq_(res[0], 6 << 28) eq_(res[1], 0) @@ -464,7 +467,7 @@ class Test_ipv6(unittest.TestCase): ipv6.option(5, 2, b'\x00\x00'), ipv6.option(1, 0, None)])]) buf = ip.serialize(bytearray(), None) - res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', str(buf)) + res = struct.unpack(ipv6.ipv6._PACK_STR + '8s', six.binary_type(buf)) eq_(res[0], 6 << 28) eq_(res[1], 8) @@ -546,18 +549,18 @@ class Test_hop_opts(unittest.TestCase): eq_(str(self.data), str(res.data)) def test_serialize(self): - buf = self.hop.serialize() - res = struct.unpack_from(self.form, str(buf)) + buf = six.binary_type(self.hop.serialize()) + res = struct.unpack_from(self.form, buf) eq_(self.nxt, res[0]) eq_(self.size, res[1]) offset = struct.calcsize(self.form) - opt1 = ipv6.option.parser(str(buf[offset:])) + opt1 = ipv6.option.parser(buf[offset:]) offset += len(opt1) - opt2 = ipv6.option.parser(str(buf[offset:])) + opt2 = ipv6.option.parser(buf[offset:]) offset += len(opt2) - opt3 = ipv6.option.parser(str(buf[offset:])) + opt3 = ipv6.option.parser(buf[offset:]) offset += len(opt3) - opt4 = ipv6.option.parser(str(buf[offset:])) + opt4 = ipv6.option.parser(buf[offset:]) eq_(5, opt1.type_) eq_(2, opt1.len_) eq_(b'\x00\x00', opt1.data) @@ -577,7 +580,7 @@ class Test_hop_opts(unittest.TestCase): def test_default_args(self): hdr = ipv6.hop_opts() buf = hdr.serialize() - res = struct.unpack('!BB', str(buf[:2])) + res = struct.unpack('!BB', six.binary_type(buf[:2])) eq_(res[0], 6) eq_(res[1], 0) @@ -627,18 +630,18 @@ class Test_dst_opts(unittest.TestCase): eq_(str(self.data), str(res.data)) def test_serialize(self): - buf = self.dst.serialize() - res = struct.unpack_from(self.form, str(buf)) + buf = six.binary_type(self.dst.serialize()) + res = struct.unpack_from(self.form, buf) eq_(self.nxt, res[0]) eq_(self.size, res[1]) offset = struct.calcsize(self.form) - opt1 = ipv6.option.parser(str(buf[offset:])) + opt1 = ipv6.option.parser(buf[offset:]) offset += len(opt1) - opt2 = ipv6.option.parser(str(buf[offset:])) + opt2 = ipv6.option.parser(buf[offset:]) offset += len(opt2) - opt3 = ipv6.option.parser(str(buf[offset:])) + opt3 = ipv6.option.parser(buf[offset:]) offset += len(opt3) - opt4 = ipv6.option.parser(str(buf[offset:])) + opt4 = ipv6.option.parser(buf[offset:]) eq_(5, opt1.type_) eq_(2, opt1.len_) eq_(b'\x00\x00', opt1.data) @@ -658,7 +661,7 @@ class Test_dst_opts(unittest.TestCase): def test_default_args(self): hdr = ipv6.dst_opts() buf = hdr.serialize() - res = struct.unpack('!BB', str(buf[:2])) + res = struct.unpack('!BB', six.binary_type(buf[:2])) eq_(res[0], 6) eq_(res[1], 0) @@ -862,7 +865,7 @@ class Test_routing_type3(unittest.TestCase): def test_serialize(self): buf = self.routing.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.size, res[1]) eq_(self.type_, res[2]) @@ -916,7 +919,7 @@ class Test_routing_type3(unittest.TestCase): cmpe, pad) buf = routing.serialize() form = '!BBBBBB2x' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) @@ -980,7 +983,7 @@ class Test_routing_type3(unittest.TestCase): nxt, size, type_, seg, cmpi, cmpe, adrs) buf = routing.serialize() form = '!BBBBBB2x8s8s8s' - res = struct.unpack_from(form, str(buf)) + res = struct.unpack_from(form, six.binary_type(buf)) eq_(nxt, res[0]) eq_(size, res[1]) eq_(type_, res[2]) @@ -999,7 +1002,8 @@ class Test_routing_type3(unittest.TestCase): hdr = ipv6.routing_type3() buf = hdr.serialize() LOG.info(repr(buf)) - res = struct.unpack_from(ipv6.routing_type3._PACK_STR, str(buf)) + res = struct.unpack_from(ipv6.routing_type3._PACK_STR, + six.binary_type(buf)) LOG.info(res) eq_(res[0], 6) @@ -1043,7 +1047,7 @@ class Test_fragment(unittest.TestCase): def test_serialize(self): buf = self.fragment.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.off_m, res[1]) eq_(self.id_, res[2]) @@ -1054,7 +1058,7 @@ class Test_fragment(unittest.TestCase): def test_default_args(self): hdr = ipv6.fragment() buf = hdr.serialize() - res = struct.unpack_from(ipv6.fragment._PACK_STR, buf) + res = struct.unpack_from(ipv6.fragment._PACK_STR, six.binary_type(buf)) eq_(res[0], 6) eq_(res[1], 0) @@ -1096,7 +1100,7 @@ class Test_auth(unittest.TestCase): def test_serialize(self): buf = self.auth.serialize() - res = struct.unpack_from(self.form, str(buf)) + res = struct.unpack_from(self.form, six.binary_type(buf)) eq_(self.nxt, res[0]) eq_(self.size, res[1]) eq_(self.spi, res[2]) @@ -1117,7 +1121,7 @@ class Test_auth(unittest.TestCase): hdr = ipv6.auth() buf = hdr.serialize() LOG.info(repr(buf)) - res = struct.unpack_from(ipv6.auth._PACK_STR, str(buf)) + res = struct.unpack_from(ipv6.auth._PACK_STR, six.binary_type(buf)) LOG.info(res) eq_(res[0], 6) diff --git a/ryu/tests/unit/packet/test_sctp.py b/ryu/tests/unit/packet/test_sctp.py index 17f00b0..89a087e 100644 --- a/ryu/tests/unit/packet/test_sctp.py +++ b/ryu/tests/unit/packet/test_sctp.py @@ -14,6 +14,7 @@ # limitations under the License. +import six import inspect import logging import struct @@ -588,7 +589,7 @@ class Test_sctp(unittest.TestCase): self.test_init() def test_parser(self): - _res = self.sc.parser(str(self.buf)) + _res = self.sc.parser(self.buf) if type(_res) is tuple: res = _res[0] else: @@ -668,14 +669,14 @@ class Test_sctp(unittest.TestCase): def _test_serialize(self): buf = self.sc.serialize(bytearray(), None) - res = struct.unpack_from(sctp.sctp._PACK_STR, buf) + res = struct.unpack_from(sctp.sctp._PACK_STR, six.binary_type(buf)) eq_(self.src_port, res[0]) eq_(self.dst_port, res[1]) eq_(self.vtag, res[2]) # skip compare checksum # eq_(self.csum, res[3]) - return buf[sctp.sctp._MIN_LEN:] + return six.binary_type(buf[sctp.sctp._MIN_LEN:]) def test_serialize(self): self._test_serialize() -- 1.9.1 ------------------------------------------------------------------------------ Monitor 25 network devices or servers for free with OpManager! OpManager is web-based network management software that monitors network devices and physical & virtual servers, alerts via email & sms for fault. Monitor 25 devices for free with no restriction. Download now http://ad.doubleclick.net/ddm/clk/292181274;119417398;o _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
