Skip to content

Commit

Permalink
Don't mock swift for unittests
Browse files Browse the repository at this point in the history
For python we can run test with a real swift, so do it.
  • Loading branch information
Mehdi Abaakouk authored and sileht committed Apr 27, 2018
1 parent 76cf9e3 commit 02ffd8b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions gnocchi/incoming/swift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down
24 changes: 21 additions & 3 deletions gnocchi/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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
Expand Down

0 comments on commit 02ffd8b

Please sign in to comment.