def __init__(self, api, lb, vip, ips, protocol=const.PROTO_TCP, may_exist=False, **columns): super(LbAddCommand, self).__init__(api) self.lb = lb self.vip = utils.normalize_ip_port(vip) self.ips = ",".join(utils.normalize_ip_port(ip) for ip in ips) self.protocol = protocol self.may_exist = may_exist self.columns = columns
def test_normalize_ip_port(self): good = [('4.4.4.4:53', '4.4.4.4:53'), ('10.0.0.0:7', '10.0.0.0:7'), ('123:12', '0.0.0.123:12'), ('[2001:0db8:85a3:0000:0000:8a2e:0370:7334]:80', '[2001:db8:85a3::8a2e:370:7334]:80')] bad = ('1.2.3.4:0', '1.2.3.4:99000', '2001:0db8:85a3:0000:0000:8a2e:0370:7334:80') for before, after in good: norm = utils.normalize_ip_port(before) self.assertEqual(after, norm, "%s does not match %s" % (after, norm)) for val in bad: self.assertRaises(netaddr.AddrFormatError, utils.normalize_ip_port, val)
def _lb_add(self, lb, vip, ips, protocol=const.PROTO_TCP, may_exist=False, **columns): lbal = self.useFixture( fixtures.LoadBalancerFixture(lb, vip, ips, protocol, may_exist, **columns)).obj self.assertEqual(lb, lbal.name) norm_vip = ovsdb_utils.normalize_ip_port(vip) self.assertIn(norm_vip, lbal.vips) self.assertEqual(",".join(ovsdb_utils.normalize_ip(ip) for ip in ips), lbal.vips[norm_vip]) self.assertIn(protocol, lbal.protocol) # because optional return lbal
def dns_add_record(self, uuid, hostname, ips): if isinstance(ips, list): ips = " ".join(utils.normalize_ip_port(ip) for ip in ips) return self.db_add('DNS', uuid, 'records', {hostname: ips})
def __init__(self, api, lb, vip=None, if_exists=False): super(LbDelCommand, self).__init__(api) self.lb = lb self.vip = utils.normalize_ip_port(vip) if vip else vip self.if_exists = if_exists