From dd1e05dc839ae6f52becf71b746b02d78d76a8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Fri, 30 Jun 2017 21:25:37 +0200 Subject: [PATCH] vm: drop rename related methods Since VM name in immutable now, drop rename-related methods. QubesOS/qubes-issues#2868 --- qubes/tests/integ/basic.py | 62 ------------------------------------ qubes/tests/vm/qubesvm.py | 44 -------------------------- qubes/vm/qubesvm.py | 65 -------------------------------------- 3 files changed, 171 deletions(-) diff --git a/qubes/tests/integ/basic.py b/qubes/tests/integ/basic.py index ebf9f6d4a..642f20d08 100644 --- a/qubes/tests/integ/basic.py +++ b/qubes/tests/integ/basic.py @@ -77,68 +77,6 @@ def setUp(self): label='red') self.loop.run_until_complete(self.vm.create_on_disk()) - @unittest.expectedFailure - def test_000_rename(self): - newname = self.make_vm_name('newname') - - self.assertEqual(self.vm.name, self.vmname) - self.vm.firewall.policy = 'drop' - self.vm.firewall.rules = [ - qubes.firewall.Rule(None, action='accept', specialtarget='dns') - ] - self.vm.firewall.save() - self.vm.autostart = True - self.addCleanup(os.system, - 'sudo systemctl -q disable qubes-vm@{}.service || :'. - format(self.vmname)) - pre_rename_firewall = self.vm.firewall.rules - - with self.assertNotRaises( - (OSError, libvirt.libvirtError, qubes.exc.QubesException)): - self.vm.name = newname - self.assertEqual(self.vm.name, newname) - self.assertEqual(self.vm.dir_path, - os.path.join( - qubes.config.system_path['qubes_base_dir'], - qubes.config.system_path['qubes_appvms_dir'], newname)) - self.assertTrue(os.path.exists( - os.path.join(self.vm.dir_path, "apps", newname + "-vm.directory"))) - # FIXME: set whitelisted-appmenus.list first - self.assertTrue(os.path.exists(os.path.join( - self.vm.dir_path, "apps", newname + "-firefox.desktop"))) - self.assertTrue(os.path.exists( - os.path.join(os.getenv("HOME"), ".local/share/desktop-directories", - newname + "-vm.directory"))) - self.assertTrue(os.path.exists( - os.path.join(os.getenv("HOME"), ".local/share/applications", - newname + "-firefox.desktop"))) - self.assertFalse(os.path.exists( - os.path.join(os.getenv("HOME"), ".local/share/desktop-directories", - self.vmname + "-vm.directory"))) - self.assertFalse(os.path.exists( - os.path.join(os.getenv("HOME"), ".local/share/applications", - self.vmname + "-firefox.desktop"))) - self.vm.firewall.load() - self.assertEqual(pre_rename_firewall, self.vm.firewall.rules) - with self.assertNotRaises((qubes.exc.QubesException, OSError)): - self.vm.firewall.save() - self.assertTrue(self.vm.autostart) - self.assertTrue(os.path.exists( - '/etc/systemd/system/multi-user.target.wants/' - 'qubes-vm@{}.service'.format(newname))) - self.assertFalse(os.path.exists( - '/etc/systemd/system/multi-user.target.wants/' - 'qubes-vm@{}.service'.format(self.vmname))) - - def test_001_rename_libvirt_undefined(self): - self.vm.libvirt_domain.undefine() - self.vm._libvirt_domain = None # pylint: disable=protected-access - - newname = self.make_vm_name('newname') - with self.assertNotRaises( - (OSError, libvirt.libvirtError, qubes.exc.QubesException)): - self.vm.name = newname - @unittest.expectedFailure def test_030_clone(self): testvm1 = self.app.add_new_vm( diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index cb006e344..60535d442 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -80,50 +80,6 @@ def test_002_setter_qid_gt_max(self): qubes.vm.qubesvm._setter_qid(self.vm, self.prop, qubes.config.max_qid + 5) - - def test_010_setter_name(self): - self.assertEqual( - qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test_name-1'), - 'test_name-1') - - def test_011_setter_name_not_a_string(self): - # pylint: disable=invalid-name - with self.assertRaises(TypeError): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, False) - - def test_012_setter_name_longer_than_31(self): - # pylint: disable=invalid-name - with self.assertRaises(ValueError): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, 't' * 32) - - def test_013_setter_name_illegal_character(self): - # pylint: disable=invalid-name - with self.assertRaises(ValueError): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'test#') - - def test_014_setter_name_first_not_letter(self): - # pylint: disable=invalid-name - with self.assertRaises(ValueError): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, '1test') - - def test_015_setter_name_running(self): - self.vm.running = True - with self.assertRaises(qubes.exc.QubesVMNotHaltedError): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname') - - def test_016_setter_name_installed_by_rpm(self): - # pylint: disable=invalid-name - self.vm.installed_by_rpm = True - with self.assertRaises(qubes.exc.QubesException): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'testname') - - def test_017_setter_name_duplicate(self): - # pylint: disable=invalid-name - self.vm.app.domains['duplicate'] = TestVM(name='duplicate') - with self.assertRaises(qubes.exc.QubesException): - qubes.vm.qubesvm._setter_name(self.vm, self.prop, 'duplicate') - - @unittest.skip('test not implemented') def test_020_setter_kernel(self): pass diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index f9e84660f..a96288dd9 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -72,28 +72,6 @@ def _setter_qid(self, prop, value): return value -def _setter_name(self, prop, value): - ''' Helper for setting the domain name ''' - qubes.vm.validate_name(self, prop, value) - - if self.is_running(): - raise qubes.exc.QubesVMNotHaltedError( - self, 'Cannot change name of running VM') - - try: - if self.installed_by_rpm: - raise qubes.exc.QubesException('Cannot rename VM installed by RPM ' - '-- first clone VM and then use yum to remove package.') - except AttributeError: - pass - - if value in self.app.domains: - raise qubes.exc.QubesPropertyValueError(self, prop, value, - 'VM named {} alread exists'.format(value)) - - return value - - def _setter_kernel(self, prop, value): ''' Helper for setting the domain kernel and running sanity checks on it. ''' # pylint: disable=unused-argument @@ -732,26 +710,6 @@ def on_property_set_label(self, event, name, newvalue, oldvalue=None): else: shutil.copy(newvalue.icon_path, self.icon_path) - @qubes.events.handler('property-pre-set:name') - def on_property_pre_set_name(self, event, name, newvalue, oldvalue=None): - # pylint: disable=unused-argument - try: - self.app.domains[newvalue] - except KeyError: - pass - else: - raise qubes.exc.QubesValueError( - 'VM named {!r} already exists'.format(newvalue)) - - # TODO not self.is_stopped() would be more appropriate - if self.is_running(): - raise qubes.exc.QubesVMNotHaltedError( - 'Cannot change name of running domain {!r}'.format(oldvalue)) - - if self.autostart: - subprocess.check_call(['sudo', 'systemctl', '-q', 'disable', - 'qubes-vm@{}.service'.format(oldvalue)]) - @qubes.events.handler('property-pre-set:kernel') def on_property_pre_set_kernel(self, event, name, newvalue, oldvalue=None): # pylint: disable=unused-argument @@ -772,29 +730,6 @@ def on_property_pre_set_kernel(self, event, name, newvalue, oldvalue=None): 'Kernel {!r} not properly installed: ' 'missing {!r} file'.format(newvalue, filename)) - @qubes.events.handler('property-set:name') - def on_property_set_name(self, event, name, newvalue, oldvalue=None): - # pylint: disable=unused-argument - self.init_log() - - old_dir_path = os.path.join(os.path.dirname(self.dir_path), oldvalue) - new_dir_path = os.path.join(os.path.dirname(self.dir_path), newvalue) - os.rename(old_dir_path, new_dir_path) - - self.storage.rename(oldvalue, newvalue) - - if self._libvirt_domain is not None: - self.libvirt_domain.undefine() - self._libvirt_domain = None - if self._qdb_connection is not None: - self._qdb_connection.close() - self._qdb_connection = None - - self._update_libvirt_domain() - - if self.autostart: - self.autostart = self.autostart - @qubes.events.handler('property-pre-set:autostart') def on_property_pre_set_autostart(self, event, name, newvalue, oldvalue=None):