diff options
author | Morgan Richomme <morgan.richomme@orange.com> | 2017-10-16 09:22:44 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-10-16 09:22:44 +0000 |
commit | 164ef1c2bf4cc3564b0044801b349f4733f2e7cf (patch) | |
tree | 6bf5adfeda59430895c0cd489dbb98449cdcb665 /utils/test/testapi/update/templates | |
parent | ff169618789d264e1ef28205eac362dddc33f57b (diff) | |
parent | b95e0889ca5a80dc4f697845673d5471727bfc09 (diff) |
Merge changes from topics 'testapi', 'yamllint'
* changes:
delete legacy update code
fix yamllint verify fail
Diffstat (limited to 'utils/test/testapi/update/templates')
-rw-r--r-- | utils/test/testapi/update/templates/__init__.py | 0 | ||||
-rw-r--r-- | utils/test/testapi/update/templates/backup_mongodb.py | 45 | ||||
-rw-r--r-- | utils/test/testapi/update/templates/changes_in_mongodb.py | 51 | ||||
-rw-r--r-- | utils/test/testapi/update/templates/restore_mongodb.py | 38 | ||||
-rwxr-xr-x | utils/test/testapi/update/templates/rm_images.sh | 8 | ||||
-rw-r--r-- | utils/test/testapi/update/templates/rm_olds.sh | 15 | ||||
-rw-r--r-- | utils/test/testapi/update/templates/update_mongodb.py | 90 | ||||
-rw-r--r-- | utils/test/testapi/update/templates/utils.py | 48 |
8 files changed, 0 insertions, 295 deletions
diff --git a/utils/test/testapi/update/templates/__init__.py b/utils/test/testapi/update/templates/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/utils/test/testapi/update/templates/__init__.py +++ /dev/null diff --git a/utils/test/testapi/update/templates/backup_mongodb.py b/utils/test/testapi/update/templates/backup_mongodb.py deleted file mode 100644 index 9c2437764..000000000 --- a/utils/test/testapi/update/templates/backup_mongodb.py +++ /dev/null @@ -1,45 +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 -import datetime -import os - -from utils import execute, main, get_abspath - -parser = argparse.ArgumentParser(description='Backup 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('-o', '--output_dir', - type=str, - required=False, - default='./', - help='Output directory for the backup.') - -parser.add_argument('-d', '--db', - type=str, - required=False, - default='test_results_collection', - help='database for the backup.') - - -def backup(args): - db = args.db - out = get_abspath(args.output_dir) - now = datetime.datetime.now() - out = os.path.join(out, '%s__%s' % (db, now.strftime('%Y_%m_%d_%H%M%S'))) - cmd = ['mongodump', '-o', '%s' % out] - execute(cmd, args) - - -if __name__ == '__main__': - main(backup, parser) diff --git a/utils/test/testapi/update/templates/changes_in_mongodb.py b/utils/test/testapi/update/templates/changes_in_mongodb.py deleted file mode 100644 index 1a4d5a16f..000000000 --- a/utils/test/testapi/update/templates/changes_in_mongodb.py +++ /dev/null @@ -1,51 +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 -# 09/06/2016: change for migration after refactoring -# 16/06/2016: Alignment of test name (JIRA: FUNCTEST-304) -############################################################################## -collections_old2New = { - # 'pod': 'pods', - # 'test_projects': 'projects', - # 'test_testcases': 'testcases', - # 'test_results': 'results' -} - -fields_old2New = { - # 'test_results': [({}, {'creation_date': 'start_date'})] -} - -docs_old2New = { - # 'test_results': [ - # ({'criteria': 'failed'}, {'criteria': 'FAILED'}), - # ({'criteria': 'passed'}, {'criteria': 'PASS'}) - # ] - # 'testcases': [ - # ({'name': 'vPing'}, {'name': 'vping_ssh'}), - # ({'name': 'Tempest'}, {'name': 'tempest_smoke_serial'}), - # ({'name': 'Rally'}, {'name': 'rally_sanity'}), - # ({'name': 'ODL'}, {'name': 'odl'}), - # ({'name': 'vIMS'}, {'name': 'vims'}), - # ({'name': 'ONOS'}, {'name': 'onos'}), - # ({'name': 'vPing_userdata'}, {'name': 'vping_userdata'}), - # ({'name': 'ovno'}, {'name': 'ocl'}) - # ], - # 'results': [ - # ({'case_name': 'vPing'}, {'case_name': 'vping_ssh'}), - # ({'case_name': 'Tempest'}, {'case_name': 'tempest_smoke_serial'}), - # ({'case_name': 'Rally'}, {'case_name': 'rally_sanity'}), - # ({'case_name': 'ODL'}, {'case_name': 'odl'}), - # ({'case_name': 'vIMS'}, {'case_name': 'vims'}), - # ({'case_name': 'ONOS'}, {'case_name': 'onos'}), - # ({'case_name': 'vPing_userdata'}, {'case_name': 'vping_userdata'}), - # ({'case_name': 'ovno'}, {'case_name': 'ocl'}) - # ] - 'results': [ - ({'trust_indicator': 0}, - {'trust_indicator': {'current': 0, 'histories': []}}) - ] -} diff --git a/utils/test/testapi/update/templates/restore_mongodb.py b/utils/test/testapi/update/templates/restore_mongodb.py deleted file mode 100644 index c45a0e621..000000000 --- a/utils/test/testapi/update/templates/restore_mongodb.py +++ /dev/null @@ -1,38 +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 utils import execute, main, get_abspath - -parser = argparse.ArgumentParser(description='Restore MongoDBs') - -parser.add_argument('-u', '--url', - type=str, - required=False, - default='mongodb://127.0.0.1:27017/', - help='Mongo DB URL for Backup') -parser.add_argument('-i', '--input_dir', - type=str, - required=True, - help='Input directory for the Restore.') -parser.add_argument('-d', '--db', - type=str, - required=False, - default='test_results_collection', - help='database name after the restore.') - - -def restore(args): - input_dir = get_abspath(args.input_dir) - cmd = ['mongorestore', '%s' % input_dir] - execute(cmd, args) - - -if __name__ == '__main__': - main(restore, parser) diff --git a/utils/test/testapi/update/templates/rm_images.sh b/utils/test/testapi/update/templates/rm_images.sh deleted file mode 100755 index 6722573b4..000000000 --- a/utils/test/testapi/update/templates/rm_images.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -number=`docker images | awk 'NR != 1' | grep testapi | wc -l` -if [ $number -gt 0 ]; then - images=`docker images -a | awk 'NR != 1' | grep testapi | awk '{print $1}'` - echo "begin to rm images $images" - docker images | awk 'NR != 1' | grep testapi | awk '{print $3}' | xargs docker rmi -f &>/dev/null -fi diff --git a/utils/test/testapi/update/templates/rm_olds.sh b/utils/test/testapi/update/templates/rm_olds.sh deleted file mode 100644 index c6bca1867..000000000 --- a/utils/test/testapi/update/templates/rm_olds.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -proc_number=`ps -ef | grep opnfv-testapi | grep -v grep | wc -l` -if [ $proc_number -gt 0 ]; then - procs=`ps -ef | grep opnfv-testapi | grep -v grep` - echo "begin to kill opnfv-testapi $procs" - ps -ef | grep opnfv-testapi | grep -v grep | awk '{print $2}' | xargs kill -kill &>/dev/null -fi - -number=`docker ps -a | awk 'NR != 1' | grep testapi | wc -l` -if [ $number -gt 0 ]; then - containers=number=`docker ps -a | awk 'NR != 1' | grep testapi` - echo "begin to rm containers $containers" - docker ps -a | awk 'NR != 1' | grep testapi | awk '{print $1}' | xargs docker rm -f &>/dev/null -fi 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) diff --git a/utils/test/testapi/update/templates/utils.py b/utils/test/testapi/update/templates/utils.py deleted file mode 100644 index 4254fee34..000000000 --- a/utils/test/testapi/update/templates/utils.py +++ /dev/null @@ -1,48 +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 os -import urlparse -import subprocess - - -def get_abspath(path): - assert os.path.isdir(path), 'Path %s can\'t be found.' % path - return os.path.abspath(path) - - -def parse_mongodb_url(url): - url = urlparse.urlparse(url) - assert url.scheme == 'mongodb', 'URL must be a MongoDB URL' - return url - - -def url_parse(url): - url = parse_mongodb_url(url) - return url.username, url.password, url.hostname, url.port - - -def execute(cmd, args): - (username, password, hostname, port) = url_parse(args.url) - cmd.extend(['--host', '%s' % hostname, '--port', '%s' % port]) - db = args.db - if db is not None: - cmd.extend(['--db', '%s' % db]) - if username is not None: - cmd.extend(['-u', '%s' % username, '-p', '%s' % password]) - print('execute: %s' % cmd) - execute_output = subprocess.check_output(cmd) - print(execute_output) - - -def main(method, parser): - args = parser.parse_args() - try: - method(args) - except AssertionError as msg: - print(msg) |