From b679db9756e935b9e5f89f59b9f467c7c73e74ed Mon Sep 17 00:00:00 2001
From: Chris Burr <christopher.burr@cern.ch>
Date: Wed, 25 Nov 2020 06:31:27 +0100
Subject: [PATCH] Remove deployment kwarg from slot configuration

---
 python/LbMsg/BuildMsg.py                      |  2 -
 python/LbNightlyTools/Configuration.py        | 18 ++----
 python/LbNightlyTools/Scripts/Common.py       | 14 ++---
 .../LbNightlyTools/Scripts/_entry_points.py   | 61 -------------------
 setup.py                                      |  1 -
 5 files changed, 9 insertions(+), 87 deletions(-)

diff --git a/python/LbMsg/BuildMsg.py b/python/LbMsg/BuildMsg.py
index 8faa3173..62a5c029 100755
--- a/python/LbMsg/BuildMsg.py
+++ b/python/LbMsg/BuildMsg.py
@@ -38,7 +38,6 @@ class NightliesMessenger(Messenger):
                       project,
                       config,
                       buildId,
-                      deployment=None,
                       priority=None,
                       date=datetime.datetime.now()):
         '''
@@ -51,7 +50,6 @@ class NightliesMessenger(Messenger):
                 'project': project,
                 'platform': config,
                 'build_id': buildId,
-                'deployment': deployment,
                 'priority': priority
             }]))
 
diff --git a/python/LbNightlyTools/Configuration.py b/python/LbNightlyTools/Configuration.py
index 9181855e..2f6c4cd2 100644
--- a/python/LbNightlyTools/Configuration.py
+++ b/python/LbNightlyTools/Configuration.py
@@ -1501,8 +1501,7 @@ class Slot(with_metaclass(_SlotMeta, object)):
     __slots__ = ('_name', '_projects', 'env', '_build_tool', 'disabled',
                  'desc', 'platforms', 'error_exceptions', 'warning_exceptions',
                  'preconditions', 'cache_entries', 'build_id', 'no_patch',
-                 'with_version_dir', 'no_test', 'deployment', 'metadata',
-                 '_source')
+                 'with_version_dir', 'no_test', 'metadata', '_source')
     __projects__ = []
     __env__ = []
 
@@ -1528,7 +1527,6 @@ class Slot(with_metaclass(_SlotMeta, object)):
         @param with_version_dir: if set to True, sources will be checkout in
                                  the path: Project/Project_version
         @param no_test: if set to True, tests should not be run for this slot)
-        @param deployment: list of deployment destinations (strings)
         @param metadata: dictionary with extra information, e.g. for the dashboard
         '''
         self._name = name
@@ -1564,8 +1562,6 @@ class Slot(with_metaclass(_SlotMeta, object)):
         self.with_version_dir = kwargs.get('with_version_dir', False)
         self.no_test = kwargs.get('no_test', False)
 
-        self.deployment = kwargs.get('deployment', [])
-
         self.metadata = kwargs.get('metadata', {})
 
         # get the name of the Python module calling the constructor,
@@ -1605,8 +1601,6 @@ class Slot(with_metaclass(_SlotMeta, object)):
             data['with_version_dir'] = True
         if self.no_test:
             data['no_test'] = True
-        if self.deployment:
-            data['deployment'] = self.deployment
         if self.metadata:
             data['metadata'] = self.metadata
 
@@ -1645,7 +1639,6 @@ class Slot(with_metaclass(_SlotMeta, object)):
             env=data.get('env', []),
             desc=data.get('description'),
             disabled=data.get('disabled', False),
-            deployment=data.get('deployment', []),
             metadata=data.get('metadata', {}))
         slot.platforms = data.get('platforms', data.get(
             'default_platforms', []))
@@ -2225,8 +2218,6 @@ def cloneSlot(slot, name):
         slot = slots[slot]
     desc = slot.toDict()
     desc['slot'] = name
-    # a clone does not inherit the deployment target
-    desc['deployment'] = []
     return Slot.fromDict(copy.deepcopy(desc))
 
 
@@ -2516,10 +2507,11 @@ def check_config():
 
     from tabulate import tabulate
     print(tabulate([[
-        name, 'X' if slots[name].enabled else ' ', ', '.join(
-            slots[name].deployment), slots[name]._source
+        name,
+        'X' if slots[name].enabled else ' ',
+        slots[name]._source,
     ] for name in sorted(slots)],
-                   headers=('slot', 'enabled', 'deployment', 'source'),
+                   headers=('slot', 'enabled', 'source'),
                    tablefmt='grid'))
 
     logging.debug('converting slots to JSON')
