Browse Source

Enhancements to Cumulus ML2 Mechanism driver

Changes in this commit:
- Added README.rst with configuration details
- Added configuration details to ml2_conf_cumulus.ini
- Added plugin.sh for devstack
- Few unit test cases are added
- Fixed dependency issues in tox.ini
changes/46/506146/1
radhika 2 years ago
parent
commit
e5547cf777
34 changed files with 528 additions and 1226 deletions
  1. 0
    0
      README.md
  2. 53
    0
      README.rst
  3. 1
    1
      debian/docs
  4. 43
    0
      devstack/plugin.sh
  5. 13
    0
      devstack/settings
  6. 37
    6
      etc/neutron/plugins/ml2/ml2_conf_cumulus.ini
  7. BIN
      images/deb/networking-cumulus_1.0.0-cl3eau1_all.deb
  8. 72
    0
      images/deb/networking_cumulus.egg-info/PKG-INFO
  9. 74
    0
      images/deb/networking_cumulus.egg-info/SOURCES.txt
  10. 1
    0
      images/deb/networking_cumulus.egg-info/dependency_links.txt
  11. 6
    0
      images/deb/networking_cumulus.egg-info/entry_points.txt
  12. 1
    0
      images/deb/networking_cumulus.egg-info/not-zip-safe
  13. 1
    0
      images/deb/networking_cumulus.egg-info/pbr.json
  14. 3
    0
      images/deb/networking_cumulus.egg-info/requires.txt
  15. 1
    0
      images/deb/networking_cumulus.egg-info/top_level.txt
  16. BIN
      images/rpm/networking-cumulus-1.0.0.dev12-1.noarch.rpm
  17. BIN
      images/rpm/networking-cumulus-1.0.0.dev12-1.src.rpm
  18. BIN
      images/rpm/networking-cumulus-1.0.0.dev12.tar.gz
  19. BIN
      images/rpm/networking-cumulus-1.0.0.dev9-1.noarch.rpm
  20. BIN
      images/rpm/networking-cumulus-1.0.0.dev9-1.src.rpm
  21. BIN
      images/rpm/networking-cumulus-1.0.0.dev9.tar.gz
  22. 54
    2
      images/rpm/networking_cumulus.egg-info/PKG-INFO
  23. 5
    6
      images/rpm/networking_cumulus.egg-info/SOURCES.txt
  24. 1
    1
      images/rpm/networking_cumulus.egg-info/pbr.json
  25. 3
    1
      images/rpm/networking_cumulus.egg-info/requires.txt
  26. 13
    59
      networking_cumulus/mech_driver/driver.py
  27. 4
    4
      networking_cumulus/mech_driver/models.py
  28. 0
    0
      networking_cumulus/tests/unit/mech_driver/__init__.py
  29. 133
    0
      networking_cumulus/tests/unit/mech_driver/test_cumulus_mech.py
  30. 0
    1143
      networking_cumulus/tests/unit/ml2/test_cumulus_mech.py
  31. 2
    0
      requirements.txt
  32. 1
    1
      setup.cfg
  33. 2
    0
      test-requirements.txt
  34. 4
    2
      tox.ini

+ 0
- 0
README.md View File


+ 53
- 0
README.rst View File

@@ -0,0 +1,53 @@
1
+=====================================
2
+networking-cumulus Neutron ML2 driver
3
+=====================================
4
+
5
+Cumulus ML2 Mechanism Driver for Neutron
6
+
7
+* Free software: Apache license
8
+* Documentation: TBD
9
+* Source: http://git.openstack.org/cgit/openstack/networking-cumulus
10
+* Bugs: http://bugs.launchpad.net/networking-cumulus
11
+
12
+Configuration
13
+=============
14
+
15
+List of switches are required to be configured in
16
+``/etc/neutron/plugins/ml2/ml2_conf_cumulus.ini``. 
17
+The list can be comma separated switch names or IPs.
18
+All other configurable parameters are optional.
19
+
20
+Cumulus ML2 driver confiuration format:
21
+
22
+    [ml2_cumulus]
23
+    switches = <list of IP addresses or names>
24
+    protocol_port = <rest api port>
25
+    sync_time = <time interval in secs>
26
+    spf_time = <True/False>
27
+    new_bridge = <True/False>
28
+
29
+Example of ``ml2_conf_cumulus.ini``:
30
+
31
+    [ml2_cumulus]
32
+    switches = 192.168.10.10,192.168.20.20
33
+    sync_time = 10
34
+    new_bridge = False
35
+    spf_enable = False
36
+
37
+
38
+The ``cumulus`` mechanism driver needs to be enabled from
39
+the ml2 config file ``/etc/neutron/plugins/ml2/ml2_conf.ini``::
40
+
41
+   [ml2]
42
+   tenant_network_types = vlan
43
+   type_drivers = vlan,vxlan
44
+   mechanism_drivers = linuxbridge,cumulus
45
+   ...
46
+   ...
47
+
48
+(Re)start ``neutron-server`` specifying cumulus additional configuration file::
49
+
50
+    neutron-server \
51
+        --config-file /etc/neutron/neutron.conf \
52
+        --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
53
+        --config-file /etc/neutron/plugins/ml2/ml2_conf_cumulus.ini

