From 765bbfdaf0572a465b00d8f4ee2451469fe3a26d Mon Sep 17 00:00:00 2001 From: Parthvi Vala Date: Mon, 13 Jul 2020 13:09:12 +0530 Subject: [PATCH] Enhance create_rest for OCP --- cfme/common/provider.py | 57 ++++++++++++++++--- cfme/containers/provider/__init__.py | 25 ++++++++ .../test_container_provider_crud.py | 27 +++++++++ 3 files changed, 100 insertions(+), 9 deletions(-) diff --git a/cfme/common/provider.py b/cfme/common/provider.py index 115ad45eea..bff6a98c79 100644 --- a/cfme/common/provider.py +++ b/cfme/common/provider.py @@ -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, @@ -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' @@ -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``. @@ -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: @@ -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): diff --git a/cfme/containers/provider/__init__.py b/cfme/containers/provider/__init__.py index 39f381b168..781cf4b95b 100644 --- a/cfme/containers/provider/__init__.py +++ b/cfme/containers/provider/__init__.py @@ -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 @@ -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 = { diff --git a/cfme/tests/containers/test_container_provider_crud.py b/cfme/tests/containers/test_container_provider_crud.py index a9a15a303e..e9d36d44c3 100644 --- a/cfme/tests/containers/test_container_provider_crud.py +++ b/cfme/tests/containers/test_container_provider_crud.py @@ -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 @@ -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