From 2de0208d7499603c78d232361030f9a73fa6adda Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Wed, 9 Dec 2009 07:33:51 -0500 Subject: SSSDConfig.get_domain() should properly detect active state --- server/config/SSSDConfig.py | 29 +++++++++++++++++++++++++++++ server/config/SSSDConfigTest.py | 1 + 2 files changed, 30 insertions(+) diff --git a/server/config/SSSDConfig.py b/server/config/SSSDConfig.py index f00824d5..10d2f02a 100644 --- a/server/config/SSSDConfig.py +++ b/server/config/SSSDConfig.py @@ -1238,6 +1238,9 @@ class SSSDConfig(SSSDChangeConf): for opt in self.strip_comments_empty(self.options('domain/%s' % name)) if opt not in providers] + # Determine if this domain is currently active + domain.active = self.is_domain_active(name) + return domain def new_domain(self, name): @@ -1266,6 +1269,32 @@ class SSSDConfig(SSSDChangeConf): self.save_domain(domain) return domain + def is_domain_active(self, name): + """ + Is a particular domain set active + + name: + The name of the configured domain to check + + === Returns === + True if the domain is active, False if it is inactive + + === Errors === + NotInitializedError: + This SSSDConfig object has not had import_config() or new_config() + run on it yet. + NoDomainError: + No domain by this name is configured + """ + + if not self.initialized: + raise NotInitializedError + + if name not in self.list_domains(): + raise NoDomainError + + return name in self.list_active_domains() + def activate_domain(self, name): """ Activate a configured domain diff --git a/server/config/SSSDConfigTest.py b/server/config/SSSDConfigTest.py index 0d42d8a6..abb2b071 100644 --- a/server/config/SSSDConfigTest.py +++ b/server/config/SSSDConfigTest.py @@ -1103,6 +1103,7 @@ class SSSDConfigTestSSSDConfig(unittest.TestCase): domain = sssdconfig.get_domain('IPA') self.assertTrue(isinstance(domain, SSSDConfig.SSSDDomain)) + self.assertTrue(domain.active) # TODO verify the contents of this domain -- cgit