Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests #646

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions Client/src/python/dbs/apis/dbsClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import cjson
import os
import time
import socket
import sys
import urllib
Expand Down Expand Up @@ -166,10 +167,18 @@ def __init__(self, url="", proxy=None, key=None, cert=None, verifypeer=True, deb
self.key = key
self.cert = cert
self.userAgent = userAgent
self.ca_info = ca_info
self.verifypeer = verifypeer
self.host = socket.gethostname()

self.rest_api = RestApi(auth=X509Auth(ssl_cert=cert, ssl_key=key, ssl_verifypeer=verifypeer, ca_info=ca_info),
proxy=Socks5Proxy(proxy_url=self.proxy) if self.proxy else None)

def get_rest_api(self):
auth = X509Auth(ssl_cert=self.cert, ssl_key=self.key, ssl_verifypeer=self.verifypeer, ca_info=self.ca_info)
proxy = Socks5Proxy(proxy_url=self.proxy) if self.proxy else None
return RestApi(auth=auth, proxy=proxy)

def __callServer(self, method="", params={}, data={}, callmethod='GET', content='application/json'):
"""
A private method to make HTTP call to the DBS Server
Expand All @@ -184,14 +193,15 @@ def __callServer(self, method="", params={}, data={}, callmethod='GET', content=
:type content: str

"""
UserID = os.environ['USER']+'@'+socket.gethostname()
time0 = time.time()
UserID = os.environ['USER']+'@'+self.host
try:
UserAgent = "DBSClient/"+os.environ['DBS3_CLIENT_VERSION']+"/"+ self.userAgent
except:
UserAgent = "DBSClient/Unknown"+"/"+ self.userAgent
request_headers = {"Content-Type": content, "Accept": content, "UserID": UserID, "User-Agent":UserAgent }

method_func = getattr(self.rest_api, callmethod.lower())
method_func = getattr(self.get_rest_api(), callmethod.lower())

data = cjson.encode(data)

Expand All @@ -206,7 +216,7 @@ def __callServer(self, method="", params={}, data={}, callmethod='GET', content=
try:
json_ret=cjson.decode(self.http_response.body)
except cjson.DecodeError:
print("The server output is not a valid json, most probably you have a typo in the url.\n%s.\n" % self.url, file=sys.stderr)
print("The server output is not a valid json, most probably you have a typo in the url.\n%s, http response body: %s, cjson decode error %s.\n" % (self.url, self.http_response.body, cjson.DecodeError), file=sys.stderr)
raise dbsClientException("Invalid url", "Possible urls are %s" %self.http_response.body)

return json_ret
Expand Down
12 changes: 10 additions & 2 deletions Client/tests/dbsclient_t/unittests/DBSClientReader_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import re
import sys
import copy
import unittest
from functools import wraps

Expand Down Expand Up @@ -45,15 +46,22 @@ def __init__(self, methodName='runTest'):
url = os.environ['DBS_READER_URL']
proxy = os.environ.get('SOCKS5_PROXY')
self.api = DbsApi(url=url, proxy=proxy)
fname = os.path.join(os.path.dirname(os.path.abspath(__file__)), "info.dict")
self.info_params = None
with open(fname, "r") as infofile:
self.info_params = importCode(infofile, "testparams", 0).info

def setUp(self):
"""setup all necessary parameters"""
infofile = open(os.path.join(os.path.dirname(os.path.abspath(__file__)), "info.dict"), "r")
self.testparams = importCode(infofile, "testparams", 0).info
self.testparams = copy.deepcopy(self.info_params)
dataset=self.testparams['dataset']
processed_ds_name = dataset.split('/')[2]
self.testparams['processed_ds_name'] = processed_ds_name

def tierDown(self):
"""tier down all stuff form unit test"""
self.testparams = None

def test000a(self):
"""test00 unittestDBSClientReader_t.requestTimingInfo"""
self.api.requestTimingInfo
Expand Down
17 changes: 13 additions & 4 deletions Client/tests/setup_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,23 @@ def run(self):
'https://cmsweb.cern.ch': 'prod/test'}

###set environment
os.environ['DBS_READER_URL'] = ("%s/dbs/%s/DBSReader") % (self.host, db_instances.get(self.host, 'dev/global'))
os.environ['DBS_WRITER_URL'] = ("%s/dbs/%s/DBSWriter") % (self.host, db_instances.get(self.host, 'dev/global'))
os.environ['DBS_MIGRATE_URL'] = ("%s/dbs/%s/DBSMigrate") % (self.host,
db_instances.get(self.host, 'dev/global'))
if self.host.find("dbs2go") != -1:
os.environ['DBS_READER_URL'] = self.host
os.environ['DBS_WRITER_URL'] = self.host
os.environ['DBS_MIGRATE_URL'] = self.host
else:
os.environ['DBS_READER_URL'] = ("%s/dbs/%s/DBSReader") % (self.host, db_instances.get(self.host, 'dev/global'))
os.environ['DBS_WRITER_URL'] = ("%s/dbs/%s/DBSWriter") % (self.host, db_instances.get(self.host, 'dev/global'))
os.environ['DBS_MIGRATE_URL'] = ("%s/dbs/%s/DBSMigrate") % (self.host,
db_instances.get(self.host, 'dev/global'))

if self.cmsweb_testbed:
self.unitall, self.validation, self.deployment = (True, True, True)

# VK, temporary comment out deployment for dbs2go
if self.host.find("dbs2go") != -1:
self.deployment = False

if self.unit in ('ClientWriter', 'ClientReader', 'ClientBlockWriter'):
TestSuite.addTests(create_test_suite(unit_tests, 'DBS%s_t.py' % self.unit, base_dir))

Expand Down