Repository: codalab/codalab-worksheets

Issue:
Supporting request-queue for both formats: tag=<X> and X
When a bundle is requested to run on a specific worker, we currently use `--request-queue tag=<worker_X>` to indicate the worker that the bundle should run on. This ticket is to add support for another format: `--request-queue worker_X`.

Discussion:
yipenghe: Does this affect #2040 ?
candicegjing: > Does this affect #2040 ?

This change will cover both `--request-queue tag=foo` and `--request-queue foo`. So I think it won't affect changes in #2040. If not, please let me know
candicegjing: @bkgoksel This is ready for another review~ Let me know if I need to change anything.

Patch:
diff --git a/codalab/server/bundle_manager.py b/codalab/server/bundle_manager.py
index 1bc20140..bc81a861 100644
--- a/codalab/server/bundle_manager.py
+++ b/codalab/server/bundle_manager.py
@@ -676,12 +676,12 @@ class BundleManager(object):
     def _get_matched_workers(request_queue, workers):
         """
         Get all of the workers that match with the name of the requested worker
-        :param request_queue: a tag that can be used to match workers
+        :param request_queue: a tag with the format "tag=worker_X" or "worker_X" that can be used to match workers
         :param workers: a list of workers
         :return: a list of matched workers
         """
-        tag_match = re.match('tag=(.+)', request_queue)
-        if tag_match != None:
+        tag_match = re.match('(?:tag=)?(.+)', request_queue)
+        if tag_match is not None:
             return [worker for worker in workers if worker['tag'] == tag_match.group(1)]
         return []
 


Test patch:
diff --git a/tests/server/bundle_manager_test.py b/tests/server/bundle_manager_test.py
index 76a84c1b..4b894c3a 100644
--- a/tests/server/bundle_manager_test.py
+++ b/tests/server/bundle_manager_test.py
@@ -84,7 +84,7 @@ class BundleManagerTest(unittest.TestCase):
                 'cpus': 6,
                 'gpus': 0,
                 'memory_bytes': 2 * 1000,
-                'tag': None,
+                'tag': 'worker_X',
                 'run_uuids': [],
                 'dependencies': [],
                 'shared_file_system': False,
@@ -111,3 +111,40 @@ class BundleManagerTest(unittest.TestCase):
         )
         self.assertEqual(len(sorted_workers_list), 5)
         self.assertEqual(sorted_workers_list[0]['worker_id'], 3)
+
+    def test__get_matched_workers_with_tag(self):
+        self.bundle.metadata.request_queue = "tag=worker_X"
+        matched_workers = BundleManager._get_matched_workers(
+            self.bundle.metadata.request_queue, self.workers_list
+        )
+        self.assertEqual(len(matched_workers), 1)
+        self.assertEqual(matched_workers[0]['worker_id'], 4)
+
+    def test__get_matched_workers_with_bad_formatted_tag(self):
+        self.bundle.metadata.request_queue = "tag="
+        matched_workers = BundleManager._get_matched_workers(
+            self.bundle.metadata.request_queue, self.workers_list
+        )
+        self.assertEqual(len(matched_workers), 0)
+
+    def test__get_matched_workers_without_tag_prefix(self):
+        self.bundle.metadata.request_queue = "worker_X"
+        matched_workers = BundleManager._get_matched_workers(
+            self.bundle.metadata.request_queue, self.workers_list
+        )
+        self.assertEqual(len(matched_workers), 1)
+        self.assertEqual(matched_workers[0]['worker_id'], 4)
+
+    def test__get_matched_workers_not_exist_tag(self):
+        self.bundle.metadata.request_queue = "worker_Y"
+        matched_workers = BundleManager._get_matched_workers(
+            self.bundle.metadata.request_queue, self.workers_list
+        )
+        self.assertEqual(len(matched_workers), 0)
+
+    def test__get_matched_workers_empty_tag(self):
+        self.bundle.metadata.request_queue = ""
+        matched_workers = BundleManager._get_matched_workers(
+            self.bundle.metadata.request_queue, self.workers_list
+        )
+        self.assertEqual(len(matched_workers), 0)