+ 1
- 1
debian/docs View File

@@ -1 +1 @@
1
-README.md
1
+README.rst

+ 43
- 0
devstack/plugin.sh View File

@@ -0,0 +1,43 @@
1
+# -*- mode: shell-script -*-
2
+
3
+function install_lldp() {
4
+    echo_summary "Installing LLDP"
5
+    install_package lldpd
6
+    start_service lldpd
7
+}
8
+
9
+function install_cumulus_driver() {
10
+    echo_summary "Installing Cumulus Mechanism Driver"
11
+    setup_develop $CUMULUS_DIR
12
+}
13
+
14
+function configure_cumulus_driver() {
15
+    echo_summary "Configuring Neutron for Cumulus Driver"
16
+    cp $CUMULUS_ML2_CONF_SAMPLE $CUMULUS_ML2_CONF_FILE
17
+}
18
+
19
+if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then
20
+    if is_service_enabled "q-agt"; then
21
+        install_lldp
22
+    fi
23
+
24
+elif [[ "$1" == "stack" && "$2" == "install" ]]; then
25
+    install_cumulus_driver
26
+
27
+elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then
28
+    configure_cumulus_driver
29
+
30
+elif [[ "$1" == "stack" && "$2" == "extra" ]]; then
31
+    # no-op
32
+    :
33
+fi
34
+
35
+if [[ "$1" == "unstack" ]]; then
36
+    # no-op
37
+    :
38
+fi
39
+
40
+if [[ "$1" == "clean" ]]; then
41
+    # no-op
42
+    :
43
+fi

+ 13
- 0
devstack/settings View File

@@ -0,0 +1,13 @@
1
+if ! [[ "$Q_ML2_PLUGIN_MECHANISM_DRIVERS" =~ "cumulus" ]]; then
2
+    Q_ML2_PLUGIN_MECHANISM_DRIVERS="$Q_ML2_PLUGIN_MECHANISM_DRIVERS,cumulus"
3
+fi
4
+
5
+CUMULUS_DIR=${CUMULUS_DIR:-$DEST/networking-cumulus}
6
+CUMULUS_ML2_CONF_FILENAME=${CUMULUS_ML2_CONF_FILENAME:-"ml2_conf_cumulus.ini"}
7
+
8
+CUMULUS_ML2_CONF_SAMPLE=$CUMULUS_DIR/etc/neutron/plugins/ml2/$CUMULUS_ML2_CONF_FILENAME
9
+CUMULUS_ML2_CONF_FILE=$NEUTRON_CONF_DIR/$CUMULUS_ML2_CONF_FILENAME
10
+
11
+Q_PLUGIN_EXTRA_CONF_PATH=$NEUTRON_CONF_DIR
12
+Q_PLUGIN_EXTRA_CONF_FILES=($CUMULUS_ML2_CONF_FILENAME)
13
+

+ 37
- 6
etc/neutron/plugins/ml2/ml2_conf_cumulus.ini View File

@@ -1,10 +1,41 @@
1 1
 # Defines configuration options for Cumulus ML2 mechanism driver
2 2
 
3 3
 [ml2_cumulus]
4
-# Example attribute to set.
5
-# Make sure LLDP is work between the compute and switches since port
6
-# to add to trunk is automatically figured out
7
-# switches = leaf1,leaf2
8
-#---
9
-# switches = 192.168.11.1,192.168.12.1
4
+# (ListOpt) List of connected Cumulus switches
5
+#
6
+# switches =
7
+# Example: switches = 192.168.11.1,192.168.12.1
8
+#
9
+# (StrOpt) Scheme for base URL for the Cumulus ML2 API
10
+#
11
+# scheme =
12
+# Example: scheme = http
13
+#
14
+# (IntOpt) Protocol port for the base URL for the Cumulus ML2 API
15
+#          Its an optional parameter. Default value is 8000
16
+#
17
+# protocol_port =
18
+# Example: protocol_port = 8000
19
+#
20
+# (IntOpt) Periodic time interval in secconds for checking connection
21
+#          with switches listed in the switches parameter.
22
+#          Its an optional parameter. Default value is 30 seconds
23
+#          Syncing can be disabled by setting the value to 0
24
+#
25
+# sync_time =
26
+# Example: sync_time = 0
27
+#
28
+# (BoolOpt) Defines if the SPF is enabled or disabled on the bridge
29
+#           configured in the switch.
30
+#           Its an optional parameter. Default value is False
31
+#
32
+# spf_enable =
33
+# Example: spf_enable = True
34
+#
35
+# (BoolOpt) Defines the bridge created on the switch is vlan aware or
36
+#           vlan unaware. Its an optional parameter.
37
+#           Default value is False (vlan unaware bridge is created)
38
+#
39
+# new_bridge =
40
+# Example: new_bridge = True
10 41
 

BIN
images/deb/networking-cumulus_1.0.0-cl3eau1_all.deb View File


+ 72
- 0
images/deb/networking_cumulus.egg-info/PKG-INFO View File

