def main(): global qubes_host qubes_host = QubesHost() global app app = QApplication(sys.argv) app.setOrganizationName("The Qubes Project") app.setOrganizationDomain("http://qubes-os.org") app.setApplicationName("Qubes VM Settings") sys.excepthook = handle_exception qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_reading() qvm_collection.load() qvm_collection.unlock_db() vm = None tab = "basic" if len(sys.argv) > 1: vm = qvm_collection.get_vm_by_name(sys.argv[1]) if vm is None or vm.qid not in qvm_collection: QMessageBox.critical(None, "Qubes VM Settings Error", "A VM with the name '{0}' does not exist in the system.".format(sys.argv[1])) sys.exit(1) if len(sys.argv) > 2: tab_arg = sys.argv[2] print tab_arg if tab_arg in VMSettingsWindow.tabs_indices: tab = tab_arg else: QMessageBox.warning(None, "Qubes VM Settings Error", "There is no such tab as '{0}'. Opening default tab instead.".format(tab_arg)) else: vms_list = [vm.name for vm in qvm_collection.values() if (vm.is_appvm() or vm.is_template())] vmname = QInputDialog.getItem(None, "Select VM", "Select VM:", vms_list, editable = False) if not vmname[1]: sys.exit(1) vm = qvm_collection.get_vm_by_name(vmname[0]) global settings_window settings_window = VMSettingsWindow(vm, app, qvm_collection, tab) settings_window.show() app.exec_() app.exit()
def main(): global qubes_host qubes_host = QubesHost() global app app = QApplication(sys.argv) app.setOrganizationName("The Qubes Project") app.setOrganizationDomain("http://qubes-os.org") app.setApplicationName("Qubes VM Settings") sys.excepthook = handle_exception qvm_collection = QubesVmCollection() qvm_collection.lock_db_for_reading() qvm_collection.load() qvm_collection.unlock_db() vm = None tab = "basic" if len(sys.argv) > 1: vm = qvm_collection.get_vm_by_name(sys.argv[1]) if vm is None or vm.qid not in qvm_collection: QMessageBox.critical(None, "Qubes VM Settings Error", "A VM with the name '{0}' does not exist in the system.".format(sys.argv[1])) sys.exit(1) if len(sys.argv) > 2: tab_arg = sys.argv[2] print tab_arg if tab_arg in VMSettingsWindow.tabs_indices: tab = tab_arg else: QMessageBox.warning(None, "Qubes VM Settings Error", "There is no such tab as '{0}'. Opening default tab instead.".format(tab_arg)) else: vms_list = [vm.name for vm in qvm_collection.values() if (vm.is_appvm() or vm.is_template())] vmname = QInputDialog.getItem(None, "Select VM", "Select VM:", vms_list, editable = False) if not vmname[1]: sys.exit(1) vm = qvm_collection.get_vm_by_name(vmname[0]) global settings_window settings_window = VMSettingsWindow(vm, app, qvm_collection, tab) settings_window.show() app.exec_() app.exit()
def notify_vms(): monitor_layout = get_monitor_layout() if len(monitor_layout) == 0: return qc = QubesVmCollection() qc.lock_db_for_reading() qc.load() qc.unlock_db() pipes = [] for vm in qc.values(): if vm.qid == 0: continue if vm.is_running(): pipes.append(notify_vm(vm, monitor_layout)) for p in pipes: p.wait()
def notify_vms(): monitor_layout = get_monitor_layout() if len(monitor_layout) == 0: return qc = QubesVmCollection() qc.lock_db_for_reading() qc.load() qc.unlock_db() pipes = [] for vm in qc.values(): if vm.qid == 0: continue if vm.is_running(): pipes.append(notify_vm(vm, monitor_layout)) for p in pipes: p.wait()
class QubesTemplateHVm(QubesHVm): """ A class that represents an HVM template. A child of QubesHVm. """ # In which order load this VM type from qubes.xml load_order = 50 def get_attrs_config(self): attrs_config = super(QubesTemplateHVm, self).get_attrs_config() attrs_config['dir_path']['func'] = \ lambda value: value if value is not None else \ os.path.join(system_path["qubes_templates_dir"], self.name) attrs_config['label']['default'] = defaults["template_label"] return attrs_config def __init__(self, **kwargs): super(QubesTemplateHVm, self).__init__(**kwargs) self.appvms = QubesVmCollection() @property def type(self): return "TemplateHVM" @property def updateable(self): return True def is_template(self): return True def is_appvm(self): return False @property def rootcow_img(self): return self.storage.rootcow_img @classmethod def is_template_compatible(cls, template): if template is None: return True return False def resize_root_img(self, size): for vm in self.appvms.values(): if vm.is_running(): raise QubesException("Cannot resize root.img while any VM " "based on this tempate is running") return super(QubesTemplateHVm, self).resize_root_img(size) def start(self, *args, **kwargs): for vm in self.appvms.values(): if vm.is_running(): raise QubesException("Cannot start HVM template while VMs based on it are running") return super(QubesTemplateHVm, self).start(*args, **kwargs) def commit_changes (self, verbose = False): self.log.debug('commit_changes()') if not vmm.offline_mode: assert not self.is_running(), "Attempt to commit changes on running Template VM!" if verbose: print >> sys.stderr, "--> Commiting template updates... COW: {0}...".format (self.rootcow_img) if dry_run: return self.storage.commit_template_changes()
class QubesTemplateHVm(QubesHVm): """ A class that represents an HVM template. A child of QubesHVm. """ # In which order load this VM type from qubes.xml load_order = 50 def get_attrs_config(self): attrs_config = super(QubesTemplateHVm, self).get_attrs_config() attrs_config['dir_path']['func'] = \ lambda value: value if value is not None else \ os.path.join(system_path["qubes_templates_dir"], self.name) attrs_config['label']['default'] = defaults["template_label"] return attrs_config def __init__(self, **kwargs): super(QubesTemplateHVm, self).__init__(**kwargs) self.appvms = QubesVmCollection() @property def type(self): return "TemplateHVM" @property def updateable(self): return True def is_template(self): return True def is_appvm(self): return False @property def rootcow_img(self): return self.storage.rootcow_img @classmethod def is_template_compatible(cls, template): if template is None: return True return False def resize_root_img(self, size): for vm in self.appvms.values(): if vm.is_running(): raise QubesException("Cannot resize root.img while any VM " "based on this tempate is running") return super(QubesTemplateHVm, self).resize_root_img(size) def start(self, *args, **kwargs): for vm in self.appvms.values(): if vm.is_running(): raise QubesException( "Cannot start HVM template while VMs based on it are running" ) return super(QubesTemplateHVm, self).start(*args, **kwargs) def commit_changes(self, verbose=False): self.log.debug('commit_changes()') if not vmm.offline_mode: assert not self.is_running( ), "Attempt to commit changes on running Template VM!" if verbose: print >> sys.stderr, "--> Commiting template updates... COW: {0}...".format( self.rootcow_img) if dry_run: return self.storage.commit_template_changes()
class QubesNetVm(QubesVm): """ A class that represents a NetVM. A child of QubesCowVM. """ # In which order load this VM type from qubes.xml load_order = 70 def get_attrs_config(self): attrs_config = super(QubesNetVm, self).get_attrs_config() attrs_config['dir_path']['func'] = \ lambda value: value if value is not None else \ os.path.join(system_path["qubes_servicevms_dir"], self.name) attrs_config['label']['default'] = defaults["servicevm_label"] attrs_config['memory']['default'] = 300 # New attributes attrs_config['netid'] = { 'save': lambda: str(self.netid), 'order': 30, 'func': lambda value: value if value is not None else self._collection.get_new_unused_netid() } attrs_config['netprefix'] = { 'func': lambda x: "10.137.{0}.".format(self.netid) } attrs_config['dispnetprefix'] = { 'func': lambda x: "10.138.{0}.".format(self.netid) } # Dont save netvm prop attrs_config['netvm'].pop('save') attrs_config['uses_default_netvm'].pop('save') return attrs_config def __init__(self, **kwargs): super(QubesNetVm, self).__init__(**kwargs) self.connected_vms = QubesVmCollection() self.__network = "10.137.{0}.0".format(self.netid) self.__netmask = defaults["vm_default_netmask"] self.__gateway = self.netprefix + "1" self.__secondary_dns = self.netprefix + "254" self.__external_ip_allowed_xids = set() self.log.debug('network={} netmask={} gateway={} secondary_dns={}'.format( self.network, self.netmask, self.gateway, self.secondary_dns)) @property def type(self): return "NetVM" def is_netvm(self): return True @property def gateway(self): return self.__gateway @property def secondary_dns(self): return self.__secondary_dns @property def netmask(self): return self.__netmask @property def network(self): return self.__network def get_ip_for_vm(self, qid): lo = qid % 253 + 2 assert lo >= 2 and lo <= 254, "Wrong IP address for VM" return self.netprefix + "{0}".format(lo) def get_ip_for_dispvm(self, dispid): lo = dispid % 254 + 1 assert lo >= 1 and lo <= 254, "Wrong IP address for VM" return self.dispnetprefix + "{0}".format(lo) def update_external_ip_permissions(self, xid = -1): # TODO: VMs in __external_ip_allowed_xids should be notified via RPC # service on exteran IP change pass def start(self, **kwargs): if dry_run: return xid=super(QubesNetVm, self).start(**kwargs) # Connect vif's of already running VMs for vm in self.connected_vms.values(): if not vm.is_running(): continue if 'verbose' in kwargs and kwargs['verbose']: print >> sys.stderr, "--> Attaching network to '{0}'...".format(vm.name) # Cleanup stale VIFs vm.cleanup_vifs() # force frontend to forget about this device # module actually will be loaded back by udev, as soon as network is attached try: vm.run("modprobe -r xen-netfront xennet", user="******") except: pass try: vm.attach_network(wait=False) except QubesException as ex: print >> sys.stderr, ("WARNING: Cannot attach to network to '{0}': {1}".format(vm.name, ex)) return xid def shutdown(self, force=False): if dry_run: return connected_vms = [vm for vm in self.connected_vms.values() if vm.is_running()] if connected_vms and not force: raise QubesException("There are other VMs connected to this VM: " + str([vm.name for vm in connected_vms])) super(QubesNetVm, self).shutdown(force=force) def add_external_ip_permission(self, xid): if int(xid) < 0: return self.__external_ip_allowed_xids.add(int(xid)) self.update_external_ip_permissions() def remove_external_ip_permission(self, xid): self.__external_ip_allowed_xids.discard(int(xid)) self.update_external_ip_permissions()
class TC_00_Dom0Upgrade(qubes.tests.QubesTestCase): cleanup_paths = [] pkg_name = 'qubes-test-pkg' dom0_update_common_opts = ['--disablerepo=*', '--enablerepo=test', '--setopt=test.copy_local=1'] @classmethod def generate_key(cls, keydir): gpg_opts = ['gpg', '--quiet', '--no-default-keyring', '--homedir', keydir] p = subprocess.Popen(gpg_opts + ['--gen-key', '--batch'], stdin=subprocess.PIPE, stderr=open(os.devnull, 'w')) p.stdin.write(''' Key-Type: RSA Key-Length: 1024 Key-Usage: sign Name-Real: Qubes test Expire-Date: 0 %commit '''.format(keydir=keydir)) p.stdin.close() p.wait() subprocess.check_call(gpg_opts + ['-a', '--export', '--output', os.path.join(keydir, 'pubkey.asc')]) p = subprocess.Popen(gpg_opts + ['--with-colons', '--list-keys'], stdout=subprocess.PIPE) for line in p.stdout.readlines(): fields = line.split(':') if fields[0] == 'pub': return fields[4][-8:].lower() raise RuntimeError @classmethod def setUpClass(cls): super(TC_00_Dom0Upgrade, cls).setUpClass() cls.tmpdir = tempfile.mkdtemp() cls.cleanup_paths += [cls.tmpdir] cls.keyid = cls.generate_key(cls.tmpdir) p = subprocess.Popen(['sudo', 'dd', 'status=none', 'of=/etc/yum.repos.d/test.repo'], stdin=subprocess.PIPE) p.stdin.write(''' [test] name = Test baseurl = file:///tmp/repo enabled = 1 ''') p.stdin.close() p.wait() @classmethod def tearDownClass(cls): subprocess.check_call(['sudo', 'rm', '-f', '/etc/yum.repos.d/test.repo']) for dir in cls.cleanup_paths: shutil.rmtree(dir) cls.cleanup_paths = [] def setUp(self): self.qc = QubesVmCollection() self.qc.lock_db_for_writing() self.qc.load() self.updatevm = self.qc.add_new_vm("QubesProxyVm", name="%supdatevm" % VM_PREFIX, template=self.qc.get_default_template()) self.updatevm.create_on_disk(verbose=False) self.saved_updatevm = self.qc.get_updatevm_vm() self.qc.set_updatevm_vm(self.updatevm) self.qc.save() self.qc.unlock_db() subprocess.call(['sudo', 'rpm', '-e', self.pkg_name], stderr=open(os.devnull, 'w')) subprocess.check_call(['sudo', 'rpm', '--import', os.path.join(self.tmpdir, 'pubkey.asc')]) self.updatevm.start() def remove_vms(self, vms): self.qc.lock_db_for_writing() self.qc.load() self.qc.set_updatevm_vm(self.qc[self.saved_updatevm.qid]) for vm in vms: if isinstance(vm, str): vm = self.qc.get_vm_by_name(vm) else: vm = self.qc[vm.qid] if vm.is_running(): try: vm.force_shutdown() except: pass try: vm.remove_from_disk() except OSError: pass self.qc.pop(vm.qid) self.qc.save() self.qc.unlock_db() def tearDown(self): vmlist = [vm for vm in self.qc.values() if vm.name.startswith( VM_PREFIX)] self.remove_vms(vmlist) subprocess.call(['sudo', 'rpm', '-e', self.pkg_name], stderr=open( os.devnull, 'w')) subprocess.call(['sudo', 'rpm', '-e', 'gpg-pubkey-{}'.format( self.keyid)], stderr=open(os.devnull, 'w')) for pkg in os.listdir(self.tmpdir): if pkg.endswith('.rpm'): os.unlink(pkg) def create_pkg(self, dir, name, version): spec_path = os.path.join(dir, name+'.spec') spec = open(spec_path, 'w') spec.write( ''' Name: {name} Summary: Test Package Version: {version} Release: 1 Vendor: Invisible Things Lab License: GPL Group: Qubes URL: http://www.qubes-os.org %description Test package %install %files '''.format(name=name, version=version) ) spec.close() subprocess.check_call( ['rpmbuild', '--quiet', '-bb', '--define', '_rpmdir {}'.format(dir), spec_path]) pkg_path = os.path.join(dir, 'x86_64', '{}-{}-1.x86_64.rpm'.format(name, version)) subprocess.check_call(['sudo', 'chmod', 'go-rw', '/dev/tty']) subprocess.check_call( ['rpm', '--quiet', '--define=_gpg_path {}'.format(dir), '--define=_gpg_name {}'.format("Qubes test"), '--addsign', pkg_path], stdin=open(os.devnull), stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) subprocess.check_call(['sudo', 'chmod', 'go+rw', '/dev/tty']) return pkg_path def send_pkg(self, filename): p = self.updatevm.run('mkdir -p /tmp/repo; cat > /tmp/repo/{}'.format( os.path.basename( filename)), passio_popen=True) p.stdin.write(open(filename).read()) p.stdin.close() p.wait() self.updatevm.run('cd /tmp/repo; createrepo .', wait=True) def test_000_update(self): filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') subprocess.check_call(['sudo', 'rpm', '-i', filename]) filename = self.create_pkg(self.tmpdir, self.pkg_name, '2.0') self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts, stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError: self.fail("qubes-dom0-update failed: " + open( logpath).read()) retcode = subprocess.call(['rpm', '-q', '{}-1.0'.format( self.pkg_name)], stdout=open(os.devnull, 'w')) self.assertEqual(retcode, 1, 'Package {}-1.0 still installed after ' 'update'.format(self.pkg_name)) retcode = subprocess.call(['rpm', '-q', '{}-2.0'.format( self.pkg_name)], stdout=open(os.devnull, 'w')) self.assertEqual(retcode, 0, 'Package {}-2.0 not installed after ' 'update'.format(self.pkg_name)) def test_010_instal(self): filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts + [ self.pkg_name], stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError: self.fail("qubes-dom0-update failed: " + open( logpath).read()) retcode = subprocess.call(['rpm', '-q', '{}-1.0'.format( self.pkg_name)], stdout=open('/dev/null', 'w')) self.assertEqual(retcode, 0, 'Package {}-1.0 not installed'.format( self.pkg_name)) def test_020_install_wrong_sign(self): subprocess.call(['sudo', 'rpm', '-e', 'gpg-pubkey-{}'.format( self.keyid)]) filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts + [ self.pkg_name], stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) self.fail("qubes-dom0-update unexpectedly succeeded: " + open( logpath).read()) except subprocess.CalledProcessError: pass retcode = subprocess.call(['rpm', '-q', '{}-1.0'.format( self.pkg_name)], stdout=open('/dev/null', 'w')) self.assertEqual(retcode, 1, 'Package {}-1.0 installed although ' 'signature is invalid'.format(self.pkg_name)) def test_030_install_unsigned(self): filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') subprocess.check_call(['rpm', '--delsign', filename], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts + [self.pkg_name], stdout=open(logpath, 'w'), stderr=subprocess.STDOUT ) self.fail("qubes-dom0-update unexpectedly succeeded: " + open( logpath).read()) except subprocess.CalledProcessError: pass retcode = subprocess.call(['rpm', '-q', '{}-1.0'.format( self.pkg_name)], stdout=open('/dev/null', 'w')) self.assertEqual(retcode, 1, 'UNSIGNED package {}-1.0 installed'.format(self.pkg_name))
class TC_00_Dom0Upgrade(qubes.tests.QubesTestCase): cleanup_paths = [] pkg_name = 'qubes-test-pkg' dom0_update_common_opts = [ '--disablerepo=*', '--enablerepo=test', '--setopt=test.copy_local=1' ] @classmethod def generate_key(cls, keydir): gpg_opts = [ 'gpg', '--quiet', '--no-default-keyring', '--homedir', keydir ] p = subprocess.Popen(gpg_opts + ['--gen-key', '--batch'], stdin=subprocess.PIPE, stderr=open(os.devnull, 'w')) p.stdin.write(''' Key-Type: RSA Key-Length: 1024 Key-Usage: sign Name-Real: Qubes test Expire-Date: 0 %commit '''.format(keydir=keydir)) p.stdin.close() p.wait() subprocess.check_call( gpg_opts + ['-a', '--export', '--output', os.path.join(keydir, 'pubkey.asc')]) p = subprocess.Popen(gpg_opts + ['--with-colons', '--list-keys'], stdout=subprocess.PIPE) for line in p.stdout.readlines(): fields = line.split(':') if fields[0] == 'pub': return fields[4][-8:].lower() raise RuntimeError @classmethod def setUpClass(cls): super(TC_00_Dom0Upgrade, cls).setUpClass() cls.tmpdir = tempfile.mkdtemp() cls.cleanup_paths += [cls.tmpdir] cls.keyid = cls.generate_key(cls.tmpdir) p = subprocess.Popen( ['sudo', 'dd', 'status=none', 'of=/etc/yum.repos.d/test.repo'], stdin=subprocess.PIPE) p.stdin.write(''' [test] name = Test baseurl = file:///tmp/repo enabled = 1 ''') p.stdin.close() p.wait() @classmethod def tearDownClass(cls): subprocess.check_call( ['sudo', 'rm', '-f', '/etc/yum.repos.d/test.repo']) for dir in cls.cleanup_paths: shutil.rmtree(dir) cls.cleanup_paths = [] def setUp(self): self.qc = QubesVmCollection() self.qc.lock_db_for_writing() self.qc.load() self.updatevm = self.qc.add_new_vm( "QubesProxyVm", name="%supdatevm" % VM_PREFIX, template=self.qc.get_default_template()) self.updatevm.create_on_disk(verbose=False) self.saved_updatevm = self.qc.get_updatevm_vm() self.qc.set_updatevm_vm(self.updatevm) self.qc.save() self.qc.unlock_db() subprocess.call(['sudo', 'rpm', '-e', self.pkg_name], stderr=open(os.devnull, 'w')) subprocess.check_call([ 'sudo', 'rpm', '--import', os.path.join(self.tmpdir, 'pubkey.asc') ]) self.updatevm.start() def remove_vms(self, vms): self.qc.lock_db_for_writing() self.qc.load() self.qc.set_updatevm_vm(self.qc[self.saved_updatevm.qid]) for vm in vms: if isinstance(vm, str): vm = self.qc.get_vm_by_name(vm) else: vm = self.qc[vm.qid] if vm.is_running(): try: vm.force_shutdown() except: pass try: vm.remove_from_disk() except OSError: pass self.qc.pop(vm.qid) self.qc.save() self.qc.unlock_db() def tearDown(self): vmlist = [ vm for vm in self.qc.values() if vm.name.startswith(VM_PREFIX) ] self.remove_vms(vmlist) subprocess.call(['sudo', 'rpm', '-e', self.pkg_name], stderr=open(os.devnull, 'w')) subprocess.call( ['sudo', 'rpm', '-e', 'gpg-pubkey-{}'.format(self.keyid)], stderr=open(os.devnull, 'w')) for pkg in os.listdir(self.tmpdir): if pkg.endswith('.rpm'): os.unlink(pkg) def create_pkg(self, dir, name, version): spec_path = os.path.join(dir, name + '.spec') spec = open(spec_path, 'w') spec.write(''' Name: {name} Summary: Test Package Version: {version} Release: 1 Vendor: Invisible Things Lab License: GPL Group: Qubes URL: http://www.qubes-os.org %description Test package %install %files '''.format(name=name, version=version)) spec.close() subprocess.check_call([ 'rpmbuild', '--quiet', '-bb', '--define', '_rpmdir {}'.format(dir), spec_path ]) pkg_path = os.path.join(dir, 'x86_64', '{}-{}-1.x86_64.rpm'.format(name, version)) subprocess.check_call(['sudo', 'chmod', 'go-rw', '/dev/tty']) subprocess.check_call([ 'rpm', '--quiet', '--define=_gpg_path {}'.format(dir), '--define=_gpg_name {}'.format("Qubes test"), '--addsign', pkg_path ], stdin=open(os.devnull), stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) subprocess.check_call(['sudo', 'chmod', 'go+rw', '/dev/tty']) return pkg_path def send_pkg(self, filename): p = self.updatevm.run('mkdir -p /tmp/repo; cat > /tmp/repo/{}'.format( os.path.basename(filename)), passio_popen=True) p.stdin.write(open(filename).read()) p.stdin.close() p.wait() self.updatevm.run('cd /tmp/repo; createrepo .', wait=True) def test_000_update(self): filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') subprocess.check_call(['sudo', 'rpm', '-i', filename]) filename = self.create_pkg(self.tmpdir, self.pkg_name, '2.0') self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts, stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError: self.fail("qubes-dom0-update failed: " + open(logpath).read()) retcode = subprocess.call( ['rpm', '-q', '{}-1.0'.format(self.pkg_name)], stdout=open(os.devnull, 'w')) self.assertEqual( retcode, 1, 'Package {}-1.0 still installed after ' 'update'.format(self.pkg_name)) retcode = subprocess.call( ['rpm', '-q', '{}-2.0'.format(self.pkg_name)], stdout=open(os.devnull, 'w')) self.assertEqual( retcode, 0, 'Package {}-2.0 not installed after ' 'update'.format(self.pkg_name)) def test_010_instal(self): filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts + [self.pkg_name], stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) except subprocess.CalledProcessError: self.fail("qubes-dom0-update failed: " + open(logpath).read()) retcode = subprocess.call( ['rpm', '-q', '{}-1.0'.format(self.pkg_name)], stdout=open('/dev/null', 'w')) self.assertEqual(retcode, 0, 'Package {}-1.0 not installed'.format(self.pkg_name)) def test_020_install_wrong_sign(self): subprocess.call( ['sudo', 'rpm', '-e', 'gpg-pubkey-{}'.format(self.keyid)]) filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts + [self.pkg_name], stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) self.fail("qubes-dom0-update unexpectedly succeeded: " + open(logpath).read()) except subprocess.CalledProcessError: pass retcode = subprocess.call( ['rpm', '-q', '{}-1.0'.format(self.pkg_name)], stdout=open('/dev/null', 'w')) self.assertEqual( retcode, 1, 'Package {}-1.0 installed although ' 'signature is invalid'.format(self.pkg_name)) def test_030_install_unsigned(self): filename = self.create_pkg(self.tmpdir, self.pkg_name, '1.0') subprocess.check_call(['rpm', '--delsign', filename], stdout=open(os.devnull, 'w'), stderr=subprocess.STDOUT) self.send_pkg(filename) logpath = os.path.join(self.tmpdir, 'dom0-update-output.txt') try: subprocess.check_call(['sudo', 'qubes-dom0-update', '-y'] + self.dom0_update_common_opts + [self.pkg_name], stdout=open(logpath, 'w'), stderr=subprocess.STDOUT) self.fail("qubes-dom0-update unexpectedly succeeded: " + open(logpath).read()) except subprocess.CalledProcessError: pass retcode = subprocess.call( ['rpm', '-q', '{}-1.0'.format(self.pkg_name)], stdout=open('/dev/null', 'w')) self.assertEqual( retcode, 1, 'UNSIGNED package {}-1.0 installed'.format(self.pkg_name))