From fc3838243a0ca29927afabee424a6956c5b52037 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 20 Aug 2016 10:32:34 +0200 Subject: [PATCH] ceph: fix write emulation Ceph never raises ObjectNotFound on write. Change-Id: Ida84fcbcb9fbd75b90eb11b57f3db271c1425102 --- gnocchi/carbonara.py | 6 ------ gnocchi/storage/ceph.py | 7 +------ gnocchi/tests/base.py | 8 ++++---- 3 files changed, 5 insertions(+), 16 deletions(-) diff --git a/gnocchi/carbonara.py b/gnocchi/carbonara.py index c0db53b30..2413fbf8b 100644 --- a/gnocchi/carbonara.py +++ b/gnocchi/carbonara.py @@ -415,12 +415,6 @@ class AggregatedTimeSerie(TimeSerie): return int((self.first.value - split) // (self.sampling * 10e8) * self.SERIAL_LEN) - @staticmethod - def padding(offset): - offset = offset // AggregatedTimeSerie.SERIAL_LEN - pad = [False] * offset * 2 - return struct.pack('<' + '?d' * offset, *pad) - def _truncate(self, quick=False): """Truncate the timeserie.""" if self.max_size is not None: diff --git a/gnocchi/storage/ceph.py b/gnocchi/storage/ceph.py index 23de86ba2..6e345ea1a 100644 --- a/gnocchi/storage/ceph.py +++ b/gnocchi/storage/ceph.py @@ -257,12 +257,7 @@ class CephStorage(_carbonara.CarbonaraBasedStorage): granularity, data, offset=0, version=3): name = self._get_object_name(metric, timestamp_key, aggregation, granularity, version) - try: - self.ioctx.write(name, data, offset=offset) - except rados.ObjectNotFound: - # first time writing data - self.ioctx.write_full( - name, carbonara.AggregatedTimeSerie.padding(offset) + data) + self.ioctx.write(name, data, offset=offset) self.ioctx.set_xattr("gnocchi_%s_container" % metric.id, name, "") def _delete_metric_measures(self, metric, timestamp_key, aggregation, diff --git a/gnocchi/tests/base.py b/gnocchi/tests/base.py index 298dcf9e5..1a0f5ad45 100644 --- a/gnocchi/tests/base.py +++ b/gnocchi/tests/base.py @@ -140,11 +140,11 @@ class FakeRadosModule(object): self._validate_key(key) try: current = self.kvs[key] - if len(current) < offset: - current += b'\x00' * (offset - len(current)) - self.kvs[key] = current[:offset] + value except KeyError: - raise FakeRadosModule.ObjectNotFound + current = b"" + if len(current) < offset: + current += b'\x00' * (offset - len(current)) + self.kvs[key] = current[:offset] + value def stat(self, key): self._validate_key(key)