本文整理汇总了Python中molecule.util.print_info函数的典型用法代码示例。如果您正苦于以下问题:Python print_info函数的具体用法?Python print_info怎么用?Python print_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了print_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _rubocop
def _rubocop(self,
serverspec_dir,
debug=False,
pattern='/**/*.rb',
out=util.callback_info,
err=util.callback_error):
"""
Executes rubocop against specified directory/pattern and returns a
:func:`sh` response object.
:param serverspec_dir: A string containing the directory with files
to lint.
:param debug: An optional bool to toggle debug output.
:param pattern: A string containing the pattern of files to lint.
:param out: An optional function to process STDOUT for underlying
:func:`sh` call.
:param err: An optional function to process STDERR for underlying
:func:`sh` call.
:return: :func:`sh` response object.
"""
kwargs = {'_out': out, '_err': err, 'debug': debug}
msg = 'Executing rubocop on *.rb files found in {}/...'.format(
serverspec_dir)
util.print_info(msg)
match = serverspec_dir + pattern
try:
cmd = sh.rubocop.bake(match, **kwargs)
except sh.CommandNotFound:
msg = 'Verifier missing, gem install rubocop.'
util.print_error(msg)
util.sysexit()
return util.run_command(cmd, debug=self._debug)
示例2: execute
def execute(self, exit=True):
util.print_info(
'Idempotence test in progress (can take a few minutes)...')
c = converge.Converge(self.command_args, self.args, self.molecule)
status, output = c.execute(idempotent=True,
exit=False,
hide_errors=True)
if status is not None:
msg = 'Skipping due to errors during converge.'
util.print_info(msg)
return status, None
idempotent, changed_tasks = self.molecule._parse_provisioning_output(
output)
if idempotent:
util.print_success('Idempotence test passed.')
return None, None
# Display the details of the idempotence test.
if changed_tasks:
LOG.error(
'Idempotence test failed because of the following tasks:')
LOG.error('{}'.format('\n'.join(changed_tasks)))
else:
# But in case the idempotence callback plugin was not found, we just display an error message.
LOG.error('Idempotence test failed.')
warning_msg = "The idempotence plugin was not found or did not provide the required information. " \
"Therefore the failure details cannot be displayed."
LOG.warning(warning_msg)
if exit:
util.sysexit()
return 1, None
示例3: _rubocop
def _rubocop(self,
serverspec_dir,
debug=False,
env=os.environ.copy(),
pattern='/**/*.rb',
out=LOG.info,
err=LOG.error):
"""
Runs rubocop against specified directory with specified pattern.
:param serverspec_dir: Directory to search for files to lint
:param debug: Pass debug flag to rubocop
:param pattern: Search pattern to pass to rubocop
:param env: Environment to pass to underlying sh call
:param out: Function to process STDOUT for underlying sh call
:param err: Function to process STDERR for underlying sh call
:return: sh response object
"""
kwargs = {'_env': env, '_out': out, '_err': err, 'debug': debug}
if 'HOME' not in kwargs['_env']:
kwargs['_env']['HOME'] = os.path.expanduser('~')
msg = 'Executing rubocop on *.rb files found in {}/.'.format(
serverspec_dir)
util.print_info(msg)
match = serverspec_dir + pattern
return sh.rubocop(match, **kwargs)
示例4: execute
def execute(self, exit=True):
"""
Execute the actions necessary to perform a `molecule create` and
return a tuple.
:param exit: An optional flag to toggle the exiting of the module
on command failure.
:return: Return a tuple of None, otherwise sys.exit on command failure.
"""
self.molecule.remove_inventory_file()
self.molecule.create_templates()
try:
util.print_info('Creating instances...')
self.molecule.driver.up(no_provision=True)
self.molecule.state.change_state('created', True)
if self.command_args.get('platform') == 'all':
self.molecule.state.change_state('multiple_platforms', True)
except subprocess.CalledProcessError as e:
util.print_error(str(e))
if exit:
util.sysexit(e.returncode)
return e.returncode, e.message
self.molecule.create_inventory_file()
self.molecule.write_instances_state()
return None, None
示例5: execute
def execute(self, exit=True):
"""
Execute the actions necessary to perform a `molecule idempotence` and
return a tuple.
:param exit: An optional flag to toggle the exiting of the module
on command failure.
:return: Return a tuple of (`exit status`, `command output`), otherwise
sys.exit on command failure.
"""
util.print_info("Idempotence test in progress (can take a few minutes) ...")
c = converge.Converge(self.command_args, self.args, self.molecule)
status, output = c.execute(idempotent=True, exit=False, hide_errors=True)
if status is not None:
msg = "Skipping due to errors during converge."
util.print_info(msg)
return status, None
idempotent = self._is_idempotent(output)
if idempotent:
util.print_success("Idempotence test passed.")
return None, None
else:
LOG.error("Idempotence test failed because of the following tasks:")
LOG.error("\n".join(self._non_idempotent_tasks(output)))
if exit:
util.sysexit()
return 1, None
示例6: _rake
def _rake(self,
rakefile,
debug=False,
env=os.environ.copy(),
out=LOG.info,
err=LOG.error):
"""
Runs rake with specified rakefile.
:param rakefile: Path to rakefile
:param debug: Pass trace flag to rake
:param env: Environment to pass to underlying sh call
:param out: Function to process STDOUT for underlying sh call
:param err: Function to process STDERR for underlying sh call
:return: sh response object
"""
kwargs = {'_env': env,
'_out': out,
'_err': err,
'trace': debug,
'rakefile': rakefile}
if 'HOME' not in kwargs['_env']:
kwargs['_env']['HOME'] = os.path.expanduser('~')
msg = 'Executing serverspec tests found in {}/.'.format(
self._serverspec_dir)
util.print_info(msg)
return sh.rake(**kwargs)
示例7: _rubocop
def _rubocop(self,
serverspec_dir,
debug=False,
pattern='/**/*.rb',
out=LOG.info,
err=LOG.error):
"""
Executes rubocop against specified directory/pattern, and returns a
:func:`sh` response object.
:param serverspec_dir: A string containing the directory with files
to lint.
:param debug: An optional bool to toggle debug output.
:param pattern: A string containing the pattern of files to lint.
:param out: An optional function to process STDOUT for underlying
:func:`sh` call.
:param err: An optional function to process STDERR for underlying
:func:`sh` call.
:return: :func:`sh` response object.
"""
kwargs = {'_out': out, '_err': err, 'debug': debug}
msg = 'Executing rubocop on *.rb files found in {}/.'.format(
serverspec_dir)
util.print_info(msg)
match = serverspec_dir + pattern
return sh.rubocop(match, **kwargs)
示例8: _testinfra
def _testinfra(self,
tests,
debug=False,
ansible_env={},
out=LOG.info,
err=LOG.error,
**kwargs):
"""
Executes testinfra against specified tests, and returns a :func:`sh`
response object.
:param tests: A list of testinfra tests.
:param debug: An optional bool to toggle debug output.
:param pattern: A string containing the pattern of files to lint.
:param ansible_env: An optional environment to pass to underlying
:func:`sh` call.
:param out: An optional function to process STDOUT for underlying
:func:`sh` call.
:param err: An optional function to process STDERR for underlying
:func:`sh` call.
:return: :func:`sh` response object.
"""
kwargs['debug'] = debug
kwargs['_env'] = ansible_env
kwargs['_out'] = out
kwargs['_err'] = err
msg = 'Executing testinfra tests found in {}/.'.format(
self._testinfra_dir)
util.print_info(msg)
return sh.testinfra(tests, **kwargs)
示例9: _testinfra
def _testinfra(self,
tests,
debug=False,
env=os.environ.copy(),
out=LOG.info,
err=LOG.error,
**kwargs):
"""
Runs testinfra and returns a sh response object.
:param tests: List of testinfra tests
:param debug: Pass debug flag to testinfra
:param env: Environment to pass to underlying sh call
:param out: Function to process STDOUT for underlying sh call
:param err: Function to process STDERR for underlying sh call
:return: sh response object
"""
kwargs['debug'] = debug
kwargs['_env'] = env
kwargs['_out'] = out
kwargs['_err'] = err
if 'HOME' not in kwargs['_env']:
kwargs['_env']['HOME'] = os.path.expanduser('~')
msg = 'Executing testinfra tests found in {}/.'.format(
self._testinfra_dir)
util.print_info(msg)
return sh.testinfra(tests, **kwargs)
示例10: _rake
def _rake(self, rakefile, debug=False, out=LOG.info, err=LOG.error):
"""
Executes rake against specified rakefile, and returns a :func:`sh`
response object.
:param rakefile: A string containing path to the rakefile.
:param debug: An optional bool to toggle debug output.
:param out: An optional function to process STDOUT for underlying
:func:`sh` call.
:param err: An optional function to process STDERR for underlying
:func:`sh` call.
:return: :func:`sh` response object.
"""
kwargs = {
'_out': out,
'_err': err,
'trace': debug,
'rakefile': rakefile
}
msg = 'Executing serverspec tests found in {}/.'.format(
self._serverspec_dir)
util.print_info(msg)
return sh.rake(**kwargs)
示例11: execute
def execute(self, exit=True):
"""
Execute the actions that should run prior to a converge and return a
tuple.
:param exit: (Unused) Provided to complete method signature.
:return: Return a tuple provided by :meth:`.AnsiblePlaybook.execute`.
"""
debug = self.args.get('debug')
if self.molecule.state.installed_deps:
return (None, None)
dependency_name = self.molecule.dependency
if dependency_name == 'galaxy':
dd = self.molecule.config.config.get('dependency')
if dd.get('requirements_file'):
msg = "Downloading dependencies with '{}'...".format(
dependency_name)
util.print_info(msg)
g = ansible_galaxy.AnsibleGalaxy(
self.molecule.config.config, debug=debug)
g.execute()
self.molecule.state.change_state('installed_deps', True)
elif dependency_name == 'shell':
dd = self.molecule.config.config.get('dependency')
if dd.get('command'):
msg = "Downloading dependencies with '{}'...".format(
dependency_name)
util.print_info(msg)
s = shell.Shell(self.molecule.config.config, debug=debug)
s.execute()
self.molecule.state.change_state('installed_deps', True)
return (None, None)
示例12: execute
def execute(self, exit=True):
"""
Execute the actions necessary to perform a `molecule check` and
return a tuple.
:param exit: (Unused) Provided to complete method signature.
:return: Return a tuple provided by :meth:`.AnsiblePlaybook.execute`.
"""
if not self.molecule.state.created:
msg = ('Instance(s) not created, `check` should be run '
'against created instance(s).')
util.print_error(msg)
util.sysexit()
debug = self.args.get('debug')
ansible = ansible_playbook.AnsiblePlaybook(
self.molecule.config.config['ansible'],
self.molecule.driver.ansible_connection_params,
debug=debug)
ansible.add_cli_arg('check', True)
util.print_info("Performing a 'Dry Run' of playbook...")
return ansible.execute(hide_errors=True)
return (None, None)
示例13: _rake
def _rake(self,
rakefile,
debug=False,
out=util.callback_info,
err=util.callback_error):
"""
Executes rake against specified rakefile and returns a :func:`sh`
response object.
:param rakefile: A string containing path to the rakefile.
:param debug: An optional bool to toggle debug output.
:param out: An optional function to process STDOUT for underlying
:func:`sh` call.
:param err: An optional function to process STDERR for underlying
:func:`sh` call.
:return: :func:`sh` response object.
"""
kwargs = {
'_out': out,
'_err': err,
'trace': debug,
'rakefile': rakefile
}
msg = 'Executing serverspec tests found in {}/...'.format(
self._serverspec_dir)
util.print_info(msg)
try:
cmd = sh.rake.bake(**kwargs)
except sh.CommandNotFound:
msg = 'Verifier missing, gem install rake.'
util.print_error(msg)
util.sysexit()
return util.run_command(cmd, debug=self._debug)
示例14: test_print_info_without_pretty
def test_print_info_without_pretty(capsys):
util.print_info("test", pretty=False)
result, _ = capsys.readouterr()
print "{}".format("test".rstrip())
expected, _ = capsys.readouterr()
assert expected == result
示例15: test_print_info
def test_print_info(capsys):
util.print_info('test')
result, _ = capsys.readouterr()
print '--> {}{}'.format(colorama.Fore.CYAN, 'test'.rstrip())
expected, _ = capsys.readouterr()
assert expected == result