def testExpandService(self):
        createManifest(self, service='.fooenv.foopool.foo')
        response = self.app.get(url(controller='service',
                                    service='.fooenv.foopool',
                                    action='get'),
                                expect_errors=True)

        body = json.loads(response.body)
        print "************** response = %s" % body

        assert body['progress'] == 100
        assert body['result']['manifest'] == ['bar']

        response = self.app.get(url(controller='service',
                                    service='.fooenv.foopool.foo',
                                    action='get'),
                                expect_errors=True)

        body = json.loads(response.body)
        print "************** response = %s" % body

        assert body['progress'] == 100
        assert body['result']['manifest'] == ['bar']

        response = self.app.get(url(controller='service',
                                    service='.fooenv',
                                    action='get'),
                                expect_errors=True)

        body = json.loads(response.body)
        print "************** response = %s" % body

        assert response.status_int == 500, "HTTP response != 500"
    def test_post5(self):

        createManifest(self, ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                              "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"])

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'pkgA-1.2.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'pkgB-0.6.0.unix.cronus')))
Exemple #3
0
    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'
Exemple #4
0
    def test_post5(self):

        createManifest(self, ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                              "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"])

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'pkgA-1.2.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'pkgB-0.6.0.unix.cronus')))
    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_package_min_age_during_forceDelete(self):
        #import pdb;pdb.set_trace();
        from agent.tests.unit.test_util import createManifest
        serviceName = 'service5'
        manifestName = 'manifestb'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName, manifest = manifestName), expect_errors = True)
        age = pylons.config['packageMgr_package_age']
        pylons.config['packageMgr_package_age'] = 86400
        minage = pylons.config['packageMgr_package_min_age']
        pylons.config['packageMgr_package_min_age'] = 86400

        disk_threshold = pylons.config['health_disk_usage_percent_threshold']
        pylons.config['health_disk_usage_percent_threshold'] = 1

        pkgs = PackageMgr.packagePath()
        self.assertEquals(len(os.listdir(pkgs)), 2)
        time.sleep(40)
        self.assertEquals(len(os.listdir(pkgs)), 2)
        pylons.config['packageMgr_package_age'] = age
        pylons.config['packageMgr_package_min_age'] = minage
        pylons.config['health_disk_usage_percent_threshold'] = disk_threshold
    def test_noAgeGarbageCollection(self):
        #from agent.controllers.service import ServiceController
        from agent.tests.unit.test_util import createManifest
        serviceName = 'service4'
        manifestName = 'manifestb'
        try:
            createManifest(
                self,
                packages=[
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"
                ],
                service=serviceName,
                manifest=manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        self.app.delete(url(controller='manifest',
                            action='delete',
                            service=serviceName,
                            manifest=manifestName),
                        expect_errors=True)
        age = pylons.config['packageMgr_package_age']
        pylons.config['packageMgr_package_age'] = 86400
        pkgs = PackageMgr.packagePath()
        self.assertEquals(len(os.listdir(pkgs)), 4)
        time.sleep(40)
        self.assertEquals(len(os.listdir(pkgs)), 4)
        pylons.config['packageMgr_package_age'] = age
    def test_forceDeletePackages(self):
        #import pdb;pdb.set_trace();
        from agent.tests.unit.test_util import createManifest
        if os.name == 'posix':
            serviceName = 'service4'
            manifestName = 'manifestb'
            try:
                createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
            except Exception as ex:
                print 'exception thrown during mf %s' % str(ex)

            self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName, manifest = manifestName), expect_errors = True)
            age = pylons.config['packageMgr_package_age']
            pylons.config['packageMgr_package_age'] = 86400
            minage = pylons.config['packageMgr_package_min_age']
            pylons.config['packageMgr_package_min_age'] = 0.0
            #appGlobal = pylons.config['pylons.app_globals']
            #appGlobal.packageMgr.start()
            disk_threshold = pylons.config['health_disk_usage_percent_threshold']
            pylons.config['health_disk_usage_percent_threshold'] = 1
            pylons.config['health_disk_usage_gc_threshold'] = 1

            pkgs = PackageMgr.packagePath()
            self.assertEquals(len(os.listdir(pkgs)), 2)
            PackageMgr.forceCleanUpDownloadedPkgs()
            self.assertEquals(len(os.listdir(pkgs)), 0)
            pylons.config['packageMgr_package_age'] = age
            pylons.config['packageMgr_package_min_age'] = minage
            pylons.config['health_disk_usage_percent_threshold'] = disk_threshold
 def test_cleanupOrphanedPackages2(self):
     from agent.lib.utils import rchown
     from agent.tests.unit.test_util import createManifest
     serviceName = 'service2'
     manifestName = 'manifestA'
     serviceName1 = 'service3'
     try:
         createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"],
                                   service = serviceName, manifest = manifestName)
         createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"],
                                   service = serviceName1, manifest = manifestName)
     except Exception as ex:
         print 'exception thrown during mf %s' % str(ex)
     installedPkgPath = os.path.realpath(os.path.join(manifestutil.serviceRootPath() , serviceName, 'installed-packages'))
     installedPkgPath1 = os.path.realpath(os.path.join(manifestutil.serviceRootPath() , serviceName1, 'installed-packages'))
     uname = configutil.getAgentUser()
     uid, gid = utils.getUidGid(uname)
     rchown(installedPkgPath, uid, gid)
     rchown(installedPkgPath1, uid, gid)
     self.assertEquals(len(os.listdir(installedPkgPath)) , 1)
     self.assertEquals(len(os.listdir(installedPkgPath1)) , 1)
     self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName, manifest = manifestName), expect_errors = True)
     self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName1, manifest = manifestName), expect_errors = True)
     pylons.config['packageMgr_install_package_age'] = 0
     pylons.config['packageMgr_install_package_min_age'] = 0.0
     PackageMgr.cleanupOrphanedPackages()
     self.assertEquals(len(os.listdir(installedPkgPath)) , 0)
     self.assertEquals(len(os.listdir(installedPkgPath1)) , 0)
