def test_audit_readonly(self): expect_same, expect_new, expect_changed, expect_unused = ( self.prepare_audit_scenario()) manager = self.service.descriptor_manager options = stackdriver_service.normalize_options({}) audit = manager.audit_descriptors(options) self.assertEquals(expect_new.keys(), audit.new_descriptors.keys()) self.assertEquals(expect_new, audit.new_descriptors) self.assertEquals(expect_changed.keys(), audit.changed_descriptors.keys()) self.assertEquals(expect_changed, audit.changed_descriptors) self.assertEquals(expect_unused.keys(), audit.unused_descriptors.keys()) self.assertEquals(expect_unused, audit.unused_descriptors) self.assertEquals(0, audit.num_fixed_issues) self.assertEquals(set(expect_same.keys()), audit.unchanged_descriptor_names) self.assertEquals(2, audit.missing_count) self.assertEquals(0, audit.created_count) self.assertEquals(1, audit.outdated_count) self.assertEquals(0, audit.updated_count) self.assertEquals(1, audit.obsoleted_count) self.assertEquals(0, audit.deleted_count) self.assertEquals(4, audit.num_unresolved_issues) self.assertEquals(4, audit.warnings) self.assertEquals(0, audit.errors) self.assertEquals(0, self.mockStub.projects.list.call_count) self.assertEquals(1, self.mockMetricDescriptors.list.call_count) self.assertEquals(0, self.mockMetricDescriptors.get.call_count) self.assertEquals(0, self.mockMetricDescriptors.delete.call_count) self.assertEquals(0, self.mockMetricDescriptors.create.call_count)
def process_commandline_request(self, options): """Implements CommandHandler.""" options = stackdriver_service.normalize_options(options) if not options.get('manage_stackdriver_descriptors'): options['manage_stackdriver_descriptors'] = 'create' stackdriver = stackdriver_service.make_service(options) manager = stackdriver_descriptors.MetricDescriptorManager( stackdriver, ResponseProcessor(options)) audit_results = manager.audit_descriptors( options, service_list=self.SERVICE_LIST) message = audit_results_to_output( audit_results, 'Metric_filters are not configured, or are empty.') self.output(options, message) if audit_results.errors: raise ValueError('Encountered %d errors' % audit_results.errors)
def test_audit_create_failure(self): expect_same, expect_new, expect_changed, expect_unused = ( self.prepare_audit_scenario()) # This delete is part of an update self.mockMetricDescriptors.create.side_effect = HttpError( ResponseStatus(400, 'Injected Error'), 'Injected Error') self.mockDeleteDescriptor.execute.return_value = {} manager = self.service.descriptor_manager options = stackdriver_service.normalize_options( {'manage_stackdriver_descriptors': 'create'}) audit = manager.audit_descriptors(options) self.assertEquals(expect_new.keys(), audit.new_descriptors.keys()) self.assertEquals(expect_new, audit.new_descriptors) self.assertEquals(expect_changed.keys(), audit.changed_descriptors.keys()) self.assertEquals(expect_changed, audit.changed_descriptors) self.assertEquals(expect_unused.keys(), audit.unused_descriptors.keys()) self.assertEquals(expect_unused, audit.unused_descriptors) self.assertEquals(0, audit.num_fixed_issues) self.assertEquals(set(expect_same.keys()), audit.unchanged_descriptor_names) self.assertEquals(2, audit.missing_count) self.assertEquals(0, audit.created_count) self.assertEquals(1, audit.outdated_count) self.assertEquals(0, audit.updated_count) self.assertEquals(1, audit.obsoleted_count) self.assertEquals(0, audit.deleted_count) self.assertEquals(4, audit.num_unresolved_issues) self.assertEquals(1, audit.warnings) # delete self.assertEquals(3, audit.errors) self.assertEquals(0, self.mockStub.projects.list.call_count) self.assertEquals(1, self.mockMetricDescriptors.list.call_count) self.assertEquals(0, self.mockMetricDescriptors.get.call_count) self.assertEquals(1, self.mockMetricDescriptors.delete.call_count) self.assertEquals(3, self.mockMetricDescriptors.create.call_count)