From 02ffd8b13109b2b2b417af260949b04d61db24bc Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Thu, 18 Jan 2018 20:12:46 +0100 Subject: [PATCH] Don't mock swift for unittests For python we can run test with a real swift, so do it. --- gnocchi/incoming/swift.py | 1 + gnocchi/tests/base.py | 24 +++++++++++++++++++++--- run-tests.sh | 8 ++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/gnocchi/incoming/swift.py b/gnocchi/incoming/swift.py index 4445eee40..ad04955e1 100644 --- a/gnocchi/incoming/swift.py +++ b/gnocchi/incoming/swift.py @@ -33,6 +33,7 @@ class SwiftStorage(incoming.IncomingDriver): def __init__(self, conf, greedy=True): super(SwiftStorage, self).__init__(conf) self.swift = swift.get_connection(conf) + # FIXME(sileht): Should we use conf.swift_container_prefix ? def __str__(self): return self.__class__.__name__ diff --git a/gnocchi/tests/base.py b/gnocchi/tests/base.py index 9a7e83961..7233b7ae5 100644 --- a/gnocchi/tests/base.py +++ b/gnocchi/tests/base.py @@ -331,7 +331,9 @@ def setUp(self): storage_driver = os.getenv("GNOCCHI_TEST_STORAGE_DRIVER", "file") self.conf.set_override('driver', storage_driver, 'storage') - if swexc: + if swexc and six.PY3: + # NOTE(sileht): swift is not py3 ready, so we mock it + # for py3 self.useFixture(fixtures.MockPatch( 'swiftclient.client.Connection', FakeSwiftClient)) @@ -351,6 +353,18 @@ def setUp(self): os.getenv("CEPH_CONF"), pool_name), shell=True, stdout=f, stderr=subprocess.STDOUT) self.conf.set_override('ceph_pool', pool_name, 'storage') + elif self.conf.storage.driver == 'swift': + self.conf.set_override("swift_user", + os.getenv("PIFPAF_SWIFT_USERNAME"), + "storage") + self.conf.set_override("swift_key", + os.getenv("PIFPAF_SWIFT_PASSWORD"), + "storage") + self.conf.set_override("swift_authurl", + os.getenv("PIFPAF_SWIFT_AUTH_URL"), + "storage") + self.conf.set_override("swift_container_prefix", + uuid.uuid4().hex, "storage") # Override the bucket prefix to be unique to avoid concurrent access # with any other test @@ -364,9 +378,13 @@ def setUp(self): # Create one prefix per test self.storage.STORAGE_PREFIX = str(uuid.uuid4()).encode() - if self.conf.incoming.driver == 'redis': + if self.conf.incoming.driver in ['redis', 'swift']: + prefix = str(uuid.uuid4()) + self.incoming.CFG_PREFIX = ( + prefix + incoming.IncomingDriver.CFG_PREFIX + ) self.incoming.SACK_NAME_FORMAT = ( - str(uuid.uuid4()) + incoming.IncomingDriver.SACK_NAME_FORMAT + prefix + incoming.IncomingDriver.SACK_NAME_FORMAT ) self.storage.upgrade() diff --git a/run-tests.sh b/run-tests.sh index 320198ae6..45a821467 100755 --- a/run-tests.sh +++ b/run-tests.sh @@ -12,6 +12,7 @@ cleanup(){ } trap cleanup EXIT +PYTHON_MAJOR_VERSION=$(python -c "import sys; print(sys.version_info[0])") PIDS="" GNOCCHI_TEST_STORAGE_DRIVERS=${GNOCCHI_TEST_STORAGE_DRIVERS:-file} GNOCCHI_TEST_INDEXER_DRIVERS=${GNOCCHI_TEST_INDEXER_DRIVERS:-postgresql} @@ -25,6 +26,13 @@ do ceph|redis) pifpaf run $GNOCCHI_TEST_STORAGE_DRIVER -- pifpaf -g GNOCCHI_INDEXER_URL run $indexer -- ./tools/pretty_tox.sh $* ;; + swift) + if [ "$PYTHON_MAJOR_VERSION" = "2" ]; then + pifpaf run $GNOCCHI_TEST_STORAGE_DRIVER -- pifpaf -g GNOCCHI_INDEXER_URL run $indexer -- ./tools/pretty_tox.sh $* + else + pifpaf -g GNOCCHI_INDEXER_URL run $indexer -- ./tools/pretty_tox.sh $* + fi + ;; s3) if ! which s3rver >/dev/null 2>&1 then