github.com/jenkins-x/test-infra@v0.0.7/scenarios/dindind_execute.py (about) 1 #!/usr/bin/env python 2 3 # Copyright 2018 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 """Prepares for nested docker, and executes a command.""" 21 # TODO(Q-Lee): check the necessity of this once MountPropagation is available in 22 # prow: https://github.com/kubernetes/kubernetes/pull/59252 23 24 import argparse 25 import os 26 import subprocess 27 import sys 28 29 def check(*cmd): 30 """Log and run the command, raising on errors.""" 31 print >>sys.stderr, 'Run:', cmd 32 subprocess.check_call(cmd) 33 34 35 def main(envs, cmd): 36 """Make important mounts r-shared, then run script and verify it exits 0.""" 37 check("mount", "--make-rshared", "/lib/modules") 38 check("mount", "--make-rshared", "/sys") 39 check("mount", "--make-rshared", "/") 40 41 for env in envs: 42 key, val = env.split('=', 1) 43 print >>sys.stderr, '%s=%s' % (key, val) 44 os.environ[key] = val 45 if not cmd: 46 raise ValueError(cmd) 47 check(*cmd) 48 49 50 if __name__ == '__main__': 51 PARSER = argparse.ArgumentParser() 52 PARSER.add_argument('--env', default=[], action='append') 53 PARSER.add_argument('cmd', nargs=1) 54 PARSER.add_argument('args', nargs='*') 55 ARGS = PARSER.parse_args() 56 main(ARGS.env, ARGS.cmd + ARGS.args)