本文整理汇总了Python中pulp.server.db.connection.initialize函数的典型用法代码示例。如果您正苦于以下问题:Python initialize函数的具体用法?Python initialize怎么用?Python initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了initialize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ssl_is_skipped_if_off
def test_ssl_is_skipped_if_off(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
config.config.set('database', 'ssl', 'false')
connection.initialize()
seeds = config.config.get('database', 'seeds')
max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
mock_mongoengine.connect.assert_called_once_with(seeds, max_pool_size=max_pool_size)
示例2: test_seeds_from_config
def test_seeds_from_config(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
config.config.set('database', 'seeds', 'other_value_for_seeds')
connection.initialize()
max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
mock_mongoengine.connect.assert_called_once_with('other_value_for_seeds',
max_pool_size=max_pool_size)
示例3: main
def main():
"""
Populate ldap server with some test data
"""
print("See populate.log for descriptive output.")
factory.initialize()
connection.initialize()
ldapserv = LDAPConnection(admin='cn=Directory Manager',
password='password',
server='ldap://ldap-server-hostname:389',
tls=False)
ldapserv.connect()
for id in range(1,100):
userid = 'pulpuser%s' % id
lattr = LDAPAttribute()
lattr.setObjectclass('Person')
lattr.setObjectclass('organizationalPerson')
lattr.setObjectclass('inetorgperson')
lattr.setCN(userid)
lattr.setSN(userid)
lattr.setOU('Candlepin')
lattr.setuserId(userid)
lattr.setuserPassword('redhat')
lattr.setDescription('pulp ldap test user')
lattr.setMail('%[email protected]' % userid)
lattr.setDN("uid=%s,dc=rdu,dc=redhat,dc=com" % userid)
attr, dn = lattr.buildBody()
ldapserv.add_users(dn, attrs=attr)
ldapserv.lookup_user("dc=rdu,dc=redhat,dc=com", "pulpuser1")
ldapserv.authenticate_user("dc=rdu,dc=redhat,dc=com", "pulpuser1", "redhat")
ldapserv.disconnect()
示例4: test_ssl_is_configured_with_ssl_certfile
def test_ssl_is_configured_with_ssl_certfile(self, mock_mongoengine, mock_ssl):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
host = 'champs.example.com:27018'
replica_set = ''
connection.initialize()
database = config.config.get('database', 'name')
max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
ssl_cert_reqs = mock_ssl.CERT_NONE
ssl_ca_certs = config.config.get('database', 'ca_path')
# There should be two calls to connect. The first will use the server version to determine
# which write concern is safe to use.
self.assertEqual(mock_mongoengine.connect.call_count, 2)
self.assertEqual(mock_mongoengine.connect.mock_calls[0][1], (database,))
self.assertEqual(
mock_mongoengine.connect.mock_calls[0][2],
{'host': host, 'maxPoolSize': max_pool_size, 'ssl': True,
'ssl_cert_reqs': ssl_cert_reqs, 'ssl_ca_certs': ssl_ca_certs,
'ssl_certfile': 'certfilepath', 'replicaSet': replica_set})
self.assertEqual(mock_mongoengine.connect.mock_calls[4][1], (database,))
self.assertEqual(
mock_mongoengine.connect.mock_calls[4][2],
{'host': host, 'maxPoolSize': max_pool_size, 'ssl': True,
'ssl_cert_reqs': ssl_cert_reqs, 'ssl_ca_certs': ssl_ca_certs,
'ssl_certfile': 'certfilepath', 'replicaSet': replica_set, 'w': 'majority'})
示例5: setup_schedule
def setup_schedule(self):
"""
This loads enabled schedules from the database and adds them to the
"_schedule" dictionary as instances of celery.beat.ScheduleEntry
"""
if not Scheduler._mongo_initialized:
_logger.debug('Initializing Mongo client connection to read celerybeat schedule')
db_connection.initialize()
Scheduler._mongo_initialized = True
_logger.debug(_('loading schedules from app'))
self._schedule = {}
for key, value in self.app.conf.CELERYBEAT_SCHEDULE.iteritems():
self._schedule[key] = beat.ScheduleEntry(**dict(value, name=key))
# include a "0" as the default in case there are no schedules to load
update_timestamps = [0]
_logger.debug(_('loading schedules from DB'))
ignored_db_count = 0
self._loaded_from_db_count = 0
for call in itertools.imap(ScheduledCall.from_db, utils.get_enabled()):
if call.remaining_runs == 0:
_logger.debug(
_('ignoring schedule with 0 remaining runs: %(id)s') % {'id': call.id})
ignored_db_count += 1
else:
self._schedule[call.id] = call.as_schedule_entry()
update_timestamps.append(call.last_updated)
self._loaded_from_db_count += 1
_logger.debug('loaded %(count)d schedules' % {'count': self._loaded_from_db_count})
self._most_recent_timestamp = max(update_timestamps)
示例6: test_initialize_username_and_shadows_password
def test_initialize_username_and_shadows_password(self, mock_mongoengine, mock_log):
"""
Assert that the password and password length are not logged.
"""
mock_mongoengine_instance = mock_mongoengine.connect.return_value
mock_mongoengine_instance.server_info.return_value = {"version":
MONGO_MIN_TEST_VERSION}
connection.initialize()
# There should be two calls to connect. The first will use the server version to determine
# which write concern is safe to use.
self.assertEqual(mock_mongoengine.connect.call_count, 2)
self.assertEqual(mock_mongoengine.connect.mock_calls[0][1], ('nbachamps',))
self.assertEqual(
mock_mongoengine.connect.mock_calls[0][2],
{'username': 'larrybird', 'host': 'champs.example.com:27018', 'password': 'celtics1981',
'maxPoolSize': 10, 'replicaSet': ''})
self.assertEqual(mock_mongoengine.connect.mock_calls[4][1], ('nbachamps',))
self.assertEqual(
mock_mongoengine.connect.mock_calls[4][2],
{'username': 'larrybird', 'host': 'champs.example.com:27018', 'password': 'celtics1981',
'maxPoolSize': 10, 'replicaSet': '', 'w': 1})
expected_calls = [
call('Attempting username and password authentication.'),
call("Connection Arguments: {'username': 'larrybird', 'host': "
"'champs.example.com:27018', 'password': '*****', 'maxPoolSize': 10, "
"'replicaSet': ''}"),
call("Connection Arguments: {'username': 'larrybird', 'replicaSet': '', 'host': "
"'champs.example.com:27018', 'maxPoolSize': 10, 'w': 1, 'password': '*****'}"),
call('Querying the database to validate the connection.')]
mock_log.assert_has_calls(expected_calls)
示例7: test_database_max_pool_size_uses_default
def test_database_max_pool_size_uses_default(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
connection.initialize()
database = config.config.get('database', 'name')
max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
mock_mongoengine.connect.assert_called_once_with(database, host='localhost',
max_pool_size=max_pool_size, port=27017)
示例8: test_multiple_calls_errors
def test_multiple_calls_errors(self, mongoengine):
"""
This test asserts that more than one call to initialize() raises a RuntimeError.
"""
mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
# The first call to initialize should be fine
connection.initialize()
# A second call to initialize() should raise a RuntimeError
self.assertRaises(RuntimeError, connection.initialize)
# The connection should still be initialized
self.assertEqual(connection._CONNECTION, mongoengine.connect.return_value)
self.assertEqual(connection._DATABASE, mongoengine.connection.get_db.return_value)
# Connect should still have been called correctly
name = config.config.get('database', 'name')
host = config.config.get('database', 'seeds')
# There should be two calls to connect. The first will use the server version to determine
# which write concern is safe to use.
self.assertEqual(mongoengine.connect.call_count, 2)
self.assertEqual(mongoengine.connect.mock_calls[0][1], (name,))
self.assertEqual(
mongoengine.connect.mock_calls[0][2],
{'host': host, 'maxPoolSize': 10})
self.assertEqual(mongoengine.connect.mock_calls[4][1], (name,))
self.assertEqual(
mongoengine.connect.mock_calls[4][2],
{'host': host, 'maxPoolSize': 10, 'w': 'majority'})
示例9: test_seeds_invalid
def test_seeds_invalid(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
connection.initialize(seeds='localhost:27017:1234')
max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
database = config.config.get('database', 'name')
mock_mongoengine.connect.assert_called_once_with(database, max_pool_size=max_pool_size,
host='localhost')
示例10: test_initialize_username_and_shadows_password
def test_initialize_username_and_shadows_password(self, mock_mongoengine, mock_log):
"""
Assert that the password and password length are not logged.
"""
mock_mongoengine_instance = mock_mongoengine.connect.return_value
mock_mongoengine_instance.server_info.return_value = {"version":
MONGO_MIN_TEST_VERSION}
config.config.set('database', 'name', 'nbachamps')
config.config.set('database', 'username', 'larrybird')
config.config.set('database', 'password', 'celtics1981')
config.config.set('database', 'seeds', 'champs.example.com:27018')
config.config.set('database', 'replica_set', '')
connection.initialize()
mock_mongoengine.connect.assert_called_once_with(
'nbachamps', username='larrybird', host='champs.example.com:27018',
password='celtics1981', max_pool_size=10, replicaSet='')
expected_calls = [
call('Attempting username and password authentication.'),
call("Connection Arguments: {'username': 'larrybird', 'host': "
"'champs.example.com:27018', 'password': '*****', 'max_pool_size': 10, "
"'replicaSet': ''}"),
call('Querying the database to validate the connection.')]
mock_log.assert_has_calls(expected_calls)
示例11: test_seeds_is_set_from_argument
def test_seeds_is_set_from_argument(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
connection.initialize(seeds='firsthost:1234,secondhost:5678')
max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
database = config.config.get('database', 'name')
mock_mongoengine.connect.assert_called_once_with(database, max_pool_size=max_pool_size,
host='firsthost', port=1234)
示例12: setUp
def setUp(self):
connection.initialize()
self.patch1 = mock.patch('pulp.server.webservices.controllers.decorators.'
'check_preauthenticated')
self.patch2 = mock.patch('pulp.server.webservices.controllers.decorators.'
'is_consumer_authorized')
self.patch3 = mock.patch('pulp.server.webservices.http.resource_path')
self.patch4 = mock.patch('pulp.server.webservices.http.header')
self.patch5 = mock.patch('web.webapi.HTTPError')
self.patch6 = mock.patch('pulp.server.managers.factory.principal_manager')
self.patch7 = mock.patch('pulp.server.managers.factory.user_query_manager')
self.patch8 = mock.patch('pulp.server.webservices.http.uri_path')
self.mock_check_pre_auth = self.patch1.start()
self.mock_check_pre_auth.return_value = 'ws-user'
self.mock_check_auth = self.patch2.start()
self.mock_check_auth.return_value = True
self.mock_http_resource_path = self.patch3.start()
self.patch4.start()
self.patch5.start()
self.patch6.start()
self.mock_user_query_manager = self.patch7.start()
self.mock_user_query_manager.return_value.is_superuser.return_value = False
self.mock_user_query_manager.return_value.is_authorized.return_value = True
self.mock_uri_path = self.patch8.start()
self.mock_uri_path.return_value = "/mock/"
示例13: main
def main():
"""
This is the high level entry method. It does logging if any Exceptions are raised.
"""
if os.getuid() == 0:
print >> sys.stderr, _('This must not be run as root, but as the same user apache runs as.')
return os.EX_USAGE
try:
options = parse_args()
_start_logging()
connection.initialize(max_timeout=1)
# Prompt the user if there are workers that have not timed out
if filter(lambda worker: (UTCDateTimeField().to_python(datetime.now()) -
worker['last_heartbeat']) <
timedelta(seconds=constants.CELERY_TIMEOUT_SECONDS), status.get_workers()):
if not _user_input_continue('There are still running workers, continuing could '
'corrupt your Pulp installation. Are you sure you wish '
'to continue?'):
return os.EX_OK
return _auto_manage_db(options)
except UnperformedMigrationException:
return 1
except DataError, e:
_logger.critical(str(e))
_logger.critical(''.join(traceback.format_exception(*sys.exc_info())))
return os.EX_DATAERR
示例14: test_name_is_set_from_argument
def test_name_is_set_from_argument(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
name = 'name_set_from_argument'
connection.initialize(name=name)
mock_mongoengine.connect.assert_called_once_with(name,
host='localhost',
max_pool_size=10,
port=27017)
示例15: test__DATABASE_uses_default_name
def test__DATABASE_uses_default_name(self, mock_mongoengine):
mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
connection.initialize()
name = config.config.get('database', 'name')
mock_mongoengine.connect.assert_called_once_with(name,
host='localhost',
max_pool_size=10,
port=27017)