def setUp(self): config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.core_instance = roster_core.Core(u'sharrell', config_instance) self.core_instance.MakeView(u'external') self.core_instance.MakeZone(u'sub.university.lcl', u'master', u'sub.university.lcl.', view_name=u'external') self.core_instance.MakeZone(u'0.168.192.in-addr.arpa', u'master', u'0.168.192.in-addr.arpa.', view_name=u'external') self.core_instance.MakeReverseRangeZoneAssignment( u'0.168.192.in-addr.arpa', u'192.168.0/24') importer_instance = zone_importer_lib.ZoneImport( ZONE_FILE, CONFIG_FILE, u'sharrell', u'external', u'sub.university.lcl') importer_instance.MakeRecordsFromZone() importer_instance = zone_importer_lib.ZoneImport( REVERSE_ZONE_FILE, CONFIG_FILE, u'sharrell', u'external', u'0.168.192.in-addr.arpa') importer_instance.MakeRecordsFromZone()
def setUp(self): config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.core_instance = roster_core.Core(u'sharrell', config_instance) self.core_instance.MakeView(u'external') self.core_instance.MakeZone(u'sub.university.lcl', u'master', u'sub.university.lcl.', view_name=u'external') self.core_instance.MakeZone(u'0.168.192.in-addr.arpa', u'master', u'0.168.192.in-addr.arpa.', view_name=u'external') self.core_instance.MakeZone(u'8.0.e.f.f.3.ip6.arpa', u'master', u'8.0.e.f.f.3.ip6.arpa.', view_name=u'external') self.core_instance.MakeReverseRangeZoneAssignment( u'0.168.192.in-addr.arpa', u'192.168.0/24') self.core_instance.MakeReverseRangeZoneAssignment( u'8.0.e.f.f.3.ip6.arpa', u'3ffe:0800:0000:0000:0000:0000:0000:0000/24')
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.cfg_server = self.config_instance.config_file['server'] self.cfg_database = self.config_instance.config_file['database'] self.cfg_exporter = self.config_instance.config_file['exporter'] self.db_instance = self.config_instance.GetDb() self.base_command = ( 'python %s -c %s/config.conf -u %s -U %s ' '-d %s -n %s ' '--ssl-cert %s --ssl-key %s ' '--root-config-dir %s --backup-dir %s --root-hint-file %s ' '-i %s/init -p %s --run-as %s --force' % (EXEC, self.cfg_exporter['backup_dir'], self.cfg_database['login'], u'new_user', self.cfg_database['database'], self.cfg_database['server'], self.cfg_server['ssl_cert_file'], self.cfg_server['ssl_key_file'], self.cfg_exporter['backup_dir'], self.cfg_exporter['backup_dir'], self.cfg_exporter['root_hint_file'], self.cfg_exporter['backup_dir'], self.cfg_database['passwd'], os.getuid())) ## The first number represents the auth_module chosen. This can change if ## more modules are added later and appear before general_ldap. self.base_communicate = ( '1\nuid=%%s,ou=People,dc=dc,dc=university,dc=edu\n' '/etc/roster_certs/host.cert\n3\nldaps://ldap.university.edu:636\n' )
def setUp(self): def PickUnusedPort(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, 0)) addr, port = s.getsockname() s.close() return port self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.port = PickUnusedPort() self.server_name = 'https://%s:%s' % (HOST, self.port) self.daemon_thread = DaemonThread(self.config_instance, self.port) self.daemon_thread.daemon = True self.daemon_thread.start() self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.password = '******' time.sleep(1) roster_client_lib.GetCredentials(USERNAME, u'test', credfile=CREDFILE, server_name=self.server_name)
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.server_instance = roster_server.Server(self.config_instance, KEYFILE, CERTFILE, core_die_time=5, inf_renew_time=5, clean_time=0) self.credential = self.server_instance.GetCredentials( USERNAME, u'test') self.server_instance.core_store = [ ] # Clear out core instance from above self.logfile = self.config_instance.config_file['server'][ 'server_log_file']
def setUp(self): self.port = PickUnusedPort() self.rndc_port = PickUnusedPort() while (self.rndc_port == self.port): self.rndc_port = PickUnusedPort() if (not os.path.exists(BINDDIR)): os.mkdir(BINDDIR) if (not os.path.exists(TESTDIR)): os.mkdir(TESTDIR) rndc_key = open(RNDC_KEY, 'w') rndc_key.write(RNDC_KEY_DATA) rndc_key.close() rndc_conf = open(RNDC_CONF, 'w') rndc_conf.write(RNDC_CONF_DATA) rndc_conf.close() fabric_api.env.warn_only = True fabric_state.output['everything'] = False fabric_state.output['warnings'] = False fabric_api.env.host_string = "%s@%s" % (SSH_USER, TEST_DNS_SERVER) self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.root_config_dir = self.config_instance.config_file['exporter'][ 'root_config_dir'].rstrip('/').lstrip('./') self.backup_dir = self.config_instance.config_file['exporter'][ 'backup_dir'].rstrip('/').lstrip('./') self.tree_exporter_instance = tree_exporter.BindTreeExport(CONFIG_FILE) self.lockfile = self.config_instance.config_file['server']['lock_file'] database_server = self.config_instance.config_file['database'][ 'server'] traceroute_output = os.popen( 'dig +trace www.google.com | grep Received').read().strip('\n') traceroute_lines = traceroute_output.split('\n') self.real_dns_server = traceroute_lines[0].split(' ')[5].split('#')[0] db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.db_instance = db_instance self.core_instance = roster_core.Core(u'sharrell', self.config_instance) self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') self.config_lib_instance = config_lib.ConfigLib(CONFIG_FILE) if (not os.path.exists(TESTDIR)): os.system('mkdir %s' % TESTDIR)
def setUp(self): self.maxDiff = None self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.db_instance = self.config_instance.GetDb() self.db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() self.db_instance.StartTransaction() self.db_instance.cursor.execute(data) self.db_instance.EndTransaction()
def setUp(self): config_instance = roster_core.Config(CONFIG_FILE) db_instance = config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() core_instance = roster_core.Core(CORE_USERNAME, config_instance) core_instance.MakeDnsServer(TEST_DNS_SERVER, SSH_USER, BINDDIR, TESTDIR)
def setUp(self): def PickUnusedPort(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, 0)) addr, port = s.getsockname() s.close() return port self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.port = PickUnusedPort() self.server_name = 'https://%s:%s' % (HOST, self.port) self.daemon_thread = DaemonThread(self.config_instance, self.port) self.daemon_thread.daemon = True self.daemon_thread.start() self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.password = '******' time.sleep(1) roster_client_lib.GetCredentials(USERNAME, u'test', credfile=CREDFILE, server_name=self.server_name) self.core_instance.MakeView(u'test_view') self.core_instance.MakeZone(u'sub.university.lcl', u'master', u'sub.university.lcl.', view_name=u'test_view') self.core_instance.MakeZone(u'0.168.192.in-addr.arpa', u'master', u'0.168.192.in-addr.arpa.', view_name=u'test_view') self.core_instance.MakeZone(u'8.0.e.f.f.3.ip6.arpa', u'master', u'8.0.e.f.f.3.ip6.arpa.', view_name=u'test_view') self.core_instance.MakeReverseRangeZoneAssignment( u'0.168.192.in-addr.arpa', u'192.168.0/24') self.core_instance.MakeReverseRangeZoneAssignment( u'8.0.e.f.f.3.ip6.arpa', u'3ffe:0800:0000:0000:0000:0000:0000:0000/24')
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.lockfile = self.config_instance.config_file['server']['lock_file'] db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close()
def setUp(self): def PickUnusedPort(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, 0)) addr, port = s.getsockname() s.close() return port self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.port = PickUnusedPort() self.server_name = 'https://%s:%s' % (HOST, self.port) self.daemon_thread = DaemonThread(self.config_instance, self.port) self.daemon_thread.daemon = True self.daemon_thread.start() self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.password = '******' time.sleep(1) self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') self.core_instance.MakeView(u'test_view') self.core_instance.MakeZone(u'test_zone', u'master', u'test_zone.', view_name=u'test_view') self.core_instance.MakeRecord( u'soa', u'machine1', u'test_zone', { u'name_server': u'ns.university.edu.', u'admin_email': u'university.edu.', u'serial_number': 123456789, u'refresh_seconds': 30, u'retry_seconds': 30, u'expiry_seconds': 30, u'minimum_seconds': 30 }, view_name=u'test_view')
def setUp(self): config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.db_instance = db_instance self.audit_log_instance = audit_log.AuditLog(db_instance=db_instance, log_file_name=TEMP_LOG)
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.cred_instance = credentials.CredCache(self.config_instance, u'sharrell') db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.core_instance = roster_core.Core(u'sharrell', self.config_instance)
def setUp(self): def PickUnusedPort(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, 0)) addr, port = s.getsockname() s.close() return port self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.cred_instance = credentials.CredCache(self.config_instance, 5) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.port = PickUnusedPort() self.server_name = 'https://%s:%s' % (HOST, self.port) self.daemon_instance = roster_server.Server(self.config_instance, KEYFILE, CERTFILE, inf_renew_time=5, core_die_time=5, clean_time=0) self.daemon_thread = DaemonThread(self.config_instance, self.port, self.daemon_instance) self.daemon_thread.daemon = True self.daemon_thread.start() time.sleep(1) ## Will create a core_instance in core_store self.credential = roster_client_lib.GetCredentials( USERNAME, PASSWORD, server_name=self.server_name) self.daemon_instance.core_store = [ ] # Clear out core instance from above if (os.path.exists(CREDFILE)): os.remove(CREDFILE) self.core_instance = roster_core.Core(u'sharrell', self.config_instance)
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.db_instance = self.config_instance.GetDb() schema = roster_core.embedded_files.SCHEMA_FILE self.db_instance.StartTransaction() self.db_instance.cursor.execute(schema) self.db_instance.EndTransaction() data = open(DATA_FILE, 'r').read() self.db_instance.StartTransaction() self.db_instance.cursor.execute(data) self.db_instance.EndTransaction() self.log_instance = audit_log.AuditLog(log_to_syslog=True) self.core_instance = roster_core.Core(u'sharrell', self.config_instance)
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.core_instance = roster_core.Core(u'sharrell', self.config_instance) self.tree_exporter_instance = tree_exporter.BindTreeExport(CONFIG_FILE) self.db_instance = db_instance if (os.path.exists(self.tree_exporter_instance.backup_dir)): shutil.rmtree(self.tree_exporter_instance.backup_dir)
def setUp(self): if( not os.path.exists(TESTDIR) ): os.system('mkdir %s' % TESTDIR) self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.root_config_dir = self.config_instance.config_file['exporter']['root_config_dir'].rstrip('/') self.backup_dir = self.config_instance.config_file['exporter']['backup_dir'].rstrip('/') db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.core_instance = roster_core.Core(u'sharrell', self.config_instance) self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') self.core_instance.MakeACL(u'internal', u'127.0.0.1') self.core_instance.MakeView(u'external') self.core_instance.MakeDnsServer(u'localhost', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServer(u'255.254.253.252', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServerSet(u'master') self.core_instance.MakeDnsServerSetAssignments(u'localhost', u'master') self.core_instance.MakeDnsServerSetAssignments(u'255.254.253.252', u'master') self.core_instance.MakeDnsServerSetViewAssignments(u'external', 1, u'master') self.core_instance.MakeViewToACLAssignments(u'external', u'master', u'internal', 1) self.core_instance.MakeZone(u'forward_zone', u'master', u'university.lcl.', u'external') self.core_instance.MakeRecord(u'soa', u'@', u'forward_zone', {u'refresh_seconds':500, u'expiry_seconds':500, u'name_server':u'ns.university.lcl.', u'minimum_seconds':500, u'retry_seconds': 500, u'serial_number':1000, u'admin_email': u'admin.localhost.lcl.'}, u'external') self.core_instance.MakeRecord(u'ns', u'@', u'forward_zone', {u'name_server':u'ns.university.lcl.'}) self.core_instance.MakeRecord(u'a', u'ns', u'forward_zone', {u'assignment_ip':u'1.2.3.4'}) self.core_instance.MakeNamedConfGlobalOption( u'master', u'include "%s/test_data/rndc.key"; options { pid-file "test_data/named.pid";};\n' 'controls { inet 127.0.0.1 port 5555 allow{localhost;} keys {rndc-key;};};' % (os.getcwd()))
def testDBBootstrapDefault(self): command = subprocess.Popen(self.base_command, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) command.communicate(self.base_communicate) if (not os.path.exists( '%s/config.conf' % self.cfg_exporter['backup_dir'])): self.fail('Conf file was not created.') if (not os.path.exists('%s/init' % self.cfg_exporter['backup_dir'])): self.fail('Init File was not created.') config = roster_core.Config(file_name='%s/config.conf' % self.cfg_exporter['backup_dir']) config_database = config.config_file['database'] config_credentials = config.config_file['credentials'] config_server = config.config_file['server'] self.assertEqual(config_database['server'], self.cfg_database['server']) self.assertEqual(config_database['ssl'], self.cfg_database['ssl']) self.assertEqual(config_database['ssl_ca'], self.cfg_database['ssl_ca'])
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.core_instance = roster_core.Core(u'sharrell', self.config_instance) self.db_recovery_instance = db_recovery.Recover( u'sharrell', self.config_instance) self.tree_exporter_instance = tree_exporter.BindTreeExport(CONFIG_FILE) self.db_instance = db_instance self.core_instance.RemoveZone(u'eas.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'cs.university.edu')
def testDBBootstrapExtraParamSSL(self): command = subprocess.Popen( '%s --infinite-renew-time %s --core-die-time %s ' '--get-credentials-wait-increment %s --credential-expiry-time %s ' '--big-lock-timeout %s --db-ssl --db-ssl-ca ca' % (self.base_command, 90210, 22221, 13, 26, 9001), shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE) ## Check base_communicate in setUp if module selected is wrong command.communicate(self.base_communicate) config = roster_core.Config(file_name='%s/config.conf' % self.cfg_exporter['backup_dir']) config_server = config.config_file['server'] config_credentials = config.config_file['credentials'] config_database = config.config_file['database'] self.assertEquals(config_server['inf_renew_time'], 90210) self.assertEquals(config_server['core_die_time'], 22221) self.assertEquals(config_server['get_credentials_wait_increment'], 13) self.assertEquals(config_credentials['exp_time'], 26) self.assertEquals(config_database['ssl'], True) self.assertEquals(config_database['ssl_ca'], 'ca')
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.config_lib_instance = config_lib.ConfigLib(CONFIG_FILE) self.root_config_dir = self.config_instance.config_file['exporter'][ 'root_config_dir'].lstrip('./').rstrip('/') self.backup_dir = self.config_instance.config_file['exporter'][ 'backup_dir'].lstrip('./').rstrip('/') self.bind_config_dir = os.path.expanduser(self.root_config_dir) self.lockfile = self.config_instance.config_file['server']['lock_file'] self.tree_exporter_instance = tree_exporter.BindTreeExport(CONFIG_FILE) self.config_lib_instance = config_lib.ConfigLib(CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.db_instance = db_instance if (not os.path.exists(TEST_DIR)): os.system('mkdir %s' % TEST_DIR) self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') self.core_instance.MakeView(u'test_view') self.core_instance.MakeZone(u'sub.university.lcl', u'master', u'sub.university.lcl.', view_name=u'test_view')
def testGetUserAuthorizationInfoSSL(self): self.db_instance.close() del self.config_instance del self.db_instance self.config_instance = roster_core.Config(file_name=SSL_CONFIG_FILE) self.db_instance = self.config_instance.GetDb() self.db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() self.db_instance.StartTransaction() self.db_instance.cursor.execute(data) self.db_instance.EndTransaction() self.db_instance.close() if (not self.config_instance.config_file['database']['ssl']): raise SSLTestError( "SSL not enabled in config file. Enable to allow for testing.") core_instance = roster_core.Core(u'sharrell', self.config_instance) self.assertEquals( self.db_instance.GetUserAuthorizationInfo(u'notindb'), {}) self.assertEquals( self.db_instance.GetUserAuthorizationInfo(u'jcollins'), { 'user_access_level': 32, 'user_name': 'jcollins', 'forward_zones': [], 'groups': [], 'reverse_ranges': [] }) self.assertEquals( self.db_instance.GetUserAuthorizationInfo(u'shuey'), { 'user_access_level': 64, 'user_name': u'shuey', 'forward_zones': [{ 'zone_name': u'cs.university.edu', 'group_permission': u'a' }, { 'zone_name': u'cs.university.edu', 'group_permission': u'aaaa' }, { 'zone_name': u'cs.university.edu', 'group_permission': u'cname' }, { 'zone_name': u'cs.university.edu', 'group_permission': u'ns' }, { 'zone_name': u'cs.university.edu', 'group_permission': u'soa' }, { 'zone_name': u'eas.university.edu', 'group_permission': u'a' }, { 'zone_name': u'eas.university.edu', 'group_permission': u'aaaa' }, { 'zone_name': u'eas.university.edu', 'group_permission': u'cname' }, { 'zone_name': u'bio.university.edu', 'group_permission': u'a' }, { 'zone_name': u'bio.university.edu', 'group_permission': u'aaaa' }], 'groups': [u'cs', u'bio'], 'reverse_ranges': [{ 'group_permission': u'cname', 'cidr_block': u'192.168.0.0/24' }, { 'group_permission': u'ns', 'cidr_block': u'192.168.0.0/24' }, { 'group_permission': u'ptr', 'cidr_block': u'192.168.0.0/24' }, { 'group_permission': u'soa', 'cidr_block': u'192.168.0.0/24' }, { 'group_permission': u'ptr', 'cidr_block': u'192.168.1.0/24' }] })
def setUp(self): def PickUnusedPort(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, 0)) addr, port = s.getsockname() s.close() return port self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.port = PickUnusedPort() self.server_name = 'https://%s:%s' % (HOST, self.port) self.daemon_thread = DaemonThread(self.config_instance, self.port) self.daemon_thread.daemon = True self.daemon_thread.start() self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.password = '******' time.sleep(1) roster_client_lib.GetCredentials(USERNAME, u'test', credfile=CREDFILE, server_name=self.server_name) self.core_instance.MakeView(u'test_view') self.core_instance.MakeView(u'test_view2') self.core_instance.MakeView(u'test_view3') self.core_instance.MakeZone(u'reverse_zone', u'master', u'1.168.192.in-addr.arpa.', view_name=u'test_view') self.core_instance.MakeZone(u'forward_zone', u'master', u'university.edu.', view_name=u'test_view') self.core_instance.MakeZone(u'forward_zone', u'master', u'university.edu.', view_name=u'test_view3') self.core_instance.MakeZone(u'ipv6_zone', u'master', u'university2.edu.', view_name=u'test_view') self.core_instance.MakeZone( u'ipv6_zone_rev', u'master', u'0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.' '0.0.0.1.0.0.2.ip6.arpa.', view_name=u'test_view') self.core_instance.MakeZone(u'reverse_zone', u'master', u'1.168.192.in-addr.arpa.', view_name=u'test_view2') self.core_instance.MakeRecord( u'soa', u'soa1', u'forward_zone', { u'name_server': u'ns1.university.edu.', u'admin_email': u'admin.university.edu.', u'serial_number': 1, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5 }, view_name=u'test_view') self.core_instance.MakeRecord( u'soa', u'soa1', u'reverse_zone', { u'name_server': u'ns1.university.edu.', u'admin_email': u'admin.university.edu.', u'serial_number': 1, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5 }, view_name=u'test_view') self.core_instance.MakeRecord( u'aaaa', u'host2', u'forward_zone', {u'assignment_ip': u'4321:0000:0001:0002:0003:0004:0567:89ab'}, view_name=u'test_view') self.core_instance.MakeRecord(u'a', u'host3', u'forward_zone', {u'assignment_ip': u'192.168.1.5'}, view_name=u'test_view') self.core_instance.MakeRecord(u'a', u'www.host3', u'forward_zone', {u'assignment_ip': u'192.168.1.5'}, view_name=u'test_view') self.core_instance.MakeRecord( u'ptr', u'4', u'reverse_zone', {u'assignment_host': u'host2.university.edu.'}, view_name=u'test_view')
def setUp(self): self.config_instance = roster_core.Config(CONFIG_FILE) self.config_lib_instance = config_lib.ConfigLib(CONFIG_FILE) self.root_config_dir = self.config_instance.config_file['exporter'][ 'root_config_dir'].rstrip('/') self.root_backup_dir = self.config_instance.config_file['exporter'][ 'backup_dir'].rstrip('/') if (os.path.exists(self.root_backup_dir)): shutil.rmtree(self.root_backup_dir) os.mkdir(self.root_backup_dir) if (os.path.exists(self.root_config_dir)): shutil.rmtree(self.root_config_dir) os.mkdir(self.root_config_dir) self.db_instance = self.config_instance.GetDb() self.db_instance.CreateRosterDatabase() self.data = open(DATA_FILE, 'r').read() self.db_instance.StartTransaction() self.db_instance.cursor.execute(self.data) self.db_instance.EndTransaction() self.db_instance.close() self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.tree_exporter_instance = tree_exporter.BindTreeExport(CONFIG_FILE) self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') self.core_instance.MakeDnsServerSet(u'set1') self.core_instance.MakeView(u'test_view') self.core_instance.MakeDnsServerSetViewAssignments( u'test_view', 1, u'set1') self.core_instance.MakeNamedConfGlobalOption( u'set1', u'include "%s/test_data/rndc.key"; options { pid-file "test_data/named.pid";};\n' 'controls { inet 127.0.0.1 port 5555 allow{localhost;} keys {rndc-key;};};' % (os.getcwd())) # So we can test self.core_instance.MakeACL(u'test_acl', u'127.0.0.1') self.core_instance.MakeViewToACLAssignments(u'test_view', u'set1', u'test_acl', 1) self.core_instance.MakeZone(u'sub.university.lcl', u'master', u'sub.university.lcl.', view_name=u'test_view') soa_args_dict = self.core_instance.GetEmptyRecordArgsDict(u'soa') soa_args_dict[u'refresh_seconds'] = 500 soa_args_dict[u'expiry_seconds'] = 500 soa_args_dict[u'name_server'] = u'ns.sub.university.lcl.' soa_args_dict[u'minimum_seconds'] = 500 soa_args_dict[u'retry_seconds'] = 500 soa_args_dict[u'serial_number'] = 1000 soa_args_dict[u'admin_email'] = u'root.sub.university.lcl.' self.core_instance.MakeRecord(u'soa', u'@', u'sub.university.lcl', soa_args_dict, view_name=u'test_view') if (not os.path.exists(TESTDIR)): os.system('mkdir %s' % TESTDIR)
def setUp(self): self.config_instance = roster_core.Config(file_name=CONFIG_FILE) self.root_config_dir = self.config_instance.config_file['exporter'][ 'root_config_dir'] self.backup_dir = self.config_instance.config_file['exporter'][ 'backup_dir'] self.db_instance = self.config_instance.GetDb() self.db_instance.CreateRosterDatabase() data = open(DATA_FILE, 'r').read() self.db_instance.StartTransaction() self.db_instance.cursor.execute(data) self.db_instance.EndTransaction() self.db_instance.close() self.core_instance = roster_core.Core(USERNAME, self.config_instance) for zone in self.core_instance.ListZones(): self.core_instance.RemoveZone(zone) self.assertEqual(self.core_instance.ListZones(), {}) self.tarfile = '' self.core_instance.MakeDnsServerSet(u'internal_dns') self.core_instance.MakeDnsServerSet(u'external_dns') self.core_instance.MakeDnsServerSet(u'private_dns') self.core_instance.MakeView(u'internal') self.core_instance.MakeView(u'external') self.core_instance.MakeView(u'private') self.core_instance.MakeZone(u'university.edu', u'master', u'university.edu.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'internal') self.core_instance.MakeZone(u'university.edu', u'master', u'university.edu.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'external') self.core_instance.MakeZone(u'university.edu', u'master', u'university.edu.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'private') self.core_instance.MakeZone(u'int.university.edu', u'master', u'university2.edu.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'internal', make_any=False) self.core_instance.MakeZone(u'priv.university.edu', u'master', u'university3.edu.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'private', make_any=False) self.core_instance.MakeZone(u'168.192.in-addr', u'master', u'168.192.in-addr.arpa.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'internal', make_any=False) self.core_instance.MakeZone(u'4.3.2.in-addr', u'master', u'4.3.2.in-addr.arpa.', zone_options=u'#Allow update\nallow-update { none; };\n', view_name=u'external', make_any=False) self.core_instance.MakeZone(u'bio.university.edu', u'slave', u'university4.edu.', zone_options=u'Allow update\nallow-update { any; };\n', view_name=u'external', make_any=False) self.core_instance.MakeDnsServer(u'dns1.university.edu', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServer(u'dns2.university.edu', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServer(u'dns3.university.edu', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServer(u'dns4.university.edu', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServer(u'ns1.university.edu', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServer(u'ns1.int.university.edu', SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServerSetAssignments(u'ns1.university.edu', u'external_dns') self.core_instance.MakeDnsServerSetAssignments(u'ns1.int.university.edu', u'internal_dns') self.core_instance.MakeDnsServerSetAssignments(u'dns1.university.edu', u'internal_dns') self.core_instance.MakeDnsServerSetAssignments(u'dns2.university.edu', u'external_dns') self.core_instance.MakeDnsServerSetAssignments(u'dns3.university.edu', u'external_dns') self.core_instance.MakeDnsServerSetAssignments(u'dns4.university.edu', u'private_dns') self.core_instance.MakeDnsServerSetViewAssignments(u'external', 1, u'internal_dns', view_options=u'recursion no;') self.core_instance.MakeDnsServerSetViewAssignments(u'internal', 2, u'internal_dns', view_options=u'recursion no;') self.core_instance.MakeDnsServerSetViewAssignments(u'external', 1, u'external_dns', view_options=u'recursion no;') self.core_instance.MakeDnsServerSetViewAssignments(u'private', 1, u'private_dns', view_options=u'recursion no;') self.core_instance.MakeRecord(u'soa', u'@', u'168.192.in-addr', {u'name_server': u'ns1.university.edu.', u'admin_email': u'[email protected].', u'serial_number': 20091223, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5}, view_name=u'internal', ttl=3600) self.core_instance.MakeRecord(u'soa', u'@', u'4.3.2.in-addr', {u'name_server': u'ns1.university.edu.', u'admin_email': u'[email protected].', u'serial_number': 20091224, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5}, view_name=u'external', ttl=3600) self.core_instance.MakeRecord(u'soa', u'@', u'university.edu', {u'name_server': u'ns1.university.edu.', u'admin_email': u'[email protected].', u'serial_number': 20091225, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5}, view_name=u'internal', ttl=3600) self.core_instance.MakeRecord(u'soa', u'@', u'university.edu', {u'name_server': u'ns1.university.edu.', u'admin_email': u'[email protected].', u'serial_number': 20091226, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5}, view_name=u'private', ttl=3600) self.core_instance.MakeRecord(u'soa', u'@', u'university.edu', {u'name_server': u'ns1.university.edu.', u'admin_email': u'[email protected].', u'serial_number': 20091227, u'refresh_seconds': 5, u'retry_seconds': 5, u'expiry_seconds': 5, u'minimum_seconds': 5}, view_name=u'external', ttl=3600) # Make Records self.core_instance.MakeRecord(u'mx', u'@', u'university.edu', {u'priority': 1, u'mail_server': u'mail1.university.edu.'}, view_name=u'any', ttl=3600) self.core_instance.MakeRecord(u'mx', u'@', u'university.edu', {u'priority': 1, u'mail_server': u'mail2.university.edu.'}, view_name=u'any', ttl=3600) self.core_instance.MakeRecord(u'a', u'computer1', u'university.edu', {u'assignment_ip': u'1.2.3.5'}, view_name=u'external', ttl=3600) self.core_instance.MakeRecord(u'a', u'computer1', u'university.edu', {u'assignment_ip': u'192.168.1.1'}, view_name=u'internal', ttl=3600) self.core_instance.MakeRecord(u'a', u'computer2', u'university.edu', {u'assignment_ip': u'192.168.1.2'}, view_name=u'internal', ttl=3600) self.core_instance.MakeRecord(u'a', u'computer3', u'university.edu', {u'assignment_ip': u'1.2.3.6'}, view_name=u'external', ttl=3600) self.core_instance.MakeRecord(u'a', u'computer4', u'university.edu', {u'assignment_ip': u'192.168.1.4'}, view_name=u'internal', ttl=3600) self.core_instance.MakeRecord(u'ns', u'@', u'university.edu', {u'name_server': u'ns1.university.edu.'}, view_name=u'any', ttl=3600) self.core_instance.MakeRecord(u'ns', u'@', u'university.edu', {u'name_server': u'ns2.university.edu.'}, view_name=u'any', ttl=3600) self.core_instance.MakeRecord(u'ptr', u'1', u'4.3.2.in-addr', {u'assignment_host': u'computer1.university.edu.'}, view_name=u'external', ttl=3600) self.core_instance.MakeRecord(u'ptr', u'4', u'168.192.in-addr', {u'assignment_host': u'computer4.university.edu.'}, view_name=u'internal', ttl=3600) self.core_instance.MakeACL(u'public', u'192.168.1.4/30') self.core_instance.MakeACL(u'public', u'10.10/32') self.core_instance.MakeACL(u'secret', u'10.10/32') self.core_instance.MakeViewToACLAssignments(u'internal', u'internal_dns', u'secret', 1) self.core_instance.MakeViewToACLAssignments(u'internal', u'internal_dns', u'public', 0) self.core_instance.MakeViewToACLAssignments(u'external', u'internal_dns', u'public', 1) self.core_instance.MakeViewToACLAssignments(u'private', u'private_dns', u'secret', 0) #self.core_instance.MakeNamedConfGlobalOption(u'internal_dns', u'null') self.core_instance.MakeNamedConfGlobalOption(u'internal_dns', u'options {\n\tdirectory "test_data/named/named";\n\trecursion no;\n' '\tmax-cache-size 512M;\n};\n\nlogging {\n\tchannel "security" {\n' '\t\tfile "/var/log/named-security.log" versions 10 size 10m;\n' '\t\tprint-time yes;\n\t};\n\tchannel "query_logging" {\n' '\t\tsyslog local5;\n\t\tseverity info;\n\t};\n' '\tcategory "client" { "null"; };\n' '\tcategory "update-security" { "security"; };\n' '\tcategory "queries" { "query_logging"; };\n};\n\ncontrols {\n' '\tinet * allow { control-hosts; } keys {rndc-key; };\n};\n\n' 'include "/etc/rndc.key";\n') self.core_instance.MakeNamedConfGlobalOption(u'external_dns', u'options {\n\tdirectory "test_data/named/named";\n\trecursion no;\n' '\tmax-cache-size 512M;\n};\n\nlogging {\n\tchannel "security" {\n' '\t\tfile "/var/log/named-security.log" versions 10 size 10m;\n' '\t\tprint-time yes;\n\t};\n\tchannel "query_logging" {\n' '\t\tsyslog local5;\n\t\tseverity info;\n\t};\n' '\tcategory "client" { "null"; };\n' '\tcategory "update-security" { "security"; };\n' '\tcategory "queries" { "query_logging"; };\n};\n\ncontrols {\n' '\tinet * allow { control-hosts; } keys {rndc-key; };\n};\n\n' 'include "/etc/rndc.key";\n') self.core_instance.MakeNamedConfGlobalOption(u'private_dns', u'options {\n\tdirectory "test_data/named/named";\n\trecursion no;\n' '\tmax-cache-size 512M;\n};\n\nlogging {\n\tchannel "security" {\n' '\t\tfile "/var/log/named-security.log" versions 10 size 10m;\n' '\t\tprint-time yes;\n\t};\n\tchannel "query_logging" {\n' '\t\tsyslog local5;\n\t\tseverity info;\n\t};\n' '\tcategory "client" { "null"; };\n' '\tcategory "update-security" { "security"; };\n' '\tcategory "queries" { "query_logging"; };\n};\n\ncontrols {\n' '\tinet * allow { control-hosts; } keys {rndc-key; };\n};\n\n' 'include "/etc/rndc.key";\n') self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') self.core_instance.RemoveZone(u'bio.university.edu')
def setUp(self): def PickUnusedPort(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((TEST_DNS_SERVER, 0)) addr, port = s.getsockname() s.close() return port self.port = PickUnusedPort() self.rndc_port = PickUnusedPort() while (self.rndc_port == self.port): self.rndc_port = PickUnusedPort() if (not os.path.exists(BINDDIR)): os.mkdir(BINDDIR) rndc_key = open(RNDC_KEY, 'w') rndc_key.write(RNDC_KEY_DATA) rndc_key.close() rndc_conf = open(RNDC_CONF, 'w') rndc_conf.write(RNDC_CONF_DATA) rndc_conf.close() fabric_api.env.warn_only = True fabric_state.output['everything'] = False fabric_state.output['warnings'] = False fabric_api.env.host_string = "%s@%s" % (SSH_USER, TEST_DNS_SERVER) self.config_instance = roster_core.Config(file_name=CONFIG_FILE) db_instance = self.config_instance.GetDb() db_instance.CreateRosterDatabase() self.root_config_dir = os.path.expanduser( self.config_instance.config_file['exporter']['root_config_dir']) self.backup_dir = os.path.expanduser( self.config_instance.config_file['exporter']['backup_dir']) self.tree_exporter_instance = tree_exporter.BindTreeExport(CONFIG_FILE) self.lockfile = self.config_instance.config_file['server']['lock_file'] data = open(DATA_FILE, 'r').read() db_instance.StartTransaction() db_instance.cursor.execute(data) db_instance.EndTransaction() db_instance.close() self.db_instance = db_instance self.core_instance = roster_core.Core(USERNAME, self.config_instance) self.core_instance.RemoveZone(u'cs.university.edu') self.core_instance.RemoveZone(u'bio.university.edu') self.core_instance.RemoveZone(u'eas.university.edu') if (not os.path.exists(BINDDIR)): os.mkdir(BINDDIR) if (not os.path.exists('%s/named/' % BINDDIR.rstrip('/'))): os.mkdir('%s/named/' % BINDDIR.rstrip('/')) if (not os.path.exists(TESTDIR)): os.mkdir(TESTDIR) self.core_instance.MakeView(u'test_view') self.core_instance.MakeZone(u'forward_zone', u'master', u'sub.university.lcl.', view_name=u'test_view') self.core_instance.MakeZone(u'reverse_zone', u'master', u'0.168.192.in-addr.arpa.', view_name=u'test_view') self.core_instance.MakeZone(u'reverse_ipv6_zone', u'master', u'8.0.e.f.f.3.ip6.arpa.', view_name=u'test_view') self.assertEqual(self.core_instance.ListRecords(), []) output = os.popen('python %s -f test_data/test_zone.db ' '--view test_view -u %s --config-file %s ' '-z forward_zone' % (ZONE_IMPORTER_EXEC, USERNAME, CONFIG_FILE)) self.assertEqual( output.read(), 'Loading in test_data/test_zone.db\n' '17 records loaded from zone test_data/test_zone.db\n' '17 total records added\n') output.close() output = os.popen('python %s -f test_data/test_reverse_zone.db ' '--view test_view -u %s --config-file %s ' '-z reverse_zone' % (ZONE_IMPORTER_EXEC, USERNAME, CONFIG_FILE)) self.assertEqual( output.read(), 'Loading in test_data/test_reverse_zone.db\n' '6 records loaded from zone ' 'test_data/test_reverse_zone.db\n' '6 total records added\n') output.close() output = os.popen('python %s -f test_data/test_reverse_ipv6_zone.db ' '--view test_view -u %s --config-file %s ' '-z reverse_ipv6_zone' % (ZONE_IMPORTER_EXEC, USERNAME, CONFIG_FILE)) self.assertEqual( output.read(), 'Loading in test_data/test_reverse_ipv6_zone.db\n' '5 records loaded from zone ' 'test_data/test_reverse_ipv6_zone.db\n' '5 total records added\n') output.close() self.core_instance.MakeDnsServer(TEST_DNS_SERVER, SSH_USER, BINDDIR, TESTDIR) self.core_instance.MakeDnsServerSet(u'set1') self.core_instance.MakeDnsServerSetAssignments(TEST_DNS_SERVER, u'set1') self.core_instance.MakeDnsServerSetViewAssignments( u'test_view', 1, u'set1') self.core_instance.MakeNamedConfGlobalOption( u'set1', u'include "%s/rndc.key"; options { pid-file "test_data/named.pid";};\n'\ 'controls { inet 127.0.0.1 port %d allow{localhost;} keys {rndc-key;};};' % (BINDDIR.rstrip('/'), self.rndc_port)) # So we can test self.core_instance.MakeViewToACLAssignments(u'test_view', u'set1', u'any', 1) self.tree_exporter_instance.ExportAllBindTrees() # Copy blank named.conf to start named with shutil.copyfile('test_data/named.blank.conf', os.path.join(BINDDIR, 'named.conf')) named_file_contents = open(os.path.join(BINDDIR, 'named.conf')).read() named_file_contents = named_file_contents.replace( 'RNDC_KEY', '%s/rndc.key' % BINDDIR.rstrip('/')) named_file_contents = named_file_contents.replace( 'NAMED_DIR', '%s/named/' % BINDDIR.rstrip('/')) named_file_contents = named_file_contents.replace( 'NAMED_PID', '%s/test_data/named.pid' % os.getcwd()) named_file_contents = named_file_contents.replace( 'RNDC_PORT', str(self.rndc_port)) named_file_contents = named_file_contents.replace( 'SESSION_KEYFILE', '%s/%s' % (os.getcwd(), str(SESSION_KEYFILE))) named_file_handle = open('%s/named.conf' % BINDDIR, 'w') named_file_handle.write(named_file_contents) named_file_handle.close() # Start named out = fabric_api.local('/usr/sbin/named -p %s -u %s -c %snamed.conf' % (self.port, SSH_USER, BINDDIR), capture=True) time.sleep(2)
def __init__(self, zone_file_name, config_file_name, user_name, view, zone_name): """Sets self.core_instance, self.zone self.domain and self.view. Inputs: zone_file_name: name of zone file to import config_file_name: name of config file to load db info from user_name: username of person running the script view: name of view to import records to zone_name: name of the zone to import records to """ config_instance = roster_core.Config(file_name=config_file_name) self.core_instance = roster_core.Core(user_name, config_instance) self.core_helper_instance = roster_core.CoreHelpers( self.core_instance) zone_file_dir = os.path.dirname(zone_file_name) zone_lines = [] zone_file = open(zone_file_name, 'r') try: for line in zone_file: if( line.startswith('$INCLUDE') ): include_file_name = line.split('$INCLUDE')[1].lstrip().rstrip() if( not include_file_name.startswith('/') ): include_file_name = os.path.join(zone_file_dir, include_file_name) include_lines = [] try: include_file = open(include_file_name, 'r') try: for line in include_file: include_lines.append(line) finally: include_file.close() except IOError: raise IncludeError('Unable to import include file: %s' % include_file_name) zone_lines.extend(include_lines) continue zone_lines.append(line) finally: zone_file.close() self.zone_file_string = unicode('\n'.join(zone_lines)) self.zone_name = zone_name self.view = view zones_dict = self.core_instance.ListZones(zone_name=zone_name) if( zone_name in zones_dict ): zones_dict = zones_dict[zone_name] if( view in zones_dict ): zones_dict = zones_dict[view] self.origin = zones_dict[u'zone_origin'] else: raise errors.InvalidInputError('View %s does not exist.' % view) else: raise errors.InvalidInputError('Zone %s does not exist.' % zone_name) self.all_views = self.core_instance.ListZones(zone_name=zone_name)[ zone_name]