def run_step(self, pipeline_data): client = redis.get_client() cluster_name = pipeline_data[data_defs.APPLICATION_CLUSTER] application_name = pipeline_data[data_defs.APPLICATION_NAME] key = f'{cluster_name}.{application_name}' redis.execute_json_delete(client, key) return pipeline_data
def run_step(self, pipeline_data): redis_client = redis.get_client() cache_key = get_cache_key(pipeline_data) cache_entry = redis.execute_json_get(redis_client, cache_key) self.log.debug('Got cache entry "%s"', cache_entry) pipeline_data[data_defs.CACHE_ENTRY] = cache_entry return pipeline_data
def run_step(self, pipeline_data): redis_client = redis.get_client() image_versions = self.generate_image_versions(pipeline_data) cache_entry = self.generate_cache_entry(pipeline_data, image_versions) cache_key = get_cache_key(pipeline_data) redis.execute_json_set(redis_client, cache_key, cache_entry) self.log.debug('Wrote cache entry "%s" for key "%s"', cache_entry, cache_key) return pipeline_data
def test_2_delete_entire_cache(self): client = redis.get_client() redis.execute_json_set(client, 'test.Key.1', {'value': 'testValue'}) redis.execute_json_set(client, 'test.Key.2', {'value': 'testValue'}) redis.delete_entire_cache() # Allow the cache to be flushed time.sleep(0.5) self.assertIsNone(redis.execute_json_get(client, 'test.Key.1')) self.assertIsNone(redis.execute_json_get(client, 'test.Key.2'))
def test_1_get_set_delete(self): client = redis.get_client() redis.execute_json_set(client, 'test.Key', {'value': 'testValue'}) # Allow the object to be written time.sleep(0.5) result = redis.execute_json_get(client, 'test.Key') self.assertEqual(result, {'value': 'testValue'}) redis.execute_json_delete(client, 'test.Key') # Allow the object to be deleted time.sleep(0.5) result = redis.execute_json_get(client, 'test.Key') self.assertIsNone(result)
def get_status(mgt_res_grp): logger = logging.getLogger(__name__) logger.info('Returning status') redis_client = redis.get_client() cache_size = redis.get_management_key_count(redis_client, mgt_res_grp) sync_thread = thread.get_sync_thread() if not sync_thread: running = False else: running = sync_thread.stopped() status = {'sync_thread_running': running, 'cache_size': cache_size} return jsonify(status)
def test_5_key_count(self): client = redis.get_client() redis.delete_entire_cache() redis.execute_json_set( client, 'dev-ev/repos/deploy/tamarack/stage/docker-stack.yml', {'value': '1'}) redis.execute_json_set( client, 'everest-management/repos/deploy/tamarack-test/test', {'value': '2'}) redis.execute_json_set( client, 'everest-management/repos/deploy/tamarack-test2/test', {'value': '3'}) key_count = redis.get_management_key_count(client, 'dev-ev') self.assertEqual(key_count, 1) key_count = redis.get_management_key_count(client, 'everest-management') self.assertEqual(key_count, 2)
def test_3_clear_cache_for_cluster_and_app(self): client = redis.get_client() redis.delete_entire_cache() time.sleep(0.5) mgt_res_grp = 'everest-management' redis.execute_json_set( client, f'{mgt_res_grp}/repos/deploy/tamarack/stage/docker-stack.yml', {'value': '1'}) redis.execute_json_set(client, f'{mgt_res_grp}/repos/deploy/tamarack/active', {'value': '2'}) redis.execute_json_set( client, f'{mgt_res_grp}/repos/deploy/kth-azure-app/active', {'value': '3'}) redis.execute_json_set( client, f'error/{mgt_res_grp}/repos/deploy/kth-azure-app/stage', {'value': '4'}) time.sleep(0.5) keys = redis.get_all_keys(client) self.assertEqual(len(keys), 4) redis.clear_cache_for_cluster_and_app(client, 'everest-management', 'stage', 'tamarack') keys = redis.get_all_keys(client) self.assertEqual(len(keys), 3) self.assertTrue(f'{mgt_res_grp}/repos/deploy/tamarack/active' in keys) self.assertTrue( f'{mgt_res_grp}/repos/deploy/kth-azure-app/active' in keys) self.assertTrue( f'error/{mgt_res_grp}/repos/deploy/kth-azure-app/stage' in keys) redis.clear_cache_for_cluster_and_app(client, 'everest-management', 'active', 'kth-azure-app') keys = redis.get_all_keys(client) self.assertEqual(len(keys), 2) self.assertTrue( f'error/{mgt_res_grp}/repos/deploy/kth-azure-app/stage' in keys) self.assertTrue(f'{mgt_res_grp}/repos/deploy/tamarack/active' in keys)
def test_4_clear_cache_for_cluster(self): client = redis.get_client() redis.delete_entire_cache() time.sleep(0.5) mgt_res_grp = 'dev-ev' redis.execute_json_set( client, f'{mgt_res_grp}/repos/deploy/tamarack/stage/docker-stack.yml', {'value': '1'}) redis.execute_json_set( client, f'{mgt_res_grp}/repos/deploy/tamarack-test/test', {'value': '2'}) redis.execute_json_set( client, f'error/{mgt_res_grp}/repos/deploy/tamarack-test/test', {'value': '2'}) redis.execute_json_set( client, f'{mgt_res_grp}/repos/deploy/tamarack-test/active', {'value': '3'}) time.sleep(0.5) redis.clear_cache_for_cluster(client, 'dev-ev', 'test') keys = redis.get_all_keys(client) self.assertEqual(len(keys), 3) self.assertTrue( f'{mgt_res_grp}/repos/deploy/tamarack/stage/docker-stack.yml' in keys) self.assertTrue( f'error/{mgt_res_grp}/repos/deploy/tamarack-test/test' in keys) self.assertTrue( f'{mgt_res_grp}/repos/deploy/tamarack-test/active' in keys) redis.clear_cache_for_cluster(client, 'dev-ev', 'stage') keys = redis.get_all_keys(client) self.assertEqual(len(keys), 2) self.assertTrue( f'error/{mgt_res_grp}/repos/deploy/tamarack-test/test' in keys) self.assertTrue( f'{mgt_res_grp}/repos/deploy/tamarack-test/active' in keys)
def get_error_cache(error_cache_key): if not error_cache_key: return None redis_client = redis.get_client() return redis.execute_json_get(redis_client, error_cache_key)
def write_to_error_cache(error: exceptions.DeploymentError): pipeline_data = error.pipeline_data cache_key = get_cache_key(pipeline_data) cache_entry = create_cache_entry(error.step_name) redis_client = redis.get_client() redis.execute_json_set(redis_client, cache_key, cache_entry)
def test_0_get_client(self): client = redis.get_client() self.assertIsNotNone(client)