def DELETE(self, autostackId, metricId): # pylint: disable=C0103,R0201 """ Remove a specific metric from autostack :: DELETE /_autostacks/{autostackId}/metrics/{metricId} """ try: # The if statement makes sure that the metric belongs to the autostack with web.ctx.connFactory() as conn: autostackObj = repository.getAutostackFromMetric(conn, metricId) if autostackId != autostackObj.uid: raise InvalidRequestResponse( {"result": "Metric=%s does not belong to autostack=%s" % (metricId, autostackId)}) with web.ctx.connFactory() as conn: repository.deleteMetric(conn, metricId) model_swapper_utils.deleteHTMModel(metricId) raise web.HTTPError(status="204 No Content") except ObjectNotFoundError: raise web.notfound(("Autostack or metric not found: autostack=%s, " "metric=%s") % (autostackId, metricId)) except web.HTTPError as ex: if bool(re.match(r"([45][0-9][0-9])\s?", web.ctx.status)): # Log 400-599 status codes as errors, ignoring 200-399 log.error(str(ex) or repr(ex)) raise except Exception as ex: log.exception("DELETE Failed") raise web.internalerror(str(ex) or repr(ex))
def tearDownClass(cls): try: engine = repository.engineFactory() with engine.connect() as conn: repository.deleteMetric(conn, cls.uid) with engine.connect() as conn: _ = repository.getMetric(conn, cls.uid) except ObjectNotFoundError: g_logger.info("Successful clean-up") else: g_logger.error("Test failed to delete metric=%s", cls.uid)
def DELETE(self, autostackId, metricId): # pylint: disable=C0103,R0201 """ Remove a specific metric from autostack :: DELETE /_autostacks/{autostackId}/metrics/{metricId} """ try: # The if statement makes sure that the metric belongs to the autostack with web.ctx.connFactory() as conn: autostackObj = repository.getAutostackFromMetric( conn, metricId) if autostackId != autostackObj.uid: raise InvalidRequestResponse({ "result": "Metric=%s does not belong to autostack=%s" % (metricId, autostackId) }) with web.ctx.connFactory() as conn: repository.deleteMetric(conn, metricId) model_swapper_utils.deleteHTMModel(metricId) raise web.HTTPError(status="204 No Content") except ObjectNotFoundError: raise web.notfound(("Autostack or metric not found: autostack=%s, " "metric=%s") % (autostackId, metricId)) except web.HTTPError as ex: if bool(re.match(r"([45][0-9][0-9])\s?", web.ctx.status)): # Log 400-599 status codes as errors, ignoring 200-399 log.error(str(ex) or repr(ex)) raise except Exception as ex: log.exception("DELETE Failed") raise web.internalerror(str(ex) or repr(ex))