def finalize(): global clients, filesToSeed, baseDirectory, sis_url, tracker global list_of_conditions conf = TestbedConfiguration() conf.set_test_name("Test constructed from external declaration") conf.set_base_directory(baseDirectory) for fileId in filesToSeed.keys(): conf.add_file(fileId, filesToSeed[fileId][0]) for client in clients.values(): c = conf.add_client(client['id']) c.set_base_directory(baseDirectory) c.set_port(client['port']) c.set_uprate(client['uprate']) c.set_downrate(client['downrate']) c.set_sis_url(sis_url) c.set_neighbour_selection_mode(client['neighbour']) c.set_peer_selection_mode(client['peer']) if 'seeding' not in client.keys(): client['seeding'] = [] if 'leeching' not in client.keys(): client['leeching'] = [] for fileId in client['seeding']: c.add_file_to_seed(fileId) for fileId in client['leeching']: c.add_file_to_leech(fileId) t = conf.add_tracker() t.set_base_directory(baseDirectory) t.set_uprate(tracker['uprate']) t.set_downrate(tracker['downrate']) tracker_url = "http://localhost:%i/announce" % tracker['port'] t.set_url(tracker_url) for condition in list_of_conditions: conf.add_condition(condition) ok, errors, warnings = TestbedConfigurationChecker.is_consistent(conf) for warning in warnings: logging.info("WARNING: %s" % warning) if not(ok): logger = logging.getLogger() logger.info("TestbedConfiguration is not consistent.") for error in errors: logging.info("ERROR: %s" % error) sys.exit() dir(conf) return conf
def testConfWithNonExistingFile(self): baseDirectory = "test" + os.path.normcase('/') + "user" file = "AFJASLDFJASDLGKFSJADFLS.sajdFASJFASLDFJASDLFSAD" conf = TestbedConfiguration(baseDirectory) # the setting of the base directory must propagate to all # subsequent clients and the tracker conf.set_test_name("Simple test") conf.set_timeout(20) # add the files that you want to distribute within the test environment # this should produce a warning! conf.add_file(1, file) conf.add_file(2, file) conf.add_file(3, file) # specify a tracker tracker = conf.add_tracker() # specify a leecher client1 = conf.add_client(1) client1.set_port(10000) client1.set_uprate(64) client1.set_downrate(64) client1.add_file_to_leech(1) # specify a seeder client2 = conf.add_client(2) client2.set_port(10002) client2.set_uprate(64) client2.set_downrate(64) client2.add_file_to_seed(1) # add some conditions the testbed shall check on conf.add_condition(IsLeechingCondition(1)) conf.add_condition(IsSeedingCondition(2)) ok, errors, warnings = TestbedConfigurationChecker.is_consistent(conf) self.assertFalse(ok) self.assertEquals(3, len(errors))
def testConfWithNonExistingFile(self): baseDirectory = "test" + os.path.normcase("/") + "user" file = "AFJASLDFJASDLGKFSJADFLS.sajdFASJFASLDFJASDLFSAD" conf = TestbedConfiguration(baseDirectory) # the setting of the base directory must propagate to all # subsequent clients and the tracker conf.set_test_name("Simple test") conf.set_timeout(20) # add the files that you want to distribute within the test environment # this should produce a warning! conf.add_file(1, file) conf.add_file(2, file) conf.add_file(3, file) # specify a tracker tracker = conf.add_tracker() # specify a leecher client1 = conf.add_client(1) client1.set_port(10000) client1.set_uprate(64) client1.set_downrate(64) client1.add_file_to_leech(1) # specify a seeder client2 = conf.add_client(2) client2.set_port(10002) client2.set_uprate(64) client2.set_downrate(64) client2.add_file_to_seed(1) # add some conditions the testbed shall check on conf.add_condition(IsLeechingCondition(1)) conf.add_condition(IsSeedingCondition(2)) ok, errors, warnings = TestbedConfigurationChecker.is_consistent(conf) self.assertFalse(ok) self.assertEquals(3, len(errors))
def testCorrectConfigurationWillNotFail(self): baseDirectory = "test" + os.path.normcase('/') + "user" file = self._TMP_TEST_FILE conf = TestbedConfiguration(baseDirectory) # the setting of the base directory must propagate to all # subsequent clients and the tracker conf.set_test_name("Simple test") conf.set_timeout(20) # add the files that you want to distribute within the test environment conf.add_file(1, file) # specify a tracker tracker = conf.add_tracker() # specify a leecher client1 = conf.add_client(1) client1.set_port(10000) client1.set_uprate(64) client1.set_downrate(64) client1.add_file_to_leech(1) # specify a seeder client2 = conf.add_client(2) client2.set_port(10002) client2.set_uprate(64) client2.set_downrate(64) client2.add_file_to_seed(1) # add some conditions the testbed shall check on conf.add_condition(IsLeechingCondition(1)) conf.add_condition(IsSeedingCondition(2)) ok, errors, warnings = TestbedConfigurationChecker.is_consistent(conf) self.assertTrue(ok) self.assertEquals(0, len(errors))
def testCorrectConfigurationWillNotFail(self): baseDirectory = "test" + os.path.normcase("/") + "user" file = self._TMP_TEST_FILE conf = TestbedConfiguration(baseDirectory) # the setting of the base directory must propagate to all # subsequent clients and the tracker conf.set_test_name("Simple test") conf.set_timeout(20) # add the files that you want to distribute within the test environment conf.add_file(1, file) # specify a tracker tracker = conf.add_tracker() # specify a leecher client1 = conf.add_client(1) client1.set_port(10000) client1.set_uprate(64) client1.set_downrate(64) client1.add_file_to_leech(1) # specify a seeder client2 = conf.add_client(2) client2.set_port(10002) client2.set_uprate(64) client2.set_downrate(64) client2.add_file_to_seed(1) # add some conditions the testbed shall check on conf.add_condition(IsLeechingCondition(1)) conf.add_condition(IsSeedingCondition(2)) ok, errors, warnings = TestbedConfigurationChecker.is_consistent(conf) self.assertTrue(ok) self.assertEquals(0, len(errors))