Fixes bug 1116542. Wrap any references to statsd's methods in a check for the statsd object, since it will be None and thus evaluate False when not configured. Change-Id: Ia07afd9dde6a30b3f7bdcb2bc336494d28e714a3
73 lines
2.0 KiB
Python
Executable File
73 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Delete a devstack VM.
|
|
|
|
# Copyright (C) 2011-2012 OpenStack LLC.
|
|
#
|
|
# 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.
|
|
|
|
import json
|
|
import os
|
|
import sys
|
|
import getopt
|
|
from statsd import statsd
|
|
import time
|
|
import traceback
|
|
import urllib
|
|
|
|
import vmdatabase
|
|
import utils
|
|
|
|
NODE_NAME = sys.argv[1]
|
|
UPSTREAM_BUILD_URL=os.environ.get('UPSTREAM_BUILD_URL', '')
|
|
UPSTREAM_JOB_NAME=os.environ.get('UPSTREAM_JOB_NAME', '')
|
|
UPSTREAM_BRANCH=os.environ.get('UPSTREAM_BRANCH', '')
|
|
|
|
|
|
def main():
|
|
db = vmdatabase.VMDatabase()
|
|
|
|
machine = db.getMachineByJenkinsName(NODE_NAME)
|
|
if machine.state != vmdatabase.HOLD:
|
|
machine.state = vmdatabase.DELETE
|
|
|
|
try:
|
|
utils.update_stats(machine.base_image.provider)
|
|
|
|
if UPSTREAM_BUILD_URL:
|
|
fd = urllib.urlopen(UPSTREAM_BUILD_URL+'api/json')
|
|
data = json.load(fd)
|
|
result = data['result']
|
|
if statsd and result == 'SUCCESS':
|
|
dt = int(data['duration'])
|
|
|
|
key = 'devstack.job.%s' % UPSTREAM_JOB_NAME
|
|
statsd.timing(key+'.runtime', dt)
|
|
statsd.incr(key+'.builds')
|
|
|
|
key += '.%s' % UPSTREAM_BRANCH
|
|
statsd.timing(key+'.runtime', dt)
|
|
statsd.incr(key+'.builds')
|
|
|
|
key += '.%s' % machine.base_image.provider.name
|
|
statsd.timing(key+'.runtime', dt)
|
|
statsd.incr(key+'.builds')
|
|
except:
|
|
print "Error getting build information"
|
|
traceback.print_exc()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|