settings apply: catch exceptions and show them to the user

Settings are applied in separate thread, so when any exception occured there,
the user had no way to know it (besides hanging "applying settings" window).
This commit is contained in:
Marek Marczykowski 2013-02-23 06:44:06 +01:00
parent 122e7d5787
commit 34ea444a42

View File

@ -154,26 +154,46 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
self.qvm_collection.lock_db_for_writing() self.qvm_collection.lock_db_for_writing()
self.anything_changed = False self.anything_changed = False
ret = self.__apply_basic_tab__() ret = []
self.__apply_advanced_tab__() try:
self.__apply_devices_tab__() ret_tmp = self.__apply_basic_tab__()
self.__apply_services_tab__() if len(ret_tmp) > 0:
ret += ["Basic tab:"] + ret_tmp
if len(ret) > 0 : ret_tmp = self.__apply_advanced_tab__()
thread_monitor.set_error_msg('\n'.join(ret)) if len(ret_tmp) > 0:
ret += ["Advanced tab:"] + ret_tmp
ret_tmp = self.__apply_devices_tab__()
if len(ret_tmp) > 0:
ret += ["Devices tab:"] + ret_tmp
ret_tmp = self.__apply_services_tab__()
if len(ret_tmp) > 0:
ret += ["Sevices tab:"] + ret_tmp
except Exception as ex:
ret.append('Error while saving changes: ' + str(ex))
if self.anything_changed == True: if self.anything_changed == True:
self.qvm_collection.save() self.qvm_collection.save()
self.qvm_collection.unlock_db() self.qvm_collection.unlock_db()
if self.tabWidget.isTabEnabled(self.tabs_indices["firewall"]): try:
self.fw_model.apply_rules(self.policyAllowRadioButton.isChecked(), self.dnsCheckBox.isChecked(), self.icmpCheckBox.isChecked(), self.yumproxyCheckBox.isChecked()) if self.tabWidget.isTabEnabled(self.tabs_indices["firewall"]):
self.fw_model.apply_rules(self.policyAllowRadioButton.isChecked(),
self.dnsCheckBox.isChecked(),
self.icmpCheckBox.isChecked(),
self.yumproxyCheckBox.isChecked())
except Exception as ex:
ret += ["Firewall tab:", str(ex)]
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]): try:
self.AppListManager.save_appmenu_select_changes() if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
self.AppListManager.save_appmenu_select_changes()
except Exception as ex:
ret += ["Applications tab:", str(ex)]
if len(ret) > 0 :
thread_monitor.set_error_msg('\n'.join(ret))
thread_monitor.set_finished() thread_monitor.set_finished()
def current_tab_changed(self, idx): def current_tab_changed(self, idx):
@ -301,55 +321,70 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
self.anything_changed = True self.anything_changed = True
except Exception as ex: except Exception as ex:
msg.append(str(ex)) msg.append(str(ex))
#vm label changed #vm label changed
if self.vmlabel.isVisible(): try:
if self.vmlabel.currentIndex() != self.label_idx: if self.vmlabel.isVisible():
label = self.label_list[self.vmlabel.currentIndex()] if self.vmlabel.currentIndex() != self.label_idx:
self.vm.label = label label = self.label_list[self.vmlabel.currentIndex()]
self.anything_changed = True self.vm.label = label
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#vm template changed #vm template changed
if self.template_name.currentIndex() != self.template_idx: try:
new_template_name = self.template_name.currentText() if self.template_name.currentIndex() != self.template_idx:
new_template_name = new_template_name.split(' ')[0] new_template_name = self.template_name.currentText()
template_vm = self.qvm_collection.get_vm_by_name(new_template_name) new_template_name = new_template_name.split(' ')[0]
assert (template_vm is not None and template_vm.qid in self.qvm_collection) template_vm = self.qvm_collection.get_vm_by_name(new_template_name)
assert template_vm.is_template() assert (template_vm is not None and template_vm.qid in self.qvm_collection)
self.vm.template = template_vm assert template_vm.is_template()
self.anything_changed = True self.vm.template = template_vm
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#vm netvm changed #vm netvm changed
if self.netVM.currentIndex() != self.netvm_idx: try:
new_netvm_name = self.netVM.currentText() if self.netVM.currentIndex() != self.netvm_idx:
new_netvm_name = new_netvm_name.split(' ')[0] new_netvm_name = self.netVM.currentText()
new_netvm_name = new_netvm_name.split(' ')[0]
uses_default_netvm = False
if new_netvm_name == "default": uses_default_netvm = False
new_netvm_name = self.qvm_collection.get_default_netvm().name
uses_default_netvm = True
if new_netvm_name == "none": if new_netvm_name == "default":
netvm = None new_netvm_name = self.qvm_collection.get_default_netvm().name
else: uses_default_netvm = True
netvm = self.qvm_collection.get_vm_by_name(new_netvm_name)
assert (netvm is None or (netvm is not None and netvm.qid in self.qvm_collection and netvm.is_netvm())) if new_netvm_name == "none":
netvm = None
self.vm.netvm = netvm else:
self.vm.uses_default_netvm = uses_default_netvm netvm = self.qvm_collection.get_vm_by_name(new_netvm_name)
self.anything_changed = True assert (netvm is None or (netvm is not None and netvm.qid in self.qvm_collection and netvm.is_netvm()))
self.vm.netvm = netvm
self.vm.uses_default_netvm = uses_default_netvm
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#include in backups #include in backups
if self.vm.include_in_backups != self.include_in_backups.isChecked(): try:
self.vm.include_in_backups = self.include_in_backups.isChecked() if self.vm.include_in_backups != self.include_in_backups.isChecked():
self.anything_changed = True self.vm.include_in_backups = self.include_in_backups.isChecked()
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#run_in_debug_mode #run_in_debug_mode
if self.run_in_debug_mode.isVisible(): try:
if self.vm.debug != self.run_in_debug_mode.isChecked(): if self.run_in_debug_mode.isVisible():
self.vm.debug = self.run_in_debug_mode.isChecked() if self.vm.debug != self.run_in_debug_mode.isChecked():
self.anything_changed = True self.vm.debug = self.run_in_debug_mode.isChecked()
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#max priv storage #max priv storage
priv_size = self.max_priv_storage.value() priv_size = self.max_priv_storage.value()
@ -449,46 +484,55 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
def __apply_advanced_tab__(self): def __apply_advanced_tab__(self):
msg = []
#mem/cpu #mem/cpu
if self.init_mem.value() != int(self.vm.memory): try:
self.vm.memory = self.init_mem.value() if self.init_mem.value() != int(self.vm.memory):
self.anything_changed = True self.vm.memory = self.init_mem.value()
self.anything_changed = True
if self.max_mem_size.value() != int(self.vm.maxmem): if self.max_mem_size.value() != int(self.vm.maxmem):
self.vm.maxmem = self.max_mem_size.value() self.vm.maxmem = self.max_mem_size.value()
self.anything_changed = True self.anything_changed = True
if self.vcpus.value() != int(self.vm.vcpus): if self.vcpus.value() != int(self.vm.vcpus):
self.vm.vcpus = self.vcpus.value() self.vm.vcpus = self.vcpus.value()
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#include_in_memory_balancing applied in services tab #include_in_memory_balancing applied in services tab
#in case VM is not Linux #in case VM is not Linux
if not hasattr(self.vm, "kernel"): if not hasattr(self.vm, "kernel"):
return; return msg;
#kernel changed #kernel changed
if not self.kernel_groupbox.isVisible(): if not self.kernel_groupbox.isVisible():
return return msg
if self.kernel.currentIndex() != self.kernel_idx: try:
new_kernel = self.kernel.currentText() if self.kernel.currentIndex() != self.kernel_idx:
new_kernel = new_kernel.split(' ')[0] new_kernel = self.kernel.currentText()
if(new_kernel == "default"): new_kernel = new_kernel.split(' ')[0]
kernel = self.qvm_collection.get_default_kernel() if(new_kernel == "default"):
self.vm.uses_default_kernel = True kernel = self.qvm_collection.get_default_kernel()
elif(new_kernel == "none"): self.vm.uses_default_kernel = True
kernel = None elif(new_kernel == "none"):
self.vm.uses_default_kernel = False; kernel = None
else: self.vm.uses_default_kernel = False;
kernel = new_kernel else:
self.vm.uses_default_kernel = False; kernel = new_kernel
self.vm.uses_default_kernel = False;
self.vm.kernel = kernel self.vm.kernel = kernel
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
return msg
######## devices tab ######## devices tab
@ -528,26 +572,32 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
def __apply_devices_tab__(self): def __apply_devices_tab__(self):
msg = []
sth_changed = False sth_changed = False
added = [] added = []
for i in range(self.dev_list.selected_list.count()): try:
item = self.dev_list.selected_list.item(i)
if item.slot not in self.vm.pcidevs:
added.append(item)
if self.dev_list.selected_list.count() - len(added) < len(self.vm.pcidevs): #sth removed
sth_changed = True;
elif len(added) > 0:
sth_changed = True;
if sth_changed == True:
pcidevs = []
for i in range(self.dev_list.selected_list.count()): for i in range(self.dev_list.selected_list.count()):
slot = self.dev_list.selected_list.item(i).slot item = self.dev_list.selected_list.item(i)
pcidevs.append(slot) if item.slot not in self.vm.pcidevs:
self.vm.pcidevs = pcidevs added.append(item)
self.anything_changed = True
if self.dev_list.selected_list.count() - len(added) < len(self.vm.pcidevs): #sth removed
sth_changed = True;
elif len(added) > 0:
sth_changed = True;
if sth_changed == True:
pcidevs = []
for i in range(self.dev_list.selected_list.count()):
slot = self.dev_list.selected_list.item(i).slot
pcidevs.append(slot)
self.vm.pcidevs = pcidevs
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
return msg
def include_in_balancing_state_changed(self, state): def include_in_balancing_state_changed(self, state):
for r in range (self.services_list.count()): for r in range (self.services_list.count()):
@ -583,7 +633,7 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
else: else:
item.setCheckState(QtCore.Qt.Unchecked) item.setCheckState(QtCore.Qt.Unchecked)
self.services_list.addItem(item) self.services_list.addItem(item)
self.connect(self.services_list, SIGNAL("itemClicked(QListWidgetItem *)"), self.services_item_clicked) self.connect(self.services_list, SIGNAL("itemClicked(QListWidgetItem *)"), self.services_item_clicked)
self.new_srv_dict = copy(self.vm.services) self.new_srv_dict = copy(self.vm.services)
@ -619,21 +669,28 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
def __apply_services_tab__(self): def __apply_services_tab__(self):
for r in range (self.services_list.count()): msg = []
item = self.services_list.item(r)
self.new_srv_dict[str(item.text())] = (item.checkState() == QtCore.Qt.Checked)
balancing_was_checked = (self.vm.services['meminfo-writer']==True)
balancing_is_checked = self.include_in_balancing.isChecked()
meminfo_writer_checked = (self.new_srv_dict['meminfo-writer'] == True)
if balancing_is_checked != meminfo_writer_checked: try:
if balancing_is_checked != balancing_was_checked: for r in range (self.services_list.count()):
self.new_srv_dict['meminfo-writer'] = balancing_is_checked item = self.services_list.item(r)
self.new_srv_dict[str(item.text())] = (item.checkState() == QtCore.Qt.Checked)
if self.new_srv_dict != self.vm.services: balancing_was_checked = (self.vm.services['meminfo-writer']==True)
self.vm.services = self.new_srv_dict balancing_is_checked = self.include_in_balancing.isChecked()
self.anything_changed = True meminfo_writer_checked = (self.new_srv_dict['meminfo-writer'] == True)
if balancing_is_checked != meminfo_writer_checked:
if balancing_is_checked != balancing_was_checked:
self.new_srv_dict['meminfo-writer'] = balancing_is_checked
if self.new_srv_dict != self.vm.services:
self.vm.services = self.new_srv_dict
self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
return msg
######### firewall tab related ######### firewall tab related