def test_pick_master_with_blacklist(self): redis.sadd(MASTER_BLACKLIST_KEY, 'http://jenkins.example.com') builder = self.get_builder() builder.master_urls = [ 'http://jenkins.example.com', 'http://jenkins-2.example.com', ] assert 'http://jenkins-2.example.com' == builder._pick_master('job1')
def post(self): """Adds or removes a master from the blacklist. The post params should include the `master_url` to be added or removed. By default, the master will be added to the blacklist. Set `remove` to be true to remove the master. Responds with the current blacklist and a warning message if it was a noop. """ args = self.parser.parse_args() master = args.master_url remove = args.remove warning = '' if remove: if 0 == redis.srem(MASTER_BLACKLIST_KEY, master): warning = 'The master was already not on the blacklist' else: if 0 == redis.sadd(MASTER_BLACKLIST_KEY, master): warning = 'The master was already on the blacklist' response = dict() blacklist = list(redis.smembers(MASTER_BLACKLIST_KEY)) response['blacklist'] = blacklist if warning: response['warning'] = warning return self.respond(response, serialize=True)
def test_pick_master_with_blacklist(self): redis.sadd(MASTER_BLACKLIST_KEY, "http://jenkins.example.com") builder = self.get_builder() builder.master_urls = ["http://jenkins.example.com", "http://jenkins-2.example.com"] assert "http://jenkins-2.example.com" == builder._pick_master("job1")