commit 79591f49db4faec56a846ddf16a77004b8579ee7
Author: Michal Domonkos <mdomonko@redhat.com>
Date:   Thu Dec 15 16:23:10 2016 +0100

    Don't recommend makecache if just running. BZ 1369389
    
    Also includes any other commands that would result in all repos obeying
    metadata_expire such as "yum install" (depending on the actual value of
    metadata_expire_filter).

diff --git a/cli.py b/cli.py
index 54a2e81..862992b 100755
--- a/cli.py
+++ b/cli.py
@@ -450,11 +450,21 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
 
         if not ts_min:
             cacheReq = 'write'
-        elif warning and (time.time() - ts_max) > (60 * 60 * 24 * 14):
-            self.logger.warning(_("Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast"))
 
+        all_obey = True
         for repo in self.repos.sort():
             repo._metadata_cache_req = cacheReq
+            if repo._matchExpireFilter():
+                all_obey = False
+
+        if warning and ts_min and (time.time() - ts_max) > (60 * 60 * 24 * 14):
+            # The warning makes no sense if we're already running a command
+            # that requires current repodata across all repos (such as "yum
+            # makecache" or others, depending on metadata_expire_filter), so
+            # don't give it if that's the case.
+            if all_obey:
+                return
+            self.logger.warning(_("Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast"))
 
     def _shell_history_write(self):
         if not hasattr(self, '_shell_history_cmds'):
diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index c6bed82..0c63de3 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -1145,33 +1145,39 @@ Insufficient space in download directory %s
             self._metadataCurrent = False
         return self._metadataCurrent
 
-    def withinCacheAge(self, myfile, expiration_time, expire_req_filter=True):
-        """check if any file is older than a certain amount of time. Used for
-           the cachecookie and the mirrorlist
-           return True if w/i the expiration time limit
-           false if the time limit has expired
-
-           Additionally compare the file to age of the newest .repo or yum.conf
-           file. If any of them are newer then invalidate the cache
-           """
-
+    def _matchExpireFilter(self):
+        """Return whether cache_req matches metadata_expire_filter."""
         # Never/write means we just skip this...
-        if (expire_req_filter and hasattr(self, '_metadata_cache_req') and
-            self._metadata_cache_req.startswith("read-only:") and
-            self.metadata_expire_filter.startswith("read-only:")):
+        if (hasattr(self, '_metadata_cache_req') and
+                self._metadata_cache_req.startswith("read-only:") and
+                self.metadata_expire_filter.startswith("read-only:")):
 
             cache_filt = self.metadata_expire_filter[len("read-only:"):]
             cache_req  = self._metadata_cache_req[len("read-only:"):]
 
             if cache_filt == 'future':
                 assert cache_req in ('past', 'present', 'future')
-                expiration_time = -1
+                return True
             if cache_filt == 'present':
                 if cache_req in ('past', 'present'):
-                    expiration_time = -1
+                    return True
             if cache_filt == 'past':
                 if cache_req == 'past':
-                    expiration_time = -1
+                    return True
+        return False
+
+    def withinCacheAge(self, myfile, expiration_time, expire_req_filter=True):
+        """check if any file is older than a certain amount of time. Used for
+           the cachecookie and the mirrorlist
+           return True if w/i the expiration time limit
+           false if the time limit has expired
+
+           Additionally compare the file to age of the newest .repo or yum.conf
+           file. If any of them are newer then invalidate the cache
+           """
+
+        if expire_req_filter and self._matchExpireFilter():
+            expiration_time = -1
 
         # -1 is special and should never get refreshed
         if expiration_time == -1 and os.path.exists(myfile):
