Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #10251 from valaparthvi/ocp_create_rest
Browse files Browse the repository at this point in the history
[1LP][RFR] Enhance create_rest for OCP
  • Loading branch information
mshriver authored Jul 31, 2020
2 parents 49fa467 + 765bbfd commit 6a0ac7d
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 9 deletions.
57 changes: 48 additions & 9 deletions cfme/common/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ def _fill_default_endpoint_dicts(self, provider_attributes, connection_configs):
}

endpoint_default = self.endpoints["default"]
if getattr(endpoint_default.credentials, "principal", None):

from cfme.containers.provider.openshift import OpenshiftProvider

if self.one_of(OpenshiftProvider) and getattr(endpoint_default.credentials, "token", None):
default_connection["authentication"] = {"auth_key": endpoint_default.credentials.token}
elif getattr(endpoint_default.credentials, "principal", None):
provider_attributes["credentials"] = {
"userid": endpoint_default.credentials.principal,
"password": endpoint_default.credentials.secret,
Expand All @@ -324,10 +329,17 @@ def _fill_default_endpoint_dicts(self, provider_attributes, connection_configs):

if getattr(endpoint_default, "api_port", None):
default_connection["endpoint"]["port"] = endpoint_default.api_port
if getattr(endpoint_default, "security_protocol", None):
security_protocol = endpoint_default.security_protocol.lower()

sec_protocol = getattr(endpoint_default, "security_protocol", None) or getattr(
endpoint_default, "sec_protocol", None
)
if sec_protocol:
security_protocol = sec_protocol.lower()
if security_protocol in ('basic (ssl)', 'ssl without validation'):
security_protocol = "ssl"
if self.one_of(OpenshiftProvider) and security_protocol == "ssl without validation":
security_protocol = "ssl-without-validation"
else:
security_protocol = "ssl"
elif security_protocol == "ssl":
security_protocol = 'ssl-with-validation'

Expand Down Expand Up @@ -473,6 +485,36 @@ def _fill_vmrc_console_endpoint_dicts(self, provider_attributes):
}
)

def _fill_hawkular_endpoint_dicts(self, connection_configs):
"""Fills dicts with hawkular endpoint data.
Helper method for ``self.create_rest``
"""
if "metrics" not in self.endpoints:
return

endpoint_hawkular = self.endpoints["metrics"]

hawkular_connection = {
"endpoint": {
"hostname": endpoint_hawkular.hostname,
"role": "hawkular",
},
}
if getattr(endpoint_hawkular, "api_port", None):
hawkular_connection["endpoint"]["port"] = endpoint_hawkular.api_port

if getattr(endpoint_hawkular, "sec_protocol", None):
security_protocol = endpoint_hawkular.sec_protocol.lower()
if security_protocol == 'ssl without validation':
security_protocol = "ssl-without-validation"
elif security_protocol == "ssl":
security_protocol = 'ssl-with-validation'

hawkular_connection["endpoint"]["security_protocol"] = security_protocol

connection_configs.append(hawkular_connection)

def _compile_connection_configurations(self, provider_attributes, connection_configs):
"""Compiles together all dicts with data for ``connection_configurations``.
Expand Down Expand Up @@ -523,6 +565,7 @@ def create_rest(self, check_existing=False, validate_inventory=False):
self._fill_ceilometer_endpoint_dicts(provider_attributes, connection_configs)
self._fill_smartstate_endpoint_dicts(provider_attributes)
self._fill_vmrc_console_endpoint_dicts(provider_attributes)
self._fill_hawkular_endpoint_dicts(connection_configs)
self._compile_connection_configurations(provider_attributes, connection_configs)

try:
Expand Down Expand Up @@ -669,11 +712,7 @@ def setup(self):
Sets up the provider robustly
"""
# TODO: Eventually this will become Sentakuified, but only after providers is CEMv3
if self.category in ['cloud', 'infra', 'physical', 'config_manager']:
return self.create_rest(check_existing=True, validate_inventory=True)
else:
return self.create(cancel=False, validate_credentials=True,
check_existing=True, validate_inventory=True)
return self.create_rest(check_existing=True, validate_inventory=True)

@variable(alias='rest')
def is_refreshed(self, refresh_timer=None, refresh_delta=600, force_refresh=True):
Expand Down
25 changes: 25 additions & 0 deletions cfme/containers/provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from cfme.utils.appliance.implementations.ui import navigator
from cfme.utils.browser import browser
from cfme.utils.log import logger
from cfme.utils.net import resolve_hostname
from cfme.utils.pretty import Pretty
from cfme.utils.version import LOWEST
from cfme.utils.version import VersionPicker
Expand Down Expand Up @@ -228,6 +229,30 @@ def __attrs_post_init__(self):
super().__attrs_post_init__()
self.parent = self.appliance.collections.containers_providers

@property
def hostname(self):
return getattr(self.default_endpoint, "hostname", None)

@hostname.setter
def hostname(self, value):
if self.default_endpoint:
if value:
self.default_endpoint.hostname = value
else:
logger.warning("can't set hostname because default endpoint is absent")

@property
def ip_address(self):
return getattr(self.default_endpoint, "ipaddress", resolve_hostname(str(self.hostname)))

@ip_address.setter
def ip_address(self, value):
if self.default_endpoint:
if value:
self.default_endpoint.ipaddress = value
else:
logger.warning("can't set ipaddress because default endpoint is absent")

@property
def view_value_mapping(self):
mapping = {
Expand Down
27 changes: 27 additions & 0 deletions cfme/tests/containers/test_container_provider_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from cfme.common.provider_views import ContainerProvidersView
from cfme.containers.provider import ContainersProvider
from cfme.markers.env_markers.provider import ONE_PER_VERSION
from cfme.utils.rest import assert_response
from cfme.utils.update import update


Expand Down Expand Up @@ -64,3 +65,29 @@ def test_container_provider_crud(request, appliance, has_no_providers, provider)
provider.wait_for_delete()

assert not provider.exists


@test_requirements.rest
def test_container_provider_crud_rest(appliance, has_no_providers, provider):
"""
Test
Polarion:
assignee: pvala
caseimportance: critical
casecomponent: Containers
initialEstimate: 1/6h
"""
provider.create_rest()
provider_rest = appliance.rest_api.collections.providers.get(name=provider.name)
assert provider_rest.type == "ManageIQ::Providers::Openshift::ContainerManager"

new_name = fauxfactory.gen_alphanumeric()
edited = provider_rest.action.edit(name=new_name)
assert_response(appliance)
provider_rest.reload()
assert provider_rest.name == new_name == edited.name

provider_rest.action.delete()
provider_rest.wait_not_exists()

assert not provider_rest.exists

0 comments on commit 6a0ac7d

Please sign in to comment.