def ensure_component_auth_page_requires_authorization( url, token=None, iteration_duration=1, iterations=5): """ Ensures component main auth page requires authorization :param url: component url :type url: str :param jenkins: if jenkins service is under test :type jenkins: boolean :param token: token for the authorization :type token: str :param iteration_duration: duration between checks in seconds :type iteration_duration: int :param iterations: maximum count of iterations :type iterations: int """ def is_page_unavailable(): res = Utils.get_component_auth_page(url, token=token) if res['response_code'] == 401 and 'Authorization Required' in res[ 'response_text']: return True return False if not wait_until(is_page_unavailable, iteration_duration=iteration_duration, iterations=iterations): raise Exception('Auth page is available')
def ensure_metric_not_present(self, model_id, model_version, model_endpoint='default'): """ Ensure that requests count metric for model not exists :param model_id: model ID :type model_id: str :param model_version: model version :type model_version: str :param model_endpoint: model endpoint :type model_endpoint: str :raises: Exception :return: None """ def is_metric_present(): try: self.metric_should_not_be_presented( model_id, model_version, model_endpoint=model_endpoint) except Exception as e: print( 'Got metric_should_not_be_presented exception: {}'.format( e)) return True return False if wait_until(is_metric_present, 5, 3): raise Exception('Metric is not present')
def wait_for_worker_is_ready(self, expected_count=1): """ Wait until expected count of Flower workers started :param int or str expected_count: expected num of online Flower workers :return: None """ expected_count = int(expected_count) worker_ready = wait_until( lambda: self.get_number_of_workers_from_flower() == expected_count, iteration_duration=10, iterations=30) if not worker_ready: raise Exception( "Expected ready workers count '{}' does not match actual '{}'". format(expected_count, self.get_number_of_workers_from_flower()))
def wait_deployment_replicas_count(self, deployment_name, namespace='default', expected_replicas_num=1): """ Wait for expected number of replicas for a specified deployment from Kubernetes API :param deployment_name: name of a deployment :type deployment_name: str :param namespace: name of a namespace to look in :type namespace: str :param expected_replicas_num: expected replicas number :type expected_replicas_num: str :return: None """ expected_replicas_num = int(expected_replicas_num) result = wait_until(lambda: self.get_deployment_replicas(deployment_name, namespace) == expected_replicas_num, iteration_duration=5, iterations=35) if not result: raise Exception("Expected ready replicas count '{}' does not match actual '{}'" .format(expected_replicas_num, self.get_deployment_replicas(deployment_name, namespace)))