From c469e396bde67db15e486a320b254de0fa6f69df Mon Sep 17 00:00:00 2001 From: kali Date: Tue, 28 Aug 2012 06:08:58 +0900 Subject: checki complete eip_config tests. completed first version of EIPChecks --- src/leap/eip/checks.py | 59 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 5 deletions(-) (limited to 'src/leap/eip/checks.py') diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py index dbb7d524..84a2ba6b 100644 --- a/src/leap/eip/checks.py +++ b/src/leap/eip/checks.py @@ -53,7 +53,7 @@ class EIPChecker(object): checker.fetch_definition() checker.fetch_eip_config() checker.check_complete_eip_config() - checker.ping_gateway() + #checker.ping_gateway() # public checks @@ -97,6 +97,13 @@ class EIPChecker(object): def fetch_definition(self, skip_download=False, config=None, uri=None): # check_and_get_definition_file + """ + fetches a definition file from server + """ + # TODO: + # - Implement diff + # - overwrite if different. + if skip_download: return True if config is None: @@ -123,11 +130,47 @@ class EIPChecker(object): with open(definition_file, 'wb') as f: f.write(json.dumps(request.json, indent=4)) - def fetch_eip_config(self): - raise NotImplementedError + def fetch_eip_config(self, skip_download=False, + config=None, uri=None): + if skip_download: + return True + if config is None: + config = self.config + if uri is None: + if config: + domain = config.get('provider', None) + else: + domain = None + uri = self._get_eip_service_uri( + domain=domain) - def check_complete_eip_config(self): - raise NotImplementedError + # XXX move to JSONConfig Fetcher + request = self.fetcher.get(uri) + request.raise_for_status() + + definition_file = os.path.join( + baseconfig.get_default_provider_path(), + eipconstants.EIP_SERVICE_EXPECTED_PATH) + + folder, filename = os.path.split(definition_file) + if not os.path.isdir(folder): + mkdir_p(folder) + with open(definition_file, 'wb') as f: + f.write(json.dumps(request.json, indent=4)) + + def check_complete_eip_config(self, config=None): + if config is None: + config = self.config + try: + 'trying assertions' + assert 'provider' in config + assert config['provider'] is not None + except AssertionError: + raise eipexceptions.EIPConfigurationError + + # XXX TODO: + # We should WRITE eip config if missing or + # incomplete at this point def ping_gateway(self): raise NotImplementedError @@ -154,3 +197,9 @@ class EIPChecker(object): path = baseconstants.DEFINITION_EXPECTED_PATH return "https://%s/%s" % (domain, path) + def _get_eip_service_uri(self, domain=None, path=None): + if domain is None: + domain = baseconstants.DEFAULT_TEST_PROVIDER + if path is None: + path = eipconstants.EIP_SERVICE_EXPECTED_PATH + return "https://%s/%s" % (domain, path) -- cgit v1.2.3