本文整理汇总了Python中servicemanager.smprocess.SmProcess类的典型用法代码示例。如果您正苦于以下问题:Python SmProcess类的具体用法?Python SmProcess怎么用?Python SmProcess使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SmProcess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _start_from_sources
def _start_from_sources(self):
service_data = self.context.service_data(self.service_name)
assets_path = self.context.application.workspace + service_data["location"]
cmd_with_params = self.service_data["sources"]["cmd"]
force_pushdir(assets_path)
run_from_file = open("RUNNING_FROM", 'w')
run_from_file.write(self.run_from)
run_from_file.close()
makedirs_if_not_exists("logs")
seconds_remaining = SmPythonServiceStarter.PROCESS_STARTUP_TIMEOUT_SECONDS
with open("logs/stdout.txt", "wb") as out, open("logs/stderr.txt", "wb") as err:
subprocess.Popen(cmd_with_params, shell=False, env=os.environ.copy(), stdout=out, stderr=err, close_fds=True)
while seconds_remaining > 0 and not len(SmProcess.processes_matching("grunt")) > 0:
time.sleep(1)
seconds_remaining -= 1
if seconds_remaining < 10 or seconds_remaining % 5 == 0:
self.log("Waiting for Assets service to start: %s second%s before timeout" % (
seconds_remaining, "s" if seconds_remaining > 1 else ""))
if len(SmProcess.processes_matching("grunt")) == 1:
process = SmProcess.processes_matching("grunt")
for i, v in enumerate(process):
return v.pid
示例2: test_successful_play_from_jar_without_waiting_with_append_args
def test_successful_play_from_jar_without_waiting_with_append_args(self):
config_dir_override = os.path.join(os.path.dirname(__file__), "conf")
sm_application = SmApplication(config_dir_override)
context = SmContext(sm_application, None, False, False)
service_resolver = ServiceResolver(sm_application)
context.kill_everything()
time.sleep(5)
response1 = actions.start_one(context, "FAKE_NEXUS", True, False, None, None, None)
self.assertTrue(response1)
self.assertIsNotNone(context.get_service("FAKE_NEXUS").status())
time.sleep(5)
servicetostart = ["PLAY_NEXUS_END_TO_END_TEST"]
appendArgs = {"PLAY_NEXUS_END_TO_END_TEST": ["-DFoo=Bar"]}
fatJar = True
release = False
proxy = None
port = None
seconds_to_wait = None
try:
actions.start_and_wait(service_resolver, context, servicetostart, fatJar, release, proxy, port, seconds_to_wait, appendArgs)
time.sleep(5)
service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
processes = SmProcess.processes_matching(service.pattern)
self.assertEqual(len(processes), 1)
self.assertTrue("-DFoo=Bar" in processes[0].args)
finally:
context.kill_everything()
示例3: stop
def stop(self):
processes = SmProcess.processes_matching(self.pattern)
for process in processes:
kill_pid(self.context, process.ppid)
kill_pid(self.context, process.pid)
print "name: %s\tppid: %s\tpid: %s\tuptime: %s" % (self.service_name, process.ppid, process.pid, process.uptime)
示例4: test_play_with_append_args
def test_play_with_append_args(self):
config_dir_override = os.path.join(os.path.dirname(__file__), "conf")
context = SmContext(SmApplication(config_dir_override), None, False, False)
context.kill_everything()
# Start up fake nexus first
response1 = actions.start_one(context, "FAKE_NEXUS", True, False, None, port=None)
self.assertTrue(response1)
self.assertIsNotNone(context.get_service("FAKE_NEXUS").status())
time.sleep(5)
server = smserverlogic.SmServer(SmApplication(config_dir_override, None))
request = dict()
request["testId"] = "foo"
request["services"] = [
{"serviceName": "PLAY_NEXUS_END_TO_END_TEST", "runFrom": "SNAPSHOT", "appendArgs": ["-Dfoo=bar"]}
]
smserverlogic.SmStartRequest(server, request, True, False).process_request()
time.sleep(5)
self.assertEqual(len(context.get_service("PLAY_NEXUS_END_TO_END_TEST").status()), 1)
service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
processes = SmProcess.processes_matching(service.pattern)
self.assertEqual(len(processes), 1)
self.assertTrue("-Dfoo=bar" in processes[0].args)
context.kill_everything()
self.assertEqual(context.get_service("TEST_ONE").status(), [])
示例5: is_started_on_default_port
def is_started_on_default_port(self):
processes = SmProcess.processes_matching(self.pattern)
default_port_argument = "-D%s=%d" % (self.get_port_argument, self.default_port)
for process in processes:
if process.has_argument(default_port_argument):
return True
return False
示例6: status
def status(self, all_processes=None):
processes = SmProcess.processes_matching(self.pattern, all_processes)
def _status_for_process(process):
port = process.extract_integer_argument('-D%s=(\d*)' % self.get_port_argument(), self.default_port)
test_id = process.extract_argument('-Dservice.manager.testId=([^ ]+)', "")
run_from = process.extract_argument('-Dservice.manager.runFrom=([^ ]+)', "")
features = process.extract_arguments('-Dfeature.([^ =]+)=true', "")
healthcheck = SmServiceStatus.HEALTHCHECK_PASS if self.run_healthcheck(process) else SmServiceStatus.HEALTHCHECK_BOOT
return SmServiceStatus.for_process(self.service_name, process, port, test_id, run_from, features, healthcheck)
return map(_status_for_process, processes)
示例7: test_successful_play_from_jar_without_waiting_with_append_args
def test_successful_play_from_jar_without_waiting_with_append_args(self):
sm_application = SmApplication(self.config_dir_override)
context = SmContext(sm_application, None, False, False)
service_resolver = ServiceResolver(sm_application)
context.kill_everything(True)
self.startFakeNexus()
servicetostart = ["PLAY_NEXUS_END_TO_END_TEST"]
appendArgs = {"PLAY_NEXUS_END_TO_END_TEST": ["-DFoo=Bar"]}
fatJar = True
release = False
proxy = None
port = None
seconds_to_wait = None
actions.start_and_wait(service_resolver, context, servicetostart, False, fatJar, release, proxy, port, seconds_to_wait, appendArgs)
service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
self.waitForCondition(lambda : len(SmProcess.processes_matching(service.pattern)), 1)
processes = SmProcess.processes_matching(service.pattern)
self.assertTrue("-DFoo=Bar" in processes[0].args)
示例8: status
def status(self):
processes = SmProcess.processes_matching(SmPythonService.get_pattern(self))
if len(processes) == 0:
return []
if len(processes) > 1:
self.log("POSSIBLE PROBLEM: Found more than one process")
def _status_for_process(process):
healthcheck = SmServiceStatus.HEALTHCHECK_PASS if self.run_healthcheck(None) else SmServiceStatus.HEALTHCHECK_BOOT
return SmServiceStatus.for_process(self.service_name, process, self.default_port, "", "", "", healthcheck)
return map(_status_for_process, processes)
示例9: test_external_with_append_args
def test_external_with_append_args(self):
context = self.createContext()
server = smserverlogic.SmServer(SmApplication(self.config_dir_override, None))
request = dict()
request["testId"] = "foo"
request["services"] = [{"serviceName": "TEST_FOUR", "runFrom": "SNAPSHOT", "appendArgs": ["2"]}]
smserverlogic.SmStartRequest(server, request, True, False, False, True).process_request()
self.assertIsNotNone(context.get_service("TEST_FOUR").status())
pattern = context.application.services["TEST_FOUR"]["pattern"]
self.waitForCondition(lambda : len(SmProcess.processes_matching(pattern)), 1)
context.kill_everything(True)
self.assertEqual(context.get_service("TEST_FOUR").status(), [])
示例10: test_external_with_append_args
def test_external_with_append_args(self):
config_dir_override = os.path.join(os.path.dirname(__file__), "conf")
context = SmContext(SmApplication(config_dir_override), None, False, False)
context.kill_everything()
server = smserverlogic.SmServer(SmApplication(config_dir_override, None))
request = dict()
request["testId"] = "foo"
request["services"] = [{"serviceName": "TEST_ONE", "runFrom": "SNAPSHOT", "appendArgs": [";echo foo"]}]
smserverlogic.SmStartRequest(server, request, True, False).process_request()
self.assertIsNotNone(context.get_service("TEST_ONE").status())
pattern = context.application.services["TEST_ONE"]["pattern"]
processes = SmProcess.processes_matching(pattern)
# stop does not currently work for extern
# smserverlogic.SmStopRequest(SERVER, request).process_request()
self.assertEqual(len(processes), 2) #we expect two proecesses to be spawned because of the appended command
self.assertTrue(";echo" in processes[0].args or ";echo" in processes[1].args)
context.kill_everything()
self.assertEqual(context.get_service("TEST_ONE").status(), [])
示例11: status
def status(self, all_processes=None):
processes = SmProcess.processes_matching(self.pattern, all_processes)
if len(processes) == 0:
return []
if len(processes) > 1:
self.log("POSSIBLE PROBLEM: Found more than one process")
def _status_for_process(process):
hc_result = self.run_healthcheck(process)
healthcheck = SmServiceStatus.HEALTHCHECK_NONE
if hc_result is not None:
healthcheck = SmServiceStatus.HEALTHCHECK_PASS if self.run_healthcheck(process) else SmServiceStatus.HEALTHCHECK_BOOT
return SmServiceStatus.for_process(self.service_name, process, "", "", "", "", healthcheck)
return map(_status_for_process, processes)
示例12: test_play_with_append_args
def test_play_with_append_args(self):
context = self.createContext()
self.startFakeNexus()
server = smserverlogic.SmServer(SmApplication(self.config_dir_override, None))
request = dict()
request["testId"] = "foo"
request["services"] = [{"serviceName": "PLAY_NEXUS_END_TO_END_TEST", "runFrom": "SNAPSHOT", "appendArgs": ["-Dfoo=bar"]}]
smserverlogic.SmStartRequest(server, request, True, False, False, True).process_request()
self.waitForCondition(lambda : len(context.get_service("PLAY_NEXUS_END_TO_END_TEST").status()), 1)
service = SmPlayService(context, "PLAY_NEXUS_END_TO_END_TEST")
processes = SmProcess.processes_matching(service.pattern)
self.assertEqual(len(processes), 1)
self.assertTrue("-Dfoo=bar" in processes[0].args)
context.kill_everything(True)
self.assertEqual(context.get_service("PLAY_NEXUS_END_TO_END_TEST").status(), [])
示例13: _wait_for_services
def _wait_for_services(context, service_names, seconds_to_wait):
waiting_for_services = []
for service_name in service_names:
if "healthcheck" in context.service_data(service_name):
waiting_for_services += [context.get_service(service_name)]
if not seconds_to_wait:
seconds_to_wait = 0
end_time = _now() + seconds_to_wait
while waiting_for_services and _now() < end_time:
services_to_check = list(waiting_for_services)
for service in services_to_check:
if _now() >= end_time:
break
processes = SmProcess.processes_matching(service.pattern)
if all(map(service.run_healthcheck, processes)):
print "Service '%s' has started successfully" % service.service_name
waiting_for_services.remove(service)
else:
seconds_remaining = end_time - _now()
if seconds_remaining % 5 == 0 or seconds_remaining < 10:
print "Waiting for %s to start, %s second%s before timeout" % (service.service_name, seconds_remaining, "s" if seconds_to_wait != 1 else "")
if waiting_for_services:
time.sleep(1)
if waiting_for_services:
services_timed_out = []
for service in waiting_for_services:
services_timed_out += [service.service_name]
raise ServiceManagerException("Timed out starting service(s): %s" % ", ".join(services_timed_out))
示例14: is_started_on_default_port
def is_started_on_default_port(self):
return len(SmProcess.processes_matching(SmPythonService.get_pattern(self))) > 0
示例15: is_started_on_default_port
def is_started_on_default_port(self):
return len(SmProcess.processes_matching(self.pattern)) > 0