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:
|
||||
raise exception.OperationNotPermitted
|
||||
|
||||
rpc_pod = objects.Pod.get_by_uuid(pecan.request.context,
|
||||
pod_uuid)
|
||||
pecan.request.rpcapi.pod_delete(rpc_pod)
|
||||
pecan.request.rpcapi.pod_delete(pod_uuid)
|
||||
|
|
|
@ -82,8 +82,8 @@ class API(rpc_service.API):
|
|||
def pod_list(self, context, limit, marker, sort_key, sort_dir):
|
||||
return objects.Pod.list(context, limit, marker, sort_key, sort_dir)
|
||||
|
||||
def pod_delete(self, pod):
|
||||
return self._call('pod_delete', pod=pod)
|
||||
def pod_delete(self, uuid):
|
||||
return self._call('pod_delete', uuid=uuid)
|
||||
|
||||
def pod_show(self, 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)
|
||||
return None
|
||||
|
||||
def pod_delete(self, master_address, uuid):
|
||||
LOG.debug("pod_delete %s" % uuid)
|
||||
def pod_delete(self, master_address, name):
|
||||
LOG.debug("pod_delete %s" % name)
|
||||
try:
|
||||
out, err = utils.trycmd('kubectl', 'delete', 'pod', uuid,
|
||||
out, err = utils.trycmd('kubectl', 'delete', 'pod', name,
|
||||
'-s', master_address,)
|
||||
if err:
|
||||
return False
|
||||
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 True
|
||||
|
||||
|
|
|
@ -142,10 +142,13 @@ class Handler(object):
|
|||
LOG.debug("pod_list")
|
||||
return self.kube_cli.pod_list()
|
||||
|
||||
def pod_delete(self, ctxt, pod):
|
||||
def pod_delete(self, ctxt, uuid):
|
||||
LOG.debug("pod_delete ")
|
||||
# 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:
|
||||
return None
|
||||
# call the pod object to persist in db
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from magnum.conductor import api
|
||||
from magnum import objects
|
||||
from magnum.tests.db import base as db_base
|
||||
|
||||
from mock import patch
|
||||
|
@ -20,7 +21,8 @@ class TestPodController(db_base.DbTestCase):
|
|||
pod.create()
|
||||
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()
|
||||
|
||||
def test_pod_api(self):
|
||||
|
|
|
@ -102,12 +102,11 @@ class RPCAPITestCase(base.DbTestCase):
|
|||
version='1.0',
|
||||
pod=self.fake_pod)
|
||||
|
||||
# TODO(sdake) the parameters to delete operations are highly suspect
|
||||
def test_pod_delete(self):
|
||||
self._test_rpcapi('pod_delete',
|
||||
'call',
|
||||
version='1.0',
|
||||
pod=self.fake_pod)
|
||||
uuid=self.fake_pod['uuid'])
|
||||
|
||||
def test_rc_create(self):
|
||||
self._test_rpcapi('rc_create',
|
||||
|
|
Loading…
Reference in New Issue