def is_run_on_requirement_satisfied(requirement):
    topology_satisfied = True
    req_topologies = requirement.get('topologies')
    if req_topologies:
        topology_satisfied = client_context.is_topology_type(req_topologies)

    min_version_satisfied = True
    req_min_server_version = requirement.get('minServerVersion')
    if req_min_server_version:
        min_version_satisfied = Version.from_string(
            req_min_server_version) <= client_context.version

    max_version_satisfied = True
    req_max_server_version = requirement.get('maxServerVersion')
    if req_max_server_version:
        max_version_satisfied = Version.from_string(
            req_max_server_version) >= client_context.version

    params_satisfied = True
    params = requirement.get('serverParameters')
    if params:
        for param, val in params.items():
            if param not in client_context.server_parameters:
                params_satisfied = False
            elif client_context.server_parameters[param] != val:
                params_satisfied = False

    return (topology_satisfied and min_version_satisfied
            and max_version_satisfied and params_satisfied)
def is_run_on_requirement_satisfied(requirement):
    topology_satisfied = True
    req_topologies = requirement.get('topologies')
    if req_topologies:
        topology_satisfied = client_context.is_topology_type(req_topologies)

    server_version = Version(*client_context.version[:3])

    min_version_satisfied = True
    req_min_server_version = requirement.get('minServerVersion')
    if req_min_server_version:
        min_version_satisfied = Version.from_string(
            req_min_server_version) <= server_version

    max_version_satisfied = True
    req_max_server_version = requirement.get('maxServerVersion')
    if req_max_server_version:
        max_version_satisfied = Version.from_string(
            req_max_server_version) >= server_version

    serverless = requirement.get('serverless')
    if serverless == "require":
        serverless_satisfied = client_context.serverless
    elif serverless == "forbid":
        serverless_satisfied = not client_context.serverless
    else:  # unset or "allow"
        serverless_satisfied = True

    params_satisfied = True
    params = requirement.get('serverParameters')
    if params:
        for param, val in params.items():
            if param not in client_context.server_parameters:
                params_satisfied = False
            elif client_context.server_parameters[param] != val:
                params_satisfied = False

    auth_satisfied = True
    req_auth = requirement.get('auth')
    if req_auth is not None:
        if req_auth:
            auth_satisfied = client_context.auth_enabled
        else:
            auth_satisfied = not client_context.auth_enabled

    return (topology_satisfied and min_version_satisfied
            and max_version_satisfied and serverless_satisfied
            and params_satisfied and auth_satisfied)
def is_run_on_requirement_satisfied(requirement):
    topology_satisfied = True
    req_topologies = requirement.get('topologies')
    if req_topologies:
        topology_satisfied = client_context.is_topology_type(req_topologies)

    min_version_satisfied = True
    req_min_server_version = requirement.get('minServerVersion')
    if req_min_server_version:
        min_version_satisfied = Version.from_string(
            req_min_server_version) <= client_context.version

    max_version_satisfied = True
    req_max_server_version = requirement.get('maxServerVersion')
    if req_max_server_version:
        max_version_satisfied = Version.from_string(
            req_max_server_version) >= client_context.version

    return (topology_satisfied and min_version_satisfied
            and max_version_satisfied)
Esempio n. 4
0
 def valid_topology(run_on_req):
     return client_context.is_topology_type(
         run_on_req.get(
             'topology',
             ['single', 'replicaset', 'sharded', 'load-balanced']))
Esempio n. 5
0
 def valid_topology(run_on_req):
     return client_context.is_topology_type(
         run_on_req.get('topology', ['single', 'replicaset', 'sharded']))
Esempio n. 6
0
    def test_versioned_api_migration(self):
        # SERVER-58785
        if (client_context.is_topology_type(["sharded"])
                and not client_context.version.at_least(5, 0, 2)):
            self.skipTest("This test needs MongoDB 5.0.2 or newer")

        client = rs_client(server_api=ServerApi("1", strict=True))
        client.db.sales.drop()

        # Start Versioned API Example 5
        def strptime(s):
            return datetime.datetime.strptime(s, "%Y-%m-%dT%H:%M:%SZ")

        client.db.sales.insert_many([{
            "_id": 1,
            "item": "abc",
            "price": 10,
            "quantity": 2,
            "date": strptime("2021-01-01T08:00:00Z")
        }, {
            "_id": 2,
            "item": "jkl",
            "price": 20,
            "quantity": 1,
            "date": strptime("2021-02-03T09:00:00Z")
        }, {
            "_id": 3,
            "item": "xyz",
            "price": 5,
            "quantity": 5,
            "date": strptime("2021-02-03T09:05:00Z")
        }, {
            "_id": 4,
            "item": "abc",
            "price": 10,
            "quantity": 10,
            "date": strptime("2021-02-15T08:00:00Z")
        }, {
            "_id": 5,
            "item": "xyz",
            "price": 5,
            "quantity": 10,
            "date": strptime("2021-02-15T09:05:00Z")
        }, {
            "_id": 6,
            "item": "xyz",
            "price": 5,
            "quantity": 5,
            "date": strptime("2021-02-15T12:05:10Z")
        }, {
            "_id": 7,
            "item": "xyz",
            "price": 5,
            "quantity": 10,
            "date": strptime("2021-02-15T14:12:12Z")
        }, {
            "_id": 8,
            "item": "abc",
            "price": 10,
            "quantity": 5,
            "date": strptime("2021-03-16T20:20:13Z")
        }])
        # End Versioned API Example 5

        with self.assertRaisesRegex(
                OperationFailure, "Provided apiStrict:true, but the command "
                "count is not in API Version 1"):
            client.db.command('count', 'sales', query={})
        # Start Versioned API Example 6
        # pymongo.errors.OperationFailure: Provided apiStrict:true, but the command count is not in API Version 1, full error: {'ok': 0.0, 'errmsg': 'Provided apiStrict:true, but the command count is not in API Version 1', 'code': 323, 'codeName': 'APIStrictError'}
        # End Versioned API Example 6

        # Start Versioned API Example 7
        client.db.sales.count_documents({})