Implement pod deletion
Pod deletion is working from magnum api. Change-Id: I6b6ccc9d95bddc42a98450cebac15bfd7aceab37
This commit is contained in:
parent
5fe240f50e
commit
b30b4f1f25
|
@ -346,6 +346,4 @@ class PodsController(rest.RestController):
|
||||||
if self.from_pods:
|
if self.from_pods:
|
||||||
raise exception.OperationNotPermitted
|
raise exception.OperationNotPermitted
|
||||||
|
|
||||||
rpc_pod = objects.Pod.get_by_uuid(pecan.request.context,
|
pecan.request.rpcapi.pod_delete(pod_uuid)
|
||||||
pod_uuid)
|
|
||||||
pecan.request.rpcapi.pod_delete(rpc_pod)
|
|
||||||
|
|
|
@ -82,8 +82,8 @@ class API(rpc_service.API):
|
||||||
def pod_list(self, context, limit, marker, sort_key, sort_dir):
|
def pod_list(self, context, limit, marker, sort_key, sort_dir):
|
||||||
return objects.Pod.list(context, limit, marker, sort_key, sort_dir)
|
return objects.Pod.list(context, limit, marker, sort_key, sort_dir)
|
||||||
|
|
||||||
def pod_delete(self, pod):
|
def pod_delete(self, uuid):
|
||||||
return self._call('pod_delete', pod=pod)
|
return self._call('pod_delete', uuid=uuid)
|
||||||
|
|
||||||
def pod_show(self, ctxt, uuid):
|
def pod_show(self, ctxt, uuid):
|
||||||
return objects.Pod.get_by_uuid(ctxt, uuid)
|
return objects.Pod.get_by_uuid(ctxt, uuid)
|
||||||
|
|
|
@ -202,15 +202,15 @@ class KubeClient(object):
|
||||||
LOG.error("Couldn't get list of pods due to error %s" % e)
|
LOG.error("Couldn't get list of pods due to error %s" % e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def pod_delete(self, master_address, uuid):
|
def pod_delete(self, master_address, name):
|
||||||
LOG.debug("pod_delete %s" % uuid)
|
LOG.debug("pod_delete %s" % name)
|
||||||
try:
|
try:
|
||||||
out, err = utils.trycmd('kubectl', 'delete', 'pod', uuid,
|
out, err = utils.trycmd('kubectl', 'delete', 'pod', name,
|
||||||
'-s', master_address,)
|
'-s', master_address,)
|
||||||
if err:
|
if err:
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("Couldn't delete pod %s due to error %s" % (uuid, e))
|
LOG.error("Couldn't delete pod %s due to error %s" % (name, e))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -142,10 +142,13 @@ class Handler(object):
|
||||||
LOG.debug("pod_list")
|
LOG.debug("pod_list")
|
||||||
return self.kube_cli.pod_list()
|
return self.kube_cli.pod_list()
|
||||||
|
|
||||||
def pod_delete(self, ctxt, pod):
|
def pod_delete(self, ctxt, uuid):
|
||||||
LOG.debug("pod_delete ")
|
LOG.debug("pod_delete ")
|
||||||
# trigger a kubectl command
|
# trigger a kubectl command
|
||||||
status = self.kube_cli.pod_delete(pod.uuid)
|
pod = objects.Pod.get_by_uuid(ctxt, uuid)
|
||||||
|
k8s_master_url = _retrive_k8s_master_url(ctxt, pod)
|
||||||
|
|
||||||
|
status = self.kube_cli.pod_delete(k8s_master_url, pod.name)
|
||||||
if not status:
|
if not status:
|
||||||
return None
|
return None
|
||||||
# call the pod object to persist in db
|
# call the pod object to persist in db
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
from magnum.conductor import api
|
from magnum.conductor import api
|
||||||
|
from magnum import objects
|
||||||
from magnum.tests.db import base as db_base
|
from magnum.tests.db import base as db_base
|
||||||
|
|
||||||
from mock import patch
|
from mock import patch
|
||||||
|
@ -20,7 +21,8 @@ class TestPodController(db_base.DbTestCase):
|
||||||
pod.create()
|
pod.create()
|
||||||
return pod
|
return pod
|
||||||
|
|
||||||
def mock_pod_destroy(self, pod):
|
def mock_pod_destroy(self, pod_uuid):
|
||||||
|
pod = objects.Pod.get_by_uuid({}, pod_uuid)
|
||||||
pod.destroy()
|
pod.destroy()
|
||||||
|
|
||||||
def test_pod_api(self):
|
def test_pod_api(self):
|
||||||
|
|
|
@ -102,12 +102,11 @@ class RPCAPITestCase(base.DbTestCase):
|
||||||
version='1.0',
|
version='1.0',
|
||||||
pod=self.fake_pod)
|
pod=self.fake_pod)
|
||||||
|
|
||||||
# TODO(sdake) the parameters to delete operations are highly suspect
|
|
||||||
def test_pod_delete(self):
|
def test_pod_delete(self):
|
||||||
self._test_rpcapi('pod_delete',
|
self._test_rpcapi('pod_delete',
|
||||||
'call',
|
'call',
|
||||||
version='1.0',
|
version='1.0',
|
||||||
pod=self.fake_pod)
|
uuid=self.fake_pod['uuid'])
|
||||||
|
|
||||||
def test_rc_create(self):
|
def test_rc_create(self):
|
||||||
self._test_rpcapi('rc_create',
|
self._test_rpcapi('rc_create',
|
||||||
|
|
Loading…
Reference in New Issue