def _delete_logs(self, resources_info: Dict): cloudwatch_logs = CloudWatchLogs(resources_info) log_group_name = cloudwatch_logs.get_log_group_name( resources_info.get('lambda').get('name')) response = cloudwatch_logs.delete_log_group(log_group_name) response_parser.parse_delete_log_response( response, log_group_name, self.scar_info.get('cli_output'))
def test_get_aws_logs(self, boto_session): session = MagicMock(['client']) client = MagicMock(['filter_log_events', 'describe_jobs']) session.client.return_value = client boto_session.return_value = session cwl = CloudWatchLogs({'lambda': {'name': 'fname'}, 'cloudwatch': {'log_stream_name': 'stream', 'request_id': 'reqid'}}) cwl.client.client.filter_log_events.return_value = {'events': [{'message': 'mess', 'timestamp': 'times'}]} cwl.client.client.describe_jobs.return_value = {'jobs': [{'status': 'SUCCEEDED'}]} self.assertEqual(cwl.get_aws_logs(), "Batch job status: SUCCEEDED\nmess")
def test_create_log_group(self, boto_session): session = MagicMock(['client']) client = MagicMock(['create_log_group', 'put_retention_policy']) session.client.return_value = client boto_session.return_value = session cwl = CloudWatchLogs({'lambda': {'name': 'fname', 'tags': {'createdby': 'scar'}}, 'cloudwatch': {'log_retention_policy_in_days': 1}}) cwl.client.client.create_log_group.return_value = "resp" self.assertEqual(cwl.create_log_group(), "resp") res = {'logGroupName': '/aws/lambda/fname', 'tags': {'createdby': 'scar'}} self.assertEqual(cwl.client.client.create_log_group.call_args_list[0][1], res)
def log(self): index = 0 if len(self.aws_resources) > 1: index = _choose_function(self.aws_resources) # We only return the logs of one function each time if index >= 0: logger.info(CloudWatchLogs(self.aws_resources[index]).get_aws_logs())
def _create_log_group(self, resources_info: Dict) -> None: cloudwatch_logs = CloudWatchLogs(resources_info) response = cloudwatch_logs.create_log_group() response_parser.parse_log_group_creation_response( response, cloudwatch_logs.get_log_group_name(), self.scar_info.get('cli_output'))
def cloudwatch_logs(self): cloudwatch_logs = CloudWatchLogs(self.aws_properties) return cloudwatch_logs
def test_get_log_group_name(self): cwl = CloudWatchLogs({'lambda': {'name': 'fname'}}) self.assertEqual(cwl.get_log_group_name(), '/aws/lambda/fname')
def test_init(self): cwl = CloudWatchLogs({}) self.assertEqual(type(cwl.client.client).__name__, "CloudWatchLogs")