metric: change delete to allow deleting several metric at once
This makes it much faster than spawning a new process each time with the CLI. Change-Id: I5a7b36f63549eeb9df4fe9e1d4985e3fe0ddcc08
This commit is contained in:
parent
6dc4cbda8e
commit
7b88c229ad
|
@ -9,11 +9,43 @@
|
|||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import uuid
|
||||
|
||||
from gnocchiclient.tests.functional import base
|
||||
|
||||
|
||||
class MetricClientTest(base.ClientTestBase):
|
||||
def test_delete_several_metrics(self):
|
||||
apname = str(uuid.uuid4())
|
||||
# PREPARE AN ACHIVE POLICY
|
||||
self.gnocchi("archive-policy", params="create %s "
|
||||
"--back-window 0 -d granularity:1s,points:86400" % apname)
|
||||
# Create 2 metrics
|
||||
result = self.gnocchi(
|
||||
u'metric', params=u"create"
|
||||
u" --archive-policy-name %s" % apname)
|
||||
metric1 = self.details_multiple(result)[0]
|
||||
|
||||
result = self.gnocchi(
|
||||
u'metric', params=u"create"
|
||||
u" --archive-policy-name %s" % apname)
|
||||
metric2 = self.details_multiple(result)[0]
|
||||
|
||||
# DELETE
|
||||
result = self.gnocchi('metric', params="delete %s %s"
|
||||
% (metric1["id"], metric2["id"]))
|
||||
self.assertEqual("", result)
|
||||
|
||||
# GET FAIL
|
||||
result = self.gnocchi('metric', params="show %s" % metric1["id"],
|
||||
fail_ok=True, merge_stderr=True)
|
||||
self.assertFirstLineStartsWith(result.split('\n'),
|
||||
"Not Found (HTTP 404)")
|
||||
result = self.gnocchi('metric', params="show %s" % metric2["id"],
|
||||
fail_ok=True, merge_stderr=True)
|
||||
self.assertFirstLineStartsWith(result.split('\n'),
|
||||
"Not Found (HTTP 404)")
|
||||
|
||||
def test_metric_scenario(self):
|
||||
# PREPARE AN ACHIVE POLICY
|
||||
self.gnocchi("archive-policy", params="create metric-test "
|
||||
|
@ -189,7 +221,8 @@ class MetricClientTest(base.ClientTestBase):
|
|||
self.assertEqual(metric[field], metric_from_list[field])
|
||||
|
||||
# DELETE
|
||||
result = self.gnocchi('metric', params="delete metric-name metric-res")
|
||||
result = self.gnocchi('metric',
|
||||
params="delete -r metric-res metric-name")
|
||||
self.assertEqual("", result)
|
||||
|
||||
# GET FAIL
|
||||
|
@ -199,7 +232,8 @@ class MetricClientTest(base.ClientTestBase):
|
|||
"Not Found (HTTP 404)")
|
||||
|
||||
# DELETE FAIL
|
||||
result = self.gnocchi('metric', params="delete metric-name metric-res",
|
||||
result = self.gnocchi('metric',
|
||||
params="delete -r metric-res metric-name",
|
||||
fail_ok=True, merge_stderr=True)
|
||||
self.assertFirstLineStartsWith(result.split('\n'),
|
||||
"Not Found (HTTP 404)")
|
||||
|
|
|
@ -76,15 +76,16 @@ class CliMetricCreate(show.ShowOne):
|
|||
class CliMetricDelete(command.Command):
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CliMetricDelete, self).get_parser(prog_name)
|
||||
parser.add_argument("metric",
|
||||
help="ID or name of the metric")
|
||||
parser.add_argument("resource_id", nargs='?',
|
||||
parser.add_argument("metric", nargs='+',
|
||||
help="IDs or names of the metric")
|
||||
parser.add_argument("--resource-id", "-r",
|
||||
help="ID of the resource")
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
self.app.client.metric.delete(metric=parsed_args.metric,
|
||||
resource_id=parsed_args.resource_id)
|
||||
for metric in parsed_args.metric:
|
||||
self.app.client.metric.delete(metric=metric,
|
||||
resource_id=parsed_args.resource_id)
|
||||
|
||||
|
||||
class CliMeasuresGet(lister.Lister):
|
||||
|
|
Loading…
Reference in New Issue