Exemple #10
0
    def test_post_manifest_inprogress_ok(self):
        service = 'foo'
        manifest = 'blahblah'
        try:
            path = ServiceController.servicePath(service)
            if os.path.exists(path):
                if os.name == 'nt':
                    cmd = 'rm -r %s' % path
                    LOG.debug("running command %s" % cmd)
                    os.system(cmd)
                else:
                    shutil.rmtree(path)
            path = ServiceController.manifestPath(service)
            os.makedirs(path)
            path = ServiceController.installedPkgPath(service)
            os.makedirs(path)
            inProgressPath = ManifestCreate.inProgress(ManifestController.manifestPath(service, manifest))
            os.makedirs(inProgressPath)
            path = ServiceController.downloadedPkgPath(service)
            os.makedirs(path)
        except Exception as excep:
            LOG.warning('got an OS Exception - %s' % str(excep))

        createManifest(self, ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus"], manifest = 'blahblah', createDirs = False)
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'blahblah'), 'pkgA')))
Exemple #11
0
    def testDelete2(self):
        createManifest(self)

        # need to change the owner of the service dir to be cronus

        servicePath = ServiceController.servicePath('foo')
        if (not os.name == 'nt'):
            import pwd
            uname = pylons.config['agent_user_account']
            uid = pwd.getpwnam(uname).pw_uid
            gid = pwd.getpwnam(uname).pw_gid
            rchown(servicePath, uid, gid)

        response = self.app.delete(
            url(controller='service', service='foo', action='delete'))
        assert response.status_int == 200, "HTTP response != 200"

        body = json.loads(response.body)
        tm = time.time()
        while (tm + 5 > time.time()):
            response = self.app.get(body['status'], expect_errors=True)
            LOG.debug('*************  Status response body = ' + response.body)
            body = json.loads(response.body)
            if (body['progress'] == 100):
                break

        assert not os.path.isdir(ServiceController.servicePath('foo'))
    def test_getAllSymLinks(self):
        #import pdb;
        #pdb.set_trace()
        serviceName = '.sbe.appService.SI1'
        manifestName = 'manifestA'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf'

        symLinks = manifestutil.getAllSymLinks(serviceName)
        """ return all the symlinks from manifests to packages for a given service"""
        LOG.debug('calling getAllSymLinks')
        linkedPaths = []
        installedPkgPath = os.path.join(ServiceController.servicePath(serviceName), 'installed-packages')
        pathToPkgA = os.path.join(installedPkgPath, 'pkgA')
        pathToPkgA120 = os.path.join(pathToPkgA, '1.2.0.unix')
        pathToPkgB = os.path.join(installedPkgPath, 'pkgB')
        pathToPkgB060 = os.path.join(pathToPkgB, '0.6.0.unix')

        bitmap = 0
        for path in symLinks:
            if path.find(pathToPkgA120) >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 1
            elif path.find(pathToPkgB060) >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 2
        self.assertEquals(3, bitmap)
    def __test_garbageCollection(self):
        from agent.tests.unit.test_util import createManifest
        serviceName = 'service3'
        manifestName = 'manifestA'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName, manifest = manifestName), expect_errors = True)


        age = pylons.config['packageMgr_package_age']
        pylons.config['packageMgr_package_age'] = 10
        pkgs = PackageMgr.packagePath()
        self.assertEquals(len(os.listdir(pkgs)), 2)
        appGlobal = pylons.config['pylons.app_globals']
        appGlobal.packageMgr.start()
        time.sleep(80)
        self.assertEquals(len(os.listdir(pkgs)), 0)
        pylons.config['packageMgr_package_age'] = age
        self.assertEquals(pylons.config['packageMgr_package_age'], age)
        appGlobal.packageMgr.stop()
        time.sleep(20)
Exemple #14
0
    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'
