summaryrefslogtreecommitdiffstats
path: root/utils/test/testapi/update/templates/update_mongodb.py
diff options
context:
space:
mode:
authorSerenaFeng <feng.xiaowei@zte.com.cn>2017-10-16 15:02:12 +0800
committerSerena Feng <feng.xiaowei@zte.com.cn>2017-10-16 08:13:55 +0000
commitb95e0889ca5a80dc4f697845673d5471727bfc09 (patch)
tree47d69a058b9202ca13bcdf8f2bcef9555cca4e83 /utils/test/testapi/update/templates/update_mongodb.py
parente1d4351f54b649ee9ad94d5b72934362c8a31413 (diff)
delete legacy update code
update directory was employed to update TestAPI before auto deployment is adopted, now it is useless and can be deleted. Change-Id: I4e5ae84e80879cd9f711dc1d02224ae4f5902e49 Signed-off-by: SerenaFeng <feng.xiaowei@zte.com.cn>
Diffstat (limited to 'utils/test/testapi/update/templates/update_mongodb.py')
-rw-r--r--utils/test/testapi/update/templates/update_mongodb.py90
1 files changed, 0 insertions, 90 deletions
diff --git a/utils/test/testapi/update/templates/update_mongodb.py b/utils/test/testapi/update/templates/update_mongodb.py
deleted file mode 100644
index f75959281..000000000
--- a/utils/test/testapi/update/templates/update_mongodb.py
+++ /dev/null
@@ -1,90 +0,0 @@
-##############################################################################
-# Copyright (c) 2016 ZTE Corporation
-# feng.xiaowei@zte.com.cn
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-##############################################################################
-import argparse
-
-from pymongo import MongoClient
-
-from changes_in_mongodb import collections_old2New, \
- fields_old2New, docs_old2New
-from utils import main, parse_mongodb_url
-
-parser = argparse.ArgumentParser(description='Update MongoDBs')
-
-parser.add_argument('-u', '--url',
- type=str,
- required=False,
- default='mongodb://127.0.0.1:27017/',
- help='Mongo DB URL for Backups')
-
-parser.add_argument('-d', '--db',
- type=str,
- required=False,
- default='test_results_collection',
- help='database for the update.')
-
-
-def assert_collections(a_dict):
- if a_dict is not None:
- collections = eval_db('collection_names')
- no_collections = []
- for collection in a_dict.keys():
- if collection not in collections:
- no_collections.append(collection)
- assert len(no_collections) == 0, \
- 'collections {} not exist'.format(no_collections)
-
-
-def rename_collections(a_dict):
- if a_dict is not None:
- for collection, new_name in a_dict.iteritems():
- eval_collection(collection, 'rename', new_name)
-
-
-def rename_fields(a_dict):
- collection_update(a_dict, '$rename')
-
-
-def change_docs(a_dict):
- collection_update(a_dict, '$set')
-
-
-def eval_db(method, *args, **kwargs):
- exec_db = db.__getattribute__(method)
- return exec_db(*args, **kwargs)
-
-
-def eval_collection(collection, method, *args, **kwargs):
- exec_collection = db.__getattr__(collection)
- return exec_collection.__getattribute__(method)(*args, **kwargs)
-
-
-def collection_update(a_dict, operator):
- if a_dict is not None:
- for collection, updates in a_dict.iteritems():
- for (query, doc) in updates:
- doc_dict = {operator: doc}
- eval_collection(collection, 'update', query,
- doc_dict, upsert=False, multi=True)
-
-
-def update(args):
- parse_mongodb_url(args.url)
- client = MongoClient(args.url)
- global db
- db = client[args.db]
- assert_collections(docs_old2New)
- assert_collections(fields_old2New)
- assert_collections(collections_old2New)
- change_docs(docs_old2New)
- rename_fields(fields_old2New)
- rename_collections(collections_old2New)
-
-
-if __name__ == '__main__':
- main(update, parser)