Skip to content
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
31 changes: 30 additions & 1 deletion tsqa/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import time
import multiprocessing
import hashlib
import socket

import tsqa.configs
import tsqa.utils
import logging
import time
import plugin.conf_plugin

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -315,6 +318,11 @@ def __init__(self, layout=None):
else:
self.layout = None

#process environment options
self.sleep_in_sec = 0
if hasattr(plugin.conf_plugin, 'args') and plugin.conf_plugin.args.sleep_in_sec:
self.sleep_in_sec = plugin.conf_plugin.args.sleep_in_sec

def create(self):
"""
"""
Expand Down Expand Up @@ -372,7 +380,10 @@ def clone(self, layout=None):
else:
os.chmod(dirname, 0777)

http_server_port = tsqa.utils.bind_unused_port()[1]
if hasattr(plugin.conf_plugin, 'args') and plugin.conf_plugin.args.standalone_server_port:
http_server_port = plugin.conf_plugin.args.standalone_server_port
else:
http_server_port = tsqa.utils.bind_unused_port()[1]
manager_mgmt_port = tsqa.utils.bind_unused_port()[1]
admin_port = tsqa.utils.bind_unused_port()[1]

Expand Down Expand Up @@ -439,6 +450,8 @@ def destroy(self):
self.layout = Layout(None)

def start(self):
if hasattr(plugin.conf_plugin, 'args') and plugin.conf_plugin.args.standalone_server_port:
return
if self.running(): # if its already running, don't start another one
raise Exception('traffic cop already started')
log.debug("Starting traffic cop")
Expand All @@ -448,6 +461,10 @@ def start(self):

# TODO: exception if already stopped?
def stop(self):
if hasattr(plugin.conf_plugin, 'args') and plugin.conf_plugin.args.standalone_server_port:
return
if self.sleep_in_sec > 0:
time.sleep(self.sleep_in_sec)
log.debug("Stopping traffic cop: %s", self.cop)
if self.running():
self.cop.kill()
Expand All @@ -462,6 +479,18 @@ def stop(self):
self.cop.terminate() # TODO: remove?? or wait...

def running(self):
if hasattr(plugin.conf_plugin, 'args') and plugin.conf_plugin.args.standalone_server_port:
#try to connect to the port
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1', int(plugin.conf_plugin.args.standalone_server_port)))
if result == 0:
log.debug("Standalone ATS server port is open")
sock.close()
return True
else:
log.error("Standalone ATS server port is not open")
sock.close()
return False
if self.cop is None:
return False
self.cop.poll()
Expand Down
19 changes: 19 additions & 0 deletions tsqa/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# initialize logger
import tsqa.log
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file doesn't need the logger


Loading