def testPkgInitConfig(self): createManifest(self, manifest = 'bar', service = 'foo') activateManifest(self, manifest = 'bar', service = 'foo') inifilepath = manifestutil.packagePath('foo', 'bar', 'perlserver') + os.path.sep + 'cronus' inifilename = os.path.join(inifilepath, 'cronus.ini') uname = pylons.config['app_user_account'] utils.runsyscmd(utils.sudoCmd('chmod -R ga+w %s' % inifilepath, uname)) data = {"key":"value","key2":"value2"} # test json format with open(inifilename, 'w') as propFile: json.dump(data, propFile) pkgPath = packagePath('foo', 'bar', 'perlserver') pkgInitConfig = manifestutil.PkgInitConfig(pkgPath) configs = pkgInitConfig.getConfigs() assert configs is not None assert isinstance(configs, dict) print configs assert configs['key'] == 'value' assert configs['key2'] == 'value2' # test eval() format with open(inifilename, 'wb+') as fp: jsonStr = json.dumps(data) fp.write(jsonStr) fp.write("\n") pkgInitConfig = manifestutil.PkgInitConfig(pkgPath) configs = pkgInitConfig.getConfigs() assert configs is not None assert isinstance(configs, dict) print configs assert configs['key'] == 'value' assert configs['key2'] == 'value2'
def testPkgInitConfig(self): createManifest(self, manifest='bar', service='foo') activateManifest(self, manifest='bar', service='foo') inifilepath = manifestutil.packagePath( 'foo', 'bar', 'perlserver') + os.path.sep + 'cronus' inifilename = os.path.join(inifilepath, 'cronus.ini') uname = pylons.config['app_user_account'] utils.runsyscmd(utils.sudoCmd('chmod -R ga+w %s' % inifilepath, uname)) data = {"key": "value", "key2": "value2"} # test json format with open(inifilename, 'w') as propFile: json.dump(data, propFile) pkgPath = packagePath('foo', 'bar', 'perlserver') pkgInitConfig = manifestutil.PkgInitConfig(pkgPath) configs = pkgInitConfig.getConfigs() assert configs is not None assert isinstance(configs, dict) print configs assert configs['key'] == 'value' assert configs['key2'] == 'value2' # test eval() format with open(inifilename, 'wb+') as fp: jsonStr = json.dumps(data) fp.write(jsonStr) fp.write("\n") pkgInitConfig = manifestutil.PkgInitConfig(pkgPath) configs = pkgInitConfig.getConfigs() assert configs is not None assert isinstance(configs, dict) print configs assert configs['key'] == 'value' assert configs['key2'] == 'value2'
def test_bad_shutdown(self): createManifest(self, ['http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/bad_shutdown_package-0.0.1.unix.cronus'], manifest = 'bar') createManifest(self, manifest = 'baz') activateManifest(self, manifest = 'bar') LOG.debug('**************** finished activating bar') body = json.dumps({'manifest':'baz'}) response = self.app.post(url(controller='action', action='activatemanifest', service="foo"), headers = {'Content-Type' : 'application/json'}, params = body) assert response.status_int == 200 body = json.loads(response.body) tm = time.time() while (tm + 20 > time.time()): response = self.app.get(body['status'], expect_errors = True) body = json.loads(response.body) print "activateManifest body = %s " % body if (response.status_int == 500): break time.sleep(0.1) # make sure this test failes out assert body['error'] != None # make sure the active link points to old manifest response = self.app.get(url(controller='service', service='foo', action='get')) body = json.loads(response.body) print "service get = %s" % body assert body['result']['activemanifest'] == 'bar'
def test_checkMonitorChanges_nochanges(self): appGlobal = pylons.config['pylons.app_globals'] appGlobal.agentMonitor._AgentMonitor__monitorSch.stop() createManifest(self) activateManifest(self) appGlobal.agentMonitor._AgentMonitor__monitorValues = {'foo': {}} appGlobal.agentMonitor._AgentMonitor__monitorTasks = {'foo': ['bar', []]} appGlobal.agentMonitor.checkMonitorChanges() assert {'foo': {}} == appGlobal.agentMonitor._AgentMonitor__monitorValues assert {'foo': ['bar', []]} == appGlobal.agentMonitor._AgentMonitor__monitorTasks
def test_checkMonitorChanges_nochanges(self): appGlobal = pylons.config['pylons.app_globals'] appGlobal.enrolled = True appGlobal.agentMonitor._AgentMonitor__monitorSch.stop() createManifest(self) activateManifest(self) appGlobal.agentMonitor._AgentMonitor__monitorValues = {'foo': {}} appGlobal.agentMonitor._AgentMonitor__monitorTasks = {'foo': ['bar', []]} appGlobal.agentMonitor.checkMonitorChanges() assert {'foo': {}} == appGlobal.agentMonitor._AgentMonitor__monitorValues assert {'foo': ['bar', []]} == appGlobal.agentMonitor._AgentMonitor__monitorTasks
def test_checkMonitorChanges_delete(self): appGlobal = pylons.config['pylons.app_globals'] stopMonitor() initMonitor() createManifest(self) activateManifest(self) appGlobal.agentMonitor._AgentMonitor__monitorValues = {('foo', 'default'): {}, ('zoo', 'default'): {}} appGlobal.agentMonitor._AgentMonitor__monitorTasks = {('foo', 'bar'): [], ('zoo', 'bar'): []} print '%s' % appGlobal.agentMonitor._AgentMonitor__monitorTasks.keys() appGlobal.agentMonitor.checkMonitorChanges() assert ('foo', 'default') in appGlobal.agentMonitor._AgentMonitor__monitorValues assert ('zoo', 'default') in appGlobal.agentMonitor._AgentMonitor__monitorValues LOG.debug('%s' % appGlobal.agentMonitor._AgentMonitor__monitorTasks.keys()) assert ('foo', 'bar') in appGlobal.agentMonitor._AgentMonitor__monitorTasks assert ('zoo', 'default') not in appGlobal.agentMonitor._AgentMonitor__monitorTasks
def test_checkMonitorChanges_delete(self): appGlobal = pylons.config['pylons.app_globals'] appGlobal.enrolled = True stopMonitor() initMonitor() createManifest(self) activateManifest(self) appGlobal.agentMonitor._AgentMonitor__monitorValues = {('foo', 'default'): {}, ('zoo', 'default'): {}} appGlobal.agentMonitor._AgentMonitor__monitorTasks = {('foo', 'bar'): [], ('zoo', 'bar'): []} print '%s' % appGlobal.agentMonitor._AgentMonitor__monitorTasks.keys() appGlobal.agentMonitor.checkMonitorChanges() assert ('foo', 'default') in appGlobal.agentMonitor._AgentMonitor__monitorValues assert ('zoo', 'default') in appGlobal.agentMonitor._AgentMonitor__monitorValues LOG.debug('%s' % appGlobal.agentMonitor._AgentMonitor__monitorTasks.keys()) assert ('foo', 'bar') in appGlobal.agentMonitor._AgentMonitor__monitorTasks assert ('zoo', 'default') not in appGlobal.agentMonitor._AgentMonitor__monitorTasks
def testServiceLog(self): createManifest(self, service='foo') activateManifest(self, service='foo') response = self.app.get('/services/foo/action/log', expect_errors = True) assert response.status_int == 200, "HTTP response != 200"
def testActiveManifestPath(self): createManifest(self) activateManifest(self) assert manifestutil.activeManifestPath('foo').endswith('bar')
def testHasActiveManifest(self): createManifest(self, manifest = 'testmanifest', service = 'testservice') assert False == manifestutil.hasActiveManifest('testservice') activateManifest(self, manifest = 'testmanifest', service = 'testservice') assert True == manifestutil.hasActiveManifest('testservice')
def testHasActiveManifest(self): createManifest(self, manifest='testmanifest', service='testservice') assert False == manifestutil.hasActiveManifest('testservice') activateManifest(self, manifest='testmanifest', service='testservice') assert True == manifestutil.hasActiveManifest('testservice')
def testServiceLog(self): createManifest(self, service='foo') activateManifest(self, service='foo') response = self.app.get('/services/foo/action/log', expect_errors=True) assert response.status_int == 200, "HTTP response != 200"