@@ -0,0 +1,72 @@
1
+Metadata-Version: 1.1
2
+Name: networking-cumulus
3
+Version: 1.0.0.dev13
4
+Summary: Cumulus ML2 driver
5
+Home-page: UNKNOWN
6
+Author: Cumulus Networks
7
+Author-email: cumulus-ml2@cumulusnetworks.com
8
+License: UNKNOWN
9
+Description: =====================================
10
+        networking-cumulus Neutron ML2 driver
11
+        =====================================
12
+        
13
+        Cumulus ML2 Mechanism Driver for Neutron
14
+        
15
+        * Free software: Apache license
16
+        * Documentation: TBD
17
+        * Source: http://git.openstack.org/cgit/openstack/networking-cumulus
18
+        * Bugs: http://bugs.launchpad.net/networking-cumulus
19
+        
20
+        Configuration
21
+        =============
22
+        
23
+        List of switches are required to be configured in
24
+        ``/etc/neutron/plugins/ml2/ml2_conf_cumulus.ini``. 
25
+        The list can be comma separated switch names or IPs.
26
+        All other configurable parameters are optional.
27
+        
28
+        Cumulus ML2 driver confiuration format:
29
+        
30
+            [ml2_cumulus]
31
+            switches = <list of IP addresses or names>
32
+            protocol_port = <rest api port>
33
+            sync_time = <time interval in secs>
34
+            spf_time = <True/False>
35
+            new_bridge = <True/False>
36
+        
37
+        Example of ``ml2_conf_cumulus.ini``:
38
+        
39
+            [ml2_cumulus]
40
+            switches = 192.168.10.10,192.168.20.20
41
+            sync_time = 10
42
+            new_bridge = False
43
+            spf_enable = False
44
+        
45
+        
46
+        The ``cumulus`` mechanism driver needs to be enabled from
47
+        the ml2 config file ``/etc/neutron/plugins/ml2/ml2_conf.ini``::
48
+        
49
+           [ml2]
50
+           tenant_network_types = vlan
51
+           type_drivers = vlan,vxlan
52
+           mechanism_drivers = linuxbridge,cumulus
53
+           ...
54
+           ...
55
+        
56
+        (Re)start ``neutron-server`` specifying cumulus additional configuration file::
57
+        
58
+            neutron-server \
59
+                --config-file /etc/neutron/neutron.conf \
60
+                --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
61
+                --config-file /etc/neutron/plugins/ml2/ml2_conf_cumulus.ini
62
+        
63
+        
64
+Platform: UNKNOWN
65
+Classifier: Environment :: OpenStack
66
+Classifier: Intended Audience :: Information Technology
67
+Classifier: Intended Audience :: System Administrators
68
+Classifier: License :: OSI Approved :: Apache Software License
69
+Classifier: Operating System :: POSIX :: Linux
70
+Classifier: Programming Language :: Python
71
+Classifier: Programming Language :: Python :: 2
72
+Classifier: Programming Language :: Python :: 2.7

+ 74
- 0
images/deb/networking_cumulus.egg-info/SOURCES.txt View File

@@ -0,0 +1,74 @@
1
+.coveragerc
2
+.testr.conf
3
+AUTHORS
4
+CONTRIBUTING.rst
5
+ChangeLog
6
+HACKING.rst
7
+LICENSE
8
+MANIFEST.in
9
+README.rst
10
+babel.cfg
11
+requirements.txt
12
+setup.cfg
13
+setup.py
14
+test-requirements.txt
15
+tox.ini
16
+debian/changelog
17
+debian/compat
18
+debian/control
19
+debian/docs
20
+debian/networking-cumulus.install
21
+debian/rules
22
+debian/source/format
23
+debian/source/options
24
+devstack/plugin.sh
25
+devstack/settings
26
+doc/source/conf.py
27
+doc/source/contributing.rst
28
+doc/source/index.rst
29
+doc/source/installation.rst
30
+doc/source/readme.rst
31
+doc/source/usage.rst
32
+etc/neutron/plugins/ml2/ml2_conf_cumulus.ini
33
+networking_cumulus/__init__.py
34
+networking_cumulus/_i18n.py
35
+networking_cumulus.egg-info/PKG-INFO
36
+networking_cumulus.egg-info/SOURCES.txt
37
+networking_cumulus.egg-info/dependency_links.txt
38
+networking_cumulus.egg-info/entry_points.txt
39
+networking_cumulus.egg-info/not-zip-safe
40
+networking_cumulus.egg-info/pbr.json
41
+networking_cumulus.egg-info/requires.txt
42
+networking_cumulus.egg-info/top_level.txt
43
+networking_cumulus/db/__init__.py
44
+networking_cumulus/db/migration/__init__.py
45
+networking_cumulus/db/migration/alembic_migrations/__init__.py
46
+networking_cumulus/db/migration/alembic_migrations/env.py
47
+networking_cumulus/db/migration/alembic_migrations/script.py.mako
48
+networking_cumulus/db/migration/alembic_migrations/versions/1134a7f4c7e5_cumulus_init_ops.py
49
+networking_cumulus/db/migration/alembic_migrations/versions/HEAD
50
+networking_cumulus/db/migration/models/__init__.py
51
+networking_cumulus/db/migration/models/head.py
52
+networking_cumulus/mech_driver/__init__.py
53
+networking_cumulus/mech_driver/config.py
54
+networking_cumulus/mech_driver/db.py
55
+networking_cumulus/mech_driver/driver.py
56
+networking_cumulus/mech_driver/hpb_bridge_agent.py
57
+networking_cumulus/mech_driver/models.py
58
+networking_cumulus/tests/__init__.py
59
+networking_cumulus/tests/base.py
60
+networking_cumulus/tests/test_networking_cumulus.py
61
+networking_cumulus/tests/unit/__init__.py
62
+networking_cumulus/tests/unit/mech_driver/.test_cumulus_mech.py.swp
63
+networking_cumulus/tests/unit/mech_driver/__init__.py
64
+networking_cumulus/tests/unit/mech_driver/test_cumulus_mech.py
65
+networking_cumulus/utils/__init__.py
66
+networking_cumulus/utils/discovery.py
67
+networking_cumulus/utils/misc.py
68
+releasenotes/notes/.placeholder
69
+releasenotes/source/conf.py
70
+releasenotes/source/index.rst
71
+releasenotes/source/unreleased.rst
72
+releasenotes/source/_static/.placeholder
73
+releasenotes/source/_templates/.placeholder
74
+rpm/SPECS/cumulus.spec

