Skip to content

Commit

Permalink
GCE CR End To End Scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
jyejare authored and JacobCallahan committed Jul 8, 2019
1 parent 092b831 commit 6177832
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 0 deletions.
12 changes: 12 additions & 0 deletions robottelo.properties.sample
Expand Up @@ -390,6 +390,18 @@ port_range=9091, 14999
# default value is private
# managed_ip=Private

#[gce]
# Google Provider as Compute Resource
# Project name in Google provider
#project_id=sat6qe
# Service Account email id which has compute admin permission
#client_email=
# client json Certificate path which is local path on satellite
#cert_path=/usr/share/foreman/sat6qetester_key.json
# Zones
#zone=
# client certificate URL
#cert_url=

# [rhev]
# RHEV to be added as a compute resource.
Expand Down
39 changes: 39 additions & 0 deletions robottelo/config/base.py
Expand Up @@ -20,6 +20,7 @@
from nailgun import entities, entity_mixins
from nailgun.config import ServerConfig
from robottelo.config import casts
from robottelo.constants import VALID_GCE_ZONES

LOGGER = logging.getLogger(__name__)
SETTINGS_FILE_NAME = 'robottelo.properties'
Expand Down Expand Up @@ -514,6 +515,43 @@ def validate(self):
return validation_errors


class GCESettings(FeatureSettings):
"""Google Compute Engine settings definitions."""

def __init__(self, *args, **kwargs):
super(GCESettings, self).__init__(*args, **kwargs)
self.project_id = None
self.client_email = None
self.cert_path = None
self.zone = None
self.cert_url = None

def read(self, reader):
"""Read GCE settings."""
self.project_id = reader.get('gce', 'project_id')
self.client_email = reader.get('gce', 'client_email')
self.cert_path = reader.get('gce', 'cert_path')
self.zone = reader.get('gce', 'zone')
self.cert_url = reader.get('gce', 'cert_url')

def validate(self):
"""Validate GCE settings."""
valid_cert_path = '/usr/share/foreman/'
validation_errors = []
if not all(self.__dict__.values()):
validation_errors.append(
'All [gce] {} options must be provided'.format(self.__dict__.keys()))
if not str(self.cert_path).startswith(valid_cert_path):
validation_errors.append(
'[gce] cert_path - cert should be available '
'from satellites {}'.format(valid_cert_path))
if self.zone not in VALID_GCE_ZONES:
validation_errors.append(
'Invalid [gce] zone - {0}, The zone should be one of {1}'.format(
self.zone, VALID_GCE_ZONES))
return validation_errors


class LDAPSettings(FeatureSettings):
"""LDAP settings definitions."""
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -1196,6 +1234,7 @@ def __init__(self):
self.ec2 = EC2Settings()
self.fake_capsules = FakeCapsuleSettings()
self.fake_manifest = FakeManifestSettings()
self.gce = GCESettings()
self.ldap = LDAPSettings()
self.ipa = LDAPIPASettings()
self.oscap = OscapSettings()
Expand Down
17 changes: 17 additions & 0 deletions robottelo/constants.py
Expand Up @@ -83,6 +83,23 @@
COMPUTE_PROFILE_LARGE = '3-Large'
COMPUTE_PROFILE_SMALL = '1-Small'

# GCE specific constants
_bcds = dict.fromkeys(['us-east1', 'europe-west1'], ['b', 'c', 'd'])
_abcfs = dict.fromkeys(['us-central1'], ['a', 'b', 'c', 'f'])
_abcs = dict.fromkeys(
['us-east4', 'us-west1', 'europe-west4', 'europe-west3', 'europe-west2', 'asia-east1',
'asia-southeast1', 'asia-northeast1', 'asia-south1', 'australia-southeast1',
'southamerica-east1', 'asia-east2', 'asia-northeast2', 'europe-north1', 'europe-west6',
'northamerica-northeast1', 'us-west2'],
['a', 'b', 'c']
)
_zones_combo = {**_bcds, **_abcfs, **_abcs}
VALID_GCE_ZONES = [f'{loc}-{zone}' for loc, zones in _zones_combo.items() for zone in zones]

GCE_MACHINE_TYPE_DEFAULT = 'f1-micro'
GCE_NETWORK_DEFAULT = 'default'
GCE_EXTERNAL_IP_DEFAULT = True

