def test_metadata_in_blueprint(self): """ Tests metadata in blueprint file """ runner = CliRunner() # Writing project name to project file for blueprint make_file_dir(LOCAL_PROJECTNAME_FILE) with open(LOCAL_PROJECTNAME_FILE, "w") as f: f.write(self.dsl_project_name) # Compile Blueprint file LOG.info("Compiling Blueprint with metadata") result = runner.invoke( cli, ["compile", "bp", "--file={}".format(DSL_BP_FILEPATH)]) if result.exit_code: cli_res_dict = { "Output": result.output, "Exception": str(result.exception) } LOG.debug("Cli Response: {}".format( json.dumps(cli_res_dict, indent=4, separators=(",", ": ")))) LOG.debug("Traceback: \n{}".format("".join( traceback.format_tb(result.exc_info[2])))) pytest.fail("BP compile command failed") bp_payload = json.loads(result.output) # Checking the presence of correct project in metadata LOG.info("Checking the project in metadata") assert (bp_payload["metadata"]["project_reference"]["name"] == self.dsl_project_name)
def update_config_file(cls, config_file, host, port, username, password, project_name, log_level): """Updates the config file data""" LOG.debug("Rendering configuration template") make_file_dir(config_file) text = cls._render_config_template(host, port, username, password, project_name, log_level) LOG.debug("Writing configuration to '{}'".format(config_file)) with open(config_file, "w") as fd: fd.write(text)
def setup_method(self): """Method to instantiate to created_bp_list and created_app_list""" # TODO add deletion of vms also. self.created_bp_list = [] self.created_app_list = [] if not self.vrp_name: vrp_data = self._create_vm_recovery_point() self.vrp_name = vrp_data["name"] self.vrp_uuid = vrp_data["uuid"] # Writing vm_ip to local directory file LOG.info("Writing vrp name {} to file '{}'".format( self.vrp_name, LOCAL_RP_NAME_PATH)) make_file_dir(LOCAL_RP_NAME_PATH) with open(LOCAL_RP_NAME_PATH, "w") as f: f.write(self.vrp_name)
def update_init_config(cls, config_file, db_file, local_dir): """updates the init file data""" # create required directories make_file_dir(config_file) make_file_dir(db_file) make_file_dir(local_dir, is_dir=True) # Note: No need to validate init data as it is rendered by template init_file = INIT_FILE_LOCATION make_file_dir(init_file) LOG.debug("Rendering init template") text = cls._render_init_template(config_file, db_file, local_dir) # Write init configuration LOG.debug("Writing configuration to '{}'".format(init_file)) with open(init_file, "w") as fd: fd.write(text)
def __init__(self): init_file = INIT_FILE_LOCATION init_config = configparser.ConfigParser() init_config.optionxform = str init_config.read(init_file) # Validate init config if not validate_init_config(init_config): raise ValueError( "Invalid init config file: {}. Please run: calm init dsl". format(init_file)) config_obj = {} for section in init_config.sections(): config_obj[section] = {} for k, v in init_config.items(section): config_obj[section][k] = v env_init_config = EnvConfig.get_init_config() if not config_obj.get("CONFIG", {}).get("location"): make_file_dir(DEFAULT_CONFIG_FILE) config_obj["CONFIG"] = {"location": DEFAULT_CONFIG_FILE} if env_init_config.get("config_file_location"): config_obj["CONFIG"]["LOCATION"] = env_init_config[ "config_file_location"] if not config_obj.get("DB", {}).get("location"): make_file_dir(DEFAULT_DB_LOCATION) config_obj["DB"] = {"location": DEFAULT_DB_LOCATION} if env_init_config.get("db_location"): config_obj["DB"]["LOCATION"] = env_init_config["db_location"] if not config_obj.get("LOCAL_DIR", {}).get("location"): make_file_dir(DEFAULT_LOCAL_DIR_LOCATION) config_obj["LOCAL_DIR"] = {"location": DEFAULT_LOCAL_DIR_LOCATION} if env_init_config.get("local_dir_location"): config_obj["LOCAL_DIR"]["LOCATION"] = env_init_config[ "local_dir_location"] self._CONFIG = config_obj
def test_app_vm_in_brownfield_bp(self): """ Steps: 1. Create Blueprint 2. Create App 3. Soft Delete app and extract vm-ip from it 4. Create Brownfield Application using that vm-ip 5. Delete brownfield application """ runner = CliRunner() # Create blueprint bp_name = "Blueprint{}".format(str(uuid.uuid4())[:10]) self._create_bp(bp_name) self.created_bp_list.append(bp_name) # Create application app_name = "App{}".format(str(uuid.uuid4())[:10]) LOG.info("Creating App {}".format(app_name)) result = runner.invoke( cli, [ "launch", "bp", bp_name, "--app_name={}".format(app_name), "--ignore_runtime_variables", ], ) if result.exit_code: LOG.error(result.output) pytest.fail("Creation of app {} failed".format(app_name)) # Wait for app creation completion self._wait_for_non_busy_state(app_name) LOG.info("Application {} created successfully".format(app_name)) LOG.info("Extracting vm ip from the app") result = runner.invoke(cli, ["describe", "app", app_name, "--out=json"]) if result.exit_code: LOG.error(result.output) pytest.fail("Describe of app {} failed".format(app_name)) # Extracting vm+ip from the app_json app_json = json.loads(result.output) app_state = app_json["status"]["state"] if app_state != APPLICATION.STATES.RUNNING: LOG.error("App went to {} state".format(app_state)) sys.exit(-1) vm_ip = app_json["status"]["resources"]["deployment_list"][0][ "substrate_configuration"]["element_list"][0]["address"] LOG.info("Soft deleting the app {}".format(app_name)) result = runner.invoke(cli, ["delete", "app", app_name, "--soft"]) if result.exit_code: LOG.error(result.output) pytest.fail("Deletion of app {} failed".format(app_name)) # Wait for app deletion completion self._wait_for_app_delete_busy_state(app_name) LOG.info("Soft Delete of app {} completed".format(app_name)) # Writing vm_ip to local directory file LOG.info("Writing vm_ip {} to file '{}'".format( vm_ip, LOCAL_VM_IP_PATH)) make_file_dir(LOCAL_VM_IP_PATH) with open(LOCAL_VM_IP_PATH, "w") as f: f.write(vm_ip) # Creating brownfield blueprint app_name = "BrownfieldApplication{}".format(str(uuid.uuid4())[:10]) LOG.info("Creating Brownfield Application {}".format(app_name)) result = runner.invoke( cli, [ "create", "app", "--file={}".format(DSL_BP_FILEPATH), "--brownfield_deployments={}".format(DSL_BP_BD_FILEPATH), "--name={}".format(app_name), ], ) if result.exit_code: cli_res_dict = { "Output": result.output, "Exception": str(result.exception) } LOG.debug("Cli Response: {}".format( json.dumps(cli_res_dict, indent=4, separators=(",", ": ")))) LOG.debug("Traceback: \n{}".format("".join( traceback.format_tb(result.exc_info[2])))) pytest.fail("Brownfield App creation failed") self._wait_for_non_busy_state(app_name) LOG.info("Brownfield App {} created successfully".format(app_name)) self.created_app_list.append(app_name)
def test_brownfield_app_from_existing_bp(self): """ Tests checks the brownfield app creation from normal greenfield blueprint Checks for ahv provider for now Steps: 1. Create a greenfield blueprint 2. Launch the bp. 3. Extract the ip from app by soft deleting app 4. Launch the bp by passing brownfield deployments as runtime """ runner = CliRunner() # Create blueprint bp_name = "Blueprint{}".format(str(uuid.uuid4())[:10]) self._create_bp(bp_name) self.created_bp_list.append(bp_name) # Create application app_name = "App{}".format(str(uuid.uuid4())[:10]) LOG.info("Creating App {}".format(app_name)) result = runner.invoke( cli, [ "launch", "bp", bp_name, "--app_name={}".format(app_name), "--ignore_runtime_variables", ], ) if result.exit_code: LOG.error(result.output) pytest.fail("Creation of app {} failed".format(app_name)) # Wait for app creation completion self.app_helper._wait_for_non_busy_state(app_name) LOG.info("Application {} created successfully".format(app_name)) LOG.info("Extracting vm ip from the app") result = runner.invoke(cli, ["describe", "app", app_name, "--out=json"]) if result.exit_code: LOG.error(result.output) pytest.fail("Describe of app {} failed".format(app_name)) # Extracting vm+ip from the app_json app_json = json.loads(result.output) app_state = app_json["status"]["state"] if app_state != APPLICATION.STATES.RUNNING: LOG.error(result.output) pytest.fail("App went to {} state".format(app_state)) vm_ip = app_json["status"]["resources"]["deployment_list"][0][ "substrate_configuration"]["element_list"][0]["address"] LOG.info("Soft deleting the app {}".format(app_name)) result = runner.invoke(cli, ["delete", "app", app_name, "--soft"]) if result.exit_code: LOG.error(result.output) pytest.fail("Deletion of app {} failed".format(app_name)) # Wait for app deletion completion self._wait_for_app_delete_busy_state(app_name) LOG.info("Soft Delete of app {} completed".format(app_name)) # Writing vm_ip to local directory file LOG.info("Writing vm_ip {} to file '{}'".format( vm_ip, LOCAL_VM_IP_PATH)) make_file_dir(LOCAL_VM_IP_PATH) with open(LOCAL_VM_IP_PATH, "w") as f: f.write(vm_ip) # Creating brownfield blueprint app_name_2 = "BrownfieldApplication{}".format(str(uuid.uuid4())[:10]) LOG.info( "Launching bluepring '{}' using brownfield deployments".format( bp_name)) result = runner.invoke( cli, [ "launch", "bp", bp_name, "--brownfield_deployments={}".format(DSL_BP_BD_FILEPATH), "--app_name={}".format(app_name_2), "-i", ], ) if result.exit_code: cli_res_dict = { "Output": result.output, "Exception": str(result.exception) } LOG.debug("Cli Response: {}".format( json.dumps(cli_res_dict, indent=4, separators=(",", ": ")))) LOG.debug("Traceback: \n{}".format("".join( traceback.format_tb(result.exc_info[2])))) pytest.fail("Brownfield App creation failed") self.app_helper._wait_for_non_busy_state(app_name_2) LOG.info("Brownfield App {} created successfully".format(app_name_2)) self.created_app_list.append(app_name_2) # Extracting vm+ip from the app_json LOG.info("Extracting vm ip from the app") result = runner.invoke(cli, ["describe", "app", app_name_2, "--out=json"]) if result.exit_code: LOG.error(result.output) pytest.fail("Describe of app {} failed".format(app_name_2)) app_json = json.loads(result.output) app_state = app_json["status"]["state"] if app_state != APPLICATION.STATES.RUNNING: LOG.error(result.output) pytest.fail("App went to {} state".format(app_state)) new_vm_ip = app_json["status"]["resources"]["deployment_list"][0][ "substrate_configuration"]["element_list"][0]["address"] assert vm_ip == new_vm_ip, "App created with different vm ip"