def test_track_custom_event_failures(self, mock_redis): fake_redis = FakeRedis() fake_redis.set('custom_event_type', '["Random Event Log", "Failure"]') # Create and initialize Salt Nanny salt_nanny = SaltNanny(self.cache_config) salt_nanny.cache_client.redis_instance = fake_redis salt_nanny.min_interval = 1 return_code = salt_nanny.track_custom_event_failures('custom_event_type', ['Failure'], 2) self.assertTrue(return_code > 0)
def test_track_custom_event_failures(self, mock_redis): fake_redis = FakeRedis() fake_redis.set('custom_event_type', '["Random Event Log", "Failure"]') # Create and initialize Salt Nanny salt_nanny = SaltNanny(self.cache_config) salt_nanny.cache_client.redis_instance = fake_redis salt_nanny.min_interval = 1 return_code = salt_nanny.track_custom_event_failures( 'custom_event_type', ['Failure'], 2) self.assertTrue(return_code > 0)
def test_job_added_with_next_id(): database = FakeRedis() database.set('last_job_id', 42) queue = JobQueue(database) queue.add_job('http://a.b.c') assert queue.get_num_jobs() == 1 job = queue.get_job() assert job['job_id'] == 43 assert job['url'] == 'http://a.b.c'
def setUp(self): self.session = Session(region_name='us-west-1') pill = placebo.attach(self.session, 'tests/sit/test_data') pill.playback() redis_client = FakeRedis() jid = 123456 redis_client.lpush('test-1-php:state.highstate', jid) redis_client.lpush('test-1-lb:state.highstate', jid) redis_client.set('test-1-php:{0}'.format(jid), '{"result": "false","return": {"test": "true"}}') redis_client.set('test-1-lb:{0}'.format(jid), '{"result": "false","return": {"test": "true"}}') self.redis_client = RedisClient() self.redis_client.redis_instance = redis_client
def setUp(self): self.session = Session(region_name='us-west-1') pill = placebo.attach(self.session, 'tests/sit/test_data') pill.playback() redis_client = FakeRedis() jid = 123456 redis_client.lpush('test-1-php:state.highstate', jid) redis_client.lpush('test-1-lb:state.highstate', jid) redis_client.set('test-1-php:{0}'.format(jid), '{"result": "false","return": {"test": "true"}}') redis_client.set('test-1-lb:{0}'.format(jid), '{"result": "false","return": {"test": "true"}}') self.redis_client = RedisClient() self.redis_client.redis_instance = redis_client
def test_parse_last_return(self, mock_redis): fake_redis = FakeRedis() # Create and initialize Salt Nanny salt_nanny = SaltNanny(self.cache_config) salt_nanny.cache_client.redis_instance = fake_redis salt_nanny.initialize(['minion1']) salt_nanny.min_interval = 1 with open('{0}/resources/highstate.json'.format(os.path.dirname(__file__)), 'r') as f: json = f.read() # Make Redis Returns available in fake redis fake_redis.set('minion1:state.highstate', '6789') fake_redis.set('minion1:6789', json) self.assertTrue(salt_nanny.parse_last_return() > 0)
def test_track_returns(self, mock_redis): fake_redis = FakeRedis() # Create and initialize Salt Nanny salt_nanny = SaltNanny(self.cache_config) salt_nanny.cache_client.redis_instance = fake_redis salt_nanny.initialize(['minion1', 'minion2']) salt_nanny.min_interval = 1 # Make Redis Returns available in fake redis fake_redis.set('minion1:state.highstate', '1234') fake_redis.set('minion2:state.highstate', '4321') fake_redis.hset('ret:1234', 'minion1', 'Highstate Result1') fake_redis.hset('ret:1234', 'minion2', 'Highstate Result1') # Start tracking returns salt_nanny.track_returns()
def test_track_returns(self, mock_redis): fake_redis = FakeRedis() # Create and initialize Salt Nanny salt_nanny = SaltNanny(self.cache_config) salt_nanny.cache_client.redis_instance = fake_redis salt_nanny.initialize(['minion1', 'minion2']) salt_nanny.min_interval = 1 # Make Redis Returns available in fake redis fake_redis.set('minion1:state.highstate', '1234') fake_redis.set('minion2:state.highstate', '4321') fake_redis.hset('ret:1234', 'minion1', 'Highstate Result1') fake_redis.hset('ret:1234', 'minion2', 'Highstate Result1') # Start tracking returns salt_nanny.track_returns()
def test_parse_last_return(self, mock_redis): fake_redis = FakeRedis() # Create and initialize Salt Nanny salt_nanny = SaltNanny(self.cache_config) salt_nanny.cache_client.redis_instance = fake_redis salt_nanny.initialize(['minion1']) salt_nanny.min_interval = 1 with open( '{0}/resources/highstate.json'.format( os.path.dirname(__file__)), 'r') as f: json = f.read() # Make Redis Returns available in fake redis fake_redis.set('minion1:state.highstate', '6789') fake_redis.set('minion1:6789', json) self.assertTrue(salt_nanny.parse_last_return() > 0)
def setup_fakeredis(self): redis_client = FakeRedis() jid = 123456 redis_client.lpush('php:state.highstate', jid) redis_client.set('php:{0}'.format(jid), '{"result": false}') self.redis_client.redis_instance = redis_client
def setup_fakeredis(self): redis_client = FakeRedis() jid = 123456 redis_client.lpush('php:state.highstate', jid) redis_client.set('php:{0}'.format(jid), '{"result": false}') self.redis_client.redis_instance = redis_client