|
| 1 | +# Copyright (C) 2017 Jolla Ltd. |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# This program is free software; you can redistribute it and/or modify |
| 5 | +# it under the terms of the GNU General Public License as published by |
| 6 | +# the Free Software Foundation; either version 2 of the License, or |
| 7 | +# (at your option) any later version. |
| 8 | +# |
| 9 | +# This program is distributed in the hope that it will be useful, but |
| 10 | +# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | +# General Public License for more details. |
| 13 | +# |
| 14 | +# You should have received a copy of the GNU General Public License |
| 15 | +# along with this program; if not, write to the Free Software |
| 16 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | +# 02110-1301, USA. |
| 18 | + |
| 19 | +"""Check to see the source state for a particular package |
| 20 | + Success if there is src ready to build |
| 21 | + service_state has more details |
| 22 | +
|
| 23 | + Packages which don't use a service are indistinguishable from a |
| 24 | + successful service run. |
| 25 | +
|
| 26 | +:term:`Workitem` fields IN: |
| 27 | +
|
| 28 | +:Parameters: |
| 29 | + :ev.namespace (string): |
| 30 | + Used to contact the right OBS instance. |
| 31 | + :package (string): |
| 32 | + Package name to be checked |
| 33 | + :project (string): |
| 34 | + OBS project in which the package lives |
| 35 | +
|
| 36 | +
|
| 37 | +:term:`Workitem` params IN |
| 38 | +
|
| 39 | +:Parameters: |
| 40 | + :package (string): |
| 41 | + Package name to be checked, overrides the package field |
| 42 | + :project (string): |
| 43 | + OBS project in which the package lives, overrides the project field |
| 44 | +
|
| 45 | +:term:`Workitem` fields OUT: |
| 46 | +
|
| 47 | +:Returns: |
| 48 | + :f.service_state (string): |
| 49 | + succeeded : src is present : service ran successfully or there's |
| 50 | + no _service |
| 51 | + running : service is in progress |
| 52 | + failed : service failed to run |
| 53 | + :result (Boolean): |
| 54 | + True if the status is succeeded |
| 55 | + False if it's runnning or failed |
| 56 | +
|
| 57 | +""" |
| 58 | + |
| 59 | +from boss.obs import BuildServiceParticipant |
| 60 | + |
| 61 | + |
| 62 | +class ParticipantHandler(BuildServiceParticipant): |
| 63 | + |
| 64 | + """ Participant class as defined by the SkyNET API """ |
| 65 | + |
| 66 | + def handle_wi_control(self, ctrl): |
| 67 | + """ job control thread """ |
| 68 | + pass |
| 69 | + |
| 70 | + @BuildServiceParticipant.get_oscrc |
| 71 | + def handle_lifecycle_control(self, ctrl): |
| 72 | + """ participant control thread """ |
| 73 | + pass |
| 74 | + |
| 75 | + @BuildServiceParticipant.setup_obs |
| 76 | + def handle_wi(self, wid): |
| 77 | + """ Workitem handling function """ |
| 78 | + wid.result = False |
| 79 | + f = wid.fields |
| 80 | + p = wid.params |
| 81 | + |
| 82 | + project = None |
| 83 | + package = None |
| 84 | + |
| 85 | + if f.project and f.package: |
| 86 | + project = f.project |
| 87 | + package = f.package |
| 88 | + print "setting %s/%s from fields" % (project, package) |
| 89 | + |
| 90 | + if p.project and p.package: |
| 91 | + project = p.project |
| 92 | + package = p.package |
| 93 | + print "setting %s/%s from params" % (project, package) |
| 94 | + |
| 95 | + err = [] |
| 96 | + if not project: |
| 97 | + err.append("no project") |
| 98 | + if not package: |
| 99 | + err.append("no package") |
| 100 | + if len(err) > 0: |
| 101 | + raise RuntimeError( |
| 102 | + "Missing mandatory field or parameter: %s" % ", ".join(err)) |
| 103 | + |
| 104 | + print "Checking service for %s/%s" % (project, package) |
| 105 | + f.service_state = self.obs.getServiceState(project, package) |
| 106 | + print "State : %s" % f.service_state |
| 107 | + if f.service_state == "succeeded": |
| 108 | + wid.result = True |
0 commit comments