def _cleanup(self, instance): target = os.path.join(FLAGS.instances_path, instance["name"]) instance_name = instance["name"] LOG.info(_("instance %(instance_name)s: deleting instance files" " %(target)s") % locals(), instance=instance) if FLAGS.baremetal_type == "lxc": disk.destroy_container(self.container) if os.path.exists(target): shutil.rmtree(target)
def _cleanup(self, instance): target = os.path.join(FLAGS.instances_path, instance['name']) instance_name = instance['name'] LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals(), instance=instance) if FLAGS.baremetal_type == 'lxc': disk.destroy_container(self.container) if os.path.exists(target): shutil.rmtree(target)
def _cleanup(self, instance): target = os.path.join(CONF.instances_path, instance['name']) instance_name = instance['name'] LOG.info(_('instance %(instance_name)s: deleting instance files' ' %(target)s') % locals(), instance=instance) if CONF.baremetal_type == 'lxc': disk.destroy_container(self.container) if os.path.exists(target): shutil.rmtree(target)
def test_lxc_destroy_container(self): def proc_mounts(self, mount_point): mount_points = { '/mnt/loop/nopart': '/dev/loop0', '/mnt/loop/part': '/dev/mapper/loop0p1', '/mnt/nbd/nopart': '/dev/nbd15', '/mnt/nbd/part': '/dev/mapper/nbd15p1', '/mnt/guestfs': 'guestmount', } return mount_points[mount_point] self.stubs.Set(os.path, 'exists', lambda _: True) self.stubs.Set(disk_api._DiskImage, '_device_for_path', proc_mounts) expected_commands = [] disk_api.destroy_container('/mnt/loop/nopart') expected_commands += [ ('umount', '/dev/loop0'), ('losetup', '--detach', '/dev/loop0'), ] disk_api.destroy_container('/mnt/loop/part') expected_commands += [ ('umount', '/dev/mapper/loop0p1'), ('kpartx', '-d', '/dev/loop0'), ('losetup', '--detach', '/dev/loop0'), ] disk_api.destroy_container('/mnt/nbd/nopart') expected_commands += [ ('umount', '/dev/nbd15'), ('qemu-nbd', '-d', '/dev/nbd15'), ] disk_api.destroy_container('/mnt/nbd/part') expected_commands += [ ('umount', '/dev/mapper/nbd15p1'), ('kpartx', '-d', '/dev/nbd15'), ('qemu-nbd', '-d', '/dev/nbd15'), ] disk_api.destroy_container('/mnt/guestfs') expected_commands += [ ('fusermount', '-u', '/mnt/guestfs'), ] # It's not worth trying to match the last timeout command self.executes.pop() self.assertEqual(self.executes, expected_commands)