Exemplo n.º 1
0
    def testGenerateAppleSUSCatalog(self):
        """Test GenerateAppleSUSCatalog()."""
        catalog_xml = self._GetTestData('applesus.sucatalog')
        track = 'testing'
        os_version = '10.6'

        product_one = self.mox.CreateMockAnything()
        product_one.product_id = 'ID1'
        product_two = self.mox.CreateMockAnything()
        product_two.product_id = 'ID3'
        products = [product_one, product_two]

        mock_catalog_obj = self.mox.CreateMockAnything()
        mock_catalog_obj.plist = catalog_xml
        mock_query = self.mox.CreateMockAnything()
        mock_new_catalog_obj = self.mox.CreateMockAnything()

        self.mox.StubOutWithMock(applesus.models.AppleSUSCatalog,
                                 'get_by_key_name')
        self.mox.StubOutWithMock(applesus.models, 'AppleSUSCatalog')
        self.mox.StubOutWithMock(applesus.models.AppleSUSProduct, 'AllActive')

        applesus.models.AppleSUSCatalog.get_by_key_name(
            '%s_untouched' % os_version).AndReturn(mock_catalog_obj)

        applesus.models.AppleSUSProduct.AllActive().AndReturn(mock_query)
        mock_query.filter('tracks =', track).AndReturn(products)

        mock_datetime = self.mox.CreateMockAnything()
        utcnow = datetime.datetime(2010, 9, 2, 19, 30, 21, 377827)
        now_str = '2010-09-02-19-30-21'
        mock_datetime.utcnow().AndReturn(utcnow)
        applesus.models.AppleSUSCatalog(
            key_name='backup_%s_%s_%s' %
            (os_version, track, now_str)).AndReturn(mock_new_catalog_obj)
        mock_new_catalog_obj.put().AndReturn(None)

        applesus.models.AppleSUSCatalog(
            key_name='%s_%s' %
            (os_version, track)).AndReturn(mock_new_catalog_obj)
        mock_new_catalog_obj.put().AndReturn(None)

        lock_name = 'lock_name'
        lock = datastore_locks.DatastoreLock(lock_name)
        lock.Acquire()

        self.mox.ReplayAll()
        _, new_plist = applesus.GenerateAppleSUSCatalog(os_version,
                                                        track,
                                                        mock_datetime,
                                                        catalog_lock=lock)
        self.assertTrue('ID1' in new_plist['Products'])
        self.assertTrue('ID2' not in new_plist['Products'])
        self.assertTrue('ID3' in new_plist['Products'])
        self.assertTrue('ID4' not in new_plist['Products'])
        self.mox.VerifyAll()

        self.assertFalse(gae_util.LockExists(lock_name))
Exemplo n.º 2
0
    def _DisplayMain(self):
        query = models.AppleSUSProduct.AllActive().order('-apple_mtime')
        products = []
        # NOTE(user): the following adds about 700ms onto the request, so we may
        #             want to pre-calculate this in a cron in the future.
        for p in gae_util.QueryIterator(query, step=100):
            if common.STABLE not in p.tracks:
                p.stable_promote_date = applesus.GetAutoPromoteDate(
                    common.STABLE, p)
            if common.TESTING not in p.tracks:
                p.testing_promote_date = applesus.GetAutoPromoteDate(
                    common.TESTING, p)
            products.append(p)

        catalogs = []
        for os_version in applesus.OS_VERSIONS:
            os_catalogs = {'os_version': os_version}
            for track in ['untouched'] + common.TRACKS:
                catalog_key = '%s_%s' % (os_version, track)
                c = models.AppleSUSCatalog.MemcacheWrappedGet(catalog_key)
                os_catalogs[track] = c.mtime if c else None
            catalogs.append(os_catalogs)

        catalogs_pending = {}
        for track in common.TRACKS:
            catalogs_pending[track] = False
            for os_version in applesus.OS_VERSIONS:
                lock_name = applesus.CatalogRegenerationLockName(
                    track, os_version)
                catalogs_pending[track] |= gae_util.LockExists(lock_name)

        install_counts, counts_mtime = models.ReportsCache.GetInstallCounts()
        data = {
            'catalogs':
            catalogs,
            'catalogs_pending':
            catalogs_pending,
            'products':
            products,
            'install_counts':
            install_counts,
            'install_counts_mtime':
            counts_mtime,
            'tracks':
            common.TRACKS,
            'auto_promote_enabled':
            settings.APPLE_AUTO_PROMOTE_ENABLED,
            'auto_promote_stable_weekday':
            calendar.day_name[settings.APPLE_AUTO_PROMOTE_STABLE_WEEKDAY],
            'unstable_grace_period_days':
            settings.APPLE_UNSTABLE_GRACE_PERIOD_DAYS,
            'testing_grace_period_days':
            settings.APPLE_TESTING_GRACE_PERIOD_DAYS,
            'report_type':
            'apple_applesus'
        }
        self.Render('applesus_list.html', data)