示例#1
0
def converge(ctx, scenario_name):  # pragma: no cover
    """ Use a provisioner to configure instances (create, converge). """
    args = ctx.obj.get('args')
    command_args = {
        'subcommand': __name__,
        'scenario_name': scenario_name,
    }

    for c in base.get_configs(args, command_args):
        for task in c.scenario.converge_sequence:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            command(c).execute()
示例#2
0
文件: test.py 项目: m4rkw/molecule
def test(ctx, scenario_name, driver_name):  # pragma: no cover
    """ Test (destroy, create, converge, lint, verify, destroy). """
    args = ctx.obj.get('args')
    command_args = {
        'subcommand': __name__,
        'scenario_name': scenario_name,
        'driver_name': driver_name,
    }

    for c in base.get_configs(args, command_args):
        for task in c.scenario.test_sequence:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            command(c).execute()
示例#3
0
def check(ctx, scenario_name):  # pragma: no cover
    """ Use a provisioner to perform a Dry-Run (create, converge, create). """
    args = ctx.obj.get('args')
    command_args = {
        'subcommand': __name__,
    }

    s = scenarios.Scenarios(base.get_configs(args, command_args),
                            scenario_name)
    for c in s.all:
        for task in c.scenario.check_sequence:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            command(c).execute()
示例#4
0
def execute_subcommand(config, subcommand):
    command_module = getattr(molecule.command, subcommand)
    command = getattr(command_module, util.camelize(subcommand))
    # knowledge of the current action is used by some provisioners
    # to ensure they behave correctly during certain sequence steps,
    # particulary the setting of ansible options in create/destroy,
    # and is also used for reporting in execute_cmdline_scenarios
    config.action = subcommand

    return command(config).execute()
示例#5
0
    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule test` and
        return a tuple.

        :param exit: (Unused) Provided to complete method signature.
        :return: Return a tuple of (`exit status`, `command output`), otherwise
         sys.exit on command failure.
        """
        command_args, args = util.remove_args(self.command_args, self.args,
                                              self.command_args)

        for task in self.molecule.config.config['molecule']['test'][
                'sequence']:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            c = command(command_args, args, self.molecule)

            for argument in self.command_args:
                if argument in c.args:
                    c.args[argument] = self.args[argument]

            status, output = c.execute(exit=False)

            # Fail fast
            if status is not 0 and status is not None:
                if output:
                    LOG.error(output)
                util.sysexit(status)

        if self.args.get('--destroy') == 'always':
            c = molecule.command.destroy.Destroy(command_args, args)
            c.execute()
            return None, None

        if self.args.get('--destroy') == 'never':
            return None, None

        # passing (default)
        if status is None:
            c = molecule.command.destroy.Destroy(command_args, args)
            c.execute()
            return None, None

        # error encountered during test
        util.sysexit(status)
示例#6
0
    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule test` and
        return a tuple.

        :param exit: (Unused) Provided to complete method signature.
        :return: Return a tuple of (`exit status`, `command output`), otherwise
         sys.exit on command failure.
        """
        if self.command_args.get('all') == True:
            ts = self.molecule.config.config['molecule']['test']['sequence']
        else:
            ts = ['destroy', 'create', 'converge']

        for task in ts:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())

            # in case we want to re-work on an already existing vm
            if task == 'destroy' and self.command_args.get('from_scratch') == False:
                util.print_info('Keep instance up...')
                continue

            c = command(self.args, self.command_args, self.molecule)
            status, output = c.execute(exit=False)

            # Fail fast
            if status is not 0 and status is not None:
                if output:
                    util.print_error(output)
                util.sysexit(status)

        if self.command_args.get('clean') == True:
            c = molecule.command.destroy.Destroy(self.args, self.command_args)
            c.execute()
            return None, None

        # passing (default)
        if status is None:
            return None, None
示例#7
0
文件: test.py 项目: russ216/molecule
    def execute(self):
        command_args, args = util.remove_args(self.command_args, self.args,
                                              self.command_args)

        for task in self.molecule.config.config['molecule']['test'][
                'sequence']:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            c = command(command_args, args, self.molecule)

            for argument in self.command_args:
                if argument in c.args:
                    c.args[argument] = self.args[argument]

            status, output = c.execute(exit=False)

            # Fail fast
            if status is not 0 and status is not None:
                LOG.error(output)
                util.sysexit(status)

        if self.args.get('--destroy') == 'always':
            c = molecule.command.destroy.Destroy(command_args, args)
            c.execute()
            return None, None

        if self.args.get('--destroy') == 'never':
            return None, None

        # passing (default)
        if status is None:
            c = molecule.command.destroy.Destroy(command_args, args)
            c.execute()
            return None, None

        # error encountered during test
        util.sysexit(status)
示例#8
0
    def execute(self):
        command_args, args = util.remove_args(self.command_args, self.args,
                                              self.command_args)

        for task in self.molecule.config.config['molecule']['test'][
                'sequence']:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            c = command(command_args, args, self.molecule)

            for argument in self.command_args:
                if argument in c.args:
                    c.args[argument] = self.args[argument]

            status, output = c.execute(exit=False)

            # Fail fast
            if status is not 0 and status is not None:
                LOG.error(output)
                util.sysexit(status)

        if self.args.get('--destroy') == 'always':
            c = molecule.command.destroy.Destroy(command_args, args)
            c.execute()
            return None, None

        if self.args.get('--destroy') == 'never':
            return None, None

        # passing (default)
        if status is None:
            c = molecule.command.destroy.Destroy(command_args, args)
            c.execute()
            return None, None

        # error encountered during test
        util.sysexit(status)
示例#9
0
    def execute(self, exit=True):
        """
        Execute the actions necessary to perform a `molecule test` and
        return a tuple.

        :param exit: (Unused) Provided to complete method signature.
        :return: Return a tuple of (`exit status`, `command output`), otherwise
         sys.exit on command failure.
        """
        for task in self.molecule.config.config['molecule']['test'][
                'sequence']:
            command_module = getattr(molecule.command, task)
            command = getattr(command_module, task.capitalize())
            c = command(self.command_args, self.args, self.molecule)

            status, output = c.execute(exit=False)

            # Fail fast
            if status is not 0 and status is not None:
                if output:
                    LOG.error(output)
                util.sysexit(status)

        if self.command_args.get('destroy') == 'always':
            c = molecule.command.destroy.Destroy(self.command_args, self.args)
            c.execute()
            return None, None

        if self.command_args.get('destroy') == 'never':
            return None, None

        # passing (default)
        if status is None:
            c = molecule.command.destroy.Destroy(self.command_args, self.args)
            c.execute()
            return None, None
示例#10
0
def execute_subcommand(config, subcommand):
    command_module = getattr(molecule.command, subcommand)
    command = getattr(command_module, util.camelize(subcommand))

    return command(config).execute()
示例#11
0
def execute_subcommand(config, subcommand):
    command_module = getattr(molecule.command, subcommand)
    command = getattr(command_module, util.camelize(subcommand))

    return command(config).execute()