Exemple #15
0
    def test_getAllSymLinks(self):
        #import pdb;
        #pdb.set_trace()
        serviceName = '.sbe.appService.SI1'
        manifestName = 'manifestA'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf'

        symLinks = ManifestController.getAllSymLinks(serviceName)
        """ return all the symlinks from manifests to packages for a given service"""
        LOG.debug('calling getAllSymLinks')
        #serviceName = '.sbe.appService.SI1'
        linkedPaths = []
        #pdb.set_trace()
        #manPath = '/ebay/srengarajan/e2e/local-deploy/service_nodes/.sbe.appService.SI1/manifests'
        installedPkgPath = os.path.join(ServiceController.servicePath(serviceName), 'installed-packages')
        pathToPkgA = os.path.join(installedPkgPath, 'pkgA')
        pathToPkgA120 = os.path.join(pathToPkgA, '1.2.0.unix')
        pathToPkgB = os.path.join(installedPkgPath, 'pkgB')
        pathToPkgB060 = os.path.join(pathToPkgB, '0.6.0.unix')

        bitmap = 0
        for path in symLinks:
            if path.find(pathToPkgA120) >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 1
            elif path.find(pathToPkgB060) >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 2
        self.assertEquals(3, bitmap)
Exemple #16
0
    def test_post2(self):
        # successful post
        createManifest(self)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'bar'), 'perlserver')))
Exemple #17
0
 def test_cleanupOrphanedPackages2(self):
     from agent.lib.utils import rchown
     from agent.controllers.service import ServiceController
     from agent.controllers.manifest import ManifestController
     from agent.tests.unit.test_util import createManifest
     if os.name == 'nt':
         pass
     else:
         serviceName = 'service2'
         manifestName = 'manifestA'
         serviceName1 = 'service3'
         try:
             createManifest(
                 self,
                 packages=[
                     "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"
                 ],
                 service=serviceName,
                 manifest=manifestName)
             createManifest(
                 self,
                 packages=[
                     "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"
                 ],
                 service=serviceName1,
                 manifest=manifestName)
         except Exception as ex:
             print 'exception thrown during mf %s' % str(ex)
         installedPkgPath = os.path.realpath(
             os.path.join(ServiceController.serviceRootPath(), serviceName,
                          'installed-packages'))
         installedPkgPath1 = os.path.realpath(
             os.path.join(ServiceController.serviceRootPath(), serviceName1,
                          'installed-packages'))
         if (not os.name == 'nt'):
             import pwd
             uname = pylons.config['agent_user_account']
             uid = pwd.getpwnam(uname).pw_uid
             gid = pwd.getpwnam(uname).pw_gid
             rchown(installedPkgPath, uid, gid)
             rchown(installedPkgPath1, uid, gid)
         self.assertEquals(len(os.listdir(installedPkgPath)), 1)
         self.assertEquals(len(os.listdir(installedPkgPath1)), 1)
         self.app.delete(url(controller='manifest',
                             action='delete',
                             service=serviceName,
                             manifest=manifestName),
                         expect_errors=True)
         self.app.delete(url(controller='manifest',
                             action='delete',
                             service=serviceName1,
                             manifest=manifestName),
                         expect_errors=True)
         pylons.config['packageMgr_install_package_age'] = 0
         pylons.config['packageMgr_install_package_min_age'] = 0.0
         PackageUtil.cleanupOrphanedPackages()
         self.assertEquals(len(os.listdir(installedPkgPath)), 0)
         self.assertEquals(len(os.listdir(installedPkgPath1)), 0)
 def testUpdateServiceMetaFileLocal(self):
     keys = ['hwPath', 'serverAddress']
     values = manifestutil.readJsonServiceMeta('foo', keys)
     assert values.get('hwPath') == values.get('serverAddress') == None
     createManifest(self, manifest = 'bar', service = 'foo')
     manifestutil.updateServiceMetaFile('foo', {'hwPath':'/env/pool/instance', 'serverAddress':'state.vip'})
     assert os.path.exists(manifestutil.serviceMetadataPath('foo'))
     values = manifestutil.readJsonServiceMeta('foo', keys)
     assert values.get('hwPath') == '/env/pool/instance'
     assert values.get('serverAddress') == 'state.vip'
     manifestutil.updateServiceMetaFile('foo', {'hwPath':None})
     values = manifestutil.readJsonServiceMeta('foo', keys)
     assert values.get('hwPath') is None
     assert values.get('serverAddress') == 'state.vip'
    def test_post3_pkg_already_installed(self):
        createManifest(self)

        # now lets remove the manifest path
        path = os.path.join(manifestutil.manifestPath('foo', 'bar'))
        shutil.rmtree(path)

        # now create the manifest again
        createManifest(self)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(manifestutil.manifestPath('foo', 'bar'), 'perlserver')))
    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_delete(self):
        createManifest(self)

        response = self.app.delete(url(controller = 'manifest', action = 'delete', service = "foo", manifest = "bar"),
                                   expect_errors = True)
        print '*************** = ' + response.body
        self.assertEquals(200, response.status_int)

        for _ in range(10):
            if not os.path.isdir(manifestutil.manifestPath('foo', 'bar')):
                break
            else:
                time.sleep(0.1)

        self.assertFalse(os.path.isdir(manifestutil.manifestPath('foo', 'bar')))