+ 1
- 0
images/deb/networking_cumulus.egg-info/dependency_links.txt View File

@@ -0,0 +1 @@
1
+

+ 6
- 0
images/deb/networking_cumulus.egg-info/entry_points.txt View File

@@ -0,0 +1,6 @@
1
+[neutron.db.alembic_migrations]
2
+networking-cumulus = networking_cumulus.db.migration:alembic_migrations
3
+
4
+[neutron.ml2.mechanism_drivers]
5
+cumulus = networking_cumulus.mech_driver.driver:CumulusMechanismDriver
6
+

+ 1
- 0
images/deb/networking_cumulus.egg-info/not-zip-safe View File

@@ -0,0 +1 @@
1
+

+ 1
- 0
images/deb/networking_cumulus.egg-info/pbr.json View File

@@ -0,0 +1 @@
1
+{"is_release": false, "git_version": "f95ce05"}

+ 3
- 0
images/deb/networking_cumulus.egg-info/requires.txt View File

@@ -0,0 +1,3 @@
1
+Babel>1.3
2
+neutron-lib>=1.0.0
3
+pbr>=1.6

+ 1
- 0
images/deb/networking_cumulus.egg-info/top_level.txt View File

@@ -0,0 +1 @@
1
+networking_cumulus

BIN
images/rpm/networking-cumulus-1.0.0.dev12-1.noarch.rpm View File


BIN
images/rpm/networking-cumulus-1.0.0.dev12-1.src.rpm View File


BIN
images/rpm/networking-cumulus-1.0.0.dev12.tar.gz View File


BIN
images/rpm/networking-cumulus-1.0.0.dev9-1.noarch.rpm View File


BIN
images/rpm/networking-cumulus-1.0.0.dev9-1.src.rpm View File


BIN
images/rpm/networking-cumulus-1.0.0.dev9.tar.gz View File


+ 54
- 2
images/rpm/networking_cumulus.egg-info/PKG-INFO View File

@@ -1,12 +1,64 @@
1 1
 Metadata-Version: 1.1
2 2
 Name: networking-cumulus
3
-Version: 1.0.0.dev9
3
+Version: 1.0.0.dev12
4 4
 Summary: Cumulus ML2 driver
5 5
 Home-page: UNKNOWN
6 6
 Author: Cumulus Networks
7 7
 Author-email: cumulus-ml2@cumulusnetworks.com
8 8
 License: UNKNOWN
9
-Description: 
9
+Description: =====================================
10
+        networking-cumulus Neutron ML2 driver
11
+        =====================================
12
+        
13
+        Cumulus ML2 Mechanism Driver for Neutron
14
+        
15
+        * Free software: Apache license
16
+        * Documentation: TBD
17
+        * Source: http://git.openstack.org/cgit/openstack/networking-cumulus
18
+        * Bugs: http://bugs.launchpad.net/networking-cumulus
19
+        
20
+        Configuration
21
+        =============
22
+        
23
+        List of switches are required to be configured in
24
+        ``/etc/neutron/plugins/ml2/ml2_conf_cumulus.ini``. 
25
+        The list can be comma separated switch names or IPs.
26
+        All other configurable parameters are optional.
27
+        
28
+        Cumulus ML2 driver confiuration format:
29
+        
30
+            [ml2_cumulus]
31
+            switches = <list of IP addresses or names>
32
+            protocol_port = <rest api port>
33
+            sync_time = <time interval in secs>
34
+            spf_time = <True/False>
35
+            new_bridge = <True/False>
36
+        
37
+        Example of ``ml2_conf_cumulus.ini``:
38
+        
39
+            [ml2_cumulus]
40
+            switches = 192.168.10.10,192.168.20.20
41
+            sync_time = 10
42
+            new_bridge = False
43
+            spf_enable = False
44
+        
45
+        
46
+        The ``cumulus`` mechanism driver needs to be enabled from
47
+        the ml2 config file ``/etc/neutron/plugins/ml2/ml2_conf.ini``::
48
+        
49
+           [ml2]
50
+           tenant_network_types = vlan
51
+           type_drivers = vlan,vxlan
52
+           mechanism_drivers = linuxbridge,cumulus
53
+           ...
54
+           ...
55
+        
56
+        (Re)start ``neutron-server`` specifying cumulus additional configuration file::
57
+        
58
+            neutron-server \
59
+                --config-file /etc/neutron/neutron.conf \
60
+                --config-file /etc/neutron/plugins/ml2/ml2_conf.ini \
61
+                --config-file /etc/neutron/plugins/ml2/ml2_conf_cumulus.ini
10 62
         
