Creates database for test, using various status checks and retry logic for reliability. - Calls helper method to check status of create db task, if possible - Exits on successful response or retry period exceeds time limit
()
| 91 | return os.path.abspath(tempPath) |
| 92 | |
| 93 | def create_test_db(): |
| 94 | """ |
| 95 | Creates database for test, using various status checks and retry logic for reliability. |
| 96 | - Calls helper method to check status of create db task, if possible |
| 97 | - Exits on successful response or retry period exceeds time limit |
| 98 | """ |
| 99 | options = create_mssql_cli_options(database='master') |
| 100 | client = create_mssql_cli_client(options) |
| 101 | |
| 102 | local_machine_name = socket.gethostname().replace( |
| 103 | '-', '_').replace('.', '_') |
| 104 | |
| 105 | test_db_name = u'mssqlcli_testdb_{0}_{1}'.format( |
| 106 | local_machine_name, random_str()) |
| 107 | query_db_create = u"CREATE DATABASE {0};".format(test_db_name) |
| 108 | |
| 109 | try: |
| 110 | for _, _, status, _, is_create_error in client.execute_query(query_db_create): |
| 111 | if _is_client_db_on_cloud(client): |
| 112 | # retry logic is only supported for sql azure |
| 113 | create_db_status, create_db_error = _check_create_db_status(test_db_name, client) |
| 114 | |
| 115 | if create_db_status == 'FAILED': |
| 116 | # break loop to assert db creation failure |
| 117 | raise AssertionError("Database creation failed. Retry logic for SQL " \ |
| 118 | "Azure DB was unsuccessful with the following error: " \ |
| 119 | "\n{}".format(create_db_error)) |
| 120 | |
| 121 | if is_create_error: |
| 122 | # break loop to assert db creation failure |
| 123 | raise AssertionError("Database creation failed: {}".format(status)) |
| 124 | |
| 125 | return test_db_name |
| 126 | |
| 127 | finally: |
| 128 | shutdown(client) |
| 129 | |
| 130 | def _is_client_db_on_cloud(client): |
| 131 | """ |
no test coverage detected