Exemple #22
0
    def test_delete(self):
        createManifest(self)

        response = self.app.delete(url(controller = 'manifest', action = 'delete', service = "foo", manifest = "bar"),
                                   expect_errors = True)
        print '*************** = ' + response.body
        self.assertEquals(200, response.status_int)

        for _ in range(10):
            if not os.path.isdir(ManifestController.manifestPath('foo', 'bar')):
                break
            else:
                time.sleep(0.1)

        self.assertFalse(os.path.isdir(ManifestController.manifestPath('foo', 'bar')))
Exemple #23
0
    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_delete_active_manifest(self):
        createManifest(self)

        self.assertTrue(os.path.isdir(ServiceController.manifestPath('foo')))
        currentPath = os.getcwd()
        os.chdir(ServiceController.manifestPath('foo'))
        manifestPath = 'bar' #ManifestController.manifestPath('foo', 'bar'); use short manifest name instead of full path
        symlink(manifestPath, 'active')
        os.chdir(currentPath)

        response = self.app.delete(url(controller = 'manifest', action = 'delete', service = "foo", manifest = "bar"),
                                   expect_errors = True)
        self.assertEquals(500, response.status_int)

        body = json.loads(response.body)
        self.assertEquals(Errors.MANIFEST_DELETING_ACTIVE_MANIFEST, body['error'])
Exemple #25
0
    def test_delete_active_manifest(self):
        createManifest(self)

        self.assertTrue(os.path.isdir(ServiceController.manifestPath('foo')))
        currentPath = os.getcwd()
        os.chdir(ServiceController.manifestPath('foo'))
        manifestPath = 'bar' #ManifestController.manifestPath('foo', 'bar'); use short manifest name instead of full path
        symlink(manifestPath, 'active')
        os.chdir(currentPath)

        response = self.app.delete(url(controller = 'manifest', action = 'delete', service = "foo", manifest = "bar"),
                                   expect_errors = True)
        self.assertEquals(500, response.status_int)

        body = json.loads(response.body)
        self.assertEquals(Errors.MANIFEST_DELETING_ACTIVE_MANIFEST, body['error'])
Exemple #26
0
    def test_post3_already_installed_manifest(self):
        createManifest(self)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'bar'), 'perlserver')))


        body = json.dumps({'package' : ['http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus']})
        response = self.app.post(url(controller = 'manifest', action = 'post', service = "foo", manifest = "bar"),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body, expect_errors = True)
        self.assertEquals(201, response.status_int, 'Manifest Post assert')
        body = json.loads(response.body)
        assert response.status_int == 201, 'Manifest Post assert'
    def test_post3_already_installed_manifest(self):
        createManifest(self)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(manifestutil.manifestPath('foo', 'bar'), 'perlserver')))


        body = json.dumps({'package' : ['http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus']})
        response = self.app.post(url(controller = 'manifest', action = 'post', service = "foo", manifest = "bar"),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body, expect_errors = True)
        self.assertEquals(201, response.status_int, 'Manifest Post assert')
        body = json.loads(response.body)
        assert response.status_int == 201, 'Manifest Post assert'
 def test_get_installed_pkgs_filter_inprogress(self):
     from agent.lib.package import PackageUtil
     serviceName = '.sbe.appService.SI1'
     manifestName = 'manifestA'
     try:
         createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                               "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                               service = serviceName, manifest = manifestName)
     except Exception as ex:
         print 'exception thrown during mf'
     installed_pkg_path = ServiceController.installedPkgPath(serviceName)
     installed_packages = PackageUtil.getAllInstalledPackages(installed_pkg_path)
     self.assertEquals(2, len(installed_packages))
     for path in installed_packages:
         os.mkdir(path + '.inprogress')
     installed_packages = PackageUtil.getAllInstalledPackages(installed_pkg_path)
     self.assertEquals(2, len(installed_packages))
Exemple #29
0
 def test_get_installed_pkgs_filter_inprogress(self):
     from agent.lib.package import PackageUtil
     serviceName = '.sbe.appService.SI1'
     manifestName = 'manifestA'
     try:
         createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                               "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                               service = serviceName, manifest = manifestName)
     except Exception as ex:
         print 'exception thrown during mf'
     installed_pkg_path = ServiceController.installedPkgPath(serviceName)
     installed_packages = PackageUtil.getAllInstalledPackages(installed_pkg_path)
     self.assertEquals(2, len(installed_packages))
     for path in installed_packages:
         os.mkdir(path + '.inprogress')
     installed_packages = PackageUtil.getAllInstalledPackages(installed_pkg_path)
     self.assertEquals(2, len(installed_packages))
