Merge "Replaces methods deprecated in pymongo3.0"
This commit is contained in:
commit
ab98a80a57
@ -58,7 +58,7 @@ class Connection(base.Connection):
|
||||
'trait_type': trait.dtype,
|
||||
'trait_value': trait.value})
|
||||
try:
|
||||
self.db.event.insert(
|
||||
self.db.event.insert_one(
|
||||
{'_id': event_model.message_id,
|
||||
'event_type': event_model.event_type,
|
||||
'timestamp': event_model.generated,
|
||||
|
@ -179,13 +179,13 @@ class Connection(pymongo_base.Connection):
|
||||
# for their ENV.
|
||||
resource_id = self._generate_random_str(
|
||||
cfg.CONF.database.db2nosql_resource_id_maxlen)
|
||||
self.db.resource.insert({'_id': resource_id,
|
||||
'no_key': resource_id})
|
||||
self.db.resource.insert_one({'_id': resource_id,
|
||||
'no_key': resource_id})
|
||||
meter_id = str(bson.objectid.ObjectId())
|
||||
timestamp = timeutils.utcnow()
|
||||
self.db.meter.insert({'_id': meter_id,
|
||||
'no_key': meter_id,
|
||||
'timestamp': timestamp})
|
||||
self.db.meter.insert_one({'_id': meter_id,
|
||||
'no_key': meter_id,
|
||||
'timestamp': timestamp})
|
||||
|
||||
self.db.resource.create_index([
|
||||
('user_id', pymongo.ASCENDING),
|
||||
@ -228,7 +228,7 @@ class Connection(pymongo_base.Connection):
|
||||
data = copy.deepcopy(data)
|
||||
data['resource_metadata'] = pymongo_utils.improve_keys(
|
||||
data.pop('resource_metadata'))
|
||||
self.db.resource.update(
|
||||
self.db.resource.update_one(
|
||||
{'_id': data['resource_id']},
|
||||
{'$set': {'project_id': data['project_id'],
|
||||
'user_id': data['user_id'] or 'null',
|
||||
@ -253,7 +253,7 @@ class Connection(pymongo_base.Connection):
|
||||
# automatically.
|
||||
if record.get('_id') is None:
|
||||
record['_id'] = str(bson.objectid.ObjectId())
|
||||
self.db.meter.insert(record)
|
||||
self.db.meter.insert_one(record)
|
||||
|
||||
def get_resources(self, user=None, project=None, source=None,
|
||||
start_timestamp=None, start_timestamp_op=None,
|
||||
|
@ -498,7 +498,7 @@ class Connection(pymongo_base.Connection):
|
||||
data = copy.deepcopy(data)
|
||||
data['resource_metadata'] = pymongo_utils.improve_keys(
|
||||
data.pop('resource_metadata'))
|
||||
resource = self.db.resource.find_and_modify(
|
||||
resource = self.db.resource.find_one_and_update(
|
||||
{'_id': data['resource_id']},
|
||||
{'$set': {'project_id': data['project_id'],
|
||||
'user_id': data['user_id'],
|
||||
@ -515,7 +515,7 @@ class Connection(pymongo_base.Connection):
|
||||
},
|
||||
},
|
||||
upsert=True,
|
||||
new=True,
|
||||
return_document=pymongo.ReturnDocument.AFTER,
|
||||
)
|
||||
|
||||
# only update last sample timestamp if actually later (the usual
|
||||
@ -523,7 +523,7 @@ class Connection(pymongo_base.Connection):
|
||||
last_sample_timestamp = resource.get('last_sample_timestamp')
|
||||
if (last_sample_timestamp is None or
|
||||
last_sample_timestamp <= data['timestamp']):
|
||||
self.db.resource.update(
|
||||
self.db.resource.update_one(
|
||||
{'_id': data['resource_id']},
|
||||
{'$set': {'metadata': data['resource_metadata'],
|
||||
'last_sample_timestamp': data['timestamp']}}
|
||||
@ -537,7 +537,7 @@ class Connection(pymongo_base.Connection):
|
||||
first_sample_timestamp = resource.get('first_sample_timestamp')
|
||||
if (first_sample_timestamp is not None and
|
||||
first_sample_timestamp > data['timestamp']):
|
||||
self.db.resource.update(
|
||||
self.db.resource.update_one(
|
||||
{'_id': data['resource_id']},
|
||||
{'$set': {'first_sample_timestamp': data['timestamp']}}
|
||||
)
|
||||
@ -547,7 +547,7 @@ class Connection(pymongo_base.Connection):
|
||||
# a new key '_id').
|
||||
record = copy.copy(data)
|
||||
record['recorded_at'] = timeutils.utcnow()
|
||||
self.db.meter.insert(record)
|
||||
self.db.meter.insert_one(record)
|
||||
|
||||
def clear_expired_metering_data(self, ttl):
|
||||
"""Clear expired data from the backend storage system.
|
||||
|
@ -253,13 +253,11 @@ class ConnectionPool(object):
|
||||
@staticmethod
|
||||
def _mongo_connect(url):
|
||||
try:
|
||||
if cfg.CONF.database.mongodb_replica_set:
|
||||
client = MongoProxy(
|
||||
pymongo.MongoReplicaSetClient(
|
||||
url,
|
||||
replicaSet=cfg.CONF.database.mongodb_replica_set))
|
||||
else:
|
||||
client = MongoProxy(pymongo.MongoClient(url))
|
||||
client = MongoProxy(
|
||||
pymongo.MongoClient(
|
||||
url, replicaSet=cfg.CONF.database.mongodb_replica_set
|
||||
)
|
||||
)
|
||||
return client
|
||||
except pymongo.errors.ConnectionFailure as e:
|
||||
LOG.warn(_('Unable to connect to the database server: '
|
||||
|
@ -114,10 +114,10 @@ class ConnectionTest(test_base.BaseTestCase):
|
||||
group='database')
|
||||
impl_db2.Connection('db2://user:pwd@localhost:27017/ceilodb2')
|
||||
resource_id = 'wew' * 247 + 'x' * 3
|
||||
conn_mock.ceilodb2.resource.insert.assert_called_with(
|
||||
conn_mock.ceilodb2.resource.insert_one.assert_called_with(
|
||||
{'_id': resource_id,
|
||||
'no_key': resource_id})
|
||||
conn_mock.ceilodb2.meter.insert.assert_called_with(
|
||||
conn_mock.ceilodb2.meter.insert_one.assert_called_with(
|
||||
{'_id': '54b8860d75bfe43b54e84ce7',
|
||||
'no_key': '54b8860d75bfe43b54e84ce7',
|
||||
'timestamp': 'timestamp'})
|
||||
|
Loading…
Reference in New Issue
Block a user