11 63
         
12 64
 Platform: UNKNOWN

+ 5
- 6
images/rpm/networking_cumulus.egg-info/SOURCES.txt View File

@@ -1,10 +1,12 @@
1 1
 .coveragerc
2 2
 .testr.conf
3
+AUTHORS
3 4
 CONTRIBUTING.rst
5
+ChangeLog
4 6
 HACKING.rst
5 7
 LICENSE
6 8
 MANIFEST.in
7
-README.md
9
+README.rst
8 10
 babel.cfg
9 11
 requirements.txt
10 12
 setup.cfg
@@ -26,9 +28,6 @@ doc/source/installation.rst
26 28
 doc/source/readme.rst
27 29
 doc/source/usage.rst
28 30
 etc/neutron/plugins/ml2/ml2_conf_cumulus.ini
29
-images/deb/cumulus-ml2-driver_1.0.0-cl3eau1_all.deb
30
-images/rpm/cumulus-ml2-driver-1.0.0.dev8-1.noarch.rpm
31
-images/rpm/cumulus-ml2-driver-1.0.0.dev8-1.src.rpm
32 31
 networking_cumulus/__init__.py
33 32
 networking_cumulus/_i18n.py
34 33
 networking_cumulus.egg-info/PKG-INFO
@@ -58,8 +57,8 @@ networking_cumulus/tests/__init__.py
58 57
 networking_cumulus/tests/base.py
59 58
 networking_cumulus/tests/test_networking_cumulus.py
60 59
 networking_cumulus/tests/unit/__init__.py
61
-networking_cumulus/tests/unit/ml2/__init__.py
62
-networking_cumulus/tests/unit/ml2/test_cumulus_mech.py
60
+networking_cumulus/tests/unit/mech_driver/__init__.py
61
+networking_cumulus/tests/unit/mech_driver/test_cumulus_mech.py
63 62
 networking_cumulus/utils/__init__.py
64 63
 networking_cumulus/utils/discovery.py
65 64
 networking_cumulus/utils/misc.py

+ 1
- 1
images/rpm/networking_cumulus.egg-info/pbr.json View File

@@ -1 +1 @@
1
-{"is_release": false, "git_version": "b6606d3"}
1
+{"is_release": false, "git_version": "1d87e07"}

+ 3
- 1
images/rpm/networking_cumulus.egg-info/requires.txt View File

@@ -1 +1,3 @@
1
-pbr>=1.6
1
+Babel>1.3
2
+neutron-lib>=1.0.0
3
+pbr>=1.6

+ 13
- 59
networking_cumulus/mech_driver/driver.py View File

@@ -28,7 +28,7 @@ from neutron.plugins.ml2.common.exceptions import MechanismDriverError
28 28
 from neutron.plugins.ml2 import driver_api as api
29 29
 
30 30
 from networking_cumulus._i18n import _, _LI
31
-from networking_cumulus.mech_driver import config
31
+from networking_cumulus.mech_driver import config  # noqa
32 32
 from networking_cumulus.mech_driver import db
33 33
 
34 34
 LOG = logging.getLogger(__name__)
@@ -51,13 +51,6 @@ class SwitchState(Enum):
51 51
 INVALID_HASH_ID = _('invalid')
52 52
 INVALID_VNI = -1
53 53
 
54
-"""list of switches is required to be configured. Add this config to the
55
-ml2_conf.ini config switch names or IPs must be separated using comma.
56
-
57
-[ml2_cumulus]
58
-switches="192.168.10.10,192.168.20.20"
59
-"""
60
-
61 54
 
62 55
 class CumulusMechanismDriver(api.MechanismDriver):
