Browse Source

Prevent NoneType error when remote IPAM options is None

Signed-off-by: Joffrey F <[email protected]>
Joffrey F 8 years ago
parent
commit
d0acefd450
2 changed files with 40 additions and 2 deletions
  1. 2 2
      compose/network.py
  2. 38 0
      tests/unit/network_test.py

+ 2 - 2
compose/network.py

@@ -158,8 +158,8 @@ def check_remote_ipam_config(remote, local):
             if sorted(lc.get('AuxiliaryAddresses')) != sorted(rc.get('AuxiliaryAddresses')):
                 raise NetworkConfigChangedError(local.full_name, 'IPAM config aux_addresses')
 
-    remote_opts = remote_ipam.get('Options', {})
-    local_opts = local.ipam.get('options', {})
+    remote_opts = remote_ipam.get('Options') or {}
+    local_opts = local.ipam.get('options') or {}
     for k in set.union(set(remote_opts.keys()), set(local_opts.keys())):
         if remote_opts.get(k) != local_opts.get(k):
             raise NetworkConfigChangedError(local.full_name, 'IPAM option "{}"'.format(k))

+ 38 - 0
tests/unit/network_test.py

@@ -100,6 +100,44 @@ class NetworkTest(unittest.TestCase):
             {'Driver': 'overlay', 'Options': None}, net
         )
 
+    def test_check_remote_network_config_null_remote_ipam_options(self):
+        ipam_config = {
+            'driver': 'default',
+            'config': [
+                {'subnet': '172.0.0.1/16', },
+                {
+                    'subnet': '156.0.0.1/25',
+                    'gateway': '156.0.0.1',
+                    'aux_addresses': ['11.0.0.1', '24.25.26.27'],
+                    'ip_range': '156.0.0.1-254'
+                }
+            ]
+        }
+        net = Network(
+            None, 'compose_test', 'net1', 'bridge', ipam=ipam_config,
+        )
+
+        check_remote_network_config(
+            {
+                'Driver': 'bridge',
+                'Attachable': True,
+                'IPAM': {
+                    'Driver': 'default',
+                    'Config': [{
+                        'Subnet': '156.0.0.1/25',
+                        'Gateway': '156.0.0.1',
+                        'AuxiliaryAddresses': ['24.25.26.27', '11.0.0.1'],
+                        'IPRange': '156.0.0.1-254'
+                    }, {
+                        'Subnet': '172.0.0.1/16',
+                        'Gateway': '172.0.0.1'
+                    }],
+                    'Options': None
+                },
+            },
+            net
+        )
+
     def test_check_remote_network_labels_mismatch(self):
         net = Network(None, 'compose_test', 'net1', 'overlay', labels={
             'com.project.touhou.character': 'sakuya.izayoi'