diff --git a/python/LbNightlyTools/Scripts/Common.py b/python/LbNightlyTools/Scripts/Common.py
index 6989ea54..f6279d74 100755
--- a/python/LbNightlyTools/Scripts/Common.py
+++ b/python/LbNightlyTools/Scripts/Common.py
@@ -626,22 +626,16 @@ class PeriodicTestMsg:
         '''
         sends the message that builds are ready
         '''
-        deployment_target = self.slot.deployment
         self.log.debug(
             'sending the message to the queue that builds '
             'are ready for slot: %s, project: %s, platform: %s, '
-            'build_id: %s, deployment: %s', self.slot.name,
-            msg['project'].name, self.platform, self.slot.build_id,
-            deployment_target)
+            'build_id: %s', self.slot.name, msg['project'].name, self.platform,
+            self.slot.build_id)
         try:
             import LbMsg.BuildMsg
             build_msg = LbMsg.BuildMsg.NightliesMessenger()
-            build_msg.sendBuildDone(
-                self.slot.name,
-                msg['project'].name,
-                self.platform,
-                self.slot.build_id,
-                deployment=deployment_target)
+            build_msg.sendBuildDone(self.slot.name, msg['project'].name,
+                                    self.platform, self.slot.build_id)
         except Exception as x:
             self.log.warning('problems sending message: %s: %s',
                              type(x).__name__, x)
diff --git a/python/LbNightlyTools/Scripts/_entry_points.py b/python/LbNightlyTools/Scripts/_entry_points.py
index 5fbb67d9..e78a93da 100644
--- a/python/LbNightlyTools/Scripts/_entry_points.py
+++ b/python/LbNightlyTools/Scripts/_entry_points.py
@@ -538,67 +538,6 @@ def rpm_validator():
     return LHCbRPMReleaseConsistency()
 
 
-def slots_by_deployment():
-    import sys
-    import logging
-    from LbNightlyTools.Scripts.Common import PlainScript
-    from LbNightlyTools.Configuration import loadConfig
-
-    CONF_ZIP_URL = ('https://gitlab.cern.ch/lhcb-core/LHCbNightlyConf/'
-                    'repository/archive.zip?ref={0}')
-
-    def getSlotsFromGit(branch='master'):
-        '''
-        Helper to get the list of slots defined on the repository.
-        '''
-        from LbNightlyTools.Utils import TemporaryDir
-        from urllib.request import urlretrieve
-        from zipfile import ZipFile
-        import os
-        with TemporaryDir(chdir=True):
-            url = CONF_ZIP_URL.format(branch)
-            logging.debug('getting config files from %s', url)
-            urlretrieve(url, 'config.zip')
-            logging.debug('unpacking')
-            z = ZipFile('config.zip')
-            z.extractall()
-            return loadConfig(z.namelist()[0])
-
-    class Script(PlainScript):
-        '''
-        Simple script to get the list of slots by deployment key.
-        '''
-        __usage__ = '%prog [options] deployment_type ...'
-
-        def defineOpts(self):
-            '''
-            Prepare the option parser.
-            '''
-            self.parser.add_option(
-                '--branch',
-                help='branch of the configuration to use '
-                '[default: %default]')
-            self.parser.add_option(
-                '--configdir',
-                help='use configuration from the given '
-                'directory instead of from gitlab')
-            self.parser.set_defaults(branch='master')
-
-        def main(self):
-            deployments = set(s.lower() for s in self.args)
-            if not deployments:
-                self.parser.error(
-                    'you must specify at least one deployment type')
-            slots = (loadConfig(self.options.configdir)
-                     if self.options.configdir else getSlotsFromGit(
-                         self.options.branch))
-            print('\n'.join(name for name, slot in sorted(slots.items())
-                            if slot.enabled and deployments.intersection(
-                                s.lower() for s in slot.deployment)))
-
-    return Script().run()
-
-
 def test_poll():
     from LbNightlyTools.Scripts.Test import Poll as Script
     return Script().run()
diff --git a/setup.py b/setup.py
index c53c64e3..d43240ca 100644
--- a/setup.py
+++ b/setup.py
@@ -222,7 +222,6 @@ setup(
             'lbn-reschedule-tests=LbNightlyTools.Scripts._entry_points:reschedule_tests',
             'lbn-rpm=LbNightlyTools.Scripts._entry_points:rpm',
             'lbn-rpm-validator=LbNightlyTools.Scripts._entry_points:rpm_validator',
-            'lbn-slots-by-deployment=LbNightlyTools.Scripts._entry_points:slots_by_deployment',
             'lbn-test=LbNightlyTools.Scripts.Test:run',
             'lbn-test-legacy=LbNightlyTools.Scripts.Test:run',
             'lbn-test-poll=LbNightlyTools.Scripts._entry_points:test_poll',
-- 
GitLab