pgreco / rpms / cockpit

Forked from forks/areguera/rpms/cockpit 5 years ago
Clone

Blame SOURCES/0011-test-Update-subscriptions-tests.patch

2587cc
From 82500f0c24c4d2eb26d4bf675a17fff8519bb845 Mon Sep 17 00:00:00 2001
2587cc
From: Dominik Perpeet <dperpeet@redhat.com>
2587cc
Date: Fri, 28 Apr 2017 08:25:38 +0200
2587cc
Subject: [PATCH 11/16] test: Update subscriptions tests
2587cc
2587cc
Original commit
2587cc
45d22efb4dffd637aca56e5e6c2c2e40683f2c13
2587cc
  test: Read ids dynamically in subscriptions test
2587cc
2587cc
Closes #7025
2587cc
Reviewed-by: Stef Walter <stefw@redhat.com>
2587cc
---
2587cc
 test/verify/check-subscriptions | 33 ++++++++++++++++++++++++++++-----
2587cc
 1 file changed, 28 insertions(+), 5 deletions(-)
2587cc
2587cc
diff --git a/test/verify/check-subscriptions b/test/verify/check-subscriptions
2587cc
index 9932bac..1167ecf 100755
2587cc
--- a/test/verify/check-subscriptions
2587cc
+++ b/test/verify/check-subscriptions
2587cc
@@ -46,6 +46,8 @@ import os
2587cc
 # curl --insecure --request POST --user admin:admin https://$IP:8443/candlepin/activation_keys/ff80808155ca50b10155ca50cd280010/pools/ff80808155ca50b10155ca51f04607e5
2587cc
 # register with: activation key "awesome_os_pool" and org "admin"
2587cc
 # or: subscription-manager register --activationkey awesome_os_pool --org admin --serverurl https://$IP:8443/candlepin
2587cc
+#
2587cc
+# in order to get the right ids for the activation key and pool, see ACTIVATION_KEY_COMMAND and POOL_COMMAND
2587cc
 
2587cc
 WAIT_SCRIPT = """
2587cc
 set -ex
2587cc
@@ -58,7 +60,25 @@ for x in $(seq 1 200); do
2587cc
 done
2587cc
 """
2587cc
 
2587cc
-@skipImage("No subscriptions", "centos-7", "continuous-atomic", "debian-8", "debian-testing", "fedora-24", "fedora-25", "fedora-i386", "fedora-atomic", "fedora-testing", "ubuntu-1604")
2587cc
+ACTIVATION_KEY_COMMAND = """curl -s --insecure --request GET --user admin:admin https://localhost:8443/candlepin/activation_keys | python -c "
2587cc
+import sys
2587cc
+import json
2587cc
+
2587cc
+data = json.loads(sys.stdin.read())
2587cc
+print [e['id'] for e in data if e['name'] == 'awesome_os_pool' and e['owner']['displayName'] == 'Admin Owner'][0]
2587cc
+"
2587cc
+"""
2587cc
+
2587cc
+POOL_COMMAND = """curl -s --insecure --request GET --user admin:admin https://localhost:8443/candlepin/pools | python -c "
2587cc
+import sys
2587cc
+import json
2587cc
+
2587cc
+data = json.loads(sys.stdin.read())
2587cc
+print [ e['id'] for e in data if e['owner']['key'] == 'admin' and e['contractNumber'] == '0' and [p for p in e['providedProducts'] if p['productId'] == '88888'] ][0]
2587cc
+"
2587cc
+"""
2587cc
+
2587cc
+@skipImage("No subscriptions", "centos-7", "continuous-atomic", "debian-8", "debian-testing", "fedora-24", "fedora-25", "fedora-26", "fedora-i386", "fedora-atomic", "fedora-testing", "ubuntu-1604")
2587cc
 class TestSubscriptions(MachineCase):
2587cc
     additional_machines = {
2587cc
         'candlepin': { 'machine': { 'image': 'candlepin' } }
2587cc
@@ -114,7 +134,7 @@ class TestSubscriptions(MachineCase):
2587cc
         # enter server and incorrect login data
2587cc
         b.wait_present("#subscription-register-url-custom")
2587cc
         b.wait_visible("#subscription-register-url-custom")
2587cc
-        b.set_val("#subscription-register-url-custom", "{0}:8443/candlepin".format(self.candlepin.address))
2587cc
+        b.set_val("#subscription-register-url-custom", "{address}:8443/candlepin".format(address=self.candlepin.address))
2587cc
         b.set_val("#subscription-register-username", "doc")
2587cc
         b.set_val("#subscription-register-password", "wrongpass")
2587cc
 
2587cc
@@ -138,7 +158,10 @@ class TestSubscriptions(MachineCase):
2587cc
         b.set_val("#subscription-register-org", "admin")
2587cc
 
2587cc
         # use an activation key
2587cc
-        self.candlepin.execute("curl --insecure --request POST --user admin:admin https://localhost:8443/candlepin/activation_keys/ff80808155ca50b10155ca50cd280010/pools/ff80808155ca50b10155ca51f04607e5")
2587cc
+        activation_key_id = self.candlepin.execute(ACTIVATION_KEY_COMMAND).strip()
2587cc
+        pool_id = self.candlepin.execute(POOL_COMMAND).strip()
2587cc
+        key_url = "https://localhost:8443/candlepin/activation_keys/{key}/pools/{pool}".format(key=activation_key_id, pool=pool_id)
2587cc
+        self.candlepin.execute("curl -s --insecure --request POST --user admin:admin {url}".format(url=key_url))
2587cc
         b.set_val("#subscription-register-username", "")
2587cc
         b.set_val("#subscription-register-password", "")
2587cc
         b.set_val("#subscription-register-password", "")
2587cc
@@ -202,10 +225,10 @@ class TestSubscriptions(MachineCase):
2587cc
         # enter server data
2587cc
         b.wait_present("#subscription-register-url-custom")
2587cc
         b.wait_visible("#subscription-register-url-custom")
2587cc
-        b.set_val("#subscription-register-url-custom", "{0}:8443/candlepin".format(self.candlepin.address))
2587cc
+        b.set_val("#subscription-register-url-custom", "{address}:8443/candlepin".format(address=self.candlepin.address))
2587cc
 
2587cc
         # make sure we have an activation key on the target machine
2587cc
-        self.candlepin.execute("curl --insecure --request POST --user admin:admin https://localhost:8443/candlepin/activation_keys/ff80808155ca50b10155ca50cd280010/pools/ff80808155ca50b10155ca51f04607e5")
2587cc
+        self.candlepin.execute("curl -s --insecure --request POST --user admin:admin {url}".format(url=key_url))
2587cc
 
2587cc
         # enter key and org
2587cc
         b.set_val("#subscription-register-key", "awesome_os_pool")
2587cc
-- 
2587cc
2.9.4
2587cc