Skip to content

Commit

Permalink
test for registering client to redhat-access-insights
Browse files Browse the repository at this point in the history
  • Loading branch information
anarang authored and Ichimonji10 committed Jul 17, 2015
1 parent 125b2a0 commit 8f6cffa
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 1 deletion.
7 changes: 7 additions & 0 deletions robottelo.properties.sample
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ admin.password=changeme
[saucelabs]
driver=firefox

[insights]
# Provide link to rhel6/7 repo here, as redhat-access-insights client rpm
# would require packages from RHEL 6/7 repo and syncing the entire repo
# on the fly would take longer for tests to run
rhel6_repo=http://example.org/released/RHEL-6/6.x/Server/x86_64/os/
rhel7_repo=http://example.org/released/RHEL-7/7.x/Server/x86_64/os/

# Section for declaring Sat5->Sat6 transition parameters
[transitions]
# URL of the exported data archive (typically a .tgz containing a bunch of CSV
Expand Down
4 changes: 3 additions & 1 deletion robottelo/test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Test utilities for writing foreman tests
All test cases for foreman tests are defined in this module and have utilities
to help writting API, CLI and UI tests.
to help writing API, CLI and UI tests.
"""
import csv
Expand Down Expand Up @@ -45,6 +45,7 @@
from robottelo.ui.products import Products
from robottelo.ui.puppetclasses import PuppetClasses
from robottelo.ui.repository import Repos
from robottelo.ui.rhai import RHAI
from robottelo.ui.role import Role
from robottelo.ui.settings import Settings
from robottelo.ui.subnet import Subnet
Expand Down Expand Up @@ -221,6 +222,7 @@ def setUp(self): # noqa
self.puppetclasses = PuppetClasses(self.browser)
self.products = Products(self.browser)
self.repository = Repos(self.browser)
self.rhai = RHAI(self.browser)
self.role = Role(self.browser)
self.settings = Settings(self.browser)
self.subnet = Subnet(self.browser)
Expand Down
29 changes: 29 additions & 0 deletions robottelo/ui/locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,29 @@ def __iter__(self):
("//div[contains(@style,'static') or contains(@style, 'fixed')]"
"//a[@id='menu_item_domains']")),

# Access Insights menu
"menu.insights": (
By.XPATH,
("//div[contains(@style,'static') or contains(@style,'fixed')]"
"//a[@id='redhat_access_top_menu']")),
"insights.overview": (
By.XPATH,
("//div[contains(@style,'static') or contains(@style,'fixed')]"
"//a[@href='/redhat_access/insights']")),
"insights.rules": (
By.XPATH,
("//div[contains(@style,'static') or contains(@style,'fixed')]"
"//a[@href='/redhat_access/insights/rules/']")),
"insights.systems": (
By.XPATH,
("//div[contains(@style,'static') or contains(@style,'fixed')]"
"//a[@href='/redhat_access/insights/systems/']")),
"insights.manage": (
By.XPATH,
("//div[contains(@style,'static') or contains(@style,'fixed')]"
"//a[@href='/redhat_access/insights/manage']")),


# Administer Menu
"menu.administer": (
By.XPATH,
Expand Down Expand Up @@ -1885,4 +1908,10 @@ def __iter__(self):
By.XPATH, "//a[@data-confirm='Delete %s?']"),
"ldapserver.ldap_servername": (
By.XPATH, "//a[contains(@href, 'edit') and contains(@href, '%s')]"),

# Red Hat Access Insights locators
"insights.registered_systems": (
By.XPATH,
("//div[@class='system-summary']/p")),

})
28 changes: 28 additions & 0 deletions robottelo/ui/navigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,34 @@ def go_to_logout(self):
menu_locators['menu.account'], menu_locators['menu.sign_out'],
)

def go_to_insights_overview(self):
"""Navigates to Red Hat Access Insights Overview"""
self.menu_click(
menu_locators['menu.insights'],
menu_locators['insights.overview']
)

def go_to_insights_rules(self):
"""Navigates to Red Hat Access Insights Rules"""
self.menu_click(
menu_locators['menu.insights'],
menu_locators['insights.rules'],
)

def go_to_insights_systems(self):
""" Navigates to Red Hat Access Insights Systems"""
self.menu_click(
menu_locators['menu.insights'],
menu_locators['insights.systems'],
)

def go_to_insights_manage(self):
""" Navigates to Red Hat Access Insights Manage Systems"""
self.menu_click(
menu_locators['menu.insights'],
menu_locators['insights.manage'],
)

def go_to_select_org(self, org):
"""Selects the specified organization.
Expand Down
14 changes: 14 additions & 0 deletions robottelo/ui/rhai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- encoding: utf-8 -*-
""" Implements methods for RHAI"""