63 56
     """Mechanism driver for Cumulus Linux
@@ -76,7 +69,7 @@ class CumulusMechanismDriver(api.MechanismDriver):
76 69
         self.password = cfg.CONF.ml2_cumulus.password
77 70
         self.switch_info = {}
78 71
         self.sync_timer = None
79
-        self.sync_thread_lock = None
72
+        self.sync_thread_lock = threading.Lock()
80 73
         self.sync = None
81 74
 
82 75
     def initialize(self):
@@ -85,21 +78,25 @@ class CumulusMechanismDriver(api.MechanismDriver):
85 78
             self.switch_info[switch_id, 'spf_enable'] = self.spf_enable
86 79
             self.switch_info[switch_id, 'new_bridge'] = self.new_bridge
87 80
 
88
-        self.sync_thread_lock = threading.Lock()
89 81
         if self.sync_timeout > 0:
90 82
             self.sync = CumulusSwitchSync(self)
91 83
             self.sync_timer = None
92
-            self._sync_thread()
84
+            self._start_sync_thread()
93 85
 
94
-    def _sync_thread(self):
86
+    def _start_sync_thread(self):
95 87
         with self.sync_thread_lock:
96 88
             self.sync.check_and_replay()
97 89
 
98 90
         self.sync_timer = threading.Timer(self.sync_timeout,
99
-                                          self._sync_thread)
91
+                                          self._start_sync_thread)
100 92
         self.sync_timer.start()
101 93
 
102
-    def _get_bridge_name(self, network_id, new_bridge):
94
+    def stop_sync_thread(self):
95
+        if self.sync_timer:
96
+            self.sync_timer.cancel()
97
+            self.sync_time = None
98
+
99
+    def get_bridge_name(self, network_id, new_bridge):
103 100
         if new_bridge:
104 101
             return NEW_BRIDGE_NAME
105 102
         else:
@@ -131,8 +128,8 @@ class CumulusMechanismDriver(api.MechanismDriver):
131 128
             db.db_create_network(tenant_id,
132 129
                                  network_id,
133 130
                                  vlan_id,
134
-                                 self._get_bridge_name(network_id,
135
-                                                       self.new_bridge))
131
+                                 self.get_bridge_name(network_id,
132
+                                                      self.new_bridge))
136 133
 
137 134
     def create_network_postcommit(self, context):
138 135
         network = context.current
@@ -171,10 +168,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
171 168
                            {'switch_id': _switch_id,
172 169
                             'error': error})
173 170
                     LOG.info(msg)
174
-#                        _LI('Error connecting to switch %s. HTTP Error:%r'),
175
-#                        _switch_id,
176
-#                        error
177
-#                    )
178 171
 
179 172
     def delete_network_postcommit(self, context):
180 173
         network_id = context.current['id']
@@ -211,10 +204,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
211 204
                        {'switch_id': _switch_id,
212 205
                         'error': error})
213 206
                 LOG.info(msg)
214
-#                    _LI('Error connecting to switch %s. HTTP Error:%r'),
215
-#                    _switch_id,
216
-#                    error
217
-#                )
218 207
 
219 208
         with self.sync_thread_lock:
220 209
             db.db_delete_network(tenant_id, network_id)
@@ -374,12 +363,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
374 363
                                 'switch_id': _switch_id})
375 364
 
376 365
                         LOG.info(msg)
377
-#                            _LI('error (%(code)) update port for %(host) on '
378
-#                            'switch: %(switch_id)'),
379
-#                            resp.status_code,
380
-#                            host,
381
-#                            _switch_id
382
-#                        )
383 366
                         return resp.status_code
384 367
 #                    raise MechanismDriverError()
385 368
 
@@ -389,10 +372,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
389 372
                            {'switch_id': _switch_id,
390 373
                             'error': error})
391 374
                     LOG.info(msg)
392
-#                        _LI('Error connecting to switch %s. HTTP Error:%r'),
393
-#                        _switch_id,
394
-#                        error
395
-#                    )
396 375
 
397 376
     def _remove_from_switch(self, port, network):
398 377
         host = port[portbindings.HOST_ID]
@@ -442,11 +421,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
442 421
                                 'host': host,
443 422
                                 'switch_id': _switch_id})
444 423
                         LOG.info(msg)
445
-#                            _LI('error (%d) del port for %s on switch: %s'),
446
-#                            resp.status_code,
447
-#                            host,
448
-#                            _switch_id
449
-#                        )
450 424
 
451 425
                 except requests.exceptions.RequestException as error:
452 426
                     msg = (_("Error connecting to switch (%(switch_id)s)."
@@ -454,10 +428,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
454 428
                            {'switch_id': _switch_id,
455 429
                             'error': error})
456 430
                     LOG.info(msg)
457
-#                        _LI('Error connecting to switch %s. HTTP Error:%r'),
458
-#                        _switch_id,
459
-#                        error
460
-#                    )
461 431
 
462 432
             with self.sync_thread_lock:
463 433
                 db.db_delete_port(network.network_id, port_id, _switch_id,
@@ -485,10 +455,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
485 455
                        {'code': resp.status_code,
486 456
                         'switch_id': switch_id})
487 457
                 LOG.info(msg)
488
-#                    _LI('Error with request to switch %s. Error:%d'),
489
-#                    switch_id,
490
-#                    resp.status_code
491
-#                )
492 458
                 return resp.status_code
493 459
 
494 460
         except requests.exceptions.RequestException as error:
@@ -497,10 +463,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
497 463
                    {'switch_id': switch_id,
498 464
                     'error': error})
499 465
             LOG.info(msg)
500
-#                _LI('Error connecting to switch %s. HTTP Error:%r'),
501
-#                switch_id,
502
-#                error
503
-#            )
504 466
 
505 467
         actions = [
506 468
             HOSTS_URL.format(
@@ -534,10 +496,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
534 496
                            {'code': resp.status_code,
535 497
                             'switch_id': switch_id})
536 498
                     LOG.info(msg)
537
-#                        _LI('Error with request to switch %s. Error:%d'),
538
-#                        switch_id,
539
-#                        resp.status_code
540
-#                    )
541 499
                     return resp.status_code
542 500
 
543 501
             except requests.exceptions.RequestException as error:
@@ -546,10 +504,6 @@ class CumulusMechanismDriver(api.MechanismDriver):
546 504
                        {'switch_id': switch_id,
547 505
                         'error': error})
548 506
                 LOG.info(msg)
549
-#                    _LI('Error connecting to switch %s. HTTP Error:%r'),
550
-#                    switch_id,
551
-#                    error
552
-#                )
553 507
 
554 508
         return requests.codes.ok
555 509
 

+ 4
- 4
networking_cumulus/mech_driver/models.py View File

@@ -16,14 +16,14 @@
16 16
 import sqlalchemy as sa
17 17
 
18 18
 from neutron.api.v2 import attributes as attr
19
-from neutron.db import model_base
20
-from neutron.db import models_v2
19
+from neutron_lib.db import model_base
21 20
 
22 21
 BRIDGE_STR_LEN = 15
23 22
 CUMULUS_UUID_FIELD_SIZE = 36
24 23
 
25 24
 
26
-class CumulusNetworks(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
25
+class CumulusNetworks(model_base.BASEV2, model_base.HasId,
26
+                      model_base.HasProject):
27 27
     """Represents a binding of network id to cumulus bridge."""
28 28
 
29 29
     __tablename__ = "cumulus_networks"
@@ -48,7 +48,7 @@ class CumulusNetworks(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
48 48
                 u'bridgeName': self.bridge_name}
49 49
 
50 50
 
51
-class CumulusPorts(model_base.BASEV2, models_v2.HasId, models_v2.HasTenant):
51
+class CumulusPorts(model_base.BASEV2, model_base.HasId, model_base.HasProject):
52 52
 
53 53
     __tablename__ = "cumulus_ports"
54 54
 

networking_cumulus/tests/unit/ml2/__init__.py → networking_cumulus/tests/unit/mech_driver/__init__.py View File


+ 133
- 0
networking_cumulus/tests/unit/mech_driver/test_cumulus_mech.py View File

@@ -0,0 +1,133 @@
1
+# Copyright 2016 Cumulus Networks
2
+# All Rights Reserved.
3
+#
4
+# Licensed under the Apache License, Version 2.0 (the "License");
5
+# you may not use this file except in compliance with the License.
6
+# You may obtain a copy of the License at
7
+#
8
+#    http://www.apache.org/licenses/LICENSE-2.0
9
+#
10
+# Unless required by applicable law or agreed to in writing, software
11
+# distributed under the License is distributed on an "AS IS" BASIS,
12
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13
+# implied.
14
+# See the License for the specific language governing permissions and
15
+# limitations under the License.
16
+
17
+import mock
18
+
19
+from neutron.tests.unit import testlib_api
20
+
21
+from networking_cumulus.mech_driver import driver as cumulus_driver
22
+
23
+TENANT_ID = 'cn_test_tenant_id'
24
+NETWORK_NAME = 'cn_test_network'
25
+NETWORK_ID = 'cn_test_network_id'
26
+VLAN_ID = 1000
27
+
28
+
29
+class CumulusMechanismDriverTestCase(testlib_api.SqlTestCase):
30
+    """Main test cases for Cumulus Mechanism driver.
31
+
32
+    Tests all mechanism driver APIs supported by Cumulus Driver. It invokes
33
+    all the APIs as they would be invoked in real world scenarios and
34
+    verifies the functionality.
35
+    """
36
+    def setUp(self):
37
+        super(CumulusMechanismDriverTestCase, self).setUp()
38
+        cumulus_driver.db = mock.MagicMock()
39
+        self.driver = cumulus_driver.CumulusMechanismDriver()
40
+
41
+    def tearDown(self):
42
+        super(CumulusMechanismDriverTestCase, self).tearDown()
43
+        self.driver.stop_sync_thread()
44
+
45
+    def test_create_network_precommit(self):
46
+        network_context = self._get_network_context(TENANT_ID,
47
+                                                    NETWORK_ID,
48
+                                                    NETWORK_NAME,
49
+                                                    VLAN_ID,
50
+                                                    False)
51
+        self.driver.create_network_precommit(network_context)
52
+        bridge_name = self.driver.get_bridge_name(NETWORK_ID,
53
+                                                  self.driver.new_bridge)
54
+
55
+        expected_calls = [
56
+            mock.call.db_create_network(TENANT_ID,
57
+                                        NETWORK_ID,
58
+                                        VLAN_ID,
59
+                                        bridge_name)
60
+        ]
61
+
62
+        cumulus_driver.db.assert_has_calls(expected_calls)
63
+
64
+    def test_create_network_postcommit(self):
65
+        network_context = self._get_network_context(TENANT_ID,
66
+                                                    NETWORK_ID,
67
+                                                    NETWORK_NAME,
68
+                                                    VLAN_ID,
69
+                                                    False)
70
+        cumulus_driver.db.db_get_bridge_name.return_value = \
71
+            self.driver.get_bridge_name(NETWORK_ID,
72
+                                        self.driver.new_bridge)
73
+
74
+        self.driver.create_network_postcommit(network_context)
75
+
76
+        expected_calls = [
77
+            mock.call.db_get_bridge_name(TENANT_ID, NETWORK_ID),
78
+        ]
79
+
80
+        cumulus_driver.db.assert_has_calls(expected_calls)
81
+
82
+    def test_delete_network_postcommit(self):
83
+        cumulus_driver.db.db_get_bridge_name.return_value = \
84
+            self.driver.get_bridge_name(NETWORK_ID,
85
+                                        self.driver.new_bridge)
86
+        network_context = self._get_network_context(TENANT_ID,
87
+                                                    NETWORK_ID,
88
+                                                    NETWORK_NAME,
89
+                                                    VLAN_ID,
90
+                                                    False)
91
+
92
+        self.driver.delete_network_postcommit(network_context)
93
+        expected_calls = [
94
+            mock.call.db_get_bridge_name(TENANT_ID, NETWORK_ID),
95
+            mock.call.db_delete_network(TENANT_ID, NETWORK_ID)
96
+        ]
97
+
98
+        cumulus_driver.db.assert_has_calls(expected_calls)
99
+
100
+    def _get_network_context(self, tenant_id, net_id, net_name,
101
+                             segmentation_id, shared):
102
+        network = {'id': net_id,
103
+                   'tenant_id': tenant_id,
104
+                   'name': net_name,
105
+                   'shared': shared}
106
+        network_segments = [{'segmentation_id': segmentation_id,
107
+                             'physical_network': u'default',
108
+                             'id': 'segment-id-for-%s' % segmentation_id,
109
+                             'network_type': 'vlan'}]
110
+        return FakeNetworkContext(tenant_id, network, network_segments,
111
+                                  network)
112
+
113
+
114
+class FakeNetworkContext(object):
115
+    """To generate network context for testing purposes only."""
116
+
117
+    def __init__(self, tenant_id, network, segments=None,
118
+                 original_network=None):
119
+        self._network = network
120
+        self._original_network = original_network
121
+        self._segments = segments
122
+
123
+    @property
124
+    def current(self):
125
+        return self._network
126
+
127
+    @property
128
+    def original(self):
129
+        return self._original_network
130
+
131
+    @property
132
+    def network_segments(self):
133
+        return self._segments

+ 0
- 1143
networking_cumulus/tests/unit/ml2/test_cumulus_mech.py
File diff suppressed because it is too large
View File


+ 2
- 0
requirements.txt View File

@@ -2,4 +2,6 @@
2 2
 # of appearance. Changing the order has an impact on the overall integration
3 3
 # process, which may cause wedges in the gate later.
4 4
 
5
+Babel>1.3
6
+neutron-lib>=1.0.0 # Apache-2.0
5 7
 pbr>=1.6 # Apache-2.0

+ 1
- 1
setup.cfg View File

@@ -3,7 +3,7 @@ name = networking-cumulus
3 3
 version = 1.0.0
4 4
 summary = Cumulus ML2 driver
5 5
 description-file =
6
-	README.md
6
+	README.rst
7 7
 author = Cumulus Networks
8 8
 author-email = cumulus-ml2@cumulusnetworks.com
9 9
 classifier =

+ 2
- 0
test-requirements.txt View File

@@ -4,6 +4,7 @@
4 4
 
5 5
 hacking>=0.11.0,<0.12 # Apache-2.0
6 6
 
7
+mock>=1.0,<1.1.0
7 8
 coverage>=3.6 # Apache-2.0
8 9
 python-subunit>=0.0.18 # Apache-2.0/BSD
9 10
 sphinx>=1.2.1,!=1.3b1,<1.4 # BSD
@@ -12,6 +13,7 @@ oslotest>=1.10.0 # Apache-2.0
12 13
 testrepository>=0.0.18 # Apache-2.0/BSD
13 14
 testscenarios>=0.4 # Apache-2.0/BSD
14 15
 testtools>=1.4.0 # MIT
16
+testresources>=0.2.4
15 17
 
16 18
 # releasenotes
17 19
 reno>=1.8.0 # Apache2

+ 4
- 2
tox.ini View File

@@ -1,15 +1,17 @@
1 1
 [tox]
2 2
 minversion = 2.0
3
-envlist = py27,pep8
3
+envlist = py34,py27,pep8
4 4
 skipsdist = True
5 5
 
6 6
 [testenv]
7 7
 usedevelop = True
8
-install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages}
8
+install_command = pip install -c{env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} -r requirements.txt -U {opts} {packages}
9 9
 setenv =
10 10
    VIRTUAL_ENV={envdir}
11 11
    PYTHONWARNINGS=default::DeprecationWarning
12 12
 deps = -r{toxinidir}/test-requirements.txt
13
+       -egit+https://git.openstack.org/openstack/neutron.git#egg=neutron
14
+whitelist_externals = sh
13 15
 commands = python setup.py testr --slowest --testr-args='{posargs}'
14 16
 
15 17
 [testenv:pep8]

Loading…
Cancel
Save