Don't threat as an error when OS_CLOUD env variable is not defined.

Change-Id: Ib9b8278e099d4227d738c368ab55bcbb6f8c0542
changes/42/683042/1
Federico Ressi 3 years ago
parent 5c88325256
commit 21d5a2a1e0

@ -95,6 +95,9 @@ class CloudsFileKeystoneCredentialsFixture(
def get_credentials(self):
cloud_name = self._get_cloud_name()
if cloud_name is None:
return None
clouds_content = self._get_clouds_content()
clouds_section = clouds_content.get("clouds")
if clouds_section is None:
@ -166,12 +169,8 @@ class CloudsFileKeystoneCredentialsFixture(
"variable: %r", cloud_name)
self.cloud_name = cloud_name
else:
message = "Undefined environment variable: 'OS_CLOUD'"
raise ValueError(message)
if not cloud_name:
message = "Invalid cloud name: {!r}".format(cloud_name)
raise ValueError(message)
return cloud_name
LOG.debug("Undefined environment variable: 'OS_CLOUD'")
return cloud_name or None
def _get_clouds_content(self):
clouds_content = self.clouds_content

@ -216,10 +216,11 @@ class CloudsFileKeystoneCredentialsFixtureTest(openstack.OpenstackTest):
clouds_file=file_fixture.clouds_file,
cloud_name='')
self.assertIsNone(credentials_fixture.credentials)
self.assertEqual('', credentials_fixture.cloud_name)
tobiko.setup_fixture(credentials_fixture)
self.assertIsNone(credentials_fixture.credentials)
self.assertEqual('', credentials_fixture.cloud_name)
ex = self.assertRaises(ValueError, tobiko.setup_fixture,
credentials_fixture)
self.assertEqual("Invalid cloud name: ''", str(ex))
def test_setup_with_empty_cloud_name_from_env(self):
file_fixture = self.useFixture(V2CloudsFileFixture())
@ -227,20 +228,22 @@ class CloudsFileKeystoneCredentialsFixtureTest(openstack.OpenstackTest):
credentials_fixture = keystone.CloudsFileKeystoneCredentialsFixture(
clouds_file=file_fixture.clouds_file)
self.assertIsNone(credentials_fixture.credentials)
self.assertIsNone(credentials_fixture.cloud_name)
tobiko.setup_fixture(credentials_fixture)
self.assertIsNone(credentials_fixture.credentials)
self.assertIsNone(credentials_fixture.cloud_name)
ex = self.assertRaises(ValueError, tobiko.setup_fixture,
credentials_fixture)
self.assertEqual("Undefined environment variable: 'OS_CLOUD'", str(ex))
def test_setup_with_no_cloud_name(self):
file_fixture = self.useFixture(V2CloudsFileFixture())
credentials_fixture = keystone.CloudsFileKeystoneCredentialsFixture(
clouds_file=file_fixture.clouds_file)
self.assertIsNone(credentials_fixture.credentials)
self.assertIsNone(credentials_fixture.cloud_name)
tobiko.setup_fixture(credentials_fixture)
self.assertIsNone(credentials_fixture.credentials)
self.assertIsNone(credentials_fixture.cloud_name)
ex = self.assertRaises(ValueError, tobiko.setup_fixture,
credentials_fixture)
self.assertEqual("Undefined environment variable: 'OS_CLOUD'", str(ex))
def test_setup_with_no_clouds_section(self):
fixture = keystone.CloudsFileKeystoneCredentialsFixture(

Loading…
Cancel
Save