def test_dump_yaml(self, dump): if hasattr(yaml, 'CSafeDumper'): yaml_dumper = yaml.CSafeDumper else: yaml_dumper = yaml.SafeDumper yamlutils.dump('version: 1') dump.assert_called_with('version: 1', Dumper=yaml_dumper)
def put(self): """Modify this plan.""" policy.check('update_plan', pecan.request.security_context) # make sure the plan exists before parsing the request handler = plan_handler.PlanHandler(pecan.request.security_context) handler.get(self._id) host_url = pecan.request.application_url.rstrip('/') if not pecan.request.body or len(pecan.request.body) < 1: raise exception.BadRequest(reason="No data.") if (pecan.request.content_type is not None and 'yaml' in pecan.request.content_type): data = init_yml_plan_by_version() updated_plan_yml = yamlutils.dump(yaml_content(handler.update( self._id, data.as_dict(objects.registry.Plan)))) else: data = init_json_plan_by_version() plan_obj = handler.update(self._id, data.as_dict(objects.registry.Plan)) updated_plan_yml = wsme_json.encode_result(plan.Plan.from_db_model( plan_obj, host_url), plan.Plan) pecan.response.status = 200 return updated_plan_yml
def test_delete(self, mock_clients, mock_registry): db_obj = fakes.FakePipeline() mock_exec = mock.MagicMock() mock_exec.context = json.dumps({'stack_id': 'foo'}) mock_mistral = mock_clients.return_value.mistral.return_value mock_mistral.executions.get.return_value = mock_exec wb = yamlutils.dump({ 'Workflow': { 'tasks': { 'start': { 'parameters': { 'stack_id': '' } } } } }) mock_mistral.workbooks.get_definition.return_value = wb mock_registry.Pipeline.get_by_uuid.return_value = db_obj handler = pipeline_handler.PipelineHandler(self.ctx) handler.delete('test_id') db_obj.destroy.assert_called_once_with(self.ctx) mock_registry.Pipeline.get_by_uuid.assert_called_once_with( self.ctx, 'test_id') mock_heat = mock_clients.return_value.heat.return_value mock_heat.stacks.delete.assert_called_once_with(stack_id='foo') mock_kc = mock_clients.return_value.keystone.return_value mock_kc.delete_trust.assert_called_once_with('trust_worthy')
def get_all(self): """Return all plans, based on the query provided.""" handler = plan_handler.PlanHandler(pecan.request.security_context) plan_yml = yamlutils.dump([yaml_content(obj) for obj in handler.get_all() if obj and obj.raw_content]) pecan.response.status = 200 return plan_yml
def get_all(self): """Return all plans, based on the query provided.""" handler = plan_handler.PlanHandler(pecan.request.security_context) plan_yml = yamlutils.dump([ yaml_content(obj) for obj in handler.get_all() if obj and obj.raw_content ]) pecan.response.status = 200 return plan_yml
def get(self): """Return this plan.""" handler = plan_handler.PlanHandler(pecan.request.security_context) if pecan.request.accept is not None and 'yaml' in pecan.request.accept: plan_serialized = yamlutils.dump( yaml_content(handler.get(self._id))) else: plan_model = plan.Plan.from_db_model( handler.get(self._id), pecan.request.host_url) plan_serialized = wsme_json.encode_result(plan_model, plan.Plan) pecan.response.status = 200 return plan_serialized
def put(self): """Modify this plan.""" if not pecan.request.body or len(pecan.request.body) < 1: raise exception.BadRequest try: yml_input_plan = yamlutils.load(pecan.request.body) except ValueError as excp: raise exception.BadRequest(reason='Plan is invalid. ' + excp.message) handler, data = init_plan_by_version(yml_input_plan) updated_plan_yml = yamlutils.dump(yaml_content(handler.update( self._id, data.as_dict(objects.registry.Plan)))) pecan.response.status = 200 return updated_plan_yml
def post(self): """Create a new plan.""" if not pecan.request.body or len(pecan.request.body) < 1: raise exception.BadRequest try: yml_input_plan = yamlutils.load(pecan.request.body) except ValueError as excp: raise exception.BadRequest(reason='Plan is invalid. ' + excp.message) handler, data = init_plan_by_version(yml_input_plan) create_plan_yml = yamlutils.dump( yaml_content(handler.create(data.as_dict(objects.registry.Plan)))) pecan.response.status = 201 return create_plan_yml
def get_all(self): """Return all plans, based on the query provided.""" handler = plan_handler.PlanHandler(pecan.request.security_context) if pecan.request.accept is not None and 'yaml' in pecan.request.accept: plan_serialized = yamlutils.dump([yaml_content(obj) for obj in handler.get_all() if obj and obj.raw_content]) else: plan_serialized = wsme_json.encode_result( [plan.Plan.from_db_model(obj, pecan.request.host_url) for obj in handler.get_all()], wsme_types.ArrayType(plan.Plan)) pecan.response.status = 200 return plan_serialized
def get(self): """Return this plan.""" policy.check('show_plan', pecan.request.security_context) handler = plan_handler.PlanHandler(pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') if pecan.request.accept is not None and 'yaml' in pecan.request.accept: plan_serialized = yamlutils.dump( yaml_content(handler.get(self._id))) else: plan_model = plan.Plan.from_db_model( handler.get(self._id), host_url) plan_serialized = wsme_json.encode_result(plan_model, plan.Plan) pecan.response.status = 200 return plan_serialized
def post(self): """Create a new plan.""" if not pecan.request.body or len(pecan.request.body) < 1: raise exception.BadRequest handler = plan_handler.PlanHandler(pecan.request.security_context) if (pecan.request.content_type is not None and 'yaml' in pecan.request.content_type): data = init_yml_plan_by_version() created_plan = yamlutils.dump(yaml_content(handler.create( data.as_dict(objects.registry.Plan)))) else: data = init_json_plan_by_version() plan_wsme = plan.Plan.from_db_model(handler.create( data.as_dict(objects.registry.Plan)), pecan.request.host_url) created_plan = wsme_json.encode_result(plan_wsme, plan.Plan) pecan.response.status = 201 return created_plan
def post(self): """Create a new plan.""" if not pecan.request.body or len(pecan.request.body) < 1: raise exception.BadRequest(reason="No data.") handler = plan_handler.PlanHandler(pecan.request.security_context) if (pecan.request.content_type is not None and 'yaml' in pecan.request.content_type): data = init_yml_plan_by_version() created_plan = yamlutils.dump(yaml_content(handler.create( data.as_dict(objects.registry.Plan)))) else: data = init_json_plan_by_version() plan_wsme = plan.Plan.from_db_model(handler.create( data.as_dict(objects.registry.Plan)), pecan.request.host_url) created_plan = wsme_json.encode_result(plan_wsme, plan.Plan) pecan.response.status = 201 return created_plan
def test_delete(self, mock_clients, mock_registry): db_obj = fakes.FakePipeline() mock_exec = mock.MagicMock() mock_exec.context = json.dumps({'stack_id': 'foo'}) mock_mistral = mock_clients.return_value.mistral.return_value mock_mistral.executions.get.return_value = mock_exec wb = yamlutils.dump({'Workflow': { 'tasks': {'start': {'parameters': {'stack_id': ''}}}}}) mock_mistral.workbooks.get_definition.return_value = wb mock_registry.Pipeline.get_by_uuid.return_value = db_obj handler = pipeline_handler.PipelineHandler(self.ctx) handler.delete('test_id') db_obj.destroy.assert_called_once_with(self.ctx) mock_registry.Pipeline.get_by_uuid.assert_called_once_with(self.ctx, 'test_id') mock_heat = mock_clients.return_value.heat.return_value mock_heat.stacks.delete.assert_called_once_with(stack_id='foo') mock_kc = mock_clients.return_value.keystone.return_value mock_kc.delete_trust.assert_called_once_with('trust_worthy')
def get(self): """Return this plan.""" handler = plan_handler.PlanHandler(pecan.request.security_context) plan_yml = yamlutils.dump(yaml_content(handler.get(self._id))) pecan.response.status = 200 return plan_yml
def process_bind_param(self, value, dialect): if value is not None: value = yamlutils.dump(value) return value