def test_openstack_configuration_copy_to_manager(self): script_path = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'scripts', 'configure.py') task = get_task(script_path, '_copy_openstack_configuration_to_manager') config_output_file_path = tempfile.mkstemp()[1] def mock_put(file_path, *args, **kwargs): shutil.copyfile(file_path, config_output_file_path) task.func_globals['fabric'].api.put = mock_put inputs_config = { 'username': '******', 'region': 'inputs-region' } file_config = { 'username': '******', 'password': '******', 'auth_url': 'file-auth-url' } conf_file_path = tempfile.mkstemp()[1] os.environ[Config.OPENSTACK_CONFIG_PATH_ENV_VAR] = conf_file_path with open(conf_file_path, 'w') as f: json.dump(file_config, f) os.environ['OS_USERNAME'] = '******' os.environ['OS_PASSWORD'] = '******' os.environ['OS_TENANT_NAME'] = 'envar-tenant-name' task(inputs_config) with open(config_output_file_path) as f: config = json.load(f) self.assertEquals('inputs-username', config.get('username')) self.assertEquals('inputs-region', config.get('region')) self.assertEquals('file-password', config.get('password')) self.assertEquals('file-auth-url', config.get('auth_url')) self.assertEquals('envar-tenant-name', config.get('tenant_name'))
def test_cloudstack_configuration_copy_to_manager(self): script_path = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'scripts', 'configure.py') task = get_task(script_path, '_copy_cloudstack_configuration_to_manager') config_output_file_path = tempfile.mkstemp()[1] def mock_put(file_path, *args, **kwargs): shutil.copyfile(file_path, config_output_file_path) task.func_globals['fabric'].api.put = mock_put inputs_config = { 'cs_api_key': 'inputs-api-key' } file_config = { 'cs_api_key': 'file-api-key', 'cs_api_secret': 'file-api-secret' } conf_file_path = tempfile.mkstemp()[1] os.environ[Config.CLOUDSTACK_CONFIG_PATH_ENV_VAR] = conf_file_path with open(conf_file_path, 'w') as f: json.dump(file_config, f) os.environ['CS_API_KEY'] = 'envar-api-key' os.environ['CS_API_SECRET'] = 'envar-api-secret' os.environ['CS_API_URL'] = 'envar-api-url' task(inputs_config) with open(config_output_file_path) as f: config = json.load(f) self.assertEquals('inputs-api-key', config.get('cs_api_key')) self.assertEquals('file-api-secret', config.get('cs_api_secret')) self.assertEquals('envar-api-url', config.get('cs_api_url'))
def test_cloudstack_configuration_copy_to_manager(self): script_path = os.path.join( os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'scripts', 'configure.py') task = get_task(script_path, '_copy_cloudstack_configuration_to_manager') config_output_file_path = tempfile.mkstemp()[1] def mock_put(file_path, *args, **kwargs): shutil.copyfile(file_path, config_output_file_path) task.func_globals['fabric'].api.put = mock_put inputs_config = {'cs_api_key': 'inputs-api-key'} file_config = { 'cs_api_key': 'file-api-key', 'cs_api_secret': 'file-api-secret' } conf_file_path = tempfile.mkstemp()[1] os.environ[Config.CLOUDSTACK_CONFIG_PATH_ENV_VAR] = conf_file_path with open(conf_file_path, 'w') as f: json.dump(file_config, f) os.environ['CS_API_KEY'] = 'envar-api-key' os.environ['CS_API_SECRET'] = 'envar-api-secret' os.environ['CS_API_URL'] = 'envar-api-url' task(inputs_config) with open(config_output_file_path) as f: config = json.load(f) self.assertEquals('inputs-api-key', config.get('cs_api_key')) self.assertEquals('file-api-secret', config.get('cs_api_secret')) self.assertEquals('envar-api-url', config.get('cs_api_url'))