From 2cee569e759bbc7d0828609bad0ff10a93215f8c Mon Sep 17 00:00:00 2001 From: James Page Date: Mon, 23 May 2016 10:08:57 +0100 Subject: [PATCH] Use JUJU_MODEL_UUID for Juju 2.0 Juju 2.0 renames the environment variable JUJU_ENV_UUID to JUJU_MODEL_UUID; use this environment variable as a fallback if JUJU_ENV_UUID is not set to support Juju 2.0, whilst continuing to provide support for Juju < 2.0. Change-Id: I26ae366c84d3cd9a9c2471385effd2a6202e9314 Closes-Bug: 1572575 (cherry picked from commit 0fa129873bf056120a403790b167ca198e8b26fc) --- lib/swift_context.py | 4 +++- unit_tests/test_swift_context.py | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/swift_context.py b/lib/swift_context.py index 7e2fa79..3132b15 100644 --- a/lib/swift_context.py +++ b/lib/swift_context.py @@ -202,7 +202,9 @@ def get_swift_hash(): with open(SWIFT_HASH_FILE, 'w') as hashfile: hashfile.write(swift_hash) else: - swift_hash = str(uuid.uuid3(uuid.UUID(os.environ.get("JUJU_ENV_UUID")), + model_uuid = os.environ.get("JUJU_ENV_UUID", + os.environ.get("JUJU_MODEL_UUID")) + swift_hash = str(uuid.uuid3(uuid.UUID(model_uuid), service_name())) with open(SWIFT_HASH_FILE, 'w') as hashfile: hashfile.write(swift_hash) diff --git a/unit_tests/test_swift_context.py b/unit_tests/test_swift_context.py index 62b96f0..c47f362 100644 --- a/unit_tests/test_swift_context.py +++ b/unit_tests/test_swift_context.py @@ -48,7 +48,11 @@ class SwiftContextTestCase(unittest.TestCase): with mock.patch('lib.swift_context.os.environ.get') as mock_env_get: mock_env_get.return_value = str(uuid.uuid4()) hash_ = swift_context.get_swift_hash() - mock_env_get.assert_called_with('JUJU_ENV_UUID') + mock_env_get.assert_has_calls([ + mock.call('JUJU_MODEL_UUID'), + mock.call('JUJU_ENV_UUID', + mock_env_get.return_value) + ]) with open(tmpfile, 'r') as fd: self.assertEqual(hash_, fd.read())