Skip to content

Commit b8d3f99

Browse files
author
Cynthia Zheng Gu
committed
eliminate temp variables and change --standalone-server-port to string to comply with ATS settings
1 parent 973a6ff commit b8d3f99

File tree

4 files changed

+15
-52
lines changed

4 files changed

+15
-52
lines changed

tsqa/conf_plugin.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

tsqa/environment.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import time
2525
import multiprocessing
2626
import hashlib
27-
import socket;
27+
import socket
2828

2929
import tsqa.configs
3030
import tsqa.utils
@@ -319,19 +319,9 @@ def __init__(self, layout=None):
319319
self.layout = None
320320

321321
#process environment options
322-
self.keep_env = False
323-
if plugin.conf_plugin.args.keep_env:
324-
self.keep_env = plugin.conf_plugin.args.keep_env
325322
self.sleep_in_sec = 0
326323
if plugin.conf_plugin.args.sleep_in_sec:
327324
self.sleep_in_sec = plugin.conf_plugin.args.sleep_in_sec
328-
self.standalone_ats_port = -1
329-
if plugin.conf_plugin.args.standalone_ats_port:
330-
self.standalone_ats_port = plugin.conf_plugin.args.standalone_ats_port
331-
if self.standalone_ats_port != -1 and plugin.conf_plugin.args.standalone_ats_port not in range(0, 65536):
332-
log.info("invalid port number assigned to --standalone_ats_port, start an ATS")
333-
334-
335325

336326
def create(self):
337327
"""
@@ -390,8 +380,8 @@ def clone(self, layout=None):
390380
else:
391381
os.chmod(dirname, 0777)
392382

393-
if self.standalone_ats_port != -1:
394-
http_server_port = self.standalone_ats_port
383+
if plugin.conf_plugin.args.standalone_server_port:
384+
http_server_port = plugin.conf_plugin.args.standalone_server_port
395385
else:
396386
http_server_port = tsqa.utils.bind_unused_port()[1]
397387
manager_mgmt_port = tsqa.utils.bind_unused_port()[1]
@@ -460,7 +450,7 @@ def destroy(self):
460450
self.layout = Layout(None)
461451

462452
def start(self):
463-
if self.standalone_ats_port != -1:
453+
if plugin.conf_plugin.args.standalone_server_port:
464454
return
465455
if self.running(): # if its already running, don't start another one
466456
raise Exception('traffic cop already started')
@@ -471,7 +461,7 @@ def start(self):
471461

472462
# TODO: exception if already stopped?
473463
def stop(self):
474-
if self.standalone_ats_port != -1:
464+
if plugin.conf_plugin.args.standalone_server_port:
475465
return
476466
if self.sleep_in_sec > 0:
477467
time.sleep(self.sleep_in_sec)
@@ -489,16 +479,16 @@ def stop(self):
489479
self.cop.terminate() # TODO: remove?? or wait...
490480

491481
def running(self):
492-
if self.standalone_ats_port != -1:
482+
if plugin.conf_plugin.args.standalone_server_port:
493483
#try to connect to the port
494484
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
495-
result = sock.connect_ex(('127.0.0.1', self.standalone_ats_port))
485+
result = sock.connect_ex(('127.0.0.1', int(plugin.conf_plugin.args.standalone_server_port)))
496486
if result == 0:
497-
log.info("The port for standalone ATS is open")
487+
log.debug("Standalone ATS server port is open")
498488
sock.close()
499489
return True
500490
else:
501-
log.info("The port for standalone ATS is not open")
491+
log.error("Standalone ATS server port is not open")
502492
sock.close()
503493
return False
504494
if self.cop is None:

tsqa/plugin/conf_plugin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ def options(self, parser, env=os.environ):
1717
help="Keep env files after running successfully")
1818
parser.add_option('--sleep-in-sec', type='int', default=0,
1919
dest='sleep_in_sec',
20-
help='Sleep time before ATS start and after ATS stop to allow enough time for async tests')
21-
parser.add_option('--standalone-ats-port', type='int', default=-1,
22-
dest='standalone_ats_port',
23-
help="Allow standalone test with pre-deployed ATS port")
20+
help='Sleep time after ATS stop to allow enough time for async logs')
21+
parser.add_option('--standalone-server-port', type='string',
22+
dest='standalone_server_port',
23+
help="Allow standalone test with pre-deployed ATS server port")
2424

2525
def configure(self, options, conf):
2626
Plugin.configure(self, options, conf)

tsqa/test_cases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import tsqa.environment
2828
import tsqa.configs
2929
import tsqa.utils
30+
import plugin.conf_plugin
3031
unittest = tsqa.utils.import_unittest()
3132

3233

@@ -117,7 +118,7 @@ def tearDownClass(cls):
117118
# call parent destructor
118119
super(EnvironmentCase, cls).tearDownClass()
119120
# if the test was successful, tear down the env
120-
if cls.__successful and (cls.environment.keep_env is False):
121+
if cls.__successful and ((not plugin.conf_plugin.args.keep_env) or (plugin.conf_plugin.args.keep_env is False)):
121122
cls.environment.destroy() # this will tear down any processes that we started
122123

123124
# Some helpful properties

0 commit comments

Comments
 (0)