Add exceptions to baremetal/db/api
Raise exceptions from baremetal/db/sqlalchemy/api.py following the precedents from nova/db/sqlalchemy/api.py. Fixes tests to expect the new exceptions. Adds __init__ so that baremetal tests work in isolation. blueprint general-bare-metal-provisioning-framework Change-Id: Ic8ef66e8f3180460a7bf117fccbfe15078905d8b
This commit is contained in:
		
							
								
								
									
										15
									
								
								nova/tests/baremetal/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								nova/tests/baremetal/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| # Copyright (c) 2012 NTT DOCOMO, INC. | ||||
| # All Rights Reserved. | ||||
| # | ||||
| #    Licensed under the Apache License, Version 2.0 (the "License"); you may | ||||
| #    not use this file except in compliance with the License. You may obtain | ||||
| #    a copy of the License at | ||||
| # | ||||
| #         http://www.apache.org/licenses/LICENSE-2.0 | ||||
| # | ||||
| #    Unless required by applicable law or agreed to in writing, software | ||||
| #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||||
| #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||||
| #    License for the specific language governing permissions and limitations | ||||
| #    under the License. | ||||
| from nova.tests import * | ||||
| @@ -42,6 +42,13 @@ class BareMetalInterfaceTestCase(base.BMDBTestCase): | ||||
|         pif2_id = db.bm_interface_create(self.context, 2, '22:22:22:22:22:22', | ||||
|                                          '0x2', 2) | ||||
|         db.bm_interface_set_vif_uuid(self.context, pif1_id, 'AAAA') | ||||
|         self.assertRaises(exception.DBError, | ||||
|         self.assertRaises(exception.NovaException, | ||||
|                           db.bm_interface_set_vif_uuid, | ||||
|                           self.context, pif2_id, 'AAAA') | ||||
|  | ||||
|     def test_vif_not_found(self): | ||||
|         pif_id = db.bm_interface_create(self.context, 1, '11:11:11:11:11:11', | ||||
|                                         '0x1', 1) | ||||
|         self.assertRaises(exception.NovaException, | ||||
|                           db.bm_interface_set_vif_uuid, | ||||
|                           self.context, pif_id + 1, 'AAAA') | ||||
|   | ||||
| @@ -17,6 +17,7 @@ | ||||
| Bare-Metal DB testcase for BareMetalNode | ||||
| """ | ||||
|  | ||||
| from nova import exception | ||||
| from nova.tests.baremetal.db import base | ||||
| from nova.tests.baremetal.db import utils | ||||
| from nova.virt.baremetal import db | ||||
| @@ -67,8 +68,10 @@ class BareMetalNodesTestCase(base.BMDBTestCase): | ||||
|         r = db.bm_node_get(self.context, self.ids[1]) | ||||
|         self.assertEquals(r['pm_address'], '1') | ||||
|  | ||||
|         r = db.bm_node_get(self.context, -1) | ||||
|         self.assertTrue(r is None) | ||||
|         self.assertRaises( | ||||
|               exception.InstanceNotFound, | ||||
|               db.bm_node_get, | ||||
|               self.context, -1) | ||||
|  | ||||
|     def test_get_by_service_host(self): | ||||
|         self._create_nodes() | ||||
| @@ -97,8 +100,10 @@ class BareMetalNodesTestCase(base.BMDBTestCase): | ||||
|  | ||||
|         db.bm_node_destroy(self.context, self.ids[0]) | ||||
|  | ||||
|         r = db.bm_node_get(self.context, self.ids[0]) | ||||
|         self.assertTrue(r is None) | ||||
|         self.assertRaises( | ||||
|               exception.InstanceNotFound, | ||||
|               db.bm_node_get, | ||||
|               self.context, self.ids[0]) | ||||
|  | ||||
|         r = db.bm_node_get_all(self.context) | ||||
|         self.assertEquals(len(r), 5) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Devananda van der Veen
					Devananda van der Veen