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
This commit is contained in:
@@ -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)
|
||||
|
@@ -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())
|
||||
|
Reference in New Issue
Block a user