BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:fbdae7e6d805 1 """
borlanic 0:fbdae7e6d805 2 mbed SDK
borlanic 0:fbdae7e6d805 3 Copyright (c) 2011-2014 ARM Limited
borlanic 0:fbdae7e6d805 4
borlanic 0:fbdae7e6d805 5 Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:fbdae7e6d805 6 you may not use this file except in compliance with the License.
borlanic 0:fbdae7e6d805 7 You may obtain a copy of the License at
borlanic 0:fbdae7e6d805 8
borlanic 0:fbdae7e6d805 9 http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:fbdae7e6d805 10
borlanic 0:fbdae7e6d805 11 Unless required by applicable law or agreed to in writing, software
borlanic 0:fbdae7e6d805 12 distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:fbdae7e6d805 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:fbdae7e6d805 14 See the License for the specific language governing permissions and
borlanic 0:fbdae7e6d805 15 limitations under the License.
borlanic 0:fbdae7e6d805 16
borlanic 0:fbdae7e6d805 17 Author: Przemyslaw Wirkus <Przemyslaw.Wirkus@arm.com>
borlanic 0:fbdae7e6d805 18 """
borlanic 0:fbdae7e6d805 19
borlanic 0:fbdae7e6d805 20 import re
borlanic 0:fbdae7e6d805 21 import json
borlanic 0:fbdae7e6d805 22
borlanic 0:fbdae7e6d805 23
borlanic 0:fbdae7e6d805 24 class BaseDBAccess():
borlanic 0:fbdae7e6d805 25 """ Class used to connect with test database and store test results
borlanic 0:fbdae7e6d805 26 """
borlanic 0:fbdae7e6d805 27 def __init__(self):
borlanic 0:fbdae7e6d805 28 self.db_object = None
borlanic 0:fbdae7e6d805 29 self.db_type = None
borlanic 0:fbdae7e6d805 30 # Connection credentials
borlanic 0:fbdae7e6d805 31 self.host = None
borlanic 0:fbdae7e6d805 32 self.user = None
borlanic 0:fbdae7e6d805 33 self.passwd = None
borlanic 0:fbdae7e6d805 34 self.db = None
borlanic 0:fbdae7e6d805 35
borlanic 0:fbdae7e6d805 36 # Test Suite DB scheme (table names)
borlanic 0:fbdae7e6d805 37 self.TABLE_BUILD_ID = 'mtest_build_id'
borlanic 0:fbdae7e6d805 38 self.TABLE_BUILD_ID_STATUS = 'mtest_build_id_status'
borlanic 0:fbdae7e6d805 39 self.TABLE_BUILD_ID_TYPE = 'mtest_build_id_type'
borlanic 0:fbdae7e6d805 40 self.TABLE_TARGET = 'mtest_target'
borlanic 0:fbdae7e6d805 41 self.TABLE_TEST_ENTRY = 'mtest_test_entry'
borlanic 0:fbdae7e6d805 42 self.TABLE_TEST_ID = 'mtest_test_id'
borlanic 0:fbdae7e6d805 43 self.TABLE_TEST_RESULT = 'mtest_test_result'
borlanic 0:fbdae7e6d805 44 self.TABLE_TEST_TYPE = 'mtest_test_type'
borlanic 0:fbdae7e6d805 45 self.TABLE_TOOLCHAIN = 'mtest_toolchain'
borlanic 0:fbdae7e6d805 46 # Build ID status PKs
borlanic 0:fbdae7e6d805 47 self.BUILD_ID_STATUS_STARTED = 1 # Started
borlanic 0:fbdae7e6d805 48 self.BUILD_ID_STATUS_IN_PROGRESS = 2 # In Progress
borlanic 0:fbdae7e6d805 49 self.BUILD_ID_STATUS_COMPLETED = 3 #Completed
borlanic 0:fbdae7e6d805 50 self.BUILD_ID_STATUS_FAILED = 4 # Failed
borlanic 0:fbdae7e6d805 51 # Build ID type PKs
borlanic 0:fbdae7e6d805 52 self.BUILD_ID_TYPE_TEST = 1 # Test
borlanic 0:fbdae7e6d805 53 self.BUILD_ID_TYPE_BUILD_ONLY = 2 # Build Only
borlanic 0:fbdae7e6d805 54
borlanic 0:fbdae7e6d805 55 def get_hostname(self):
borlanic 0:fbdae7e6d805 56 """ Useful when creating build_id in database
borlanic 0:fbdae7e6d805 57 Function returns (hostname, uname) which can be used as (build_id_name, build_id_desc)
borlanic 0:fbdae7e6d805 58 """
borlanic 0:fbdae7e6d805 59 # Get hostname from socket
borlanic 0:fbdae7e6d805 60 import socket
borlanic 0:fbdae7e6d805 61 hostname = socket.gethostbyaddr(socket.gethostname())[0]
borlanic 0:fbdae7e6d805 62 # Get uname from platform resources
borlanic 0:fbdae7e6d805 63 import platform
borlanic 0:fbdae7e6d805 64 uname = json.dumps(platform.uname())
borlanic 0:fbdae7e6d805 65 return (hostname, uname)
borlanic 0:fbdae7e6d805 66
borlanic 0:fbdae7e6d805 67 def get_db_type(self):
borlanic 0:fbdae7e6d805 68 """ Returns database type. E.g. 'mysql', 'sqlLite' etc.
borlanic 0:fbdae7e6d805 69 """
borlanic 0:fbdae7e6d805 70 return self.db_type
borlanic 0:fbdae7e6d805 71
borlanic 0:fbdae7e6d805 72 def detect_database(self, verbose=False):
borlanic 0:fbdae7e6d805 73 """ detect database and return VERION data structure or string (verbose=True)
borlanic 0:fbdae7e6d805 74 """
borlanic 0:fbdae7e6d805 75 return None
borlanic 0:fbdae7e6d805 76
borlanic 0:fbdae7e6d805 77 def parse_db_connection_string(self, str):
borlanic 0:fbdae7e6d805 78 """ Parsing SQL DB connection string. String should contain:
borlanic 0:fbdae7e6d805 79 - DB Name, user name, password, URL (DB host), name
borlanic 0:fbdae7e6d805 80 Function should return tuple with parsed (db_type, username, password, host, db_name) or None if error
borlanic 0:fbdae7e6d805 81
borlanic 0:fbdae7e6d805 82 (db_type, username, password, host, db_name) = self.parse_db_connection_string(db_url)
borlanic 0:fbdae7e6d805 83
borlanic 0:fbdae7e6d805 84 E.g. connection string: 'mysql://username:password@127.0.0.1/db_name'
borlanic 0:fbdae7e6d805 85 """
borlanic 0:fbdae7e6d805 86 result = None
borlanic 0:fbdae7e6d805 87 if type(str) == type(''):
borlanic 0:fbdae7e6d805 88 PATTERN = '^([\w]+)://([\w]+):([\w]*)@(.*)/([\w]+)'
borlanic 0:fbdae7e6d805 89 result = re.match(PATTERN, str)
borlanic 0:fbdae7e6d805 90 if result is not None:
borlanic 0:fbdae7e6d805 91 result = result.groups() # Tuple (db_name, host, user, passwd, db)
borlanic 0:fbdae7e6d805 92 return result # (db_type, username, password, host, db_name)
borlanic 0:fbdae7e6d805 93
borlanic 0:fbdae7e6d805 94 def is_connected(self):
borlanic 0:fbdae7e6d805 95 """ Returns True if we are connected to database
borlanic 0:fbdae7e6d805 96 """
borlanic 0:fbdae7e6d805 97 pass
borlanic 0:fbdae7e6d805 98
borlanic 0:fbdae7e6d805 99 def connect(self, host, user, passwd, db):
borlanic 0:fbdae7e6d805 100 """ Connects to DB and returns DB object
borlanic 0:fbdae7e6d805 101 """
borlanic 0:fbdae7e6d805 102 pass
borlanic 0:fbdae7e6d805 103
borlanic 0:fbdae7e6d805 104 def connect_url(self, db_url):
borlanic 0:fbdae7e6d805 105 """ Connects to database using db_url (database url parsing),
borlanic 0:fbdae7e6d805 106 store host, username, password, db_name
borlanic 0:fbdae7e6d805 107 """
borlanic 0:fbdae7e6d805 108 pass
borlanic 0:fbdae7e6d805 109
borlanic 0:fbdae7e6d805 110 def reconnect(self):
borlanic 0:fbdae7e6d805 111 """ Reconnects to DB and returns DB object using stored host name,
borlanic 0:fbdae7e6d805 112 database name and credentials (user name and password)
borlanic 0:fbdae7e6d805 113 """
borlanic 0:fbdae7e6d805 114 pass
borlanic 0:fbdae7e6d805 115
borlanic 0:fbdae7e6d805 116 def disconnect(self):
borlanic 0:fbdae7e6d805 117 """ Close DB connection
borlanic 0:fbdae7e6d805 118 """
borlanic 0:fbdae7e6d805 119 pass
borlanic 0:fbdae7e6d805 120
borlanic 0:fbdae7e6d805 121 def escape_string(self, str):
borlanic 0:fbdae7e6d805 122 """ Escapes string so it can be put in SQL query between quotes
borlanic 0:fbdae7e6d805 123 """
borlanic 0:fbdae7e6d805 124 pass
borlanic 0:fbdae7e6d805 125
borlanic 0:fbdae7e6d805 126 def select_all(self, query):
borlanic 0:fbdae7e6d805 127 """ Execute SELECT query and get all results
borlanic 0:fbdae7e6d805 128 """
borlanic 0:fbdae7e6d805 129 pass
borlanic 0:fbdae7e6d805 130
borlanic 0:fbdae7e6d805 131 def insert(self, query, commit=True):
borlanic 0:fbdae7e6d805 132 """ Execute INSERT query, define if you want to commit
borlanic 0:fbdae7e6d805 133 """
borlanic 0:fbdae7e6d805 134 pass
borlanic 0:fbdae7e6d805 135
borlanic 0:fbdae7e6d805 136 def get_next_build_id(self, name, desc='', location='', type=None, status=None):
borlanic 0:fbdae7e6d805 137 """ Insert new build_id (DB unique build like ID number to send all test results)
borlanic 0:fbdae7e6d805 138 """
borlanic 0:fbdae7e6d805 139 pass
borlanic 0:fbdae7e6d805 140
borlanic 0:fbdae7e6d805 141 def get_table_entry_pk(self, table, column, value, update_db=True):
borlanic 0:fbdae7e6d805 142 """ Checks for entries in tables with two columns (<TABLE_NAME>_pk, <column>)
borlanic 0:fbdae7e6d805 143 If update_db is True updates table entry if value in specified column doesn't exist
borlanic 0:fbdae7e6d805 144 """
borlanic 0:fbdae7e6d805 145 pass
borlanic 0:fbdae7e6d805 146
borlanic 0:fbdae7e6d805 147 def update_table_entry(self, table, column, value):
borlanic 0:fbdae7e6d805 148 """ Updates table entry if value in specified column doesn't exist
borlanic 0:fbdae7e6d805 149 Locks table to perform atomic read + update
borlanic 0:fbdae7e6d805 150 """
borlanic 0:fbdae7e6d805 151 pass
borlanic 0:fbdae7e6d805 152
borlanic 0:fbdae7e6d805 153 def update_build_id_info(self, build_id, **kw):
borlanic 0:fbdae7e6d805 154 """ Update additional data inside build_id table
borlanic 0:fbdae7e6d805 155 Examples:
borlanic 0:fbdae7e6d805 156 db.update_build_is(build_id, _status_fk=self.BUILD_ID_STATUS_COMPLETED, _shuffle_seed=0.0123456789):
borlanic 0:fbdae7e6d805 157 """
borlanic 0:fbdae7e6d805 158 pass
borlanic 0:fbdae7e6d805 159
borlanic 0:fbdae7e6d805 160 def insert_test_entry(self, build_id, target, toolchain, test_type, test_id, test_result, test_time, test_timeout, test_loop, test_extra=''):
borlanic 0:fbdae7e6d805 161 """ Inserts test result entry to database. All checks regarding existing
borlanic 0:fbdae7e6d805 162 toolchain names in DB are performed.
borlanic 0:fbdae7e6d805 163 If some data is missing DB will be updated
borlanic 0:fbdae7e6d805 164 """
borlanic 0:fbdae7e6d805 165 pass