Skip to content

Commit

Permalink
Fixes SatelliteQE#7560 - Tests for assigning http_proxy to repos.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jameer Pathan authored and ntkathole committed Jan 9, 2020
1 parent b7f89fe commit 8c952ff
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 3 deletions.
78 changes: 76 additions & 2 deletions tests/foreman/api/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@
:Upstream: No
"""
import pytest
from fauxfactory import gen_string
import re
from fauxfactory import (
gen_integer,
gen_string,
gen_url
)
from nailgun import entities
from requests.exceptions import HTTPError
from robottelo import manifests
from robottelo import manifests, ssh
from robottelo.api.utils import upload_manifest
from robottelo.constants import (
FAKE_1_PUPPET_REPO,
Expand Down Expand Up @@ -399,3 +404,72 @@ def test_positive_filter_product_list(self):
self.assertGreater(len(rh_products), 1)
self.assertNotIn(product.name, [prod.name for prod in rh_products])
self.assertIn('Red Hat Beta', [prod.name for prod in rh_products])

@tier2
def test_positive_assign_http_proxy_to_products(self):
"""Assign http_proxy to Products and check whether http-proxy is
used during sync.
:id: c9d23aa1-3325-4abd-a1a6-d5e75c12b08a
:expectedresults: HTTP Proxy is assigned to all repos present
in Products and sync operation uses assigned http-proxy.
:CaseImportance: Critical
"""
# create HTTP proxies
http_proxy_url_a = '{}:{}'.format(
gen_url(scheme='https'), gen_integer(min_value=10, max_value=9999))
http_proxy_a = entities.HTTPProxy(
name=gen_string('alpha', 15),
url=http_proxy_url_a,
organization=[self.org.id]
).create()
http_proxy_url_b = '{}:{}'.format(
gen_url(scheme='https'), gen_integer(min_value=10, max_value=9999))
http_proxy_b = entities.HTTPProxy(
name=gen_string('alpha', 15),
url=http_proxy_url_b,
organization=[self.org.id]
).create()
proxy_fqdn = re.split(r'[:]', http_proxy_b.url)[1].strip("//")
# Create products and repositories
product_a = entities.Product(organization=self.org).create()
product_b = entities.Product(organization=self.org).create()
repo_a1 = entities.Repository(
product=product_a,
http_proxy_policy='none',
).create()
repo_a2 = entities.Repository(
product=product_a,
http_proxy_policy='use_selected_http_proxy',
http_proxy_id=http_proxy_a.id

).create()
repo_b1 = entities.Repository(
product=product_b,
http_proxy_policy='none',
).create()
repo_b2 = entities.Repository(
product=product_b,
http_proxy_policy='global_default_http_proxy',
).create()
# Add http_proxy to products
entities.ProductBulkAction().http_proxy(
data={
"ids": [product_a.id, product_b.id],
"http_proxy_policy": "use_selected_http_proxy",
"http_proxy_id": http_proxy_b.id
})
assert repo_a1.read().http_proxy_policy == "use_selected_http_proxy"
assert repo_a2.read().http_proxy_policy == "use_selected_http_proxy"
assert repo_b1.read().http_proxy_policy == "use_selected_http_proxy"
assert repo_b2.read().http_proxy_policy == "use_selected_http_proxy"
assert repo_a1.read().http_proxy_id == http_proxy_b.id
assert repo_a2.read().http_proxy_id == http_proxy_b.id
assert repo_b1.read().http_proxy_id == http_proxy_b.id
assert repo_b2.read().http_proxy_id == http_proxy_b.id
# check if proxy fqdn is present in log during sync
product_a.sync({'async': True})
result = ssh.command('grep -F {} /var/log/messages'.format(proxy_fqdn))
assert result.return_code == 0
66 changes: 65 additions & 1 deletion tests/foreman/api/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
:Upstream: No
"""
import pytest
import re
import tempfile

from six.moves.urllib.parse import urljoin
from fauxfactory import gen_string
from fauxfactory import (
gen_integer,
gen_string,
gen_url,
)
from nailgun import client, entities
from nailgun.entity_mixins import TaskFailedError
from requests.exceptions import HTTPError, SSLError
Expand Down Expand Up @@ -84,8 +89,15 @@ class RepositoryTestCase(APITestCase):
def setUpClass(cls):
"""Create an organization and product which can be re-used in tests."""
super(RepositoryTestCase, cls).setUpClass()
http_proxy_url = '{}:{}'.format(
gen_url(scheme='https'), gen_integer(min_value=10, max_value=9999))
cls.org = entities.Organization().create()
cls.product = entities.Product(organization=cls.org).create()
cls.http_proxy = entities.HTTPProxy(
name=gen_string('alpha', 15),
url=http_proxy_url,
organization=[cls.org.id]
).create()

@tier1
def test_positive_create_with_name(self):
Expand All @@ -103,6 +115,58 @@ def test_positive_create_with_name(self):
product=self.product, name=name).create()
self.assertEqual(name, repo.name)

@tier2
@upgrade
def test_positive_assign_http_proxy_to_repository(self):
"""Assign http_proxy to Repositories and check whether http-proxy is
used during sync.
:id: 5b3b992e-02d3-4b16-95ed-21f1588c7741
:expectedresults: HTTP Proxy can be assigned to repository and sync operation
uses assigned http-proxy.
:CaseImportance: Critical
"""
http_proxy_url = '{}:{}'.format(
gen_url(scheme='https'), gen_integer(min_value=10, max_value=9999))
http_proxy = entities.HTTPProxy(
name=gen_string('alpha', 15),
url=http_proxy_url,
organization=[self.org.id]
).create()
proxy_fqdn = re.split(r'[:]', http_proxy.url)[1].strip("//")
# no http_proxy
repo_a = entities.Repository(
url=FAKE_2_YUM_REPO,
product=self.product,
http_proxy_policy='none',
).create()
assert repo_a.http_proxy_policy == 'none'
repo_a.sync()
assert repo_a.read().content_counts['rpm'] >= 1
# Use global_default_http_proxy
repo_b = entities.Repository(
url=FAKE_2_YUM_REPO,
product=self.product,
http_proxy_policy='global_default_http_proxy',
).create()
assert repo_b.http_proxy_policy == 'global_default_http_proxy'
# Update to selected_http_proxy
repo_b = entities.Repository(
id=repo_b.id,
http_proxy_policy='use_selected_http_proxy',
http_proxy_id=http_proxy.id
).update()
assert repo_b.http_proxy_policy == 'use_selected_http_proxy'
assert repo_b.http_proxy_id == http_proxy.id
repo_b.sync({'async': True})
result = ssh.command('grep -F {} /var/log/messages'.format(proxy_fqdn))
assert result.return_code == 0
# Delete repositories
entities.Repository(id=repo_a.id).delete()
entities.Repository(id=repo_b.id).delete()

@tier1
def test_positive_create_with_label(self):
"""Create a repository providing label which is different from its name
Expand Down

0 comments on commit 8c952ff

Please sign in to comment.