github.com/jenkins-x/test-infra@v0.0.7/scenarios/maintenance.py (about) 1 #!/usr/bin/env python 2 3 # Copyright 2017 The Kubernetes Authors. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # Need to figure out why this only fails on travis 18 # pylint: disable=bad-continuation 19 20 """update gcloud on Jenkins vms.""" 21 22 import os 23 import subprocess 24 import sys 25 26 def check(*cmd): 27 """Log and run the command, raising on errors.""" 28 print >>sys.stderr, 'Run:', cmd 29 subprocess.check_call(cmd) 30 31 32 def main(): 33 """update gcloud for Jenkins vms""" 34 host = os.environ.get('HOSTNAME') 35 if host == 'jenkins-master' or host == 'pull-jenkins-master': 36 check('sudo', 'gcloud', 'components', 'update') 37 check('sudo', 'gcloud', 'components', 'update', 'beta') 38 check('sudo', 'gcloud', 'components', 'update', 'alpha') 39 else: 40 try: 41 check('sudo', 'apt-get', 'update') 42 except subprocess.CalledProcessError: 43 check('sudo', 'rm', '/var/lib/apt/lists/partial/*') 44 check('sudo', 'apt-get', 'update') 45 check('sudo', 'apt-get', 'install', '-y', 'google-cloud-sdk') 46 47 48 if __name__ == '__main__': 49 main()