def delete(self, _id): context = t_context.extract_context_from_environ() if not t_context.is_admin_context(context): pecan.abort(400, _('Admin role required to delete pods')) return try: with context.session.begin(): pod = core.get_resource(context, models.Pod, _id) if pod is not None: ag_name = utils.get_ag_name(pod['pod_name']) ag = az_ag.get_ag_by_name(context, ag_name) if ag is not None: az_ag.delete_ag(context, ag['id']) core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.exception( _LE('Failed to delete pod: %(pod_id)s,' '%(exception)s'), { 'pod_id': _id, 'exception': e }) return Response(_('Failed to delete pod'), 500)
def delete(self, _id): context = t_context.extract_context_from_environ() if not policy.enforce(context, policy.ADMIN_API_PODS_DELETE): pecan.abort(401, _('Unauthorized to delete pods')) return try: with context.session.begin(): pod = core.get_resource(context, models.Pod, _id) if pod is not None: ag_name = utils.get_ag_name(pod['pod_name']) ag = az_ag.get_ag_by_name(context, ag_name) if ag is not None: az_ag.delete_ag(context, ag['id']) core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 return {} except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.exception(_LE('Failed to delete pod: %(pod_id)s,' '%(exception)s'), {'pod_id': _id, 'exception': e}) return Response(_('Failed to delete pod'), 500)
def delete(self, _id): context = t_context.extract_context_from_environ() if not t_context.is_admin_context(context): pecan.abort(400, _('Admin role required to delete pods')) return try: with context.session.begin(): pod = core.get_resource(context, models.Pod, _id) if pod is not None: ag_name = utils.get_ag_name(pod['pod_name']) ag = az_ag.get_ag_by_name(context, ag_name) if ag is not None: az_ag.delete_ag(context, ag['id']) core.delete_resource(context, models.Pod, _id) pecan.response.status = 200 except t_exc.ResourceNotFound: return Response(_('Pod not found'), 404) except Exception as e: LOG.error(_LE('Fail to delete pod: %(exception)s'), {'exception': e}) return Response(_('Fail to delete pod'), 500)
def test_get_delete_one(self, mock_context): mock_context.return_value = self.context pods = [ { "pod": { "pod_name": "Pod1", "pod_az_name": "az1", "dc_name": "dc2", "az_name": "AZ1" }, "expected_error": 200, }, { "pod": { "pod_name": "Pod2", "pod_az_name": "az1", "dc_name": "dc2", "az_name": "AZ1" }, "expected_error": 200, }, { "pod": { "pod_name": "Pod3", "pod_az_name": "az1", "dc_name": "dc2", "az_name": "AZ2" }, "expected_error": 200, }, ] self._test_and_check(pods) response = self.app.get('/v1.0/pods') self.assertEqual(response.status_int, 200) return_pods = response.json for ret_pod in return_pods['pods']: _id = ret_pod['pod_id'] single_ret = self.app.get('/v1.0/pods/' + str(_id)) self.assertEqual(single_ret.status_int, 200) one_pod_ret = single_ret.json get_one_pod = one_pod_ret['pod'] self.assertEqual(get_one_pod['pod_id'], ret_pod['pod_id']) self.assertEqual(get_one_pod['pod_name'], ret_pod['pod_name']) self.assertEqual(get_one_pod['pod_az_name'], ret_pod['pod_az_name']) self.assertEqual(get_one_pod['dc_name'], ret_pod['dc_name']) self.assertEqual(get_one_pod['az_name'], ret_pod['az_name']) _id = ret_pod['pod_id'] # check ag and az automaticly added ag_name = utils.get_ag_name(ret_pod['pod_name']) ag = az_ag.get_ag_by_name(self.context, ag_name) self.assertIsNotNone(ag) self.assertEqual(ag['name'], utils.get_ag_name(ret_pod['pod_name'])) self.assertEqual(ag['availability_zone'], ret_pod['az_name']) single_ret = self.app.delete('/v1.0/pods/' + str(_id)) self.assertEqual(single_ret.status_int, 200) # make sure ag is deleted ag = az_ag.get_ag_by_name(self.context, ag_name) self.assertIsNone(ag)