Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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