Exemple #30
0
 def testUpdateServiceMetaFileLocal(self):
     keys = ['hwPath', 'serverAddress']
     values = manifestutil.readJsonServiceMeta('foo', keys)
     assert values.get('hwPath') == values.get('serverAddress') == None
     createManifest(self, manifest='bar', service='foo')
     manifestutil.updateServiceMetaFile('foo', {
         'hwPath': '/env/pool/instance',
         'serverAddress': 'state.vip'
     })
     assert os.path.exists(manifestutil.serviceMetadataPath('foo'))
     values = manifestutil.readJsonServiceMeta('foo', keys)
     assert values.get('hwPath') == '/env/pool/instance'
     assert values.get('serverAddress') == 'state.vip'
     manifestutil.updateServiceMetaFile('foo', {'hwPath': None})
     values = manifestutil.readJsonServiceMeta('foo', keys)
     assert values.get('hwPath') is None
     assert values.get('serverAddress') == 'state.vip'
    def test_getAllInstalledPackages(self):
        from agent.tests.unit.test_util import createManifest

        serviceName = 'service1'
        manifestName = 'manifestA'

        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)

        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)
        time.sleep(2)
        installedPkgPath = os.path.join(manifestutil.servicePath(serviceName), 'installed-packages')
        pkgs = PackageUtil.getAllInstalledPackages(installedPkgPath)
        self.assertEquals(pkgs.__len__(), 2)
Exemple #32
0
    def test_package_reuse(self):
        createManifest(self)
        body = json.dumps({'package' : ['/packages/perlserver']})
        body = self.app.post(url(controller = 'manifest', action = 'post', service = "foo", manifest = "baz"),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body, expect_errors = True)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'bar'), 'perlserver')))

        for _ in range(10):
            if islink(os.path.join(ManifestController.manifestPath('foo', 'baz'), 'perlserver')):
                break
            time.sleep(1)

        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'baz'), 'perlserver')))
    def test_package_reuse(self):
        createManifest(self)
        body = json.dumps({'package' : ['/packages/perlserver']})
        body = self.app.post(url(controller = 'manifest', action = 'post', service = "foo", manifest = "baz"),
                                 headers = {'Content-Type' : 'application/json'},
                                 params = body, expect_errors = True)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(manifestutil.manifestPath('foo', 'bar'), 'perlserver')))

        for _ in range(10):
            if islink(os.path.join(manifestutil.manifestPath('foo', 'baz'), 'perlserver')):
                break
            time.sleep(1)

        self.assertTrue(islink(os.path.join(manifestutil.manifestPath('foo', 'baz'), 'perlserver')))
Exemple #34
0
    def test_cleanupOrphanedPackages(self):
        from agent.lib.utils import rchown
        from agent.controllers.service import ServiceController
        from agent.controllers.manifest import ManifestController
        from agent.tests.unit.test_util import createManifest
        if os.name == 'nt':
            pass
        else:
            serviceName = 'service2'
            manifestName = 'manifestA'
            try:
                createManifest(
                    self,
                    packages=[
                        "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"
                    ],
                    service=serviceName,
                    manifest=manifestName)
            except Exception as ex:
                print 'exception thrown during mf %s' % str(ex)
            installedPkgPath = os.path.realpath(
                os.path.join(ServiceController.serviceRootPath(), serviceName,
                             'installed-packages'))

            if (not os.name == 'nt'):
                import pwd
                uname = pylons.config['agent_user_account']
                uid = pwd.getpwnam(uname).pw_uid
                gid = pwd.getpwnam(uname).pw_gid
                rchown(installedPkgPath, uid, gid)
            #installedPkgPath = os.path.realpath(os.path.join('/ebay/srengarajan/e2e/local-deploy/service_nodes/' , '.sbe.appService.SI1', 'installed-packages' ))
            #pkgs = os.listdir('C:\\srini\\projects\\gc\\agent\\trunk')

            self.assertEquals(len(os.listdir(installedPkgPath)), 1)
            self.app.delete(url(controller='manifest',
                                action='delete',
                                service=serviceName,
                                manifest=manifestName),
                            expect_errors=True)
            pylons.config['packageMgr_install_package_age'] = 0
            pylons.config['packageMgr_install_package_min_age'] = 0.0
            time.sleep(1)
            PackageUtil.cleanupOrphanedPackages()
            self.assertEquals(len(os.listdir(installedPkgPath)), 0)
    def test_cleanUpAllInstalledPackages(self):
        from agent.lib.utils import rchown
        from agent.tests.unit.test_util import createManifest
        #import pdb;pdb.set_trace();
        serviceName = 'service3'
        manifestName = 'manifestB'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        installedPkgPath = os.path.realpath(os.path.join(manifestutil.serviceRootPath() , serviceName, 'installed-packages'))

        uname = configutil.getAgentUser()
        uid, gid = utils.getUidGid(uname)
        rchown(installedPkgPath, uid, gid)


        pkgs = []
        for pkg in os.listdir(installedPkgPath):
            pkgs.append(os.path.join(installedPkgPath, pkg))

        pkgVers = []
        for pkg in pkgs:
            for pkgVer in os.listdir(pkg):
                pkgVers.append(os.path.join(pkg, pkgVer))

        self.assertEquals(len(os.listdir(installedPkgPath)) , 1)

        self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName, manifest = manifestName), expect_errors = True)
        #import pdb; pdb.set_trace();
        symLinks = [] #ManifestController.getAllSymLinks(serviceName)
        orphans = set(pkgVers) - set(symLinks)
        age = pylons.config['packageMgr_install_package_age']
        minage = pylons.config['packageMgr_install_package_min_age']
        pylons.config['packageMgr_install_package_age'] = 0
        pylons.config['packageMgr_install_package_min_age'] = 0.0
        self.assertEquals(len(os.listdir(installedPkgPath)) , 1)
        PackageUtil.cleanupInstalledPkgs(installedPkgPath, orphans)
        #PackageUtil.cleanUpInstalledPkgs(installedPkgPath, orphans)
        self.assertEquals(len(os.listdir(installedPkgPath)) , 0)
        pylons.config['packageMgr_install_package_age'] = age
        pylons.config['packageMgr_install_package_min_age'] = minage
    def test_inprogress_pkg_download(self):
        service = 'foo'
        try:
            path = ServiceController.manifestPath(service)
            os.makedirs(path)
            path = ServiceController.installedPkgPath(service)
            os.makedirs(path)
            path = ServiceController.downloadedPkgPath(service)
            os.makedirs(path)
            inprogressPath = os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus.inprogress')
            inprogressFile = open(inprogressPath, 'w')
            inprogressFile.write('somegarbage')
            inprogressFile.close()
        except Exception as excep:
            LOG.warning('got an OS Exception - %s' % str(excep))

        createManifest(self)
        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(islink(os.path.join(manifestutil.manifestPath('foo', 'bar'), 'perlserver')))
