def test_utils_trace_method_outer_decorator_with_functools(self): mock_log = mock.Mock() mock_log.isEnabledFor = lambda x: True self.mock_object(utils.logging, 'getLogger', mock_log) mock_log = self.mock_object(utils, 'LOG') def _test_decorator(f): @functools.wraps(f) def wraps(*args, **kwargs): return f(*args, **kwargs) return wraps @utils.trace_method @_test_decorator def _trace_test_method(*args, **kwargs): return 'OK' utils.setup_tracing(['method']) result = _trace_test_method() self.assertEqual('OK', result) self.assertEqual(2, mock_log.debug.call_count) # Ensure the incorrect function name was logged for call in mock_log.debug.call_args_list: self.assertTrue('_trace_test_method' in str(call)) self.assertFalse('wraps' in str(call))
def __init__(self, *args, **kwargs): super(DateraDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(d_opts) self.username = self.configuration.san_login self.password = self.configuration.san_password self.cluster_stats = {} self.datera_api_token = None self.interval = self.configuration.datera_503_interval self.retry_attempts = (self.configuration.datera_503_timeout / self.interval) self.driver_prefix = str(uuid.uuid4())[:4] self.datera_debug = self.configuration.datera_debug self.datera_api_versions = [] if self.datera_debug: utils.setup_tracing(['method']) self.tenant_id = self.configuration.datera_tenant_id if self.tenant_id and self.tenant_id.lower() == 'none': self.tenant_id = None self.api_check = time.time() self.api_cache = [] self.api_timeout = 0 self.do_profile = not self.configuration.datera_disable_profiler self.thread_local = threading.local() backend_name = self.configuration.safe_get('volume_backend_name') self.backend_name = backend_name or 'Datera' datc.register_driver(self)
def test_utils_trace_method_outer_decorator(self): mock_logging = self.mock_object(utils, 'logging') mock_log = mock.Mock() mock_log.isEnabledFor = lambda x: True mock_logging.getLogger = mock.Mock(return_value=mock_log) def _test_decorator(f): def blah(*args, **kwargs): return f(*args, **kwargs) return blah @utils.trace_method @_test_decorator def _trace_test_method(*args, **kwargs): return 'OK' utils.setup_tracing(['method']) result = _trace_test_method(self) self.assertEqual('OK', result) self.assertEqual(2, mock_log.debug.call_count) # Ensure the incorrect function name was logged for call in mock_log.debug.call_args_list: self.assertFalse('_trace_test_method' in str(call)) self.assertTrue('blah' in str(call))
def __init__(self, *args, **kwargs): super(DateraDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(d_opts) self.username = self.configuration.san_login self.password = self.configuration.san_password self.cluster_stats = {} self.datera_api_token = None self.interval = self.configuration.datera_503_interval self.retry_attempts = (self.configuration.datera_503_timeout / self.interval) self.driver_prefix = str(uuid.uuid4())[:4] self.datera_debug = self.configuration.datera_debug self.datera_api_versions = [] if self.datera_debug: utils.setup_tracing(['method']) self.tenant_id = self.configuration.datera_tenant_id if self.tenant_id and self.tenant_id.lower() == 'none': self.tenant_id = None self.api_check = time.time() self.api_cache = [] self.api_timeout = 0 self.do_profile = not self.configuration.datera_disable_profiler self.thread_local = threading.local() backend_name = self.configuration.safe_get( 'volume_backend_name') self.backend_name = backend_name or 'Datera' datc.register_driver(self)
def test_utils_setup_tracing_valid_and_invalid_key(self): self.mock_object(utils, 'LOG') utils.setup_tracing(['method', 'fake']) self.assertFalse(utils.TRACE_API) self.assertTrue(utils.TRACE_METHOD) self.assertEqual(1, utils.LOG.warning.call_count)
def test_utils_trace_api(self): self.mock_object(utils, 'LOG') @utils.trace_api def _trace_test_api(*args, **kwargs): return 'OK' utils.setup_tracing(['api']) result = _trace_test_api() self.assertEqual('OK', result) self.assertEqual(2, utils.LOG.debug.call_count)
def test_utils_trace_method_default_logger(self): mock_log = self.mock_object(utils, 'LOG') @utils.trace_method def _trace_test_method_custom_logger(*args, **kwargs): return 'OK' utils.setup_tracing(['method']) result = _trace_test_method_custom_logger() self.assertEqual('OK', result) self.assertEqual(2, mock_log.debug.call_count)
def test_trace_no_tracing(self): self.mock_object(utils, 'LOG') @utils.trace_method def _trace_test_method(*args, **kwargs): return 'OK' utils.setup_tracing(None) result = _trace_test_method() self.assertEqual('OK', result) self.assertEqual(0, utils.LOG.debug.call_count)
def __init__(self, context, db_driver=None): # Ensure we have room for offset headers chunk_size = CONF.backup_datera_chunk_size * units.Gi - TOTAL_OFFSET # We don't care about chunks any smaller than our normal chunk size sha_size = chunk_size container_name = "replace-me" super(DateraBackupDriver, self).__init__(context, chunk_size, sha_size, container_name, db_driver) self.ctxt = context self.db_driver = db_driver self.support_force_delete = True self._backup = None self.san_ip = CONF.backup_datera_san_ip self.username = CONF.backup_datera_san_login self.password = CONF.backup_datera_san_password self.api_port = CONF.backup_datera_api_port self.driver_use_ssl = CONF.backup_driver_use_ssl self.driver_client_cert = CONF.backup_driver_client_cert self.driver_client_cert_key = CONF.backup_driver_client_cert_key self.replica_count = CONF.backup_datera_replica_count self.placement_mode = CONF.backup_datera_placement_mode self.driver_strs = CONF.backup_datera_secondary_backup_drivers self.driver = None self.drivers = {} self.type = 'datera' self.cluster_stats = {} self.datera_api_token = None self.interval = CONF.backup_datera_503_interval self.retry_attempts = (CONF.backup_datera_503_timeout / self.interval) self.driver_prefix = str(uuid.uuid4())[:4] self.datera_debug = CONF.backup_datera_debug self.datera_api_versions = [] if self.datera_debug: utils.setup_tracing(['method']) self.tenant_id = CONF.backup_datera_tenant_id if self.tenant_id and self.tenant_id.lower() == 'none': self.tenant_id = None self.api_check = time.time() self.api_cache = [] self.api_timeout = 0 self.do_profile = not CONF.backup_datera_disable_profiler self.thread_local = threading.local() self.thread_local.trace_id = "" self._populate_secondary_drivers() datc.register_driver(self) self._check_options()
def test_utils_trace_method_with_exception(self): self.LOG = self.mock_object(utils, 'LOG') @utils.trace_method def _trace_test_method(*args, **kwargs): raise exception.APITimeout('test message') utils.setup_tracing(['method']) self.assertRaises(exception.APITimeout, _trace_test_method) exception_log = self.LOG.debug.call_args_list[1] self.assertTrue('exception' in str(exception_log)) self.assertTrue('test message' in str(exception_log))
def __init__(self, *args, **kwargs): super(DateraDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(d_opts) self.username = self.configuration.san_login self.password = self.configuration.san_password self.cluster_stats = {} self.datera_api_token = None self.interval = self.configuration.datera_503_interval self.retry_attempts = (self.configuration.datera_503_timeout / self.interval) self.driver_prefix = str(uuid.uuid4())[:4] self.datera_debug = self.configuration.datera_debug if self.datera_debug: utils.setup_tracing(['method'])
def __init__(self, *args, **kwargs): super(DateraDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(d_opts) self.username = self.configuration.san_login self.password = self.configuration.san_password self.ldap = self.configuration.datera_ldap_server self.cluster_stats = {} self.datera_api_token = None self.interval = self.configuration.datera_503_interval self.retry_attempts = (self.configuration.datera_503_timeout / self.interval) self.driver_prefix = str(uuid.uuid4())[:4] self.datera_debug = self.configuration.datera_debug if self.datera_debug: utils.setup_tracing(['method']) self.tenant_id = self.configuration.datera_tenant_id if self.tenant_id is None: self.tenant_id = '' self.defaults = self.configuration.datera_volume_type_defaults if self.tenant_id and self.tenant_id.lower() == 'none': self.tenant_id = None self.template_override = ( not self.configuration.datera_disable_template_override) self.api_check = time.time() self.api_cache = [] self.api_timeout = 0 self.do_profile = not self.configuration.datera_disable_profiler self.do_metadata = ( not self.configuration.datera_disable_extended_metadata) self.image_cache = self.configuration.datera_enable_image_cache self.image_type = self.configuration.datera_image_cache_volume_type_id self.thread_local = threading.local() # pylint: disable=no-member self.datera_version = None self.apiv = None self.api = None self.filterf = self.get_filter_function() self.goodnessf = self.get_goodness_function() self.use_chap_auth = self.configuration.use_chap_auth self.chap_username = self.configuration.chap_username self.chap_password = self.configuration.chap_password backend_name = self.configuration.safe_get('volume_backend_name') self.backend_name = backend_name or 'Datera' datc.register_driver(self)
def test_utils_trace_wrapper_class(self): mock_logging = self.mock_object(utils, 'logging') mock_log = mock.Mock() mock_log.isEnabledFor = lambda x: True mock_logging.getLogger = mock.Mock(return_value=mock_log) utils.setup_tracing(['method']) @six.add_metaclass(utils.TraceWrapperMetaclass) class MyClass(object): def trace_test_method(self): return 'OK' test_class = MyClass() result = test_class.trace_test_method() self.assertEqual('OK', result) self.assertEqual(2, mock_log.debug.call_count)
def test_utils_trace_method_with_time(self): mock_logging = self.mock_object(utils, 'logging') mock_log = mock.Mock() mock_log.isEnabledFor = lambda x: True mock_logging.getLogger = mock.Mock(return_value=mock_log) mock_time = mock.Mock(side_effect=[3.1, 6]) self.mock_object(time, 'time', mock_time) @utils.trace_method def _trace_test_method(*args, **kwargs): return 'OK' utils.setup_tracing(['method']) result = _trace_test_method(self) self.assertEqual('OK', result) return_log = mock_log.debug.call_args_list[1] self.assertTrue('2900' in str(return_log))
def __init__(self, *args, **kwargs): super(DateraDriver, self).__init__(*args, **kwargs) self.configuration.append_config_values(d_opts) self.username = self.configuration.san_login self.password = self.configuration.san_password self.cluster_stats = {} self.datera_api_token = None self.interval = self.configuration.datera_503_interval self.retry_attempts = (self.configuration.datera_503_timeout / self.interval) self.driver_prefix = str(uuid.uuid4())[:4] self.datera_debug = self.configuration.datera_debug self.datera_api_versions = [] if self.datera_debug: utils.setup_tracing(['method']) self.tenant_id = self.configuration.datera_tenant_id if self.tenant_id and self.tenant_id.lower() == 'none': self.tenant_id = None self.api_check = time.time() self.api_cache = []
def test_utils_setup_tracing(self): self.mock_object(utils, 'LOG') utils.setup_tracing(None) self.assertFalse(utils.TRACE_API) self.assertFalse(utils.TRACE_METHOD) self.assertEqual(0, utils.LOG.warning.call_count) utils.setup_tracing(['method']) self.assertFalse(utils.TRACE_API) self.assertTrue(utils.TRACE_METHOD) self.assertEqual(0, utils.LOG.warning.call_count) utils.setup_tracing(['method', 'api']) self.assertTrue(utils.TRACE_API) self.assertTrue(utils.TRACE_METHOD) self.assertEqual(0, utils.LOG.warning.call_count)