How to use the molecule.util.sysexit function in molecule

To help you get started, we’ve selected a few molecule examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible / molecule / molecule / verifier / testinfra.py View on Github external
LOG.warn(msg)
            return

        if self._testinfra_command is None:
            self.bake()

        msg = 'Executing Testinfra tests found in {}/...'.format(self.directory)
        LOG.info(msg)

        try:
            util.run_command(self._testinfra_command, debug=self._config.debug)
            msg = 'Verifier completed successfully.'
            LOG.success(msg)

        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
github ansible / molecule / molecule / core.py View on Github external
def _get_driver(self):
        """
        Return an instance of the driver as returned by `_get_driver_name()`.

        .. todo:: Implement a pluggable solution vs inline imports.
        """
        driver = self._get_driver_name()

        if (self.state.driver is not None) and (self.state.driver != driver):
            msg = ("Instance(s) were converged with the '{}' driver, "
                   "but the subcommand is using '{}' driver.")
            util.print_error(msg.format(self.state.driver, driver))
            util.sysexit()

        if driver == 'vagrant':
            from molecule.driver import vagrantdriver
            return vagrantdriver.VagrantDriver(self)
        elif driver == 'docker':
            from molecule.driver import dockerdriver
            return dockerdriver.DockerDriver(self)
        elif driver == 'openstack':
            from molecule.driver import openstackdriver
            return openstackdriver.OpenstackDriver(self)
        raise basedriver.InvalidDriverSpecified()
github ansible / molecule / molecule / command / base.py View on Github external
except SystemExit:
            # if the command has a 'destroy' arg, like test does,
            # handle that behavior here.
            if command_args.get('destroy') == 'always':
                msg = (
                    'An error occurred during the {} sequence action: '
                    "'{}'. Cleaning up."
                ).format(scenario.config.subcommand, scenario.config.action)
                LOG.warning(msg)
                execute_subcommand(scenario.config, 'cleanup')
                execute_subcommand(scenario.config, 'destroy')
                # always prune ephemeral dir if destroying on failure
                scenario.prune()
                if scenario.config.is_parallel:
                    scenario._remove_scenario_state_directory()
                util.sysexit()
            else:
                raise
github ansible / molecule / molecule / driver / openstackdriver.py View on Github external
}

        util.print_warn('Creating openstack instances...')
        for instance in self.instances:

            try:
                # We divide the ssh_timeout by 2, because the connect
                # itself takes at least a second and is followed by
                # a 1 sec sleep
                ssh_timeout = int(
                    instance.get('ssh_timeout', self.ssh_timeout) / 2)
            except TypeError:
                util.print_error('Can not cast ssh_timeout setting "%s"'
                                 ' to int' %
                                 instance.get('ssh_timeout', self.ssh_timeout))
                util.sysexit()

            if instance['name'] not in active_instance_names:
                msg = '\tBringing up {}...'.format(instance['name'])
                util.print_info(msg)
                server = self._openstack.create_server(
                    name=instance['name'],
                    image=self._openstack.get_image(instance['image']),
                    flavor=self._openstack.get_flavor(instance['flavor']),
                    auto_ip=True,
                    wait=False,
                    key_name=kpn,
                    ip_pool=instance.get('ip_pool')
                    if instance.get('ip_pool') else self.ip_pool,
                    network=instance.get('networks', []),
                    security_groups=instance.get('security_groups', []))
                instance['created'] = True
github ansible / molecule / molecule / lint / yamllint.py View on Github external
return

        if self._yamllint_command is None:
            self.bake()

        msg = 'Executing Yamllint on files found in {}/...'.format(
            self._config.project_directory
        )
        LOG.info(msg)

        try:
            util.run_command(self._yamllint_command, debug=self._config.debug)
            msg = 'Lint completed successfully.'
            LOG.success(msg)
        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
github ansible / molecule / molecule / verifier / serverspec.py View on Github external
'_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)
github ansible / molecule / molecule / provisioner / lint / ansible_lint.py View on Github external
msg = 'Skipping, lint is disabled.'
            LOG.warn(msg)
            return

        if self._ansible_lint_command is None:
            self.bake()

        msg = 'Executing Ansible Lint on {}...'.format(self._playbook)
        LOG.info(msg)

        try:
            util.run_command(self._ansible_lint_command, debug=self._config.debug)
            msg = 'Lint completed successfully.'
            LOG.success(msg)
        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)
github ansible / molecule / molecule / dependency / base.py View on Github external
LOG.warning(msg)

            msg = 'Sleeping {} seconds before retrying ...'.format(self.SLEEP)
            LOG.warning(msg)
            time.sleep(self.SLEEP)
            self.SLEEP += self.BACKOFF

            try:
                util.run_command(self._sh_command, debug=self._config.debug)
                msg = 'Dependency completed successfully.'
                LOG.success(msg)
                return
            except sh.ErrorReturnCode as _exception:
                exception = _exception

        util.sysexit(exception.exit_code)
github ansible / molecule / molecule / verifier / lint / flake8.py View on Github external
return

        if self._flake8_command is None:
            self.bake()

        msg = 'Executing Flake8 on files found in {}/...'.format(
            self._config.verifier.directory
        )
        LOG.info(msg)

        try:
            util.run_command(self._flake8_command, debug=self._config.debug)
            msg = 'Lint completed successfully.'
            LOG.success(msg)
        except sh.ErrorReturnCode as e:
            util.sysexit(e.exit_code)