HTML_TAGS = [
'A', 'ABBR', 'ACRONYM', 'ADDRESS', 'APPLET', 'AREA', 'B',
'BASE', 'BASEFONT', 'BDO', 'BIG', 'BLINK', 'BLOCKQUOTE', 'BODY', 'BR',
Expand Down
159 changes: 159 additions & 0 deletions tests/foreman/ui/test_computeresource_gce.py
@@ -0,0 +1,159 @@
"""Test for Compute Resource UI
:Requirement: ComputeResources GCE
:CaseAutomation: Automated
:CaseLevel: Acceptance
:CaseComponent: ComputeResourcesGCE
:TestType: Functional
:CaseImportance: High
:Upstream: No
"""
from fauxfactory import gen_string
from nailgun import entities
from pytest import skip
from robottelo import ssh
from robottelo.config import settings
from robottelo.constants import (
COMPUTE_PROFILE_SMALL,
FOREMAN_PROVIDERS,
GCE_EXTERNAL_IP_DEFAULT,
GCE_MACHINE_TYPE_DEFAULT,
GCE_NETWORK_DEFAULT
)
from robottelo.decorators import bz_bug_is_open, fixture, setting_is_set, tier2, upgrade


if not setting_is_set('gce'):
skip('skipping tests due to missing gce settings', allow_module_level=True)


class GCECertNotFoundError(Exception):
"""An exception to raise when GCE Cert json is not available for creating GCE CR"""


@fixture(scope='module')
def module_org():
return entities.Organization().create()


@fixture(scope='module')
def module_loc():
return entities.Location().create()


@fixture(scope='module')
def module_gce_settings():
return dict(
project_id=settings.gce.project_id,
client_email=settings.gce.client_email,
cert_path=settings.gce.cert_path,
zone=settings.gce.zone
)


@fixture(scope='module')
def download_cert():
ssh.command('curl {0} -o {1}'.format(settings.gce.cert_url, settings.gce.cert_path))
if not ssh.command('[ -f {} ]'.format(settings.gce.cert_path)).return_code == 0:
raise GCECertNotFoundError("The GCE certificate {} is not found in satellite.".format(
settings.gce.cert_path))


@tier2
@upgrade
def test_positive_default_end_to_end_with_custom_profile(
session, module_org, module_loc, module_gce_settings, download_cert):
"""Create GCE compute resource with default properties and apply it's basic functionality.
:id: 59ffd83e-a984-4c22-b91b-cad055b4fbd7
:Steps:
1. Create an GCE compute resource with default properties.
2. Update the compute resource name and add new taxonomies.
3. Associate compute profile with custom properties to GCE compute resource
4. Delete the compute resource.
:expectedresults: The GCE compute resource is created, updated, compute profile associated and
deleted.
:CaseLevel: Integration
:CaseImportance: Critical
"""
cr_name = gen_string('alpha')
new_cr_name = gen_string('alpha')
cr_description = gen_string('alpha')
new_org = entities.Organization().create()
new_loc = entities.Location().create()

with session:
# Compute Resource Create and Assertions
session.computeresource.create({
'name': cr_name,
'description': cr_description,
'provider': FOREMAN_PROVIDERS['google'],
'provider_content.google_project_id': module_gce_settings['project_id'],
'provider_content.client_email': module_gce_settings['client_email'],
'provider_content.certificate_path': module_gce_settings['cert_path'],
'organizations.resources.assigned': [module_org.name],
'locations.resources.assigned': [module_loc.name],
})
cr_values = session.computeresource.read(cr_name)
assert cr_values['name'] == cr_name
assert cr_values['provider_content']['zone']['value']
assert (cr_values['organizations']['resources']['assigned']
== [module_org.name])
assert (cr_values['locations']['resources']['assigned']
== [module_loc.name])
assert cr_values['provider_content']['google_project_id'] == module_gce_settings[
'project_id']
assert cr_values['provider_content']['client_email'] == module_gce_settings[
'client_email']
# Compute Resource Edit/Updates and Assertions
session.computeresource.edit(cr_name, {
'name': new_cr_name,
'organizations.resources.assigned': [new_org.name],
'locations.resources.assigned': [new_loc.name],
})
assert not session.computeresource.search(cr_name)
cr_values = session.computeresource.read(new_cr_name)
assert cr_values['name'] == new_cr_name
assert (set(cr_values['organizations']['resources']['assigned'])
== {module_org.name, new_org.name})
assert (set(cr_values['locations']['resources']['assigned'])
== {module_loc.name, new_loc.name})

# Compute Profile edit/updates and Assertions
session.computeresource.update_computeprofile(
new_cr_name,
COMPUTE_PROFILE_SMALL,
{
'provider_content.machine_type': GCE_MACHINE_TYPE_DEFAULT,
'provider_content.network': GCE_NETWORK_DEFAULT,
'provider_content.external_ip': GCE_EXTERNAL_IP_DEFAULT,
'provider_content.default_disk_size': '15'
}
)
cr_profile_values = session.computeresource.read_computeprofile(
new_cr_name, COMPUTE_PROFILE_SMALL)
assert cr_profile_values['breadcrumb'] == 'Edit {0}'.format(COMPUTE_PROFILE_SMALL)
assert cr_profile_values['compute_profile'] == COMPUTE_PROFILE_SMALL
assert cr_profile_values['compute_resource'] == '{0} ({1}-{2})'.format(
new_cr_name, module_gce_settings['zone'], FOREMAN_PROVIDERS['google'])
assert (cr_profile_values['provider_content']['machine_type']
== GCE_MACHINE_TYPE_DEFAULT)
assert cr_profile_values['provider_content']['network'] == GCE_NETWORK_DEFAULT
if not bz_bug_is_open(1721871):
assert cr_profile_values['provider_content']['external_ip'] == GCE_EXTERNAL_IP_DEFAULT
assert cr_profile_values['provider_content']['default_disk_size'] == '15'

# Compute Resource Delete and Assertion
session.computeresource.delete(new_cr_name)
assert not session.computeresource.search(new_cr_name)

0 comments on commit 6177832

Please sign in to comment.