def random_line_staff(): """create random line to import random staff""" return '%s,%s,%s,%s%s.%s%s.%s,%s,%s\n' % ( uts.random_username(), uts.random_name(), uts.random_name(), uts.random_int(0, 2), uts.random_int(1, 8), uts.random_int(0, 0), uts.random_int(1, 9), uts.random_int(1980, 2014), uts.random_name(), random_email(), )
def random_line_stu_tea(school): """create random line to import random student/teacher/teacher and staff""" return '%s,%s,%s,%s%s.%s%s.%s,%s,%s,%s\n' % ( uts.random_username(), uts.random_name(), uts.random_name(), uts.random_int(1, 2), uts.random_int(1, 8), uts.random_int(0, 0), uts.random_int(1, 9), uts.random_int(1980, 2014), uts.random_name(), random_email(), "{}-{}".format(school, uts.random_string()), )
def test__dns_alias_record_check_resolve(self, udm): """Creates DNS alias record and tries to resolve it""" zone = '%s.%s.' % (uts.random_name(), uts.random_name()) pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) forward_zone_properties = { 'zone': zone, 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), } forward_zone = udm.create_object('dns/forward_zone', position=pos, **forward_zone_properties) # IPv4 / IPv6 host = uts.random_name() ipv4 = uts.random_ip() ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041' # create random_ipv6()-method? host_record_properties = { 'name': host, 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'a': [ipv4, ipv6], 'mx': '50 %s' % uts.random_string(), 'txt': uts.random_string() } udm.create_object('dns/host_record', superordinate=forward_zone, **host_record_properties) alias_name = uts.random_name() fqhn = '%s.%s' % (host, zone) udm.create_object('dns/alias', superordinate=forward_zone, name=alias_name, cname=fqhn) qname = '%s.%s' % (alias_name, zone) time.sleep(5) answers = resolve_dns_entry(qname, 'CNAME') answer = [rdata.target.to_text() for rdata in answers] assert answer == [ fqhn ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [fqhn])
def test__dns_forward_zone_check_resolve(self, udm): """Creates DNS forward zone entry and try to resolve it""" zone = '%s.%s.' % (uts.random_name(), uts.random_name()) pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) forward_zone_properties = { 'zone': zone, 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), 'a': ['%s' % (uts.random_ip())] } udm.create_object('dns/forward_zone', position=pos, **forward_zone_properties) time.sleep(5) answers = resolve_dns_entry(zone, 'SOA') answer = answers.qname.to_text() assert answer == zone, 'resolved name "%s" != created ldap-object "%s"' % ( answer, zone)
def test__dns_reverse_zone_check_resolve(self, udm): """Creates DNS reverse zone entry and try to resolve it""" pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) # IPv4 ipv4 = uts.random_ip().split('.') subnet = ipv4[:3] reverse_zone_properties = { 'subnet': '.'.join(subnet), 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), } udm.create_object('dns/reverse_zone', position=pos, **reverse_zone_properties) zoneName = '.'.join(list(reversed(subnet)) + ['in-addr', 'arpa', '']) time.sleep(5) answers = resolve_dns_entry(zoneName, 'SOA') answer = answers.qname.to_text() assert answer == zoneName, 'IPv4: resolved name "%s" != created ldap-object "%s"' % ( answer, zoneName) # IPv6 ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'.split( ':') # create uts.random_ipV6()? subnet = ipv6[:7] reverse_zone_properties.update({ 'subnet': ':'.join(subnet), }) udm.create_object('dns/reverse_zone', position=pos, **reverse_zone_properties) zoneName = '.'.join( list(reversed([nibble for block in subnet for nibble in block])) + ['ip6', 'arpa', '']) time.sleep(5) answers = resolve_dns_entry(zoneName, 'SOA') answer = answers.qname.to_text() assert answer == zoneName, 'IPv6: resolved name "%s" != created ldap-object "%s"' % ( answer, zoneName)
def create_dc_slave_in_container(container_dn): """Create random computer in a specific container:\n :param container_dn: container dn to create the group in :type container_dn: ldap object dn """ cmd = [ 'udm', 'computers/domaincontroller_slave', 'create', '--position', '%(container)s', '--set', 'name=%(name)s' ] out, err = run_commands( [cmd], { 'container': container_dn, 'name': uts.random_name(), 'uidNumber': uts.random_int() })[0] if out: return out.split(': ')[1].strip()
def test__dns_txt_record_check_resolve(self, udm): """Creates DNS pointer record entry and try to resolve it""" zone = '%s.%s.' % (uts.random_name(), uts.random_name()) pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) txt = uts.random_string() forward_zone_properties = { 'zone': zone, 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), 'txt': txt, } udm.create_object('dns/forward_zone', position=pos, **forward_zone_properties) time.sleep(5) answers = resolve_dns_entry(zone, 'TXT') # FIXME PMH-2017-01-14: returned TXT data is enclosed in " answer = [rdata.to_text().strip('"') for rdata in answers] assert answer == [ txt ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [txt])
def get_schema_attribute_id(): return random_int() + random_int() + random_int() + random_int( ) + random_int()
def test__dns_pointer_record_check_resolve(self, udm): """Creates DNS pointer record entry and try to resolve it""" pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) ptr_record = '%s.%s.' % (uts.random_name(), uts.random_name()) # IPv4 ipv4 = uts.random_ip().split('.') subnet = ipv4[:3] reverse_zone_properties = { 'subnet': '.'.join(subnet), 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), } reverse_zone = udm.create_object('dns/reverse_zone', position=pos, **reverse_zone_properties) udm.create_object('dns/ptr_record', address=ipv4[3], superordinate=reverse_zone, ptr_record=ptr_record) zoneName = '.'.join(list(reversed(ipv4)) + ['in-addr', 'arpa', '']) time.sleep(5) answers = resolve_dns_entry(zoneName, 'PTR') answer = [rdata.to_text() for rdata in answers] assert answer == [ ptr_record ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [ptr_record]) # IPv6 ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041'.split( ':') # create uts.random_ipV6()? subnet = ipv6[:7] reverse_zone_properties.update({ 'subnet': ':'.join(subnet), }) reverse_zone = udm.create_object('dns/reverse_zone', position=pos, **reverse_zone_properties) addr = '.'.join(reversed(ipv6[7])) udm.create_object('dns/ptr_record', address=addr, superordinate=reverse_zone, ptr_record=ptr_record) zoneName = '.'.join( list(reversed([nibble for block in ipv6 for nibble in block])) + ['ip6', 'arpa', '']) time.sleep(5) answers = resolve_dns_entry(zoneName, 'PTR') answer = [rdata.to_text() for rdata in answers] assert answer == [ ptr_record ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [ptr_record])
def test__dns_srv_record_check_resolve(self, udm): """Creates DNS srv record and try to resolve it""" zone = '%s.%s.' % (uts.random_name(), uts.random_name()) pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) forward_zone_properties = { 'zone': zone, 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), } forward_zone = udm.create_object('dns/forward_zone', position=pos, **forward_zone_properties) # IPv4 / IPv6 host = uts.random_name() ipv4 = uts.random_ip() ipv6 = '2011:06f8:13dc:0002:19b7:d592:09dd:1041' # create random_ipv6()-method? host_record_properties = { 'name': host, 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'a': [ipv4, ipv6], 'mx': '50 %s' % uts.random_string(), 'txt': uts.random_string() } udm.create_object('dns/host_record', superordinate=forward_zone, **host_record_properties) service = uts.random_string() protocol = 'tcp' extension = uts.random_string() priority = 1 weight = 100 port = uts.random_int(top_end=65535) fqhn = '%s.%s' % (host, zone) srv_record_properties = { 'name': '%s %s %s' % (service, protocol, extension), 'location': '%d %d %s %s' % (priority, weight, port, fqhn), 'zonettl': '128' } udm.create_object('dns/srv_record', superordinate=forward_zone, **srv_record_properties) zoneName = '_%s._%s.%s.%s' % (service, protocol, extension, zone) answers = resolve_dns_entry(zoneName, 'SRV') answer = [rdata.target.to_text() for rdata in answers] assert answer == [ fqhn ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [fqhn])
def test__dns_host_record_check_resolve(self, udm): """Creates DNS host record entry and try to resolve it""" zone = '%s.%s.' % (uts.random_name(), uts.random_name()) pos = 'cn=dns,%s' % (udm.LDAP_BASE, ) forward_zone_properties = { 'zone': zone, 'nameserver': udm.FQHN, 'contact': '%s@%s.%s' % (uts.random_name(), uts.random_name(), uts.random_name()), 'serial': '%s' % (uts.random_int()), 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'refresh': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'expire': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'ttl': '%s' % (uts.random_int(bottom_end=10, top_end=99)), 'retry': '%s' % (uts.random_int()), } forward_zone = udm.create_object('dns/forward_zone', position=pos, **forward_zone_properties) # IPv4 ip = uts.random_ip() host = uts.random_name() host_record_properties = { 'name': host, 'zonettl': '%s' % (uts.random_int(bottom_end=100, top_end=999)), 'a': ip, 'mx': '50 %s' % uts.random_string(), 'txt': uts.random_string() } udm.create_object('dns/host_record', superordinate=forward_zone, **host_record_properties) qname = '%s.%s' % (host, zone) answers = resolve_dns_entry(qname, 'A') answer = [ip_address(u'%s' % (rdata.address, )) for rdata in answers] assert answer == [ ip_address(u'%s' % (ip, )) ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [ip]) # IPv6 ip = '2011:06f8:13dc:0002:19b7:d592:09dd:1041' # create random_ipv6()-method? host = uts.random_name() host_record_properties.update({ 'name': host, 'a': ip, }) udm.create_object('dns/host_record', superordinate=forward_zone, **host_record_properties) qname = '%s.%s' % (host, zone) time.sleep(5) answers = resolve_dns_entry(qname, 'AAAA') answer = [ip_address(u'%s' % (rdata.address, )) for rdata in answers] assert answer == [ ip_address(u'%s' % (ip, )) ], 'resolved name "%s" != created ldap-object "%s"' % (answer, [ip])
def udm_user_args(ucr, minimal=True): res = dict(firstname=uts.random_string(), lastname=uts.random_string(), set=dict( displayName=uts.random_string(), password=uts.random_string(), mailHomeServer="{}.{}".format(ucr["hostname"], ucr["domainname"]), mailPrimaryAddress="{}@{}".format(uts.random_username(), ucr["domainname"]), )) res["append"] = dict() if not minimal: res["set"].update( dict(birthday="19{}-0{}-{}{}".format(2 * uts.random_int(), uts.random_int(1, 9), uts.random_int(0, 2), uts.random_int(1)), city=uts.random_string(), country=random.choice( map(itemgetter(0), udm_syntax.Country.choices)), departmentNumber=uts.random_string(), description=uts.random_string(), employeeNumber=3 * uts.random_int(), employeeType=uts.random_string(), organisation=uts.random_string(), postcode=3 * uts.random_int(), roomNumber=3 * uts.random_int(), street=uts.random_string(), title=uts.random_string())) res["append"].update( dict( homePostalAddress=[ '"{}" "{}" "{}"'.format(uts.random_string(), uts.random_string(), uts.random_string()), '"{}" "{}" "{}"'.format(uts.random_string(), uts.random_string(), uts.random_string()) ], homeTelephoneNumber=[uts.random_string(), uts.random_string()], mailAlternativeAddress=[ "{}@{}".format(uts.random_username(), ucr["domainname"]), "{}@{}".format(uts.random_username(), ucr["domainname"]) ], mobileTelephoneNumber=[ uts.random_string(), uts.random_string() ], pagerTelephoneNumber=[ uts.random_string(), uts.random_string() ], phone=[12 * uts.random_int(), 12 * uts.random_int()], secretary=[ "uid=Administrator,cn=users,{}".format(ucr["ldap/base"]), "uid=Guest,cn=users,{}".format(ucr["ldap/base"]) ])) # func arg name with '-' not allowed res["append"]["e-mail"] = [ "{}@{}".format(uts.random_username(), uts.random_username()), "{}@{}".format(uts.random_username(), uts.random_username()) ] return res
def append_random_class(self, schools=None): if not schools: schools = [self.school] for school in schools: self.school_classes.setdefault(school, []).append('%s-%s%s%s' % (school, uts.random_int(), uts.random_int(), uts.random_string(length=2, alpha=True, numeric=False)))