def set_access_token_provider(config, tenant_id): if is_cloudsim(): authorization_provider = NoSecurityAccessTokenProvider(tenant_id) elif is_dev_pod() or is_minicloud(): authorization_provider = KeystoreAccessTokenProvider().set_tenant( tenant_id) elif is_prod_pod(): if credentials_file is None: raise IllegalArgumentException( 'Must specify the credentials file path.') creds_provider = PropertiesCredentialsProvider().set_properties_file( credentials_file) authorization_provider = DefaultAccessTokenProvider( idcs_url=idcs_url(), entitlement_id=entitlement_id, creds_provider=creds_provider, timeout_ms=timeout) elif is_onprem(): if user_name is None and password is None: authorization_provider = StoreAccessTokenProvider() else: if user_name is None or password is None: raise IllegalArgumentException( 'Please set both the user_name and password.') authorization_provider = StoreAccessTokenProvider( user_name, password) else: raise IllegalArgumentException('Please set the test server.') config.set_authorization_provider(authorization_provider)
def delete_tenant(tenant_id): if is_minicloud(): tenant_url = sc_nd_tenant_base + tenant_id response = delete(tenant_url, data=None) # allow 404 -- not found -- in this path if (response.status_code != codes.ok and response.status_code != codes.not_found): raise IllegalStateException('Delete tenant failed.')
def delete_tier(): if is_minicloud(): tier_url = sc_tier_base + tier_name response = delete(tier_url, data=None) # allow 404 -- not found -- in this path if (response.status_code != codes.ok and response.status_code != codes.not_found): raise IllegalStateException('Delete tier failed.')
def testGetTableNormal(self): self.get_table_request.set_table_name(table_name) result = self.handle.get_table(self.get_table_request) if is_minicloud() or is_pod(): self.check_table_result(result, State.ACTIVE, table_limits) else: self.check_table_result(result, State.ACTIVE, table_limits, has_operation_id=False)
def _check_table_result(self, result, state, table_limits=None, has_schema=True, check_limit=True): # TODO: For minicloud, the SC module doesn't return operation id for # now. This affects drop table as well as create/drop index. When the SC # is changed to return the operation id, the test need to be changed. if is_minicloud(): self.check_table_result(result, state, table_limits, has_schema, False, check_limit) else: self.check_table_result(result, state, table_limits, has_schema, check_limit=check_limit)
def add_tier(): if is_minicloud(): tier_url = sc_tier_base + tier_name limits = {"version": 1, "numTables": 10, "tenantSize": 5000, "tenantReadUnits": 100000, "tenantWriteUnits": 40000, "tableSize": 5000, "tableReadUnits": 40000, "tableWriteUnits": 20000, "indexesPerTable": 5, "columnsPerTable": 20, "ddlRequestsRate": 400, "tableLimitReductionsRate": 4, "schemaEvolutions": 6} response = post(tier_url, json=limits) if response.status_code != codes.ok: raise IllegalStateException('Add tier failed.')
def _wait_for_completion(self, result): # TODO: For minicloud, the SC module doesn't return operation id for # now. In TableResult.wait_for_completion, it check if the operation id # is none, if none, raise IllegalArgumentException, at the moment we # should ignore this exception in minicloud testing. This affects drop # table as well as create/drop index. When the SC is changed to return # the operation id, the test need to be changed. if is_minicloud(): result.wait_for_state(self.handle, [State.ACTIVE, State.DROPPED], wait_timeout, 1000, result=result) else: result.wait_for_completion(self.handle, wait_timeout, 1000)
def testGetTableWithOperationId(self): drop_request = TableRequest().set_statement('DROP TABLE IF EXISTS ' + table_name) table_result = self.handle.table_request(drop_request) self.get_table_request.set_table_name(table_name).set_operation_id( table_result.get_operation_id()) result = self.handle.get_table(self.get_table_request) if is_minicloud() or is_pod(): self.check_table_result(result, [State.DROPPING, State.DROPPED], table_limits) else: self.check_table_result(result, [State.DROPPING, State.DROPPED]) table_result.wait_for_completion(self.handle, wait_timeout, 1000)
def _check_list_tables_result(self, names, last_returned_index, eq=False): for handle in range(self.num_handles): result = self.handles[handle].list_tables(self.list_tables_request) if is_minicloud(): # TODO: Minicloud doesn't handle start index and limit so far, # and the last index returned is always 0. self.assertEqual(result.get_tables(), table_names[handle]) self.assertEqual(result.get_last_returned_index(), 0) elif is_onprem() and not eq: self.assertGreater(set(result.get_tables()), set(names[handle])) self.assertGreater(result.get_last_returned_index(), last_returned_index[handle]) else: self.assertEqual(result.get_tables(), names[handle]) self.assertEqual(result.get_last_returned_index(), last_returned_index[handle])
def testGetTableWithOperationId(self): drop_request = TableRequest().set_statement('DROP TABLE IF EXISTS ' + table_name) table_result = self.handle.table_request(drop_request) self.get_table_request.set_table_name(table_name).set_operation_id( table_result.get_operation_id()) result = self.handle.get_table(self.get_table_request) # TODO: A difference between old cloud proxy and new cloud proxy, during # DROPPING phase, the table limit is not none for old proxy but none for # new proxy. self.check_table_result(result, State.DROPPING, check_limit=False) if is_minicloud(): table_result.wait_for_state(self.handle, [State.ACTIVE, State.DROPPED], wait_timeout, 1000, result=table_result) else: table_result.wait_for_completion(self.handle, wait_timeout, 1000)
def generate_authorization_provider(tenant_id): if is_cloudsim(): authorization_provider = InsecureAuthorizationProvider(tenant_id) elif is_dev_pod() or is_minicloud(): authorization_provider = TestSignatureProvider(tenant_id) elif is_prod_pod(): if iam_principal() == 'user principal': if credentials_file is None: raise IllegalArgumentException( 'Must specify the credentials file path.') authorization_provider = SignatureProvider( config_file=credentials_file) elif iam_principal() == 'instance principal': if isinstance(endpoint, str): region = Regions.from_region_id(endpoint) else: region = endpoint if region is None: authorization_provider = ( SignatureProvider.create_with_instance_principal()) else: authorization_provider = ( SignatureProvider.create_with_instance_principal( region=region)) elif iam_principal() == 'resource principals': authorization_provider = ( SignatureProvider.create_with_resource_principal()) else: raise IllegalArgumentException('Must specify the principal.') elif is_onprem(): if user_name is None and password is None: authorization_provider = StoreAccessTokenProvider() else: if user_name is None or password is None: raise IllegalArgumentException( 'Please set both the user_name and password.') authorization_provider = StoreAccessTokenProvider( user_name, password) else: raise IllegalArgumentException('Please set the test server.') return authorization_provider
def setUpClass(cls): cls.set_up_class() global table_names, index_names, num_indexes, index_fields table_names = list() num_tables = 2 index_names = list() num_indexes = 1 index_fields = list() for index in range(2): index_fields.append(list()) index_fields[0].append('fld_double') index_fields[1].append('fld_str') for table in range(num_tables): tb_name = table_name + str(table) table_names.append(tb_name) create_statement = ('CREATE TABLE ' + tb_name + '(fld_id INTEGER, \ fld_long LONG, fld_float FLOAT, fld_double DOUBLE, fld_bool BOOLEAN, \ fld_str STRING, fld_bin BINARY, fld_time TIMESTAMP(0), fld_num NUMBER, \ fld_json JSON, fld_arr ARRAY(STRING), fld_map MAP(STRING), \ fld_rec RECORD(fld_id LONG, fld_bool BOOLEAN, fld_str STRING), \ PRIMARY KEY(fld_id)) USING TTL 2 DAYS') limits = TableLimits(50, 50, 1) create_request = TableRequest().set_statement( create_statement).set_table_limits(limits) cls.table_request(create_request) index_names.append(list()) for index in range(table + num_indexes): idx_name = index_name + str(index) index_names[table].append(idx_name) create_index_statement = ('CREATE INDEX ' + idx_name + ' ON ' + tb_name + '(' + ','.join(index_fields[index]) + ')') create_index_request = TableRequest().set_statement( create_index_statement) cls.table_request(create_index_request) if is_minicloud(): index_names[table].reverse()
def table_request(cls, request, test_handle=None): test_handle = cls.handle if test_handle is None else test_handle # # Optionally delay to handle the 4 DDL ops/minute limit # in the real service # if is_pod(): sleep(20) # TODO: For minicloud, the SC module doesn't return operation id for # now. In TableResult.wait_for_completion, it check if the operation id # is none, if none, raise IllegalArgumentException, at the moment we # should ignore this exception in minicloud testing. This affects drop # table as well as create/drop index. When the SC is changed to return # the operation id, the test need to be changed. if is_minicloud(): result = test_handle.table_request(request) TableResult.wait_for_state(test_handle, [State.ACTIVE, State.DROPPED], wait_timeout, 1000, result=result) else: test_handle.do_table_request(request, wait_timeout, 1000)
def add_tenant(tenant_id): if is_minicloud(): tenant_url = sc_nd_tenant_base + tenant_id + '/' + tier_name response = post(tenant_url) if response.status_code != codes.ok: raise IllegalStateException('Add tenant failed.')