Exemplo n.º 1
0
def make_inet_address(subnet=None):
    """Fake an AF_INET address."""
    if subnet is None:
        subnet = factory.getRandomNetwork()
    return {
        'broadcast': subnet.broadcast,
        'netmask': subnet.netmask,
        'addr': factory.getRandomIPInNetwork(subnet),
    }
Exemplo n.º 2
0
def make_inet_address(subnet=None):
    """Fake an AF_INET address."""
    if subnet is None:
        subnet = factory.getRandomNetwork()
    return {
        'broadcast': subnet.broadcast,
        'netmask': subnet.netmask,
        'addr': factory.getRandomIPInNetwork(subnet),
    }
Exemplo n.º 3
0
 def test_reverse_config_file_is_world_readable(self):
     self.patch(DNSReverseZoneConfig, 'target_dir', self.make_dir())
     dns_zone_config = DNSReverseZoneConfig(
         factory.getRandomString(), serial=random.randint(1, 100),
         dns_ip=factory.getRandomIPAddress(),
         network=factory.getRandomNetwork())
     dns_zone_config.write_config()
     filepath = FilePath(dns_zone_config.target_path)
     self.assertTrue(filepath.getPermissions().other.read)
Exemplo n.º 4
0
 def test_writes_dns_zone_config_with_NS_record(self):
     target_dir = self.make_dir()
     self.patch(DNSReverseZoneConfig, 'target_dir', target_dir)
     network = factory.getRandomNetwork()
     dns_ip = factory.getRandomIPAddress()
     dns_zone_config = DNSReverseZoneConfig(
         factory.getRandomString(), serial=random.randint(1, 100),
         dns_ip=dns_ip, network=network)
     dns_zone_config.write_config()
     self.assertThat(
         os.path.join(
             target_dir, 'zone.%s' % dns_zone_config.zone_name),
         FileContains(
             matcher=Contains('IN  NS  %s.' % dns_zone_config.domain)))
Exemplo n.º 5
0
 def test_writes_dns_zone_config_with_NS_record(self):
     target_dir = self.make_dir()
     self.patch(DNSForwardZoneConfig, 'target_dir', target_dir)
     network = factory.getRandomNetwork()
     dns_ip = factory.getRandomIPAddress()
     dns_zone_config = DNSForwardZoneConfig(
         factory.getRandomString(), serial=random.randint(1, 100),
         dns_ip=dns_ip, networks=[network])
     dns_zone_config.write_config()
     self.assertThat(
         os.path.join(target_dir, 'zone.%s' % dns_zone_config.domain),
         FileContains(
             matcher=ContainsAll(
                 [
                     'IN  NS  %s.' % dns_zone_config.domain,
                     '%s. IN A %s' % (dns_zone_config.domain, dns_ip),
                 ])))
Exemplo n.º 6
0
 def test_fields(self):
     domain = factory.getRandomString()
     serial = random.randint(1, 200)
     hostname = factory.getRandomString()
     network = factory.getRandomNetwork()
     ip = factory.getRandomIPInNetwork(network)
     mapping = {hostname: ip}
     dns_zone_config = DNSReverseZoneConfig(
         domain, serial, mapping, network=network)
     self.assertThat(
         dns_zone_config,
         MatchesStructure.byEquality(
             domain=domain,
             serial=serial,
             mapping=mapping,
             network=network,
             )
         )
Exemplo n.º 7
0
 def test_writes_dns_zone_config(self):
     target_dir = self.make_dir()
     self.patch(DNSForwardZoneConfig, 'target_dir', target_dir)
     domain = factory.getRandomString()
     hostname = factory.getRandomString()
     network = factory.getRandomNetwork()
     ip = factory.getRandomIPInNetwork(network)
     dns_zone_config = DNSForwardZoneConfig(
         domain, serial=random.randint(1, 100),
         mapping={hostname: ip}, networks=[network])
     dns_zone_config.write_config()
     self.assertThat(
         os.path.join(target_dir, 'zone.%s' % domain),
         FileContains(
             matcher=ContainsAll(
                 [
                     '%s IN CNAME %s' % (hostname, generated_hostname(ip)),
                     '%s IN A %s' % (generated_hostname(ip), ip),
                 ])))
Exemplo n.º 8
0
 def test_getRandomIPInNetwork(self):
     network = factory.getRandomNetwork()
     ip = factory.getRandomIPInNetwork(network)
     self.assertTrue(network.first <= IPAddress(ip).value <= network.last)
Exemplo n.º 9
0
 def test_getRandomNetwork(self):
     network = factory.getRandomNetwork()
     self.assertIsInstance(network, IPNetwork)
Exemplo n.º 10
0
 def test_getRandomIPInNetwork(self):
     network = factory.getRandomNetwork()
     ip = factory.getRandomIPInNetwork(network)
     self.assertTrue(
         network.first <= IPAddress(ip).value <= network.last)
Exemplo n.º 11
0
 def test_getRandomNetwork(self):
     network = factory.getRandomNetwork()
     self.assertIsInstance(network, IPNetwork)