def __init__(self, config_map_request_timeout: int = None): self.__dict__ = self.__shared_state if not self.__dict__: config_map_data = get_config_map_data( name=NAUTA_CONFIGURATION_CM, namespace=NAUTA_NAMESPACE, request_timeout=config_map_request_timeout) self.registry = config_map_data[self.REGISTRY_FIELD] self.image_tiller = '{}/{}'.format( config_map_data[self.REGISTRY_FIELD], config_map_data[self.IMAGE_TILLER_FIELD]) self.external_ip = config_map_data[self.EXTERNAL_IP_FIELD] self.image_tensorboard_service = '{}/{}'.format( config_map_data[self.REGISTRY_FIELD], config_map_data[self.IMAGE_TENSORBOARD_SERVICE_FIELD]) self.platform_version = config_map_data.get(self.PLATFORM_VERSION) self.py2_image_name = config_map_data.get(self.PY2_IMAGE_NAME) self.py3_image_name = config_map_data.get(self.PY3_IMAGE_NAME) self.py2_horovod_image_name = config_map_data.get( NAUTAConfigMap.PY2_HOROVOD_IMAGE_CONFIG_KEY) self.py3_horovod_image_name = config_map_data.get( NAUTAConfigMap.PY3_HOROVOD_IMAGE_CONFIG_KEY) self.minimal_node_memory_amount = config_map_data.get( NAUTAConfigMap.MINIMAL_NODE_MEMORY_AMOUNT) self.minimal_node_cpu_number = config_map_data.get( NAUTAConfigMap.MINIMAL_NODE_CPU_NUMBER) self.pytorch_image_name = config_map_data.get( NAUTAConfigMap.PYTORCH_IMAGE_CONFIG_KEY)
def delete(state: State, username: str, purge: bool): """ Deletes a user with a name given as a parameter. :param username: name of a user that should be deleted :param purge: if set - command removes also all artifacts associated with a user """ try: click.echo(Texts.DELETION_CHECK_PRESENCE) user_state = check_users_presence(username) if user_state == UserState.NOT_EXISTS: handle_error(user_msg=Texts.USER_NOT_EXISTS_ERROR_MSG.format( username=username)) exit(1) if user_state == UserState.TERMINATING: handle_error(user_msg=Texts.USER_BEING_REMOVED_ERROR_MSG) exit(1) except Exception: handle_error(logger, Texts.USER_PRESENCE_VERIFICATION_ERROR_MSG, Texts.USER_PRESENCE_VERIFICATION_ERROR_MSG, add_verbosity_msg=state.verbosity == 0) exit(1) click.echo() if not click.confirm(Texts.DELETE_CONFIRM_MSG.format(username=username)): click.echo(Texts.DELETE_ABORT_MSG) exit(0) click.echo() try: click.echo(Texts.DELETION_START_DELETING) delete_user(username) patch_config_map_data(name=USER_DEL_CM, namespace=NAUTA_NAMESPACE, key=username, value="1") if purge: try: click.echo(Texts.DELETION_START_PURGING) # failure during purging a user doesn't mean that user wasn't deleted purge_user(username) except Exception: handle_error(logger, Texts.PURGE_ERROR_MSG, Texts.PURGE_ERROR_MSG) # CAN-616 - wait until user has been really deleted with spinner(text=Texts.DELETION_VERIFICATION_OF_DELETING ) as user_del_spinner: for i in range(60): user_state = check_users_presence(username) user_del_cm_content = get_config_map_data( name=USER_DEL_CM, namespace=NAUTA_NAMESPACE, request_timeout=1) if (not user_state or user_state == UserState.NOT_EXISTS) and \ (not user_del_cm_content or not user_del_cm_content.get(username)): break time.sleep(1) else: user_del_spinner.stop() click.echo() click.echo(Texts.DELETE_IN_PROGRESS_MSG) exit(0) click.echo() click.echo(Texts.DELETE_SUCCESS_MSG.format(username=username)) except K8sProxyCloseError: handle_error(logger, Texts.PROXY_ERROR_LOG_MSG, Texts.PROXY_ERROR_USER_MSG, add_verbosity_msg=state.verbosity == 0) exit(1) except Exception: handle_error(logger, Texts.OTHER_ERROR_LOG_MSG, Texts.OTHER_ERROR_USER_MSG, add_verbosity_msg=state.verbosity == 0) exit(1)
def test_get_config_map_data(mocker, mocked_k8s_CoreV1Api, mocked_kubeconfig): data = get_config_map_data("config_map_name", test_namespace) assert data.get(NAUTAConfigMap.EXTERNAL_IP_FIELD) == TEST_EXTERNAL_IP assert data.get(NAUTAConfigMap.IMAGE_TILLER_FIELD) == TEST_IMAGE_TILLER