Exemple #37
0
    def test_inprogress_pkg_download(self):
        service = 'foo'
        try:
            path = ServiceController.manifestPath(service)
            os.makedirs(path)
            path = ServiceController.installedPkgPath(service)
            os.makedirs(path)
            path = ServiceController.downloadedPkgPath(service)
            os.makedirs(path)
            inprogressPath = os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus.inprogress')
            inprogressFile = open(inprogressPath, 'w')
            inprogressFile.write('somegarbage')
            inprogressFile.close()
        except Exception as excep:
            LOG.warning('got an OS Exception - %s' % str(excep))

        createManifest(self)
        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'bar'), 'perlserver')))
Exemple #38
0
    def test_post3_pkg_already_installed(self):
        createManifest(self)

        # now lets remove the manifest path
        path = os.path.join(ManifestController.manifestPath('foo', 'bar'))
        if os.name == 'nt':
            cmd = 'rm -r %s' % path
            LOG.debug("running command %s" % cmd)
            os.system(cmd)
        else:
            shutil.rmtree(path)

        # now create the manifest again
        createManifest(self)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'perlserver-1.0.0.unix.cronus')))
        self.assertTrue(os.path.exists(os.path.join(ServiceController.installedPkgPath('foo'), 'perlserver', '1.0.0.unix',
                                           'cronus', 'scripts', 'activate')))
        self.assertTrue(islink(os.path.join(ManifestController.manifestPath('foo', 'bar'), 'perlserver')))
Exemple #39
0
    def test_forceDeletePackages(self):
        #import pdb;pdb.set_trace();
        from agent.tests.unit.test_util import createManifest
        if os.name == 'posix':
            serviceName = 'service4'
            manifestName = 'manifestb'
            try:
                createManifest(
                    self,
                    packages=[
                        "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                        "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"
                    ],
                    service=serviceName,
                    manifest=manifestName)
            except Exception as ex:
                print 'exception thrown during mf %s' % str(ex)

            self.app.delete(url(controller='manifest',
                                action='delete',
                                service=serviceName,
                                manifest=manifestName),
                            expect_errors=True)
            age = pylons.config['packageMgr_package_age']
            pylons.config['packageMgr_package_age'] = 86400
            minage = pylons.config['packageMgr_package_min_age']
            pylons.config['packageMgr_package_min_age'] = 0.0
            #appGlobal = pylons.config['pylons.app_globals']
            #appGlobal.packageMgr.start()
            disk_threshold = pylons.config[
                'health_disk_usage_percent_threshold']
            pylons.config['health_disk_usage_percent_threshold'] = 1
            pylons.config['health_disk_usage_gc_threshold'] = 1

            pkgs = PackageMgr.packagePath()
            self.assertEquals(len(os.listdir(pkgs)), 4)
            PackageUtil.forceCleanUpDownloadedPkgs()
            self.assertEquals(len(os.listdir(pkgs)), 0)
            pylons.config['packageMgr_package_age'] = age
            pylons.config['packageMgr_package_min_age'] = minage
            pylons.config[
                'health_disk_usage_percent_threshold'] = disk_threshold
    def test_noAgeGarbageCollection(self):
        #from agent.controllers.service import ServiceController
        from agent.tests.unit.test_util import createManifest
        serviceName = 'service4'
        manifestName = 'manifestb'
        try:
            createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                                  "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                                  service = serviceName, manifest = manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        self.app.delete(url(controller = 'manifest', action = 'delete', service = serviceName, manifest = manifestName), expect_errors = True)
        age = pylons.config['packageMgr_package_age']
        pylons.config['packageMgr_package_age'] = 86400
        pkgs = PackageMgr.packagePath()
        self.assertEquals(len(os.listdir(pkgs)), 2)
        time.sleep(40)
        self.assertEquals(len(os.listdir(pkgs)), 2)
        pylons.config['packageMgr_package_age'] = age
    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
