def init_config(provider, provider_kwargs, **kwargs): path = get_config_path() if "path" in kwargs: path = kwargs["path"] response = {} provider_config = prepare_provider_config(provider, provider_kwargs, **kwargs) # If no config exists -> create it _config = {} if not config_exists(path=path): _config = generate_default_config() save_config(_config, path=path) else: _config = load_config(path=path) if not config_exists(path=path): response["msg"] = "Failed to find a config" return False, response # Update with user arguments _config["corc"]["providers"].update(provider_config) if not save_config(_config, path=path): response["msg"] = "Failed to save new config" return False, response if not valid_config(_config, verbose=True): response["msg"] = "The generated config is invalid" return False, response response["msg"] = "Generated a new configuration" return True, response
def test_valid_load_instance_config(self): test_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tmp") config_path = os.path.join(test_dir, "config") config = generate_default_config() oci_config = generate_oci_config() config["corc"]["providers"].update(oci_config) self.assertTrue(save_config(config, path=config_path)) options = OCIInstanceOrchestrator.load_config_options(path=config_path) self.assertIsNone(OCIInstanceOrchestrator.validate_options(options)) self.assertTrue(remove_config(config_path))
def test_provider_profile(self): provider = "oci" config = generate_default_config() save_config(config, path=self.config_path) profile = get_provider_profile(provider, config_path=self.config_path) self.assertDictEqual(profile, {}) test_profile = {"name": "DEFAULT", "compartment_id": "test"} self.assertTrue( set_provider_profile(provider, test_profile, config_path=self.config_path)) profile = get_provider_profile(provider, config_path=self.config_path) self.assertDictEqual(profile, test_profile) self.assertTrue(valid_config(config)) self.assertTrue(remove_config(path=self.config_path))
def test_valid_config(self): config = generate_default_config() local_copy = copy.deepcopy(config) self.assertTrue(valid_config(config, verbose=True)) self.assertDictEqual(local_copy, config)
def test_load_config(self): config = generate_default_config() self.assertTrue(save_config(config, path=self.config_path)) loaded_config = load_config(self.config_path) self.assertIsInstance(loaded_config, dict) self.assertDictEqual(config, loaded_config)
def test_save_config(self): config = generate_default_config() self.assertTrue(save_config(config, path=self.config_path))
def test_generate_config(self): self.assertDictEqual(generate_default_config(), default_corc_config)