Best Python code snippet using locust
server.py
Source:server.py
1import grp2import logging3import os4import pwd5import sys6from skunk.net.server.socketmgr import SocketManager7from skunk.web.config import (Configuration,8 loadConfig,9 updateConfig,10 mergeDefaults)11from skunk.util.hooks import Hook12"""13Bootstrap does need a spot to configure the logging. A separate conf14file, I suppose; at least until I figure out a better way of dealing15with configuration.16"""17ChildStart=Hook()18class Server(SocketManager):19 """ the skunkweb server itself."""20 def __init__(self, *configFiles):21 super(Server, self).__init__(Configuration.pidFile,22 Configuration)23 self.configFiles=configFiles24 25 def run(self):26 ChildStart()27 super(Server, self).run()28 def reload(self):29 super(Server, self).reload()30 loadServices()31 loadConfig(*self.configFiles)32 configDefaults()33 updateConfig()34 configLogging() 35def configDefaults():36 mergeDefaults(pidFile='/tmp/skunk_server.pid',37 run_group=None,38 run_user=None,39 services=(),40 jobs=())41_svr=None42def loadServices():43 for servicename in Configuration.services:44 try:45 __import__(servicename)46 except ImportError:47 servicename='skunk.web.services.%s' % servicename48 __import__(servicename)49 mod=sys.modules[servicename]50 if hasattr(mod, 'serviceInit'):51 mod.serviceInit()52def configLogging():53 54 # a placeholder; this should have better defaults and also look55 # for a logging config file. because of the latter, which is56 # probably configuration dependent, perhaps this should happen57 # after the configuration is loaded58 # TO BE DONE 59 #logging.basicConfig()60 pass61def init(*configFiles):62 global _svr63 if _svr:64 raise RuntimeError, "already initialized"65 loadConfig(*configFiles)66 configDefaults()67 updateConfig()68 configLogging() 69 # set effective user/group, if necessary70 isroot=os.getuid()==071 run_user=Configuration.run_user72 run_group=Configuration.run_group73 if isroot and run_user is None:74 raise RuntimeError, "won't run as root with out run_user being defined"75 if run_group is not None:76 gid=grp.getnrnam(run_group)[2]77 if hasattr(os, 'setegid'):78 os.setegid(gid)79 #else?80 if run_user is not None:81 uid=pwd.getpwnam(run_user)[2]82 if hasattr(os, 'seteuid'):83 os.seteuid(uid)84 #else?85 loadServices()86 87 # revv 'er up88 _svr=Server(configFiles)89 _svr.mainloop()90 ...
entrypoint.py
Source:entrypoint.py
1#!/usr/bin/python32import shutil3from entrypoint_helpers import env, gen_cfg, str2bool, start_app, set_perms, set_ownership, activate_ssl, sed4RUN_USER = env['run_user']5RUN_GROUP = env['run_group']6CONFLUENCE_INSTALL_DIR = env['confluence_install_dir']7CONFLUENCE_HOME = env['confluence_home']8CONFLUENCE_CFG_OVERWRITE = env.get('atl_confluence_cfg_overwrite', False)9CONFLUENCE_TLS_PROTOCOLS = env.get('atl_confluence_tls_protocols', 'TLSv1.1,TLSv1.2')10SSL_ENABLED = env['atl_sslenabled']11sed('TLSv1.1,TLSv1.2', CONFLUENCE_TLS_PROTOCOLS, f'{CONFLUENCE_INSTALL_DIR}/bin/setenv.sh')12if SSL_ENABLED == 'True' or SSL_ENABLED == True or SSL_ENABLED == 'true' :13 PATH_KEYSTORE = env.get('atl_certificate_location', '/opt/atlassian/confluence/keystore')14 PASSWORD_KEYSTORE = env.get('atl_certificate_password', "changeit")15 PATH_CERTIFICATE_KEY = env.get('atl_certificate_key_location', '/opt/atlassian/etc/certificate.key')16 PATH_CERTIFICATE = env.get('atl_certificate_location', '/opt/atlassian/etc/certificate.crt')17 PATH_CA = env.get('atl_ca_location','/opt/atlassian/etc/ca.cert')18 PATH_P12= env.get('atl_p12_location', '/opt/atlassian/etc/certificate.p12')19 PASSWORD_P12 = env.get('atl_p12_password', 'confluence')20 activate_ssl( f'{CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/web.xml', PATH_KEYSTORE, PASSWORD_KEYSTORE, PATH_CERTIFICATE_KEY, PATH_CERTIFICATE, PATH_CA, PASSWORD_P12, PATH_P12)21gen_cfg('server.xml.j2', f'{CONFLUENCE_INSTALL_DIR}/conf/server.xml')22gen_cfg('seraph-config.xml.j2',23 f'{CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/seraph-config.xml')24gen_cfg('confluence-init.properties.j2',25 f'{CONFLUENCE_INSTALL_DIR}/confluence/WEB-INF/classes/confluence-init.properties')26gen_cfg('confluence.cfg.xml.j2', f'{CONFLUENCE_HOME}/confluence.cfg.xml',27 user=RUN_USER, group=RUN_GROUP, overwrite=CONFLUENCE_CFG_OVERWRITE)28set_ownership(f'{CONFLUENCE_INSTALL_DIR}/logs', user=RUN_USER, group=RUN_GROUP)29set_ownership(f'{CONFLUENCE_INSTALL_DIR}/temp', user=RUN_USER, group=RUN_GROUP)30set_ownership(f'{CONFLUENCE_INSTALL_DIR}/work', user=RUN_USER, group=RUN_GROUP)31set_ownership(f'{CONFLUENCE_INSTALL_DIR}/conf', user=RUN_USER, group=RUN_GROUP)32set_ownership(f'{CONFLUENCE_INSTALL_DIR}/bin', user=RUN_USER, group=RUN_GROUP)33shutil.chown(CONFLUENCE_HOME, user=RUN_USER, group=RUN_GROUP)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!