예제 #1
0
def validate_boolean(data, valid_values=None):
    try:
        converters.convert_to_boolean(data)
    except n_exc.InvalidInput:
        msg = _("'%s' is not a valid boolean value") % data
        LOG.debug(msg)
        return msg
예제 #2
0
def validate_boolean(data, valid_values=None):
    try:
        converters.convert_to_boolean(data)
    except n_exc.InvalidInput:
        msg = _("'%s' is not a valid boolean value") % data
        LOG.debug(msg)
        return msg
예제 #3
0
def validate_boolean(data, valid_values=None):
    """Validate data is a python bool compatible object.

    :param data: The data to validate.
    :param valid_values: Not used!
    :return: None if the value can be converted to a bool, otherwise a
    human readable message indicating why data is invalid.
    """
    try:
        converters.convert_to_boolean(data)
    except n_exc.InvalidInput:
        msg = _("'%s' is not a valid boolean value") % data
        LOG.debug(msg)
        return msg
예제 #4
0
 def get_agents(self, context, filters=None, fields=None):
     agents = self._get_collection(context, Agent,
                                   self._make_agent_dict,
                                   filters=filters, fields=fields)
     alive = filters and filters.get('alive', None)
     if alive:
         alive = converters.convert_to_boolean(alive[0])
         agents = [agent for agent in agents if agent['alive'] == alive]
     return agents
예제 #5
0
파일: agents_db.py 프로젝트: wmousa/neutron
 def get_agents(self, context, filters=None, fields=None):
     filters = filters or {}
     alive = filters and filters.pop('alive', None)
     agents = agent_obj.Agent.get_objects(context, **filters)
     if alive:
         alive = converters.convert_to_boolean(alive[0])
         agents = [agent for agent in agents if agent.is_active == alive]
     return [self._make_agent_dict(agent, fields=fields)
             for agent in agents]
예제 #6
0
 def get_agents(self, context, filters=None, fields=None):
     agents = self._get_collection(context, Agent,
                                   self._make_agent_dict,
                                   filters=filters, fields=fields)
     alive = filters and filters.get('alive', None)
     if alive:
         alive = converters.convert_to_boolean(alive[0])
         agents = [agent for agent in agents if agent['alive'] == alive]
     return agents
예제 #7
0
 def get_agents(self, context, filters=None, fields=None):
     filters = filters or {}
     alive = filters and filters.pop('alive', None)
     agents = agent_obj.Agent.get_objects(context, **filters)
     if alive:
         alive = converters.convert_to_boolean(alive[0])
         agents = [agent for agent in agents if agent.is_active == alive]
     return [self._make_agent_dict(agent, fields=fields)
             for agent in agents]
예제 #8
0
 def test_convert_to_boolean_str(self):
     self.assertIs(converters.convert_to_boolean('True'), True)
     self.assertIs(converters.convert_to_boolean('true'), True)
     self.assertIs(converters.convert_to_boolean('False'), False)
     self.assertIs(converters.convert_to_boolean('false'), False)
     self.assertIs(converters.convert_to_boolean('0'), False)
     self.assertIs(converters.convert_to_boolean('1'), True)
     self.assertRaises(n_exc.InvalidInput, converters.convert_to_boolean,
                       '7')
예제 #9
0
 def test_convert_to_boolean_str(self):
     self.assertIs(converters.convert_to_boolean('True'), True)
     self.assertIs(converters.convert_to_boolean('true'), True)
     self.assertIs(converters.convert_to_boolean('False'), False)
     self.assertIs(converters.convert_to_boolean('false'), False)
     self.assertIs(converters.convert_to_boolean('0'), False)
     self.assertIs(converters.convert_to_boolean('1'), True)
     self.assertRaises(n_exc.InvalidInput,
                       converters.convert_to_boolean,
                       '7')
예제 #10
0
 def test_convert_to_boolean_int(self):
     self.assertIs(converters.convert_to_boolean(0), False)
     self.assertIs(converters.convert_to_boolean(1), True)
     self.assertRaises(n_exc.InvalidInput, converters.convert_to_boolean, 7)
예제 #11
0
 def test_convert_to_boolean_bool(self):
     self.assertIs(converters.convert_to_boolean(True), True)
     self.assertIs(converters.convert_to_boolean(False), False)
예제 #12
0
 def test_convert_to_boolean_int(self):
     self.assertIs(converters.convert_to_boolean(0), False)
     self.assertIs(converters.convert_to_boolean(1), True)
     self.assertRaises(n_exc.InvalidInput,
                       converters.convert_to_boolean,
                       7)
예제 #13
0
 def test_convert_to_boolean_bool(self):
     self.assertIs(converters.convert_to_boolean(True), True)
     self.assertIs(converters.convert_to_boolean(False), False)