def _get_eipconfig(self, fromfile=True, data=sample_config, api_ver='1'): """ Helper that returns an EIPConfig object using the data parameter or a sample data. :param fromfile: sets if we should use a file or a string :type fromfile: bool :param data: sets the data to be used to load in the EIPConfig object :type data: dict (valid json) :param api_ver: the api_version schema to use. :type api_ver: str :rtype: EIPConfig """ config = EIPConfig() config.set_api_version(api_ver) loaded = False if fromfile: self._write_config(data) loaded = config.load(self.configfile, relative=False) else: json_string = json.dumps(data) loaded = config.load(data=json_string) if not loaded: return None return config
def _download_config(self, *args): """ Downloads the EIP config for the given provider """ leap_assert(self._provider_config, "We need a provider configuration!") logger.debug("Downloading EIP config for %s" % (self._provider_config.get_domain(), )) self._eip_config = EIPConfig() download_service_config(self._provider_config, self._eip_config, self._session, self._download_if_needed)
def _download_certificate_test_template(self, ifneeded, createcert): """ All download client certificate tests have the same structure, so this is a parametrized test for that. :param ifneeded: sets _download_if_needed :type ifneeded: bool :param createcert: if True it creates a dummy file to play the part of a downloaded certificate :type createcert: bool :returns: the temp eip cert path and the dummy cert contents :rtype: tuple of str, str """ pc = ProviderConfig() ec = EIPConfig() self.eb._provider_config = pc self.eb._eip_config = ec pc.get_domain = mock.MagicMock( return_value="localhost:%s" % (self.https_port)) pc.get_api_uri = mock.MagicMock( return_value="https://%s" % (pc.get_domain())) pc.get_api_version = mock.MagicMock(return_value="1") pc.get_ca_cert_path = mock.MagicMock(return_value=False) path_prefix = tempfile.mkdtemp() util.get_path_prefix = mock.MagicMock(return_value=path_prefix) EIPConfig.save = mock.MagicMock() EIPConfig.load = mock.MagicMock() self.eb._download_if_needed = ifneeded provider_dir = os.path.join(util.get_path_prefix(), "leap", "providers", "somedomain") mkdir_p(provider_dir) eip_cert_path = os.path.join(provider_dir, "cert") ec.get_client_cert_path = mock.MagicMock( return_value=eip_cert_path) cert_content = "A" if createcert: with open(eip_cert_path, "w") as ec: ec.write(cert_content) return eip_cert_path, cert_content
def setUp(self): self.eipconfig = EIPConfig() self.eipconfig.get_gateways = Mock(return_value=sample_gateways) self.eipconfig.get_locations = Mock(return_value=sample_locations)
def test_fails_without_api_set(self): config = EIPConfig() with self.assertRaises(AssertionError): config.load('non-relevant-path')