def test_commands_pack(self):
        """ Test commands pack build

        :return: None
        """
        t = {
            'command_name': 'check_command_test',
            'command_line': '/tmp/dummy_command.sh $ARG1$ $ARG2$',
            'module_type': 'nrpe-booster',
            'poller_tag': 'DMZ',
            'reactionner_tag': 'REAC'
        }
        c = Command(t)

        # now create a commands packs
        cs = Commands([c])
        dummy_call = "check_command_test!titi!toto"
        cc = CommandCall({"commands": cs, "call": dummy_call})
        assert True == cc.is_valid()
        assert c == cc.command
        assert 'DMZ' == cc.poller_tag
        assert 'REAC' == cc.reactionner_tag
class CheckModulation(Item):
    """CheckModulation class is simply a modulation of the check command (of a Host/Service)
    during a check_period.

    """
    my_type = 'checkmodulation'

    properties = Item.properties.copy()
    properties.update({
        'checkmodulation_name':
        StringProp(fill_brok=['full_status']),
        'check_command':
        StringProp(fill_brok=['full_status']),
        'check_period':
        StringProp(brok_transformation=to_name_if_possible,
                   fill_brok=['full_status']),
    })

    running_properties = Item.running_properties.copy()

    special_properties = ('check_period', )

    macros = {}

    def __init__(self, params=None, parsing=True):
        if params is None:
            params = {}

        # At deserialization, thoses are dict
        # TODO: Separate parsing instance from recreated ones
        if 'check_command' in params and isinstance(params['check_command'],
                                                    dict):
            # We recreate the object
            self.check_command = CommandCall(params['check_command'])
            # And remove prop, to prevent from being overridden
            del params['check_command']

        super(CheckModulation, self).__init__(params, parsing=parsing)

    def serialize(self):
        res = super(CheckModulation, self).serialize()
        res['check_command'] = None
        if getattr(self, 'check_command', None):
            res['check_command'] = self.check_command.serialize()
        return res

    def get_name(self):
        """Accessor to checkmodulation_name attribute

        :return: check modulation name
        :rtype: str
        """
        if hasattr(self, 'checkmodulation_name'):
            return self.checkmodulation_name
        return 'Unnamed'

    def get_check_command(self, timeperiods, t_to_go):
        """Get the check_command if we are in the check period modulation

        :param t_to_go: time to check if we are in the timeperiod
        :type t_to_go:
        :return: A check command if we are in the check period, None otherwise
        :rtype: fusionsupervision.objects.command.Command
        """
        if not self.check_period or timeperiods[
                self.check_period].is_time_valid(t_to_go):
            return self.check_command
        return None

    def is_correct(self):
        """Check if this object configuration is correct ::

        * Check our own specific properties
        * Call our parent class is_correct checker

        :return: True if the configuration is correct, otherwise False
        :rtype: bool
        """
        state = True

        # Internal checks before executing inherited function...
        if not hasattr(self, 'check_command'):
            msg = "[checkmodulation::%s] do not have any check_command defined" % (
                self.get_name())
            self.add_error(msg)
            state = False
        else:
            if self.check_command is None:
                msg = "[checkmodulation::%s] a check_command is missing" % (
                    self.get_name())
                self.add_error(msg)
                state = False
            if self.check_command and not self.check_command.is_valid():
                msg = "[checkmodulation::%s] a check_command is invalid" % (
                    self.get_name())
                self.add_error(msg)
                state = False

        # Ok just put None as check_period, means 24x7
        if not hasattr(self, 'check_period'):
            self.check_period = None

        return super(CheckModulation, self).is_correct() and state