def test_remove_interface_by_address(self): node_id = 1 interfaces = [ { 'id': 1, 'address': '11:11:11:11:11:11' }, { 'id': 2, 'address': '22:22:22:22:22:22' }, { 'id': 3, 'address': '33:33:33:33:33:33' }, ] self.mox.StubOutWithMock(db, 'bm_node_get') self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id') self.mox.StubOutWithMock(db, 'bm_interface_destroy') db.bm_node_get(self.context, node_id) db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\ AndReturn(interfaces) db.bm_interface_destroy(self.context, 2) self.mox.ReplayAll() body = {'remove_interface': {'address': '22:22:22:22:22:22'}} self.controller._remove_interface(self.request, node_id, body)
def test_unique_address(self): pif1_id = db.bm_interface_create(self.context, 1, '11:11:11:11:11:11', '0x1', 1) self.assertRaises(db_session.DBError, db.bm_interface_create, self.context, 2, '11:11:11:11:11:11', '0x2', 2) # succeed after delete pif1 db.bm_interface_destroy(self.context, pif1_id) pif2_id = db.bm_interface_create(self.context, 2, '11:11:11:11:11:11', '0x2', 2) self.assertTrue(pif2_id is not None)
def test_unique_address(self): pif1_id = db.bm_interface_create(self.context, 1, '11:11:11:11:11:11', '0x1', 1) self.assertRaises(db_exc.DBError, db.bm_interface_create, self.context, 2, '11:11:11:11:11:11', '0x2', 2) # succeed after delete pif1 db.bm_interface_destroy(self.context, pif1_id) pif2_id = db.bm_interface_create(self.context, 2, '11:11:11:11:11:11', '0x2', 2) self.assertTrue(pif2_id is not None)
def test_remove_interface(self): node_id = 1 interfaces = [{"id": 1}, {"id": 2}, {"id": 3}] body = {"remove_interface": {"id": 2}} self.mox.StubOutWithMock(db, "bm_node_get") self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id") self.mox.StubOutWithMock(db, "bm_interface_destroy") db.bm_node_get(self.context, node_id) db.bm_interface_get_all_by_bm_node_id(self.context, node_id).AndReturn(interfaces) db.bm_interface_destroy(self.context, 2) self.mox.ReplayAll() self.controller._remove_interface(self.request, node_id, body)
def test_remove_interface_by_address(self): node_id = 1 interfaces = [{'id': 1, 'address': '11:11:11:11:11:11'}, {'id': 2, 'address': '22:22:22:22:22:22'}, {'id': 3, 'address': '33:33:33:33:33:33'}, ] self.mox.StubOutWithMock(db, 'bm_node_get') self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id') self.mox.StubOutWithMock(db, 'bm_interface_destroy') db.bm_node_get(self.context, node_id) db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\ AndReturn(interfaces) db.bm_interface_destroy(self.context, 2) self.mox.ReplayAll() body = {'remove_interface': {'address': '22:22:22:22:22:22'}} self.controller._remove_interface(self.request, node_id, body)
def test_remove_interface(self): node_id = 1 interfaces = [{'id': 1}, {'id': 2}, {'id': 3}, ] body = {'remove_interface': {'id': 2}} self.mox.StubOutWithMock(db, 'bm_node_get') self.mox.StubOutWithMock(db, 'bm_interface_get_all_by_bm_node_id') self.mox.StubOutWithMock(db, 'bm_interface_destroy') db.bm_node_get(self.context, node_id) db.bm_interface_get_all_by_bm_node_id(self.context, node_id).\ AndReturn(interfaces) db.bm_interface_destroy(self.context, 2) self.mox.ReplayAll() self.controller._remove_interface(self.request, node_id, body)
def test_remove_interface_by_address(self): node_id = 1 interfaces = [ {"id": 1, "address": "11:11:11:11:11:11"}, {"id": 2, "address": "22:22:22:22:22:22"}, {"id": 3, "address": "33:33:33:33:33:33"}, ] self.mox.StubOutWithMock(db, "bm_node_get") self.mox.StubOutWithMock(db, "bm_interface_get_all_by_bm_node_id") self.mox.StubOutWithMock(db, "bm_interface_destroy") db.bm_node_get(self.context, node_id) db.bm_interface_get_all_by_bm_node_id(self.context, node_id).AndReturn(interfaces) db.bm_interface_destroy(self.context, 2) self.mox.ReplayAll() body = {"remove_interface": {"address": "22:22:22:22:22:22"}} self.controller._remove_interface(self.request, node_id, body)
def _remove_interface(self, req, id, body): context = req.environ["nova.context"] authorize(context) self._check_node_exists(context, id) body = body["remove_interface"] if_id = body.get("id") address = body.get("address") if not if_id and not address: raise webob.exc.HTTPBadRequest(explanation=_("Must specify id or address")) ifs = db.bm_interface_get_all_by_bm_node_id(context, id) for i in ifs: if if_id and if_id != i["id"]: continue if address and address != i["address"]: continue db.bm_interface_destroy(context, i["id"]) return webob.Response(status_int=202) raise webob.exc.HTTPNotFound()
def _remove_interface(self, req, id, body): context = req.environ['nova.context'] authorize(context) self._check_node_exists(context, id) body = body['remove_interface'] if_id = body.get('id') address = body.get('address') if not if_id and not address: raise webob.exc.HTTPBadRequest( explanation=_("Must specify id or address")) ifs = db.bm_interface_get_all_by_bm_node_id(context, id) for i in ifs: if if_id and if_id != i['id']: continue if address and address != i['address']: continue db.bm_interface_destroy(context, i['id']) return webob.Response(status_int=202) raise webob.exc.HTTPNotFound()
def _remove_interface(self, req, id, body): context = req.environ['nova.context'] authorize(context) self._check_node_exists(context, id) body = body['remove_interface'] if_id = body.get('id') address = body.get('address') if not if_id and not address: raise webob.exc.HTTPBadRequest( explanation=_("Must specify id or address")) ifs = db.bm_interface_get_all_by_bm_node_id(context, id) for i in ifs: if if_id and if_id != i['id']: continue if address and address != i['address']: continue db.bm_interface_destroy(context, i['id']) return raise webob.exc.HTTPNotFound()