github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/scenarios/kubernetes_heapster.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 """Runs heapster tests for kubernetes/heapster.""" 21 22 import argparse 23 import os 24 import shutil 25 import subprocess 26 import sys 27 import tempfile 28 29 30 def check(*cmd): 31 """Log and run the command, raising on errors.""" 32 print >>sys.stderr, 'Run:', cmd 33 subprocess.check_call(cmd) 34 35 HEAPSTER_IMAGE_VERSION = '0.7' 36 37 def main(ssh, ssh_pub, robot, project): 38 """Run unit/integration heapster test against master in docker""" 39 40 img = 'gcr.io/k8s-testimages/heapster-test:%s' % HEAPSTER_IMAGE_VERSION 41 artifacts = '%s/_artifacts' % os.environ['WORKSPACE'] 42 if not os.path.isdir(artifacts): 43 os.makedirs(artifacts) 44 heapster = os.getcwd() 45 if not os.path.basename(heapster) == 'heapster': 46 raise ValueError(heapster) 47 48 for path in [ssh, ssh_pub, robot]: 49 if not os.path.isfile(os.path.expandvars(path)): 50 raise IOError(path, os.path.expandvars(path)) 51 private = '/root/.ssh/google_compute_engine' 52 public = '%s.pub' % private 53 service = '/service-account.json' 54 55 temp = tempfile.mkdtemp(prefix='heapster-') 56 try: 57 check( 58 'docker', 'run', '--rm=true', 59 '-v', '/etc/localtime:/etc/localtime:ro', 60 '-v', '/var/run/docker.sock:/var/run/docker.sock', 61 '-v', '%s:/go/src/k8s.io/heapster' % heapster, 62 '-v', '%s:%s' % (temp, temp), 63 '-v', '%s:/workspace/_artifacts' % artifacts, 64 '-v', '%s:%s:ro' % (robot, service), 65 '-v', '%s:%s:ro' % (ssh, private), 66 '-v', '%s:%s:ro' % (ssh_pub, public), 67 '-e', 'GOOGLE_APPLICATION_CREDENTIALS=%s' % service, 68 '-e', 'JENKINS_GCE_SSH_PRIVATE_KEY_FILE=%s' % private, 69 '-e', 'JENKINS_GCE_SSH_PUBLIC_KEY_FILE=%s' % public, 70 '-e', 'REPO_DIR=%s' % heapster, # Used in heapster/Makefile 71 '-e', 'TEMP_DIR=%s' % temp, 72 '-e', 'PROJECT=%s' % project, 73 img, 74 ) 75 shutil.rmtree(temp) 76 except subprocess.CalledProcessError: 77 shutil.rmtree(temp) 78 raise 79 80 if __name__ == '__main__': 81 PARSER = argparse.ArgumentParser( 82 'Runs heapster tests with the specified creds') 83 PARSER.add_argument( 84 '--gce-ssh', 85 default=os.environ.get('JENKINS_GCE_SSH_PRIVATE_KEY_FILE'), 86 help='Path to .ssh/google_compute_engine keys') 87 PARSER.add_argument( 88 '--gce-pub', 89 default=os.environ.get('JENKINS_GCE_SSH_PUBLIC_KEY_FILE'), 90 help='Path to pub gce ssh key') 91 PARSER.add_argument( 92 '--service-account', 93 default=os.environ.get('GOOGLE_APPLICATION_CREDENTIALS'), 94 help='Path to service-account.json') 95 # TODO(https://github.com/kubernetes/heapster/issues/1501): Move this to heapster 96 PARSER.add_argument( 97 '--project', 98 default='kubernetes-jenkins-pull', 99 help='GCP project where heapster test runs from') 100 ARGS = PARSER.parse_args() 101 main( 102 ARGS.gce_ssh, 103 ARGS.gce_pub, 104 ARGS.service_account, 105 ARGS.project 106 )