Exemple #42
0
    def test_getPackagePaths(self):
        serviceName = 'service1'
        manifestName = 'manifestA'
        createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                              "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                              service = serviceName, manifest = manifestName)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'pkgA-1.2.0.unix.cronus')))

        packagePaths = ManifestController.getPackagePaths(serviceName, manifestName);
        print ">>>>>>>>>>>>" + str(packagePaths)
        self.assertTrue(len(packagePaths) >= 2)
        bitmap = 0
        for path in packagePaths:
            if path.find("pkgA") >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 1
            elif path.find("pkgB") >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 2
        self.assertEquals(3, bitmap)
    def test_getPackagePaths(self):
        serviceName = 'service1'
        manifestName = 'manifestA'
        createManifest(self, packages = ["http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                              "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"],
                              service = serviceName, manifest = manifestName)

        self.assertTrue(os.path.exists(os.path.join(PackageMgr.packagePath(), 'pkgA-1.2.0.unix.cronus')))

        packagePaths = manifestutil.packagePaths(serviceName, manifestName);
        print ">>>>>>>>>>>>" + str(packagePaths)
        self.assertTrue(len(packagePaths) >= 2)
        bitmap = 0
        for path in packagePaths:
            if path.find("pkgA") >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 1
            elif path.find("pkgB") >= 0:
                self.assertTrue(os.path.isdir(path))
                bitmap |= 2
        self.assertEquals(3, bitmap)
Exemple #44
0
    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
Exemple #45
0
    def test_package_min_age_during_forceDelete(self):
        #import pdb;pdb.set_trace();
        from agent.tests.unit.test_util import createManifest
        serviceName = 'service5'
        manifestName = 'manifestb'
        try:
            createManifest(
                self,
                packages=[
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"
                ],
                service=serviceName,
                manifest=manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        self.app.delete(url(controller='manifest',
                            action='delete',
                            service=serviceName,
                            manifest=manifestName),
                        expect_errors=True)
        age = pylons.config['packageMgr_package_age']
        pylons.config['packageMgr_package_age'] = 86400
        minage = pylons.config['packageMgr_package_min_age']
        pylons.config['packageMgr_package_min_age'] = 86400

        disk_threshold = pylons.config['health_disk_usage_percent_threshold']
        pylons.config['health_disk_usage_percent_threshold'] = 1

        pkgs = PackageMgr.packagePath()
        self.assertEquals(len(os.listdir(pkgs)), 4)
        time.sleep(40)
        self.assertEquals(len(os.listdir(pkgs)), 4)
        pylons.config['packageMgr_package_age'] = age
        pylons.config['packageMgr_package_min_age'] = minage
        pylons.config['health_disk_usage_percent_threshold'] = disk_threshold
Exemple #46
0
    def test_getAllInstalledPackages(self):
        from agent.tests.unit.test_util import createManifest
        from agent.controllers.service import ServiceController

        serviceName = 'service1'
        manifestName = 'manifestA'

        try:
            createManifest(
                self,
                packages=[
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgA-1.2.0.unix.cronus",
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/pkgB-0.6.0.unix.cronus"
                ],
                service=serviceName,
                manifest=manifestName)

        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)
        time.sleep(2)
        installedPkgPath = os.path.join(
            ServiceController.servicePath(serviceName), 'installed-packages')
        pkgs = PackageUtil.getAllInstalledPackages(installedPkgPath)
        self.assertEquals(pkgs.__len__(), 2)
    def testExpandService(self):
        createManifest(self, service='.fooenv.foopool.foo')
        response = self.app.get(url(controller='service', service='.fooenv.foopool', action='get'), expect_errors = True)

        body = json.loads(response.body)
        print "************** response = %s" % body

        assert body['progress'] == 100
        assert body['result']['manifest'] == ['bar']

        response = self.app.get(url(controller='service', service='.fooenv.foopool.foo', action='get'), expect_errors = True)

        body = json.loads(response.body)
        print "************** response = %s" % body

        assert body['progress'] == 100
        assert body['result']['manifest'] == ['bar']

        response = self.app.get(url(controller='service', service='.fooenv', action='get'), expect_errors = True)

        body = json.loads(response.body)
        print "************** response = %s" % body

        assert response.status_int == 500, "HTTP response != 500"
    def testDelete2(self):
        createManifest(self)

        # need to change the owner of the service dir to be cronus

        servicePath = ServiceController.servicePath('foo')
        uname = configutil.getAgentUser()
        uid, gid = utils.getUidGid(uname)
        rchown(servicePath, uid, gid)


        response = self.app.delete(url(controller='service', service='foo', action='delete'))
        assert response.status_int == 200, "HTTP response != 200"

        body = json.loads(response.body)
        tm = time.time()
        while (tm + 5 > time.time()):
            response = self.app.get(body['status'], expect_errors = True)
            LOG.debug ('*************  Status response body = ' + response.body)
            body = json.loads(response.body)
            if (body['progress'] == 100):
                break

        assert not os.path.isdir(ServiceController.servicePath('foo'))
Exemple #49
0
 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')
Exemple #50
0
    def test_cleanUpAllInstalledPackages(self):
        from agent.lib.utils import rchown
        from agent.controllers.service import ServiceController
        from agent.controllers.manifest import ManifestController
        from agent.tests.unit.test_util import createManifest
        #import pdb;pdb.set_trace();
        serviceName = 'service3'
        manifestName = 'manifestB'
        try:
            createManifest(
                self,
                packages=[
                    "http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus"
                ],
                service=serviceName,
                manifest=manifestName)
        except Exception as ex:
            print 'exception thrown during mf %s' % str(ex)

        installedPkgPath = os.path.realpath(
            os.path.join(ServiceController.serviceRootPath(), serviceName,
                         'installed-packages'))

        if (not os.name == 'nt'):
            import pwd
            uname = pylons.config['agent_user_account']
            uid = pwd.getpwnam(uname).pw_uid
            gid = pwd.getpwnam(uname).pw_gid
            rchown(installedPkgPath, uid, gid)

        #installedPkgPath = os.path.realpath(os.path.join('/ebay/srengarajan/e2e/local-deploy/service_nodes/' , '.sbe.appService.SI1', 'installed-packages' ))
        #pkgs = os.listdir('C:\\srini\\projects\\gc\\agent\\trunk')
        pkgs = []
        for pkg in os.listdir(installedPkgPath):
            pkgs.append(os.path.join(installedPkgPath, pkg))

        pkgVers = []
        for pkg in pkgs:
            for pkgVer in os.listdir(pkg):
                pkgVers.append(os.path.join(pkg, pkgVer))

        self.assertEquals(len(os.listdir(installedPkgPath)), 1)

        self.app.delete(url(controller='manifest',
                            action='delete',
                            service=serviceName,
                            manifest=manifestName),
                        expect_errors=True)
        #import pdb; pdb.set_trace();
        symLinks = []  #ManifestController.getAllSymLinks(serviceName)
        orphans = set(pkgVers) - set(symLinks)
        age = pylons.config['packageMgr_install_package_age']
        minage = pylons.config['packageMgr_install_package_min_age']
        pylons.config['packageMgr_install_package_age'] = 0
        pylons.config['packageMgr_install_package_min_age'] = 0.0
        self.assertEquals(len(os.listdir(installedPkgPath)), 1)
        PackageUtil.cleanupInstalledPkgs(installedPkgPath, orphans)
        #PackageUtil.cleanUpInstalledPkgs(installedPkgPath, orphans)
        self.assertEquals(len(os.listdir(installedPkgPath)), 0)
        pylons.config['packageMgr_install_package_age'] = age
        pylons.config['packageMgr_install_package_min_age'] = minage
Exemple #51
0
 def testGetServices(self):
     createManifest(self, manifest='bar', service='foo')
     assert 'foo' in manifestutil.getServices()
     assert manifestutil.servicePath('foo').endswith('foo')
    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"
Exemple #53
0
 def testPackagesInManifest(self):
     createManifest(self, manifest='bar', service='foo')
     print manifestutil.packagesInManifest('foo', 'bar')
     assert len(manifestutil.packagesInManifest('foo', 'bar')) > 0
Exemple #54
0
 def testActiveManifestPath(self):
     createManifest(self)
     activateManifest(self)
     assert manifestutil.activeManifestPath('foo').endswith('bar')
 def testActiveManifestPath(self):
     createManifest(self)
     activateManifest(self)
     assert manifestutil.activeManifestPath('foo').endswith('bar')
 def testPackagesInManifest(self):
     createManifest(self, manifest = 'bar', service = 'foo')
     print manifestutil.packagesInManifest('foo', 'bar')
     assert len(manifestutil.packagesInManifest('foo', 'bar')) > 0