• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python connection.initialize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulp.server.db.connection.initialize函数的典型用法代码示例。如果您正苦于以下问题:Python initialize函数的具体用法?Python initialize怎么用?Python initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了initialize函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:VuokkoVuorinnen,项目名称:pulp,代码行数:7,代码来源:test_connection.py


示例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)
开发者ID:VuokkoVuorinnen,项目名称:pulp,代码行数:7,代码来源:test_connection.py


示例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()
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:32,代码来源:populate_users.py


示例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'})
开发者ID:alanoe,项目名称:pulp,代码行数:26,代码来源:test_connection.py


示例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)
开发者ID:hjensas,项目名称:pulp,代码行数:33,代码来源:scheduler.py


示例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)
开发者ID:alanoe,项目名称:pulp,代码行数:32,代码来源:test_connection.py


示例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)
开发者ID:beav,项目名称:pulp,代码行数:7,代码来源:test_connection.py


示例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'})
开发者ID:alanoe,项目名称:pulp,代码行数:28,代码来源:test_connection.py


示例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')
开发者ID:hgschmie,项目名称:pulp,代码行数:7,代码来源:test_connection.py


示例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)
开发者ID:ktdreyer,项目名称:pulp,代码行数:25,代码来源:test_connection.py


示例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)
开发者ID:hgschmie,项目名称:pulp,代码行数:7,代码来源:test_connection.py


示例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/"
开发者ID:signull,项目名称:pulp,代码行数:26,代码来源:base.py


示例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
开发者ID:seandst,项目名称:pulp,代码行数:27,代码来源:manage.py


示例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)
开发者ID:beav,项目名称:pulp,代码行数:8,代码来源:test_connection.py


示例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)
开发者ID:beav,项目名称:pulp,代码行数:8,代码来源:test_connection.py


示例16: test_database_replica_set_from_config

 def test_database_replica_set_from_config(self, mock_mongoengine):
     mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}
     config.config.set('database', 'replica_set', 'real_replica_set')
     connection.initialize()
     database = config.config.get('database', 'seeds')
     max_pool_size = connection._DEFAULT_MAX_POOL_SIZE
     mock_mongoengine.connect.assert_called_once_with(database, max_pool_size=max_pool_size,
                                                      replicaset='real_replica_set')
开发者ID:VuokkoVuorinnen,项目名称:pulp,代码行数:8,代码来源:test_connection.py


示例17: test_retry_uses_itertools_chain_and_repeat

    def test_retry_uses_itertools_chain_and_repeat(self, mock_itertools, mock_mongoengine):
        mock_mongoengine.connect.return_value.server_info.return_value = {'version': '2.6.0'}

        connection.initialize()

        mock_itertools.repeat.assert_called_once_with(32)
        mock_itertools.chain.assert_called_once_with([1, 2, 4, 8, 16],
                                                     mock_itertools.repeat.return_value)
开发者ID:alanoe,项目名称:pulp,代码行数:8,代码来源:test_connection.py


示例18: test_initialize_username_no_password

 def test_initialize_username_no_password(self, mock_mongoengine):
     mock_mongoengine_instance = mock_mongoengine.connect.return_value
     mock_mongoengine_instance.server_info.return_value = {"version":
                                                           connection.MONGO_MINIMUM_VERSION}
     config.config.set('database', 'username', 'admin')
     config.config.set('database', 'password', '')
     # ensure no exception is raised (redmine #708)
     connection.initialize()
开发者ID:hgschmie,项目名称:pulp,代码行数:8,代码来源:test_connection.py


示例19: test_initialize_no_username_or_password

 def test_initialize_no_username_or_password(self, mock_mongoengine):
     mock_mongoengine_instance = mock_mongoengine.connect.return_value
     mock_mongoengine_instance.server_info.return_value = {"version":
                                                           connection.MONGO_MINIMUM_VERSION}
     config.config.set('database', 'username', '')
     config.config.set('database', 'password', '')
     connection.initialize()
     self.assertFalse(connection._DATABASE.authenticate.called)
开发者ID:hgschmie,项目名称:pulp,代码行数:8,代码来源:test_connection.py


示例20: start_database_connection

def start_database_connection():
    """
    Start the database connection, if it is not already established.
    """
    # It's important to only call this once during the process
    if not connection._CONNECTION:
        _load_test_config()
        connection.initialize()
开发者ID:maxamillion,项目名称:pulp,代码行数:8,代码来源:base.py



注:本文中的pulp.server.db.connection.initialize函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python manage.main函数代码示例发布时间:2022-05-25
下一篇:
Python connection.get_database函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap