Ejemplo n.º 1
0
    def _ProcessCatalogAndNotifyAdmins(cls, catalog, os_version):
        """Wrapper method to process a catalog and notify admin of changes.

    Args:
      catalog: models.AppleSUSCatalog object to process.
      os_version: str OS version like 10.5, 10.6, 10.7, etc.
    """
        catalog_plist = plist.ApplePlist(catalog.plist)
        try:
            catalog_plist.Parse()
        except plist.Error:
            logging.exception('Error parsing Apple Updates catalog: %s',
                              catalog.key().name())
            return

        new_products = cls._UpdateProductDataFromCatalog(catalog_plist)
        deprecated_products = cls._DeprecateOrphanedProducts()

        cls._NotifyAdminsOfCatalogSync(catalog, new_products,
                                       deprecated_products)

        # Regenerate the unstable catalog, including new updates but excluding
        # any that were previously manually disabled.
        applesus.GenerateAppleSUSCatalog(os_version, common.UNSTABLE)

        models.AdminAppleSUSProductLog.Log(new_products,
                                           'new for %s' % os_version)
        models.AdminAppleSUSProductLog.Log(deprecated_products,
                                           'deprecated for %s' % os_version)
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
    def testGenerateAppleSUSCatalogWhereUntouchedDoesNotExist(self):
        """Test GenerateAppleSUSCatalog() where untouched catalog does not exist."""
        os_version = 'foo-version'
        track = 'foo'

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

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

        self.mox.ReplayAll()
        catalog, new_plist = applesus.GenerateAppleSUSCatalog(
            os_version, track)
        self.assertEqual(None, catalog)
        self.assertEqual(None, new_plist)
        self.mox.VerifyAll()