From fdb7d66cf3e25d2cbfd36b58ba4b221260c654d4 Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: May 02 2020 20:00:42 +0000
Subject: [PATCH 1/3] Stop hardcoding AMIs for us-east-2 and eu-west-3


This shouldn't be needed any longer.

Fixes: https://pagure.io/releng/issue/9196

---

diff --git a/alt.fedoraproject.org/build/fedimg_vars.py b/alt.fedoraproject.org/build/fedimg_vars.py
index 9c041e5..c5b63b4 100755
--- a/alt.fedoraproject.org/build/fedimg_vars.py
+++ b/alt.fedoraproject.org/build/fedimg_vars.py
@@ -90,14 +90,6 @@ def collect(release):
                     region = upload['destination']
                     results[name][region] = ami
 
-    # Hardcode AMIs for regions eu-west-3 and us-east-2 for F28 cloud-base
-    # This is because fedmsg topic 'org.fedoraproject.prod.fedimg.image.upload'
-    # doesn't have AMI information for these two regions.
-    results['HVM_base_AMI']['us-east-2'] = 'ami-00b43acad6bfbc73a'
-    results['HVM_base_AMI']['eu-west-3'] = 'ami-04abc80987c29d6fb'
-    results['GP2_HVM_base_AMI']['us-east-2'] = 'ami-08d6e766d9302926c'
-    results['GP2_HVM_base_AMI']['eu-west-3'] = 'ami-0e37bf70f74c79410'
-
     shelf['timestamp'] = datetime.utcnow()
     shelf['collected'] = results
     shelf.close()

From b8d446ce572fc6afd25f34cb5e44545eb8d1544b Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: May 02 2020 20:56:38 +0000
Subject: [PATCH 2/3] fedimg: remove eu-west-3


fedimg doesn't properly upload eu-west-3 images so just remove them
from the website for now.

---

diff --git a/build.d/globalvar.py b/build.d/globalvar.py
index f4f38c0..6d44723 100644
--- a/build.d/globalvar.py
+++ b/build.d/globalvar.py
@@ -336,7 +336,8 @@ EC2_regions = [
     region(u'EU West (Ireland)',               u'Ireland',      u'eu-west-1'),
     region(u'EU Central (Frankfurt)',          u'Frankfurt',    u'eu-central-1'),
     region(u'EU West (London)',                u'London',       u'eu-west-2'),
-    region(u'EU West (Paris)',                 u'Paris',        u'eu-west-3'),
+# fedimg fails to upload to eu-west-3 for now
+#   region(u'EU West (Paris)',                 u'Paris',        u'eu-west-3'),
     region(u'Asia Pacific SE (Singapore)',     u'Singapore',    u'ap-southeast-1'),
     region(u'Asia Pacific NE (Tokyo)',         u'Tokyo',        u'ap-northeast-1'),
     region(u'Asia Pacific SE (Sydney)',        u'Sydney',       u'ap-southeast-2'),
diff --git a/tools/fedimg_vars_lib.py b/tools/fedimg_vars_lib.py
index 0a56172..1e008ce 100755
--- a/tools/fedimg_vars_lib.py
+++ b/tools/fedimg_vars_lib.py
@@ -139,10 +139,11 @@ def sanity_check(globalvar, collected_fedimg_vars):
 
 
 def mocked_fedimg(templates):
+    # eu-west-3 is left out because fedimg fails to upload there for now
     regions = ['us-east-1', 'ap-northeast-1', 'sa-east-1', 'ap-southeast-1',
                'ap-southeast-2', 'us-west-2', 'us-west-1', 'eu-central-1',
                'eu-west-1', 'ap-northeast-2', 'ap-south-1', 'ca-central-1',
-               'eu-west-2', 'us-east-2', 'eu-west-3']
+               'eu-west-2', 'us-east-2']
     mockdata = {}
     for region in regions:
         mockdata[region] = 'ami-mocked'

From c5bab16df25068fd90989fef31f37972bf04e0df Mon Sep 17 00:00:00 2001
From: Dusty Mabe <dusty@dustymabe.com>
Date: May 02 2020 20:57:16 +0000
Subject: [PATCH 3/3] fedimg_vars_lib: fix cache file check


- If the file doesn't exist then don't check permissions
- FileNotFoundError doesn't exist in python2.7

---

diff --git a/tools/fedimg_vars_lib.py b/tools/fedimg_vars_lib.py
index 1e008ce..dc22a98 100755
--- a/tools/fedimg_vars_lib.py
+++ b/tools/fedimg_vars_lib.py
@@ -89,15 +89,15 @@ def check_permissions(fd=None, filename=None):
 
 def get_messages(target):
     """ Filter the messages on target. """
-    check_permissions(filename=cache_file)
-    try:
+    if os.path.isfile(cache_file):
+        check_permissions(filename=cache_file)
         with open(cache_file, 'r') as cf:
             check_permissions(fd=cf.fileno())
             cache = json.load(cf)
             cachetime = datetime.strptime(cache['timestamp'], dateformat)
             if cachetime > (datetime.utcnow() - timedelta(days=1)):
                 return filter_messages(cache['messages'], target)
-    except FileNotFoundError:
+    else:
         log.info('No cache, loading from scratch')
 
     messages = list(retrieve_messages())

