ref: refs/heads/master commit 32ae9fbf0d3670c7fa3d8440f4979f1a8d055600 Author: Josef Reidinger <jreidinger@suse.cz> Date: Mon Nov 23 15:16:57 2009 +0100 don't write to backend if form is not changed (prevent network restart) (bnc#552548) release 0.0.10 --- .../network/app/controllers/network_controller.rb | 34 ++++++++++++++++--- .../package/yast2-webclient-network.changes | 6 +++ .../network/package/yast2-webclient-network.spec | 2 +- .../test/functional/network_controller_test.rb | 14 ++++++++ 4 files changed, 49 insertions(+), 7 deletions(-) diff --git a/plugins/network/app/controllers/network_controller.rb b/plugins/network/app/controllers/network_controller.rb index 515a326..0400038 100644 --- a/plugins/network/app/controllers/network_controller.rb +++ b/plugins/network/app/controllers/network_controller.rb @@ -73,35 +73,56 @@ class NetworkController < ApplicationController # PUT /users/1 # PUT /users/1.xml def update + dirty = false rt = load_proxy "org.opensuse.yast.modules.yapi.network.routes", "default" return false unless rt + dirty = true unless rt.via == params["default_route"] rt.via = params["default_route"] + logger.info "dirty after default routing: #{dirty}" dns = load_proxy "org.opensuse.yast.modules.yapi.network.dns" return false unless dns + #compare empty array and nill cause true, so at first test emptyness + unless (dns.nameservers.empty? && params["nameservers"].blank?) + dirty = true unless ( dns.nameservers == params["nameservers"].split) + end + unless (dns.searches.empty? && params["searchdomains"].blank?) + dirty = true if (dns.searches == params["searchdomains"].split) + end + logger.info "dirty after dns: #{dirty}" # FIXME: params bellow should be arrays dns.nameservers = params["nameservers"]#.split dns.searches = params["searchdomains"]#.split hn = load_proxy "org.opensuse.yast.modules.yapi.network.hostname" return false unless hn + dirty = true unless (hn.name == params["name"] && hn.domain == params["domain"]) + logger.info "dirty after hostname: #{dirty}" hn.name = params["name"] hn.domain = params["domain"] ifc = load_proxy "org.opensuse.yast.modules.yapi.network.interfaces", params["interface"] return false unless ifc + dirty = true unless (ifc.bootproto == params["conf_mode"]) + logger.info "dirty after interface config: #{dirty}" ifc.bootproto=params["conf_mode"] if ifc.bootproto=="static" + #ip addr is returned in another state then given, but restart of static address is not problem + dirty = true ifc.ipaddr=params["ip"]+"/"+params["netmask"] end - + begin # this is not transaction! # if any *.save failed, the previous will be applied - rt.save - dns.save - hn.save - ifc.save + # FIXME JR: I think that if user choose dhcp not all settings should be written + if dirty + rt.save + dns.save + hn.save + ifc.save + end +#write to avoid confusion, with another string flash[:notice] = _('Network settings have been written.') rescue ActiveResource::ServerError => e response = Hash.from_xml(e.response.body) @@ -111,10 +132,11 @@ class NetworkController < ApplicationController else raise end + #XXX FIXME don't catch universal exception, it is not user friendly and break testing of update rescue Exception => e flash[:error] = e.message logger.warn e - end + end redirect_success end diff --git a/plugins/network/package/yast2-webclient-network.changes b/plugins/network/package/yast2-webclient-network.changes index 42464cc..ac5f10a 100644 --- a/plugins/network/package/yast2-webclient-network.changes +++ b/plugins/network/package/yast2-webclient-network.changes @@ -1,4 +1,10 @@ ------------------------------------------------------------------- +Mon Nov 23 14:14:16 UTC 2009 - jreidinger@novell.com + +- write to backend only if form is changed (bnc#552548) +- 0.0.10 + +------------------------------------------------------------------- Thu Nov 12 11:25:14 UTC 2009 - jreidinger@novell.com - update translation (schubi) diff --git a/plugins/network/package/yast2-webclient-network.spec b/plugins/network/package/yast2-webclient-network.spec index 5f40e91..3a0e737 100644 --- a/plugins/network/package/yast2-webclient-network.spec +++ b/plugins/network/package/yast2-webclient-network.spec @@ -13,7 +13,7 @@ Name: yast2-webclient-network License: GPL v2 only Group: Productivity/Networking/Web/Utilities Autoreqprov: on -Version: 0.0.9 +Version: 0.0.10 Release: 0 Summary: YaST2 - Webclient - network Source: www.tar.bz2 diff --git a/plugins/network/test/functional/network_controller_test.rb b/plugins/network/test/functional/network_controller_test.rb index f71fd2e..c382205 100644 --- a/plugins/network/test/functional/network_controller_test.rb +++ b/plugins/network/test/functional/network_controller_test.rb @@ -1,6 +1,7 @@ require 'test_helper' require 'ostruct' require File.expand_path( File.join("test","validation_assert"), RailsParent.parent ) +require 'mocha' class OpenStruct undef_method :id # so that it looks for our id @@ -10,6 +11,11 @@ class NetworkControllerTest < ActionController::TestCase class Proxy attr_accessor :result, :timeout + + def initialize + @saved = false + end + def permissions return { :read => true, :execute => true } end @@ -81,4 +87,12 @@ class NetworkControllerTest < ActionController::TestCase assert_not_nil assigns(:name) end + def test_dhcp_without_change + @if_proxy.result["eth1"] = OpenStruct.new("bootproto" => "dhcp") + @if_proxy.expects(:save).never #don't call save if dhcp is not saved + post :update, { :interface => "eth1", :conf_mode => "dhcp" } + assert_response :redirect + assert_redirected_to :action => "index" + end + end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org