本文整理匯總了Python中agent.controllers.service.ServiceController.serviceRootPath方法的典型用法代碼示例。如果您正苦於以下問題:Python ServiceController.serviceRootPath方法的具體用法?Python ServiceController.serviceRootPath怎麽用?Python ServiceController.serviceRootPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類agent.controllers.service.ServiceController
的用法示例。
在下文中一共展示了ServiceController.serviceRootPath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: cleanupOrphanedPackages
# 需要導入模塊: from agent.controllers.service import ServiceController [as 別名]
# 或者: from agent.controllers.service.ServiceController import serviceRootPath [as 別名]
def cleanupOrphanedPackages(checkAge = False):
''' API to cleanup Orphaned Packages For All Services '''
from agent.controllers.service import ServiceController
#services = os.listdir(service_nodes)
from agent.controllers.manifest import ManifestController
#import pdb;pdb.set_trace()
services = ServiceController.getServices()
service_nodes = ServiceController.serviceRootPath()
linkedPaths = []
sysServices = ['agent']
LOG.info('Garbage collecting orphaned installed packages')
for service in services:
try:
if service in sysServices:
LOG.debug('system services cannot be garbage collected')
else:
servicePath = os.path.join(service_nodes, service)
installedPkgPath = os.path.join(servicePath, 'installed-packages')
linkedPaths.extend(ManifestController.getAllSymLinks(service))
linkedPaths.extend(manifestutil.getModuleSymLinks(service))
LOG.debug('symLinks returned %s' % linkedPaths)
installedPkgPaths = PackageUtil.getAllInstalledPackages(installedPkgPath)
LOG.debug('installedPkgPaths returned for the service %s' % installedPkgPaths)
if len(installedPkgPaths) > 0:
orphanPkgs = set(installedPkgPaths) - set(linkedPaths)
LOG.debug('orphanPkgs returned %s' % orphanPkgs)
PackageUtil.cleanupInstalledPkgs(installedPkgPath, orphanPkgs)
except BaseException as excep:
LOG.error('Failed to proceed with garbage collection %s' % str(excep))
# agent-804, manifests only contains folders, need to delete if file is in manifests
servicePath = os.path.join(service_nodes, service)
if not os.path.isdir(servicePath):
utils.runsyscmd('rm -f %s' % servicePath)
LOG.info('Garbage collecting orphaned installed packages completed')
示例2: testDelete
# 需要導入模塊: from agent.controllers.service import ServiceController [as 別名]
# 或者: from agent.controllers.service.ServiceController import serviceRootPath [as 別名]
def testDelete(self):
def deleteTestDir(service):
LOG.debug('************ service = %s' % service)
response = self.app.delete(url(controller='service', service=service, action='delete'), expect_errors = True)
# make sure the responses are correct
LOG.debug('status = ' + str(response.status_int))
# assert response.status_int == 500, "HTTP response != 500"
def makeTestDir(path):
os.makedirs(path)
os.makedirs(os.path.join(path, 'manifests'))
os.makedirs(os.path.join(path, 'installed-packages'))
def createManifests(mf_path):
os.makedirs(os.path.join(mf_path, 'm1.0', 'dummy_dir1.0'))
os.makedirs(os.path.join(mf_path, 'm2.0', 'dummy_dir2.0'))
latest = os.path.join(mf_path, 'm3.0')
os.makedirs(os.path.join(latest, 'dummy_dir3.0'))
utils.symlink(latest, os.path.join(mf_path, 'active'))
return (['m1.0', 'm2.0', 'm3.0'], 'm3.0')
def makePackageContent(path, pkgPath, pkgPropPath):
pkgFile = file(pkgPath, 'w')
for index in range(10):
pkgFile.write(('%s%s') % (index, index))
pkgFile.close()
pkgFile = file(pkgPropPath, 'w')
for index in range(10):
pkgFile.write(('%s%s') % (index, index))
pkgFile.close()
uname = pylons.config['agent_user_account']
TestCleanupController.rchown(path, uname)
def createTestThread(serviceName):
appGlobal = config['pylons.app_globals']
testTh = WaitThread(appGlobal.threadMgr, ServiceController.serviceCat(serviceName))
testTh.start()
return testTh
def startTestProcess():
cmd = utils.sudoCmd(["sleep", "5"], pylons.config['app_user_account'])
return Popen(cmd)
path1 = os.path.join(pylons.config['agent_root'], 'service_nodes', 'foo')
path2 = os.path.join(pylons.config['agent_root'], 'service_nodes', 'bar')
path3 = os.path.join(pylons.config['agent_root'], 'service_nodes', 'agent')
deleteTestDir('foo')
deleteTestDir('bar')
deleteTestDir('agent')
# make dirs
makeTestDir(path1)
makeTestDir(path2)
makeTestDir(path3)
all_mf, active_mf = createManifests(ServiceController.manifestPath('agent'))
uname = pylons.config['agent_user_account']
TestCleanupController.rchown(ServiceController.serviceRootPath(), uname)
pkgDir = PackageMgr.packagePath()
pkgPath = os.path.join(pkgDir, "foo.cronus")
pkgPropPath = os.path.join(pkgDir, "foo.cronus.prop")
makePackageContent(pkgDir, pkgPath, pkgPropPath)
# create threads
testThFoo = createTestThread('foo')
testThBar = createTestThread('bar')
testThAgent = createTestThread('agent')
# start process
process = startTestProcess()
# start testing
LOG.debug('************ start cleanup')
response = self.app.post(url(controller='cleanup', action='post'))
LOG.debug ('Delete response body = ' + response.body)
body = json.loads(response.body)
tm = time.time()
while (tm + 10 > time.time()):
response = self.app.get(body['status'], expect_errors = True)
LOG.debug ('Status response body = ' + response.body)
body = json.loads(response.body)
print body
if (body['progress'] == 100):
break
time.sleep(0.1)
# make sure the responses are correct
LOG.debug('status = ' + str(response.status_int))
assert response.status_int == 200, "HTTP response != 200"
time.sleep(0.1)
assert not os.path.exists(path1), 'service foo does exist or is not a directory'
assert not os.path.exists(path2), 'service bar does exist or is not a directory'
assert os.path.exists(path3), 'service agent does NOT exist or is not a directory'
#.........這裏部分代碼省略.........