def setUp(self): self.settings = { 'DBHOST': 'localhost', 'RTRUSER': '******', 'RTRKEY': 'keyfile', 'MAPFILE': 'test/mapfile', 'JOBSURL': 'http://localhost:8000', 'POLLINTERVAL': '0.1', 'DNS_BASE': 'jobs.domain.org', 'DNS_PREFIX': 'job', 'DNS_ZONE': 'domain.org', 'DNS_SERVER': 'ns.domain.org', 'DNS_KEYFILE': './kf' } client = MongoClient("localhost") self.db = client["sdn"] self.routes = self.db.routes self.initdb() self.router = router.Router(self.settings) self.jobfile = '/tmp/sqjobs' self.data = { 'user': '******', 'uid': 501, 'end_time': time() + 60, 'jobid': '1234' }
def test_cleanup(self): """ Test the cleanup thread """ # We want the cleanup thread to run in this context # but it is an infitite loop. So let's delay a shtudown. sd2 = "/tmp/shut2" rec = { 'address': '1.2.3.4', 'ip': '10.128.0.1', 'router': 'router', 'last_associated': time(), 'end_time': 0, 'uid': 501, 'user': '******', 'jobid': '1233', 'status': 'used' } self.db.routes2.insert(rec) # We want to shutdown the thread that is started on init with open(sd2, 'w') as f: f.write('1') settings = self.settings.copy() settings['COLLECTION'] = 'routes2' settings['SHUTFILE'] = sd2 rt = router.Router(settings) # Wait for the init thread to shutdown sleep(0.2) # Now let's start our own if os.path.exists(sd2): os.remove(sd2) shut = Process(target=self._shutdown) shut.start() rt.cleanup() shut.terminate() r = self.db.routes2.find_one({'address': '1.2.3.4'}) self.assertEquals(r['status'], 'available') self.db.routes2.remove({}) rv = rt.cleanup() self.assertEquals(-1, rv)
application.config['AUTHMODE'] = 'munge' application.config['ALLOWED'] = [0] application.config['JOBSURL'] = 'http://*****:*****@application.route("/") def hello(): return "/{associate,release}"
def test_db(self): self.routes.remove() with self.assertRaises(OSError): router.Router(self.settings)
def test_notinitalized(self): settings = self.settings.copy() settings['COLLECTION'] = 'routes3' with self.assertRaises(OSError): router.Router(settings)