Skip to content

Commit

Permalink
changed behaviour of add_test_package_product to work with new fucnti…
Browse files Browse the repository at this point in the history
…onality of add_product
  • Loading branch information
feyruzb committed Sep 2, 2024
1 parent 3b34e82 commit 043bd88
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 25 deletions.
36 changes: 21 additions & 15 deletions web/server/codechecker_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,35 +915,41 @@ def add_product(self, orm_product, init_db=False):

self.__products[prod.endpoint] = prod

def get_if_database_in_use(self, product_connection_string):
def get_if_database_in_use(self, product):
"""
Returns the product endpoint if the given database is in use
"""
# get the database name from the product connection string
to_add = product_connection_string.database
is_sqlite = False
if product.database.endswith('.sqlite'):
to_add = product.database.replace('////', '/')
is_sqlite = True
else:
to_add = f"@{product.host}:{product.port}/{product.database}"

LOG.info("The database string that will be added: %s", to_add)

# if str(product_connection_string.engine) == "sqlite":
# to_add = str(to_add).rsplit('/', maxsplit=1)[-1]
# if to_add.endswith('.sqlite'):
# to_add = to_add[:-7]
LOG.info("to add: %s", to_add)

# get the current state of connected databases from products
dynamic_list = [
a.connection
a.connection.replace('////', '/')
for a in self.cfg_sess_private.query(ORMProduct).all()
]

# log dynamic list
# LOG.info("dynamic list: %s", dynamic_list)
# dynamic_list = [
# d[:-7] if d.endswith('.sqlite') else d
# for d in dynamic_list
# ]
LOG.info("dynamic list: %s", dynamic_list)
dynamic_list = [
d[16:] if d.endswith('.sqlite') else d
for d in dynamic_list
]

return to_add in dynamic_list # True if found, False otherwise
# True if found, False otherwise
LOG.info("dynamic list: %s", dynamic_list)
for d in dynamic_list:
if d == to_add and is_sqlite:
return True
elif to_add in d and not is_sqlite:
return True
return False

@property
def num_products(self):
Expand Down
19 changes: 13 additions & 6 deletions web/tests/functional/products/test_config_db_share.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import unittest

from codechecker_api_shared.ttypes import Permission
# from codechecker_api_shared.ttypes import RequestFailed
from codechecker_api_shared.ttypes import RequestFailed

from codechecker_api.ProductManagement_v6.ttypes import ProductConfiguration
from codechecker_api.ProductManagement_v6.ttypes import DatabaseConnection
Expand Down Expand Up @@ -160,7 +160,7 @@ def create_test_product(product_name, product_endpoint):
username_b64='',
password_b64='',
database=os.path.join(self.test_workspace_secondary,
'data.sqlite')))
'data_test.sqlite')))

product_cfg = create_test_product('producttest_second',
'producttest_second')
Expand All @@ -171,8 +171,15 @@ def create_test_product(product_name, product_endpoint):
product_cfg = create_test_product('producttest_second 2',
'producttest_second_2')

self.assertTrue(self._pr_client_2.addProduct(product_cfg),
"Cannot create product on secondary server.")
# self.assertTrue(self._pr_client_2.addProduct(product_cfg),
# "Cannot create product on secondary server.")

# expect request to fail
with self.assertRaises(RequestFailed):
self._pr_client_2.addProduct(product_cfg)

# self.assertTrue(self._pr_client_2.addProduct(product_cfg),
# "Cannot create product on secondary server.")

# Product name full string match.
products = self._pr_client_2.getProducts('producttest_second', None)
Expand All @@ -184,10 +191,10 @@ def create_test_product(product_name, product_endpoint):

# Product name substring match.
products = self._pr_client_2.getProducts('producttest_second*', None)
self.assertEqual(len(products), 2)
self.assertEqual(len(products), 1)

products = self._pr_client_2.getProducts(None, 'producttest_second*')
self.assertEqual(len(products), 2)
self.assertEqual(len(products), 1)

# Use the same CodeChecker config that was used on the main server,
# but store into the secondary one.
Expand Down
5 changes: 3 additions & 2 deletions web/tests/functional/store/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ def setup_class(self):

server_access['viewer_product'] = 'store_limited_product'
codechecker.add_test_package_product(server_access, TEST_WORKSPACE,
report_limit=2)
report_limit=2, database_name='store_limited_product')

server_access['viewer_product'] = 'store_test'
codechecker.add_test_package_product(server_access, TEST_WORKSPACE)
codechecker.add_test_package_product(server_access, TEST_WORKSPACE,
database_name='store_test')

# Extend the checker configuration with the server access.
codechecker_cfg.update(server_access)
Expand Down
4 changes: 2 additions & 2 deletions web/tests/libtest/codechecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ def start_server_proc(event, server_cmd, checking_env):

def add_test_package_product(server_data, test_folder, check_env=None,
protocol='http', report_limit=None,
user_permissions=None):
user_permissions=None, database_name="data.sqlite"):
"""
Add a product for a test suite to the server provided by server_data.
Server must be running before called.
Expand Down Expand Up @@ -781,7 +781,7 @@ def add_test_package_product(server_data, test_folder, check_env=None,
else:
# SQLite databases are put under the workspace of the appropriate test.
add_command += ['--sqlite',
os.path.join(test_folder, 'data.sqlite')]
os.path.join(test_folder, database_name)]

print(' '.join(add_command))

Expand Down

0 comments on commit 043bd88

Please sign in to comment.