Exemplo n.º 1
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'))
Exemplo n.º 2
0
    def __deleteServices(self):
        """ delete all services except agent itself; clear all manifests in 'agent' itself except current active"""
        self._updateStatus(progress=60)
        services = ServiceController.getServices()

        #kill all service threads
        self._threadMgr.stopServiceThread()

        #remove folder
        for service in services:
            if 'agent' == service:
                self.__delAllExceptActiveManifests(service)
                continue

            path = ServiceController.servicePath(service)
            # retry service cleanup
            for _ in range(3):
                if not os.path.exists(path):
                    break
                ServiceDelete.deleteFolderContents(path)
                # sleep here a bit to ensure delete is complete
                time.sleep(1)

            if os.path.exists(path):
                msg = 'Could not delete service %s completely even after 3 retries.' % service
                LOG.error(msg)
                raise Exception(msg)

        self._updateStatus(progress=90)
Exemplo n.º 3
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 = 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)
Exemplo n.º 4
0
    def __deleteServices(self):
        """ delete all services except agent itself; clear all manifests in 'agent' itself except current active"""
        self._updateStatus(progress = 60)
        services = ServiceController.getServices()

        #kill all service threads
        self._threadMgr.stopServiceThread()

        #remove folder
        for service in services:
            if 'agent' == service:
                self.__delAllExceptActiveManifests(service)
                continue

            path = ServiceController.servicePath(service)
            # retry service cleanup
            for _ in range(3):
                if not os.path.exists(path):
                    break
                ServiceDelete.deleteFolderContents(path)
                # sleep here a bit to ensure delete is complete
                time.sleep(1)

            if os.path.exists(path):
                msg = 'Could not delete service %s completely even after 3 retries.' % service
                LOG.error(msg)
                raise Exception(msg)

        self._updateStatus(progress = 90)
Exemplo n.º 5
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)
Exemplo n.º 6
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')))
Exemplo n.º 7
0
def createManifest(testController,
                   packages = ['http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus'],
                   manifest = 'bar', service = 'foo', createDirs = True):
    try:
        path = ServiceController.servicePath(service)
        os.makedirs(os.path.join(path, 'manifests'))
        os.makedirs(os.path.join(path, 'modules'))
        os.makedirs(os.path.join(path, '.appdata'))
        os.makedirs(os.path.join(path, '.data'))
        
        path = ServiceController.installedPkgPath(service)
        os.makedirs(path)
    except Exception as excep:
        LOG.warning('got an OS Exception - %s' % str(excep))


    try:
        for pkgUri in packages:
            mockDownloadPkg(pkgUri)
#             pkgDict = PackageUtil.parseUri(pkgUri)
#             pkgName = pkgDict['package']
#             localPkgRoot = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'packages')
#             src = os.path.join(localPkgRoot, pkgName)
#             shutil.copy(src, pkgDict['packagePath'])
#             propPkgName = pkgDict['propName']
#             propSrc = os.path.join(localPkgRoot, propPkgName)
#             shutil.copy(propSrc, pkgDict['propPath'])
    except Exception as excep:
        LOG.warning('got an OS Exception - %s' % str(excep))
        
    body = json.dumps({'package' : packages})
    response = testController.app.post(url(controller = 'manifest', action = 'post', service = service, manifest = manifest),
                             headers = {'Content-Type' : 'application/json'},
                             params = body)
    assert response.status_int == 200, 'Manifest Post assert'

    LOG.debug('response body = %s' % response.body)

    body = json.loads(response.body)

    # wait until the status is done
    tm = time.time()
    now = tm
    while (tm + 120 > now):
        response = testController.app.get(body['status'])
        body = json.loads(response.body)

        LOG.debug("createManifest  ********** progress = %s" % body['progress'])
        if (int(body['progress']) == 100):
            break
        time.sleep(0.1)
        now = time.time()

    assert tm + 120 >= now, 'Create manifest timed out'
    LOG.debug('status = ' + str(response.status_int))
    assert response.status_int == 200, "HTTP response != 200"
    LOG.debug ('Status response body = %s' % str(body))
    assert int(body['progress']) == 100
Exemplo n.º 8
0
    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'))
Exemplo n.º 9
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)
Exemplo n.º 10
0
def createManifest(
        testController,
        packages=[
            'http://github.com/yubin154/cronusagent/blob/master/agent/agent/tests/unit/packages/perlserver-1.0.0.unix.cronus'
        ],
        manifest='bar',
        service='foo',
        createDirs=True):
    try:
        path = ServiceController.servicePath(service)
        os.makedirs(os.path.join(path, 'manifests'))
        os.makedirs(os.path.join(path, 'modules'))
        os.makedirs(os.path.join(path, '.appdata'))
        os.makedirs(os.path.join(path, '.data'))

        path = ServiceController.installedPkgPath(service)
        os.makedirs(path)
    except Exception as excep:
        LOG.warning('got an OS Exception - %s' % str(excep))

    try:
        for pkgUri in packages:
            pkgDict = PackageUtil.parseUri(pkgUri)
            pkgName = pkgDict['package']
            localPkgRoot = os.path.join(
                os.path.dirname(os.path.realpath(__file__)), 'packages')
            src = os.path.join(localPkgRoot, pkgName)
            shutil.copy(src, pkgDict['packagePath'])
            propPkgName = pkgDict['propName']
            propSrc = os.path.join(localPkgRoot, propPkgName)
            shutil.copy(propSrc, pkgDict['propPath'])
    except Exception as excep:
        LOG.warning('got an OS Exception - %s' % str(excep))

    body = json.dumps({'package': packages})
    response = testController.app.post(
        url(controller='manifest',
            action='post',
            service=service,
            manifest=manifest),
        headers={'Content-Type': 'application/json'},
        params=body)
    assert response.status_int == 200, 'Manifest Post assert'

    LOG.debug('response body = %s' % response.body)

    body = json.loads(response.body)

    # wait until the status is done
    tm = time.time()
    now = tm
    while (tm + 120 > now):
        response = testController.app.get(body['status'])
        body = json.loads(response.body)

        LOG.debug("createManifest  ********** progress = %s" %
                  body['progress'])
        if (int(body['progress']) == 100):
            break
        time.sleep(0.1)
        now = time.time()

    assert tm + 120 >= now, 'Create manifest timed out'
    LOG.debug('status = ' + str(response.status_int))
    assert response.status_int == 200, "HTTP response != 200"
    LOG.debug('Status response body = %s' % str(body))
    assert int(body['progress']) == 100