From eef8726bd6c8b2d0b7f7ee355132f0aec6a39826 Mon Sep 17 00:00:00 2001
From: mprahl <mprahl@redhat.com>
Date: Feb 04 2019 13:59:09 +0000
Subject: [PATCH 1/3] Return a deprecation error when a user tries to use !PackageSpecificBuild or !FedoraAtomicCi


---

diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py
index 06cc3f2..46f9a7d 100644
--- a/functional-tests/test_api_v1.py
+++ b/functional-tests/test_api_v1.py
@@ -974,6 +974,27 @@ def test_validate_gating_yaml_empty(requests_session, greenwave_server):
     assert result.status_code == 400
 
 
+def test_validate_gating_yaml_deprecated_rule(requests_session, greenwave_server):
+    gating_yaml = dedent("""
+        --- !Policy
+        id: "test"
+        product_versions:
+          - fedora-26
+        decision_context: test
+        rules:
+          - !PackageSpecificBuild {
+              test_case_name: osci.brew-build.tier0.functional,
+              repos: ["avahi", "cockpit"]
+            }
+    """)
+    result = requests_session.post(
+        greenwave_server + 'api/v1.0/validate-gating-yaml', data=gating_yaml)
+    assert result.json().get('message') == (
+        'Policy \'test\': Attribute \'rules\': !PackageSpecificBuild is deprecated. '
+        'Please use the "packages" whitelist instead.')
+    assert result.status_code == 400
+
+
 def test_validate_gating_yaml_missing_tag(requests_session, greenwave_server):
     gating_yaml = dedent("""
         ---
diff --git a/greenwave/policies.py b/greenwave/policies.py
index 6b93a68..4a6578f 100644
--- a/greenwave/policies.py
+++ b/greenwave/policies.py
@@ -494,6 +494,31 @@ class PassingTestCaseRule(Rule):
                                 self.scenario, result['id'])
 
 
+class DeprecatedRule(Rule):
+    """
+    The base class for a deprecated rule.
+    When these rules are parsed, a SafeYAMLError exception will be raised.
+    """
+    advice = 'Please refer to the documentation for more information.'
+    safe_yaml_attributes = {}
+
+    def __init__(self):
+        tag = self.yaml_tag or '!' + type(self).__name__
+        raise SafeYAMLError('{} is deprecated. {}'.format(tag, self.advice))
+
+    def check(self, policy, product_version, subject_identifier, results_retriever, waivers):
+        raise ValueError('This rule is deprecated and can\'t be checked')
+
+
+class PackageSpecificBuild(DeprecatedRule):
+    yaml_tag = '!PackageSpecificBuild'
+    advice = 'Please use the "packages" whitelist instead.'
+
+
+class FedoraAtomicCi(PackageSpecificBuild):
+    yaml_tag = '!FedoraAtomicCi'
+
+
 class Policy(SafeYAMLObject):
     root_yaml_tag = '!Policy'
 

From 1a21fa4fc2e6df5f0161ee1c7d4085e2f7d5716e Mon Sep 17 00:00:00 2001
From: mprahl <mprahl@redhat.com>
Date: Feb 04 2019 13:59:10 +0000
Subject: [PATCH 2/3] Add a deprecation warning for the use of the "blacklist" key


---

diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py
index 46f9a7d..b691f67 100644
--- a/functional-tests/test_api_v1.py
+++ b/functional-tests/test_api_v1.py
@@ -968,6 +968,26 @@ def test_validate_gating_yaml_valid(requests_session, greenwave_server):
     assert result.status_code == 200
 
 
+def test_validate_gating_yaml_deprecated_blacklist(requests_session, greenwave_server):
+    gating_yaml = dedent("""
+        --- !Policy
+        id: "test"
+        product_versions:
+          - fedora-26
+        decision_context: test
+        rules:
+          - !PassingTestCaseRule {test_case_name: test}
+        blacklist:
+          - python-requests
+    """)
+    result = requests_session.post(
+        greenwave_server + 'api/v1.0/validate-gating-yaml', data=gating_yaml)
+    assert result.json().get('message') == (
+        'The gating.yaml file is valid but it is using the deprecated '
+        '"blacklist" key. Please use "excluded_packages" instead.')
+    assert result.status_code == 200
+
+
 def test_validate_gating_yaml_empty(requests_session, greenwave_server):
     result = requests_session.post(greenwave_server + 'api/v1.0/validate-gating-yaml')
     assert result.json().get('message') == 'No policies defined'
diff --git a/greenwave/api_v1.py b/greenwave/api_v1.py
index fe11adf..32a2612 100644
--- a/greenwave/api_v1.py
+++ b/greenwave/api_v1.py
@@ -436,7 +436,12 @@ def validate_gating_yaml_post():
         log.error('No policies defined')
         raise BadRequest('No policies defined')
 
-    return jsonify({'message': 'All OK'})
+    if any(True for policy in policies if policy.blacklist):
+        msg = {'message': ('The gating.yaml file is valid but it is using the deprecated '
+                           '"blacklist" key. Please use "excluded_packages" instead.')}
+    else:
+        msg = {'message': 'All OK'}
+    return jsonify(msg)
 
 
 @api.route('/metrics', methods=['GET'])

From d45a5e38641c3b1930d79b402b97f16216ce4925 Mon Sep 17 00:00:00 2001
From: mprahl <mprahl@redhat.com>
Date: Feb 04 2019 13:59:10 +0000
Subject: [PATCH 3/3] Install pylint in the Vagrant VM


---

diff --git a/Vagrantfile b/Vagrantfile
index e85aeb3..3a39ec1 100644
--- a/Vagrantfile
+++ b/Vagrantfile
@@ -10,6 +10,7 @@ $script = <<-'SCRIPT'
         postgresql-contrib \
         python3-gunicorn \
         python3-psycopg2 \
+        python3-pylint \
         vim
 
     systemctl enable postgresql

