def wait_for_realized_state(cls, client_obj, id_=None, timeout=None, desired_state=None, **get_realized_state_kwargs): if id_ is None: if client_obj.id_ is None: raise ValueError("UUID of %r is not provided, can't poll the " "realized state") else: id_ = client_obj.id_ for required_attr in cls._REQUIRED_STATE_ATTRS: if not getattr(cls, required_attr): raise RuntimeError("%r is not defined in %r" % (required_attr, cls)) pylogger.debug("Checking for %r %r realization ..." % (cls._client_class, id_)) if desired_state is None: desired_state = cls._SUCCESS def _realized_logical_state_checker(result_dict): return (result_dict["response"]["state"] == desired_state) def _state_checker_exc_handler(exc): pylogger.debug("%s state checker returned " "exception: %r" % (cls._client_class, exc)) result = timeouts.logical_component_realization_timeout.wait_until( cls.get_realized_state, args=[client_obj, cls._get_state_class(), cls._id_param, id_], kwargs=get_realized_state_kwargs, timeout=timeout, checker=_realized_logical_state_checker, exc_handler=_state_checker_exc_handler, logger=pylogger) if 'state' not in result['response']: pylogger.debug("No state found in result: %s" % pprint.pformat(result)) reason = "No state found in result object" raise errors.Error(status_code=common.status_codes.FAILURE, reason=reason) if result['response']['state'] != desired_state: reason = ( "%r %r state realization failed: %s" % (cls._client_class, id_, pprint.pformat(result['response']))) raise errors.Error(status_code=common.status_codes.FAILURE, reason=reason)
def verify_ui_component(cls, client_obj, test_name=None, **kwargs): client_class_obj = cls.get_sdk_client_object(client_obj) pylogger.debug("Execute UI test: %s", test_name) method = constants.HTTPVerb.PUT endpoint = cls._url_prefix + '/ui-driver' headers = {"Content-type": "application/text"} conn = client_class_obj.get_connection() response = conn.request(method, endpoint, test_name, headers) response_data = response.read() if response.status not in [httplib.OK]: pylogger.error('REST call failed: Details: %s', response_data) pylogger.error('ErrorCode: %s', response.status) pylogger.error('Reason: %s', response.reason) raise errors.Error(status_code=common.status_codes.FAILURE, reason=response.reason) result_dict = json.loads(response_data) return result_dict