from robottelo.ui.base import Base
from robottelo.ui.locators import locators


class RHAI(Base):
def view_registered_systems(self):
"""To view the number of registered systems"""
result = self.wait_until_element(
locators['insights.registered_systems']
).text
return result
133 changes: 133 additions & 0 deletions tests/foreman/ui/test_rhai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""Tests for Red Hat Access Insights"""


from nailgun import entities
from fauxfactory import gen_string
from robottelo.common import conf
from robottelo.common import manifests
from robottelo.ui.navigator import Navigator
from robottelo.ui.session import Session
from robottelo.test import UITestCase
from robottelo.vm import VirtualMachine


class RHAITestCase(UITestCase):
def test_rhai_client_setup(self):
"""@Test: Check for client registration to redhat-access-insights
service.
@Feature: RHEL client registration to rhai
@Assert: Registered client should appear in the Systems sub-menu of Red
Hat Access Insights
"""
# Create a new organization with prefix 'insights'
org = entities.Organization(
name='insights_{0}'.format(gen_string('alpha', 6))
).create()

# Create new lifecycle environment
lifecycle_env = entities.LifecycleEnvironment(
name='rhai_env_{0}'.format(gen_string('alpha', 6)),
organization=org,
).create()

# Upload manifest
org.upload_manifest(path=manifests.clone())

# Create a custom product for RHAI
custom_product = entities.Product(
name='rhai_product_{0}'.format(gen_string('alpha', 6)),
organization=org,
).create()

# Add insights repo to the custom product
custom_repo = entities.Repository(
content_type=u'yum',
name=u'insights_repo_{0}'.format(gen_string('alpha', 6)),
product=custom_product,
url=u'http://access.redhat.com/insights/repo/6/',
).create()

# Sync custom repository
custom_repo.sync()

# Create content view
content_view = entities.ContentView(
name='rhai_cv_{0}'.format(gen_string('alpha', 6)),
organization=org,
).create()

# Associate custom repository to new content view
content_view.set_repository_ids([custom_repo.id])

# Publish content view
content_view.publish()

# Promote content view to lifecycle_env
content_view = content_view.read()
self.assertEqual(len(content_view.version), 1)
content_view.version[0].promote(lifecycle_env.id)

# Create activation key
activation_key = entities.ActivationKey(
auto_attach=True,
content_view=content_view,
environment=lifecycle_env,
name=gen_string('alpha'),
organization=org,
).create()

for subscription in org.subscriptions():
# Attach custom product subscription to the activation key
if subscription['product_name'] == custom_product.name:
activation_key.add_subscriptions({
'quantity': 1,
'subscription_id': subscription['id'],
})
break

# Create VM
with VirtualMachine(distro='rhel66') as vm:
# Download and Install ketello-ca rpm
vm.install_katello_cert()
vm.register_contenthost(activation_key.name, org.label)

# Red Hat Access Insights requires RHEL 6/7 repo and it not
# possible to sync the repo during the tests,
# adding a file in /etc/yum.repos.d/rhel6/7.repo

rhel6_repo = conf.properties.get('insights.rhel6_repo')

repo_file = (
'[rhel6-rpms]\n'
'name=RHEL6\n'
'baseurl={0}\n'
'enabled=1\n'
.format(rhel6_repo)
)

vm.run(
'echo "{0}" >> /etc/yum.repos.d/rhel6.repo'
.format(repo_file)
)

# Install redhat-access-insights package
package_name = 'redhat-access-insights'
result = vm.run('yum install -y {0}'.format(package_name))
self.assertEqual(result.return_code, 0)

# Verify if package is installed by query it
result = vm.run('rpm -q {0}'.format(package_name))
self.assertEqual(result.return_code, 0)

# Register client with Red Hat Access Insights
result = vm.run('redhat-access-insights --register')
self.assertEqual(result.return_code, 0)

with Session(self.browser) as session:
# view clients registered to Red Hat Access Insights
session.nav.go_to_select_org(org.name)
Navigator(self.browser).go_to_insights_systems()
result = self.rhai.view_registered_systems()
self.assertIn("1", result, 'Registered clients are not listed')

0 comments on commit 8f6cffa

Please sign in to comment.