def test_storage_serialization_and_response(self): now = utils.get_formatted_timestamp() sm = get_storage_manager() deployment_update = models.DeploymentUpdate( deployment_id='deployment-id', deployment_plan={'name': 'my-bp'}, state='staged', id='depup-id', steps=[], deployment_update_nodes=None, deployment_update_node_instances=None, deployment_update_deployment=None, modified_entity_ids=None, execution_id='execution-id', created_at=now) sm.put_deployment_update(deployment_update) depup_from_client = self.client.deployment_updates.get('depup-id') depup_response_attributes = { 'id', 'state', 'deployment_id', 'steps', 'execution_id', 'created_at' } for att in depup_response_attributes: self.assertEqual(getattr(depup_from_client, att), getattr(deployment_update, att))
def stage_deployment_update(self, deployment_id, app_dir, app_blueprint, additional_inputs, new_blueprint_id=None, preview=False, runtime_only_evaluation=False, auto_correct_types=False, reevaluate_active_statuses=False): # validate no active updates are running for a deployment_id if reevaluate_active_statuses: self.reevaluate_updates_statuses_per_deployment(deployment_id) self.validate_no_active_updates_per_deployment(deployment_id) # enables reverting to original blueprint resources deployment = self.sm.get(models.Deployment, deployment_id) old_blueprint = deployment.blueprint runtime_only_evaluation = (runtime_only_evaluation or deployment.runtime_only_evaluation) parsed_deployment = get_parsed_deployment(old_blueprint, app_dir, app_blueprint) # Updating the new inputs with the deployment inputs # (overriding old values and adding new ones) old_inputs = copy.deepcopy(deployment.inputs) new_inputs = {k: old_inputs[k] for k in parsed_deployment.inputs if k in old_inputs} new_inputs.update(additional_inputs) # applying intrinsic functions plan = get_deployment_plan(parsed_deployment, new_inputs, runtime_only_evaluation, auto_correct_types) deployment_update_id = '{0}-{1}'.format(deployment.id, uuid.uuid4()) deployment_update = models.DeploymentUpdate( id=deployment_update_id, deployment_plan=plan, runtime_only_evaluation=runtime_only_evaluation, created_at=get_formatted_timestamp() ) deployment_update.set_deployment(deployment) deployment_update.preview = preview deployment_update.old_inputs = old_inputs deployment_update.new_inputs = new_inputs if new_blueprint_id: new_blueprint = self.sm.get(models.Blueprint, new_blueprint_id) verify_blueprint_uploaded_state(new_blueprint) deployment_update.old_blueprint = old_blueprint deployment_update.new_blueprint = new_blueprint self.sm.put(deployment_update) return deployment_update
def _add_deployment_update(self, blueprint_id, execution_id, deployment_update_id=None): if not deployment_update_id: unique_str = str(uuid.uuid4()) deployment_update_id = 'deployment_update-{0}'.format(unique_str) now = utils.get_formatted_timestamp() deployment_update = models.DeploymentUpdate( deployment_id=blueprint_id, deployment_plan={'name': 'my-bp'}, state='staged', id=deployment_update_id, deployment_update_nodes=None, deployment_update_node_instances=None, deployment_update_deployment=None, modified_entity_ids=None, execution_id=execution_id, created_at=now) return self.sm.put_deployment_update(deployment_update)
def _restore_deployment_updates_and_modifications(self): for line in open(self._deployments_ex_path, 'r'): elem = json.loads(line) node_data = elem['_source'] node_type = elem['_type'] self._update_deployment(node_data) if node_type == 'deployment_updates': dep_update = models.DeploymentUpdate(**node_data) self._storage_manager.put(dep_update) if 'steps' in node_data: steps = node_data['steps'] for step in steps: dep_step = models.DeploymentUpdateStep(**step) self._storage_manager.put(dep_step) elif node_type == 'deployment_modifications': dep_modification = models.DeploymentModification(**node_data) self._storage_manager.put(dep_modification) else: logger.warning('Unknown node type: {0}'.format(node_type))
def stage_deployment_update(self, deployment_id, app_dir, app_blueprint, additional_inputs, new_blueprint_id=None, preview=False, runtime_only_evaluation=False): # enables reverting to original blueprint resources deployment = self.sm.get(models.Deployment, deployment_id) old_blueprint = deployment.blueprint file_server_root = config.instance.file_server_root blueprint_resource_dir = os.path.join(file_server_root, 'blueprints', old_blueprint.tenant_name, old_blueprint.id) runtime_only_evaluation = runtime_only_evaluation or \ deployment.runtime_only_evaluation # The dsl parser expects a URL blueprint_resource_dir_url = 'file:{0}'.format(blueprint_resource_dir) app_path = os.path.join(file_server_root, app_dir, app_blueprint) # parsing the blueprint from here try: plan = tasks.parse_dsl( app_path, resources_base_path=file_server_root, additional_resources=[blueprint_resource_dir_url], **app_context.get_parser_context()) except parser_exceptions.DSLParsingException as ex: raise manager_exceptions.InvalidBlueprintError( 'Invalid blueprint - {0}'.format(ex)) # Updating the new inputs with the deployment inputs # (overriding old values and adding new ones) old_inputs = copy.deepcopy(deployment.inputs) new_inputs = { k: old_inputs[k] for k in plan.inputs.keys() if k in old_inputs } new_inputs.update(additional_inputs) # applying intrinsic functions try: prepared_plan = tasks.prepare_deployment_plan( plan, get_secret_method, inputs=new_inputs, runtime_only_evaluation=runtime_only_evaluation) except parser_exceptions.MissingRequiredInputError as e: raise manager_exceptions.MissingRequiredDeploymentInputError( str(e)) except parser_exceptions.UnknownInputError as e: raise manager_exceptions.UnknownDeploymentInputError(str(e)) except parser_exceptions.UnknownSecretError as e: raise manager_exceptions.UnknownDeploymentSecretError(str(e)) except parser_exceptions.UnsupportedGetSecretError as e: raise manager_exceptions.UnsupportedDeploymentGetSecretError( str(e)) deployment_update_id = '{0}-{1}'.format(deployment.id, uuid.uuid4()) deployment_update = models.DeploymentUpdate( id=deployment_update_id, deployment_plan=prepared_plan, runtime_only_evaluation=runtime_only_evaluation, created_at=utils.get_formatted_timestamp()) deployment_update.set_deployment(deployment) deployment_update.preview = preview deployment_update.old_inputs = old_inputs deployment_update.new_inputs = new_inputs if new_blueprint_id: new_blueprint = self.sm.get(models.Blueprint, new_blueprint_id) deployment_update.old_blueprint = old_blueprint deployment_update.new_blueprint = new_blueprint self.sm.put(deployment_update) return deployment_update
runtime_only_evaluation=runtime_only_evaluation) except parser_exceptions.MissingRequiredInputError, e: raise manager_exceptions.MissingRequiredDeploymentInputError( str(e)) except parser_exceptions.UnknownInputError, e: raise manager_exceptions.UnknownDeploymentInputError(str(e)) except parser_exceptions.UnknownSecretError, e: raise manager_exceptions.UnknownDeploymentSecretError(str(e)) except parser_exceptions.UnsupportedGetSecretError, e: raise manager_exceptions.UnsupportedDeploymentGetSecretError( str(e)) deployment_update_id = '{0}-{1}'.format(deployment.id, uuid.uuid4()) deployment_update = models.DeploymentUpdate( id=deployment_update_id, deployment_plan=prepared_plan, runtime_only_evaluation=runtime_only_evaluation, created_at=utils.get_formatted_timestamp()) deployment_update.set_deployment(deployment) deployment_update.preview = preview deployment_update.old_inputs = old_inputs deployment_update.new_inputs = new_inputs if new_blueprint_id: new_blueprint = self.sm.get(models.Blueprint, new_blueprint_id) deployment_update.old_blueprint = old_blueprint deployment_update.new_blueprint = new_blueprint self.sm.put(deployment_update) return deployment_update def create_deployment_update_step(self, deployment_update, action, entity_type, entity_id):
inputs=inputs) except parser_exceptions.MissingRequiredInputError, e: raise manager_exceptions.MissingRequiredDeploymentInputError( str(e)) except parser_exceptions.UnknownInputError, e: raise manager_exceptions.UnknownDeploymentInputError(str(e)) except parser_exceptions.UnknownSecretError, e: raise manager_exceptions.UnknownDeploymentSecretError(str(e)) except parser_exceptions.UnsupportedGetSecretError, e: raise manager_exceptions.UnsupportedDeploymentGetSecretError( str(e)) deployment_update_id = '{0}-{1}'.format(deployment.id, uuid.uuid4()) deployment_update = models.DeploymentUpdate( id=deployment_update_id, deployment_plan=prepared_plan, created_at=utils.get_formatted_timestamp() ) deployment_update.set_deployment(deployment) self.sm.put(deployment_update) return deployment_update def create_deployment_update_step(self, deployment_update_id, action, entity_type, entity_id): """Create deployment update step :param deployment_update_id: :param action: add/remove/modify