Repository: kytos/python-openflow

Issue:
Error while migrating to python 3.6
While testing the full project on python 3.6 (running kyco against a mininet instance with 3 hosts and 3 switches, no loop version), the error below were throughed on the kytos console:

> Exception in thread Thread-198:
> Traceback (most recent call last):
>   File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
>     self.run()
>   File "/usr/local/lib/python3.6/threading.py", line 864, in run
>     self._target(*self._args, **self._kwargs)
>   File "/home/diraol/devel/kyco/kyco/utils.py", line 70, in threaded_handler
>     handler(*args)
>   File "/home/diraol/.virtualenvs/python-openflow/var/lib/kytos/napps/kytos/of_lldp/main.py", line 78, in update_links
>     lldp.unpack(ethernet.data.value)
>   File "/home/diraol/devel/python-openflow/pyof/foundation/base.py", line 431, in unpack
>     size = self._unpack_attribute(name, value, buff, begin)
>   File "/home/diraol/devel/python-openflow/pyof/foundation/base.py", line 441, in _unpack_attribute
>     attribute.unpack(buff, begin)
>   File "/home/diraol/devel/python-openflow/pyof/foundation/network_types.py", line 132, in unpack
>     self.value = BinaryData(buffer[begin:end])
> AttributeError: can't set attribute

@cemsbr, please, address this error as soon as possible so we can have the project working on Python 3.6 =)

Discussion:

Patch:
diff --git a/docs/.gitignore b/docs/.gitignore
index 6b8dea0..5ce97da 100644
--- a/docs/.gitignore
+++ b/docs/.gitignore
@@ -1,1 +1,3 @@
+_rebuild
+modules.rst
 python.inv
diff --git a/pyof/foundation/network_types.py b/pyof/foundation/network_types.py
index a538631..d91847c 100644
--- a/pyof/foundation/network_types.py
+++ b/pyof/foundation/network_types.py
@@ -67,7 +67,7 @@ class GenericTLV:
         """Create an instance and set its attributes."""
         #: type (int): The Type of the TLV Structure
         self.type = tlv_type
-        #: value (int): The value of the TLV Structure
+        #: value (BinaryData): The value of the TLV Structure
         self._value = value
 
     @property
@@ -78,7 +78,7 @@ class GenericTLV:
     @property
     def length(self):
         """Struct length in bytes."""
-        return len(self.value.pack())
+        return len(self._value.pack())
 
     @property
     def header(self):
@@ -101,7 +101,7 @@ class GenericTLV:
         """
         if value is None:
             output = self.header.pack()
-            output += self.value.pack()
+            output += self._value.pack()
             return output
 
         elif isinstance(value, type(self)):
@@ -129,7 +129,7 @@ class GenericTLV:
         self.type = header.value >> 9
         length = header.value & 511
         begin, end = offset + 2, offset + 2 + length
-        self.value = BinaryData(buffer[begin:end])
+        self._value = BinaryData(buffer[begin:end])
 
     def get_size(self, value=None):
         """Return struct size."""
diff --git a/requirements-dev.txt b/requirements-dev.txt
index e8aacce..816c26a 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -2,6 +2,7 @@
 
 # For running doctests (during "python setup.py test")
 Sphinx >= 1.4.5
+sphinx_bootstrap_theme
 
 # Linters
 git+git://github.com/cemsbr/pylama_pylint.git@master
diff --git a/setup.py b/setup.py
index ca5e1f0..b6a20ef 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ descriptions.
 """
 import sys
 from abc import abstractmethod
-from subprocess import call, check_call
+from subprocess import CalledProcessError, call, check_call
 
 from setuptools import Command, find_packages, setup
 
@@ -15,11 +15,13 @@ from pyof import __version__
 def lint():
     """Run pylama and radon."""
     files = 'tests setup.py pyof'
-    print('Pylama is running. It may take a while...')
+    print('Pylama is running. It may take several seconds...')
     cmd = 'pylama {}'.format(files)
-    check_call(cmd, shell=True)
-    print('Low grades (<= C) for Maintainability Index (if any):')
-    check_call('radon mi --min=C ' + files, shell=True)
+    try:
+        check_call(cmd, shell=True)
+    except CalledProcessError as e:
+        print('Please, fix linter errors above.')
+        sys.exit(e.returncode)
 
 
 class SimpleCommand(Command):


Test patch:
diff --git a/tests/test_foundation/test_network_types.py b/tests/test_foundation/test_network_types.py
new file mode 100644
index 0000000..747a862
--- /dev/null
+++ b/tests/test_foundation/test_network_types.py
@@ -0,0 +1,17 @@
+"""Test Python-openflow network types."""
+import unittest
+
+from pyof.foundation.basic_types import BinaryData
+from pyof.foundation.network_types import GenericTLV
+
+
+class TestNetworkTypes(unittest.TestCase):
+    """Reproduce bugs found."""
+
+    def test_GenTLV_value_unpack(self):
+        """Value attribute should be the same after unpacking."""
+        value = BinaryData(b'test')
+        tlv = GenericTLV(value=value)
+        tlv_unpacked = GenericTLV()
+        tlv_unpacked.unpack(tlv.pack())
+        self.assertEqual(tlv.value.value, tlv_unpacked.value.value)