10
10
# License for the specific language governing permissions and limitations
11
11
# under the License.
12
12
13
- from unittest import mock
14
-
15
13
import fixtures
16
14
15
+ from unittest import mock
16
+
17
17
from nova import context as nova_context
18
18
from nova import exception
19
19
from nova import objects
20
20
from nova .tests import fixtures as nova_fixtures
21
21
from nova .tests .fixtures import libvirt as fakelibvirt
22
+ from nova .tests .functional .api import client
22
23
from nova .tests .functional .libvirt import base
23
24
from nova .virt import hardware
24
25
from nova .virt .libvirt .cpu import api as cpu_api
@@ -240,7 +241,6 @@ def setUp(self):
240
241
cpu_cores = 5 , cpu_threads = 2 )
241
242
self .compute1 = self .start_compute (host_info = self .host_info ,
242
243
hostname = 'compute1' )
243
-
244
244
# All cores are shutdown at startup, let's check.
245
245
cpu_dedicated_set = hardware .get_cpu_dedicated_set ()
246
246
self ._assert_cpu_set_state (cpu_dedicated_set , expected = 'offline' )
@@ -266,6 +266,33 @@ def test_create_server(self):
266
266
cpu_dedicated_set = hardware .get_cpu_dedicated_set ()
267
267
unused_cpus = cpu_dedicated_set - instance_pcpus
268
268
self ._assert_cpu_set_state (unused_cpus , expected = 'offline' )
269
+ return server
270
+
271
+ def test_delete_server (self ):
272
+ server = self .test_create_server ()
273
+ self ._delete_server (server )
274
+ # Let's verify that the pinned CPUs are now offline
275
+ cpu_dedicated_set = hardware .get_cpu_dedicated_set ()
276
+ self ._assert_cpu_set_state (cpu_dedicated_set , expected = 'offline' )
277
+
278
+ def test_delete_server_device_busy (self ):
279
+ server = self .test_create_server ()
280
+
281
+ inst = objects .Instance .get_by_uuid (self .ctxt , server ['id' ])
282
+ instance_pcpus = inst .numa_topology .cpu_pinning
283
+ self ._assert_cpu_set_state (instance_pcpus , expected = 'online' )
284
+ with mock .patch (
285
+ 'nova.filesystem.write_sys' ,
286
+ side_effect = exception .FileNotFound (file_path = 'fake' )):
287
+ # This is bug 2065927
288
+ self .assertRaises (
289
+ client .OpenStackApiException , self ._delete_server , server )
290
+ cpu_dedicated_set = hardware .get_cpu_dedicated_set ()
291
+ # Verify that the unused CPUs are still offline
292
+ unused_cpus = cpu_dedicated_set - instance_pcpus
293
+ self ._assert_cpu_set_state (unused_cpus , expected = 'offline' )
294
+ # but the instance cpus are still online
295
+ self ._assert_cpu_set_state (instance_pcpus , expected = 'online' )
269
296
270
297
def test_create_server_with_emulator_threads_isolate (self ):
271
298
server = self ._create_server (
0 commit comments