Repository: buildbot/buildbot

Issue:
wth 1382003: unreachable code?
This ticket is a migrated Trac ticket [3646](http://trac.buildbot.net/ticket/3646)

People contributed to the original ticket: @sa2ajj
Ticket created on: `Nov 28 2016`
Ticket last modified on: `Nov 28 2016`

---

while reviewing Coverity findings, I found this code:

[[buildbot/worker/ec2.py:293|https://github.com/buildbot/buildbot/blob/master/master/buildbot/worker/ec2.py#L293]]:

        def _convert_deprecated_block_device_mapping(self, mapping_definitions):
            new_mapping_definitions = []
            for dev_name, dev_config in iteritems(mapping_definitions):
                new_dev_config = {}
                new_dev_config['[[DeviceName]]'] = dev_name
                if dev_config:
                    new_dev_config['Ebs'] = {}
                    new_dev_config['Ebs']['[[DeleteOnTermination]]'] = dev_config.get(
                        'delete_on_termination', True)
                    new_dev_config[[                        'Encrypted'|'Ebs'][]] = dev_config.get('encrypted')
                    new_dev_config['Ebs']['Iops'] = dev_config.get('iops')
                    new_dev_config[[                        '[[SnapshotId]]'|'Ebs'][]] = dev_config.get('snapshot_id')
                    new_dev_config['Ebs']['[[VolumeSize]]'] = dev_config.get('size')
                    new_dev_config[[                        '[[VolumeType]]'|'Ebs'][]] = dev_config.get('volume_type')
                    new_dev_config['Ebs'] = self._remove_none_opts(
                        new_dev_config['Ebs'])
                new_mapping_definitions.append(new_dev_config)
            return new_mapping_definitions
            if not mapping_definitions:
                return None
    
            for mapping_definition in mapping_definitions:
                ebs = mapping_definition.get('Ebs')
                if ebs:
                    ebs.setdefault('[[DeleteOnTermination]]', True)
    
            return mapping_definitions


what the heck is going on here?

(the number in the summary is CID (Coverity ID))


---





Discussion:

Resolving patch:
diff --git a/master/buildbot/worker/ec2.py b/master/buildbot/worker/ec2.py
--- a/master/buildbot/worker/ec2.py
+++ b/master/buildbot/worker/ec2.py
@@ -314,15 +314,6 @@ def _convert_deprecated_block_device_mapping(self, mapping_definitions):
                     new_dev_config['Ebs'])
             new_mapping_definitions.append(new_dev_config)
         return new_mapping_definitions
-        if not mapping_definitions:
-            return None
-
-        for mapping_definition in mapping_definitions:
-            ebs = mapping_definition.get('Ebs')
-            if ebs:
-                ebs.setdefault('DeleteOnTermination', True)
-
-        return mapping_definitions
 
     def get_image(self):
         # pylint: disable=too-many-nested-blocks


Test patch:
diff --git a/master/buildbot/test/unit/test_data_types.py b/master/buildbot/test/unit/test_data_types.py
--- a/master/buildbot/test/unit/test_data_types.py
+++ b/master/buildbot/test/unit/test_data_types.py
@@ -140,7 +140,7 @@ def makeInstance(self):
         (b'abcd', u'abcd'),
     ]
     badStringValues = [
-        b'', '\N{SNOWMAN}', b'abcdef'
+        b'', r'\N{SNOWMAN}', b'abcdef'
     ]
     cmpResults = [
         (u'aaaa', b'bbbb', -1),