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,28 +154,48 @@ 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()
try:
if self.tabWidget.isTabEnabled(self.tabs_indices["firewall"]): 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()) 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)]
try:
if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]): if self.tabWidget.isTabEnabled(self.tabs_indices["applications"]):
self.AppListManager.save_appmenu_select_changes() 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):
if idx == self.tabs_indices["firewall"]: if idx == self.tabs_indices["firewall"]:
if self.vm.netvm is not None and not self.vm.netvm.is_proxyvm(): if self.vm.netvm is not None and not self.vm.netvm.is_proxyvm():
@ -303,13 +323,17 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
msg.append(str(ex)) msg.append(str(ex))
#vm label changed #vm label changed
try:
if self.vmlabel.isVisible(): if self.vmlabel.isVisible():
if self.vmlabel.currentIndex() != self.label_idx: if self.vmlabel.currentIndex() != self.label_idx:
label = self.label_list[self.vmlabel.currentIndex()] label = self.label_list[self.vmlabel.currentIndex()]
self.vm.label = label self.vm.label = label
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#vm template changed #vm template changed
try:
if self.template_name.currentIndex() != self.template_idx: if self.template_name.currentIndex() != self.template_idx:
new_template_name = self.template_name.currentText() new_template_name = self.template_name.currentText()
new_template_name = new_template_name.split(' ')[0] new_template_name = new_template_name.split(' ')[0]
@ -318,8 +342,11 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
assert template_vm.is_template() assert template_vm.is_template()
self.vm.template = template_vm self.vm.template = template_vm
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#vm netvm changed #vm netvm changed
try:
if self.netVM.currentIndex() != self.netvm_idx: if self.netVM.currentIndex() != self.netvm_idx:
new_netvm_name = self.netVM.currentText() new_netvm_name = self.netVM.currentText()
new_netvm_name = new_netvm_name.split(' ')[0] new_netvm_name = new_netvm_name.split(' ')[0]
@ -339,17 +366,25 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
self.vm.netvm = netvm self.vm.netvm = netvm
self.vm.uses_default_netvm = uses_default_netvm self.vm.uses_default_netvm = uses_default_netvm
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#include in backups #include in backups
try:
if self.vm.include_in_backups != self.include_in_backups.isChecked(): if self.vm.include_in_backups != self.include_in_backups.isChecked():
self.vm.include_in_backups = self.include_in_backups.isChecked() self.vm.include_in_backups = self.include_in_backups.isChecked()
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
#run_in_debug_mode #run_in_debug_mode
try:
if self.run_in_debug_mode.isVisible(): if self.run_in_debug_mode.isVisible():
if self.vm.debug != self.run_in_debug_mode.isChecked(): if self.vm.debug != self.run_in_debug_mode.isChecked():
self.vm.debug = self.run_in_debug_mode.isChecked() self.vm.debug = self.run_in_debug_mode.isChecked()
self.anything_changed = True 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,8 +484,10 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
def __apply_advanced_tab__(self): def __apply_advanced_tab__(self):
msg = []
#mem/cpu #mem/cpu
try:
if self.init_mem.value() != int(self.vm.memory): if self.init_mem.value() != int(self.vm.memory):
self.vm.memory = self.init_mem.value() self.vm.memory = self.init_mem.value()
self.anything_changed = True self.anything_changed = True
@ -462,18 +499,21 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
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
try:
if self.kernel.currentIndex() != self.kernel_idx: if self.kernel.currentIndex() != self.kernel_idx:
new_kernel = self.kernel.currentText() new_kernel = self.kernel.currentText()
new_kernel = new_kernel.split(' ')[0] new_kernel = new_kernel.split(' ')[0]
@ -489,6 +529,10 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
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,9 +572,11 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
def __apply_devices_tab__(self): def __apply_devices_tab__(self):
msg = []
sth_changed = False sth_changed = False
added = [] added = []
try:
for i in range(self.dev_list.selected_list.count()): for i in range(self.dev_list.selected_list.count()):
item = self.dev_list.selected_list.item(i) item = self.dev_list.selected_list.item(i)
if item.slot not in self.vm.pcidevs: if item.slot not in self.vm.pcidevs:
@ -548,6 +594,10 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
pcidevs.append(slot) pcidevs.append(slot)
self.vm.pcidevs = pcidevs self.vm.pcidevs = pcidevs
self.anything_changed = True 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()):
@ -619,6 +669,9 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
def __apply_services_tab__(self): def __apply_services_tab__(self):
msg = []
try:
for r in range (self.services_list.count()): for r in range (self.services_list.count()):
item = self.services_list.item(r) item = self.services_list.item(r)
self.new_srv_dict[str(item.text())] = (item.checkState() == QtCore.Qt.Checked) self.new_srv_dict[str(item.text())] = (item.checkState() == QtCore.Qt.Checked)
@ -634,6 +687,10 @@ class VMSettingsWindow(Ui_SettingsDialog, QDialog):
if self.new_srv_dict != self.vm.services: if self.new_srv_dict != self.vm.services:
self.vm.services = self.new_srv_dict self.vm.services = self.new_srv_dict
self.anything_changed = True self.anything_changed = True
except Exception as ex:
msg.append(str(ex))
return msg
######### firewall tab related ######### firewall tab related