Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def verify_tab_complete(vm):
# TODO: Also check completion by running 'complete' and using grep to verify the output
try:
vm(['grep', '-q', "\"source '/usr/local/az/az.completion'\"", '~/.bashrc'])
except sh.ErrorReturnCode_1 as e:
raise Exception("Tab completion should be enabled but source command not found in rc file")
def test_executes_catches_and_exits_return_code(
patched_run_command, patched_yamllint, _instance
):
patched_run_command.side_effect = sh.ErrorReturnCode_1(sh.ansible_lint, b'', b'')
with pytest.raises(SystemExit) as e:
_instance.execute()
assert 1 == e.value.code
host1.listen(calicoctl % "profile PROF_A_C_E member add workload-A")
host1.listen(calicoctl % "profile PROF_B member add workload-B")
host1.listen(calicoctl % "profile PROF_A_C_E member add workload-C")
host2.listen(calicoctl % "profile PROF_D member add workload-D")
host2.listen(calicoctl % "profile PROF_A_C_E member add workload-E")
# Wait for the workload networking to converge.
sleep(1)
host1.execute("docker exec workload-A ping -c 4 192.168.1.3")
try:
host1.execute("docker exec workload-A ping -c 4 192.168.1.2")
raise
except ErrorReturnCode_1:
pass
try:
host1.execute("docker exec workload-A ping -c 4 192.168.1.4")
raise
except ErrorReturnCode_1:
pass
host1.execute("docker exec workload-A ping -c 4 192.168.1.5")
def test_executes_catches_and_exits_return_code(
patched_run_command, _patched_get_tests, _instance
):
patched_run_command.side_effect = sh.ErrorReturnCode_1(sh.yamllint, b'', b'')
with pytest.raises(SystemExit) as e:
_instance.execute()
assert 1 == e.value.code
tmp.append(line)
f.close()
note_contents = ''.join(tmp)
f = open(path, 'w')
f.write(note_contents.encode('utf8'))
f.close()
self.application.git.add(path)
try:
if note_contents == '':
message = 'creating %s' % path
else:
message = 'updating %s' % path
self.application.git.commit('-m', message)
except ErrorReturnCode_1 as e:
if 'nothing to commit' not in e.message:
raise
if note_name_rename and note_name_rename != note_name:
# rename note
message = 'moving %s to %s' % (path, rename_path)
# TODO: don't force; do something more graceful
self.application.git.mv('-f', path, rename_path)
self.application.git.commit('-m', message)
note_enc = rename_note_enc
self.redirect(note_enc.replace('#', '%23'))
info('Python was loaded from CrystaX, skipping strip')
return
env = arch.get_env()
strip = which('arm-linux-androideabi-strip', env['PATH'])
if strip is None:
warning('Can\'t find strip in PATH...')
return
strip = sh.Command(strip)
filens = shprint(sh.find, join(self.dist_dir, 'private'),
join(self.dist_dir, 'libs'),
'-iname', '*.so', _env=env).stdout.decode('utf-8')
logger.info('Stripping libraries in private dir')
for filen in filens.split('\n'):
try:
strip(filen, _env=env)
except sh.ErrorReturnCode_1:
logger.debug('Failed to strip ' + filen)
strip = strip.bake(tokens[1:])
libs_dir = join(self.dist_dir, '_python_bundle',
'_python_bundle', 'modules')
if self.ctx.python_recipe.name == 'python2legacy':
libs_dir = join(self.dist_dir, 'private')
filens = shprint(sh.find, libs_dir, join(self.dist_dir, 'libs'),
'-iname', '*.so', _env=env).stdout.decode('utf-8')
logger.info('Stripping libraries in private dir')
for filen in filens.split('\n'):
if not filen:
continue # skip the last ''
try:
strip(filen, _env=env)
except sh.ErrorReturnCode_1:
logger.debug('Failed to strip ' + filen)
if os.path.isdir(role):
msg = 'The directory {} already exists. Cannot create new role.'
utilities.logger.error(msg.format(role))
sys.exit(1)
role_path = os.path.join(os.curdir, role)
utilities.print_info("Initializing role {}...".format(role))
try:
if self.molecule._args['--offline']:
sh.ansible_galaxy('init', '--offline', role)
else:
sh.ansible_galaxy('init', role)
except (subprocess.CalledProcessError, sh.ErrorReturnCode_1) as e:
utilities.logger.error('ERROR: {}'.format(e))
sys.exit(e.returncode)
self.clean_meta_main(role_path)
env = jinja2.Environment(
loader=jinja2.PackageLoader('molecule', 'templates'),
keep_trailing_newline=True)
t_molecule = env.get_template(self.molecule._config.config['molecule'][
'init']['templates']['molecule'])
t_playbook = env.get_template(self.molecule._config.config['molecule'][
'init']['templates']['playbook'])
t_test_default = env.get_template(self.molecule._config.config[
'molecule']['init']['templates']['test_default'])
def push(self, src_path, dst_path):
mace_check(os.path.exists(src_path), "Device",
'{} not found'.format(src_path))
six.print_("Push %s to %s" % (src_path, dst_path))
if self.system == SystemType.android:
sh_commands.adb_push(src_path, dst_path, self.address)
elif self.system == SystemType.arm_linux:
try:
sh.scp(src_path, '{}@{}:{}'.format(self.username,
self.address,
dst_path))
except sh.ErrorReturnCode_1 as e:
six.print_('Push Failed !', e, file=sys.stderr)
raise e
info('Cythonizing anything necessary in {}'.format(self.name))
env = self.get_recipe_env(arch)
with current_directory(self.get_build_dir(arch.arch)):
hostpython = sh.Command(self.ctx.hostpython)
shprint(hostpython, '-c', 'import sys; print(sys.path)', _env=env)
debug('cwd is {}'.format(realpath(curdir)))
info('Trying first build of {} to get cython files: this is '
'expected to fail'.format(self.name))
manually_cythonise = False
try:
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
*self.setup_extra_args)
except sh.ErrorReturnCode_1:
print()
info('{} first build failed (as expected)'.format(self.name))
manually_cythonise = True
if manually_cythonise:
self.cythonize_build(env=env)
shprint(hostpython, 'setup.py', 'build_ext', '-v', _env=env,
_tail=20, _critical=True, *self.setup_extra_args)
else:
info('First build appeared to complete correctly, skipping manual'
'cythonising.')
self.strip_object_files(arch, env)