Merge "Remove TestScheduler.test_nonexistent_job" into feature/zuulv3
diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py
index e807d0a..8fa7b7b 100755
--- a/tests/test_scheduler.py
+++ b/tests/test_scheduler.py
@@ -4517,7 +4517,7 @@
         self.launch_server.release('.*-test*')
         self.waitUntilSettled()
 
-        for x in range(2):
+        for x in range(3):
             self.assertEqual(len(self.builds), 1,
                              'len of builds at x=%d is wrong' % x)
             self.builds[0].requeue = True
@@ -4527,7 +4527,7 @@
         self.launch_server.hold_jobs_in_build = False
         self.launch_server.release()
         self.waitUntilSettled()
-        self.assertEqual(len(self.history), 5)
+        self.assertEqual(len(self.history), 6)
         self.assertEqual(self.countJobResults(self.history, 'SUCCESS'), 2)
         self.assertEqual(A.reported, 1)
         self.assertIn('RETRY_LIMIT', A.messages[0])
diff --git a/tools/update-storyboard.py b/tools/update-storyboard.py
new file mode 100644
index 0000000..6800a35
--- /dev/null
+++ b/tools/update-storyboard.py
@@ -0,0 +1,99 @@
+#!/usr/bin/env python
+# Copyright (C) 2016 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# This script updates the Zuul v3 Storyboard.  It uses a .boartty.yaml
+# file to get credential information.
+
+import requests
+import boartty.config
+import boartty.sync
+import logging  # noqa
+from pprint import pprint as p  # noqa
+
+
+class App(object):
+    pass
+
+
+def get_tasks(sync):
+    task_list = []
+    for story in sync.get('/v1/stories?tags=zuulv3'):
+        print("Story %s: %s" % (story['id'], story['title']))
+        for task in sync.get('/v1/stories/%s/tasks' % (story['id'])):
+            print("  %s" % (task['title'],))
+            task_list.append(task)
+    return task_list
+
+
+def task_in_lane(task, lane):
+    for item in lane['worklist']['items']:
+        if 'task' in item and item['task']['id'] == task['id']:
+            return True
+    return False
+
+
+def add_task(sync, task, lane):
+    print("Add task %s to %s" % (task['id'], lane['worklist']['id']))
+    r = sync.post('v1/worklists/%s/items/' % lane['worklist']['id'],
+                  dict(item_id=task['id'],
+                       item_type='task',
+                       list_position=0))
+    print(r)
+
+
+def remove_task(sync, task, lane):
+    print("Remove task %s from %s" % (task['id'], lane['worklist']['id']))
+    for item in lane['worklist']['items']:
+        if 'task' in item and item['task']['id'] == task['id']:
+            r = sync.delete('v1/worklists/%s/items/' % lane['worklist']['id'],
+                            dict(item_id=item['id']))
+            print(r)
+
+
+MAP = {
+    'todo': ['New', 'Backlog', 'Todo'],
+    'inprogress': ['In Progress', 'Blocked'],
+    'review': ['In Progress', 'Blocked'],
+    'merged': None,
+}
+
+
+def main():
+    requests.packages.urllib3.disable_warnings()
+    # logging.basicConfig(level=logging.DEBUG)
+    app = App()
+    app.config = boartty.config.Config('openstack')
+    sync = boartty.sync.Sync(app, False)
+    board = sync.get('v1/boards/41')
+    tasks = get_tasks(sync)
+
+    lanes = dict()
+    for lane in board['lanes']:
+        lanes[lane['worklist']['title']] = lane
+
+    for task in tasks:
+        ok_lanes = MAP[task['status']]
+        task_found = False
+        for lane_name, lane in lanes.items():
+            if task_in_lane(task, lane):
+                if ok_lanes and lane_name in ok_lanes:
+                    task_found = True
+                else:
+                    remove_task(sync, task, lane)
+        if ok_lanes and not task_found:
+            add_task(sync, task, lanes[ok_lanes[0]])
+
+if __name__ == '__main__':
+    main()
diff --git a/zuul/launcher/ansiblelaunchserver.py b/zuul/launcher/ansiblelaunchserver.py
index eeea8f8..5935c68 100644
--- a/zuul/launcher/ansiblelaunchserver.py
+++ b/zuul/launcher/ansiblelaunchserver.py
@@ -12,6 +12,13 @@
 # License for the specific language governing permissions and limitations
 # under the License.
 
+############################################################################
+# NOTE(jhesketh): This file has been superceeded by zuul/launcher/server.py.
+# It is kept here to make merging master back into v3 easier. Once closer
+# to completion it can be removed.
+############################################################################
+
+
 import json
 import logging
 import os
diff --git a/zuul/launcher/server.py b/zuul/launcher/server.py
index 74cc2be..bfcc8a4 100644
--- a/zuul/launcher/server.py
+++ b/zuul/launcher/server.py
@@ -280,7 +280,8 @@
         while self._command_running:
             try:
                 command = self.command_socket.get()
-                self.command_map[command]()
+                if command != '_stop':
+                    self.command_map[command]()
             except Exception:
                 self.log.exception("Exception while processing command")
 
diff --git a/zuul/model.py b/zuul/model.py
index 6e0176f..e90142d 100644
--- a/zuul/model.py
+++ b/zuul/model.py
@@ -666,7 +666,7 @@
     def addBuild(self, build):
         self.builds[build.job.name] = build
         if build.job.name not in self.tries:
-            self.tries[build.job.name] = 1
+            self.tries[build.job.name] = 0
         build.build_set = self
 
     def removeBuild(self, build):