Example #1
0
def _validate_subnet2(data):
    msg = None
    try:
        net = netaddr.IPNetwork(lib_validators.validate_no_whitespace(data))
        if '/' not in data or (net.network != net.ip):
            msg = _("'%(data)s' isn't a recognized IP subnet cidr,"
                    " '%(cidr)s' is recommended") % {
                        "data": data,
                        "cidr": net.cidr
                    }
        else:
            return
    except Exception:
        msg = _("'%s' is not a valid IP subnet") % data
    return msg
Example #2
0
    def test_validate_no_whitespace(self):
        data = 'no_white_space'
        result = validators.validate_no_whitespace(data)
        self.assertEqual(data, result)

        self.assertRaises(n_exc.InvalidInput,
                          validators.validate_no_whitespace,
                          'i have whitespace')

        self.assertRaises(n_exc.InvalidInput,
                          validators.validate_no_whitespace,
                          'i\thave\twhitespace')

        for ws in string.whitespace:
            self.assertRaises(n_exc.InvalidInput,
                              validators.validate_no_whitespace,
                              '%swhitespace-at-head' % ws)
            self.assertRaises(n_exc.InvalidInput,
                              validators.validate_no_whitespace,
                              'whitespace-at-tail%s' % ws)
Example #3
0
    def test_validate_no_whitespace(self):
        data = 'no_white_space'
        result = validators.validate_no_whitespace(data)
        self.assertEqual(data, result)

        self.assertRaises(n_exc.InvalidInput,
                          validators.validate_no_whitespace,
                          'i have whitespace')

        self.assertRaises(n_exc.InvalidInput,
                          validators.validate_no_whitespace,
                          'i\thave\twhitespace')

        for ws in string.whitespace:
            self.assertRaises(n_exc.InvalidInput,
                              validators.validate_no_whitespace,
                              '%swhitespace-at-head' % ws)
            self.assertRaises(n_exc.InvalidInput,
                              validators.validate_no_whitespace,
                              'whitespace-at-tail%s' % ws)