Changeset e67e28d59604c3c34a634ea37824b23bc828b268
- Timestamp:
- 07/28/10 11:43:16 (6 weeks ago)
- Author:
- Alban Peignier <alban.peignier@…>
- Parents:
- b71a93afaa069e73dee680b0a22e95f77a1cd660, 1b611f11cff8150feef05ffeef67461d875d87fc
- git-committer:
- Alban Peignier <alban.peignier@free.fr> / 2010-07-28T11:43:16Z+0200
- Message:
-
Merge branch 'master' of www.dbx.tryphon.priv:/srv/git/boxcontrol
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
rb034d2a
|
r1b611f1
|
|
| 1 | 1 | <p> |
| 2 | | Si la configuration de votre LinkBox vous convient, vous pouvez |
| | 2 | Si la configuration de votre Box vous convient, vous pouvez |
| 3 | 3 | la sauvegarder pour qu'elle soit utilisée au prochain redémarrage. |
| 4 | 4 | </p> |
| … |
… |
|
| 6 | 6 | <p> |
| 7 | 7 | <strong>Attention</strong> : si vous sauvegardez une configuration |
| 8 | | incorrecte, votre LinkBox pourrait ne pas redémarrer correctement ! |
| | 8 | incorrecte, votre Box pourrait ne pas redémarrer correctement ! |
| 9 | 9 | </p> |
-
|
rb034d2a
|
r1b611f1
|
|
| 1 | 1 | <p> |
| 2 | | If the settings of your LinkBox seem fine, you can save it |
| | 2 | If the settings of your Box seem fine, you can save it |
| 3 | 3 | to use these settings at the next boot. |
| 4 | 4 | </p> |
| … |
… |
|
| 6 | 6 | <p> |
| 7 | 7 | <strong>Warning</strong> : if you save a wrong configuration, |
| 8 | | your LinkBox may not reboot correctly ! |
| | 8 | your Box may not reboot correctly ! |
| 9 | 9 | </p> |
-
|
r9c57242
|
r79d3977
|
|
| 37 | 37 | new: |
| 38 | 38 | submit: Save |
| 39 | | or: or |
| 40 | | actions: |
| 41 | | edit: Edit |
-
|
r9c57242
|
r79d3977
|
|
| 37 | 37 | new: |
| 38 | 38 | submit: Sauvegarder |
| 39 | | or: ou |
| 40 | | actions: |
| 41 | | edit: Modifier |
-
|
rd4a3873
|
rb71a93a
|
|
| 9 | 9 | def acts_as_ip_port(*names) |
| 10 | 10 | options = names.extract_options! |
| | 11 | |
| | 12 | options = { :allow_blank => false }.update(options) |
| 11 | 13 | |
| 12 | 14 | minimum_value, message = |
| … |
… |
|
| 25 | 27 | end |
| 26 | 28 | |
| 27 | | validates_numericality_of name, :only_integer => true, :greater_than => minimum_value, :less_than => 65536, :message => message |
| | 29 | validates_numericality_of name, :only_integer => true, :greater_than => minimum_value, :less_than => 65536, :message => message, :allow_blank => options[:allow_blank] |
| 28 | 30 | end |
| 29 | 31 | end |
-
|
re5e4d56
|
r278d3c3
|
|
| 3 | 3 | def self.included(base) |
| 4 | 4 | base.extend ClassMethods |
| | 5 | base.class_eval do |
| | 6 | alias_method_chain :update_attributes, :save |
| | 7 | end |
| 5 | 8 | end |
| 6 | 9 | |
| … |
… |
|
| 21 | 24 | end |
| 22 | 25 | |
| | 26 | def update_attributes_with_save(attributes) |
| | 27 | update_attributes_without_save attributes |
| | 28 | save |
| | 29 | end |
| | 30 | |
| 23 | 31 | def save |
| 24 | 32 | return false if respond_to?(:valid?) and not valid? |
| | 33 | logger.debug "Save #{puppet_configuration_prefix} attributes: #{attributes.inspect}" if respond_to?(:logger) |
| 25 | 34 | PuppetConfiguration.load.update_attributes(self.attributes, puppet_configuration_prefix).save |
| 26 | 35 | end |
-
|
r4b8aa76
|
ree2829e
|
|
| 47 | 47 | self |
| 48 | 48 | end |
| | 49 | |
| | 50 | def clear(prefix = "") |
| | 51 | prefix = prefix.to_s |
| | 52 | @attributes.each_key do |key| |
| | 53 | @attributes.delete(key) if key.start_with?(prefix) |
| | 54 | end |
| | 55 | self |
| | 56 | end |
| 49 | 57 | |
| 50 | 58 | def normalize_prefix(prefix) |
| … |
… |
|
| 66 | 74 | |
| 67 | 75 | def self.load |
| 68 | | self.new.tap(&:load) |
| | 76 | unless pending_transaction? |
| | 77 | self.new.tap(&:load) |
| | 78 | else |
| | 79 | Thread.current[:puppet_configuration] |
| | 80 | end |
| | 81 | end |
| | 82 | |
| | 83 | def self.transaction(&block) |
| | 84 | configuration = PuppetConfiguration.load |
| | 85 | Thread.current[:puppet_configuration] = configuration |
| | 86 | begin |
| | 87 | yield configuration |
| | 88 | ensure |
| | 89 | Thread.current[:puppet_configuration] = nil |
| | 90 | end |
| | 91 | configuration.save |
| | 92 | end |
| | 93 | |
| | 94 | def self.pending_transaction? |
| | 95 | not Thread.current[:puppet_configuration].nil? |
| 69 | 96 | end |
| 70 | 97 | |
| 71 | 98 | def save |
| | 99 | return true if PuppetConfiguration.pending_transaction? |
| | 100 | |
| | 101 | Rails.logger.debug "write puppet configuration into #{configuration_file}" |
| 72 | 102 | File.open(configuration_file, "w") do |f| |
| 73 | 103 | @attributes.each_pair do |key, value| |
| … |
… |
|
| 84 | 114 | false |
| 85 | 115 | end |
| | 116 | |
| | 117 | def self.destroy |
| | 118 | File.delete(PuppetConfiguration.configuration_file) if File.exists?(PuppetConfiguration.configuration_file) |
| | 119 | end |
| 86 | 120 | |
| 87 | 121 | end |
-
|
rd4a3873
|
rb71a93a
|
|
| 10 | 10 | acts_as_ip_port :port |
| 11 | 11 | acts_as_ip_port :user_port, :user_port => true |
| | 12 | acts_as_ip_port :optionnal_port, :allow_blank => true |
| 12 | 13 | end |
| 13 | 14 | |
| … |
… |
|
| 41 | 42 | end |
| 42 | 43 | |
| | 44 | it "should not accept value blank value by default" do |
| | 45 | @model.should_not allow_values_for(:port, "") |
| | 46 | end |
| | 47 | |
| | 48 | context "when allow_blank is true" do |
| | 49 | |
| | 50 | it "should accept value blank value" do |
| | 51 | @model.should allow_values_for(:optionnal_port, "") |
| | 52 | end |
| | 53 | |
| | 54 | end |
| | 55 | |
| 43 | 56 | describe "user port" do |
| 44 | 57 | |
-
|
re5e4d56
|
r89da180
|
|
| 5 | 5 | |
| 6 | 6 | class TestConfigurable |
| | 7 | attr_accessor :attributes |
| | 8 | alias_method :update_attributes, :attributes= |
| | 9 | |
| 7 | 10 | include PuppetConfigurable |
| 8 | | |
| 9 | | attr_accessor :attributes |
| 10 | 11 | |
| 11 | 12 | def initialize(attributes = {}) |
| 12 | 13 | @attributes = attributes |
| 13 | 14 | end |
| 14 | | |
| 15 | | alias_method :update_attributes, :attributes= |
| 16 | 15 | end |
| 17 | 16 | |
| … |
… |
|
| 87 | 86 | describe "class method load" do |
| 88 | 87 | |
| 89 | | it "should create a new Network instance and load it" do |
| | 88 | it "should create a new instance and load it" do |
| 90 | 89 | TestConfigurable.should_receive(:new).and_return(@configurable) |
| 91 | 90 | @configurable.should_receive(:load) |
| … |
… |
|
| 95 | 94 | end |
| 96 | 95 | |
| | 96 | describe "update_attributes" do |
| | 97 | |
| | 98 | it "should save the instance" do |
| | 99 | @configurable.should_receive(:save) |
| | 100 | @configurable.update_attributes(:dummy => true) |
| | 101 | end |
| | 102 | |
| | 103 | end |
| | 104 | |
| 97 | 105 | end |
-
|
r4b8aa76
|
ree2829e
|
|
| 14 | 14 | def delete_configuration_file |
| 15 | 15 | File.delete(PuppetConfiguration.configuration_file) if File.exists?(PuppetConfiguration.configuration_file) |
| 16 | | end |
| 17 | | |
| 18 | | it "should use tmp/config.pp as default configuration file" do |
| 19 | | PuppetConfiguration.configuration_file.should == "tmp/config.pp" |
| 20 | 16 | end |
| 21 | 17 | |
| … |
… |
|
| 80 | 76 | @puppet_configuration.save.should be_false |
| 81 | 77 | end |
| | 78 | |
| | 79 | it "should not store configuration if transaction is pending" do |
| | 80 | PuppetConfiguration.stub!(:pending_transaction?).and_return(true) |
| | 81 | File.should_not_receive(:open) |
| | 82 | @puppet_configuration.save.should be_true |
| | 83 | end |
| 82 | 84 | |
| 83 | 85 | end |
| … |
… |
|
| 119 | 121 | end |
| 120 | 122 | |
| | 123 | describe "clear" do |
| | 124 | |
| | 125 | it "should remove keys with given prefix" do |
| | 126 | @puppet_configuration[:prefix_key] = "value" |
| | 127 | @puppet_configuration.clear(:prefix) |
| | 128 | @puppet_configuration[:prefix_key].should be_nil |
| | 129 | end |
| | 130 | |
| | 131 | it "should keep keys with doesn't match the prefix" do |
| | 132 | @puppet_configuration[:key] = "value" |
| | 133 | @puppet_configuration.clear(:prefix) |
| | 134 | @puppet_configuration[:key].should == "value" |
| | 135 | end |
| | 136 | |
| | 137 | it "should clear all keys without prefix" do |
| | 138 | @puppet_configuration[:key] = "value" |
| | 139 | @puppet_configuration.clear |
| | 140 | @puppet_configuration.should be_empty |
| | 141 | end |
| | 142 | |
| | 143 | it "should return the PuppetConfiguration instance" do |
| | 144 | @puppet_configuration.clear.should == @puppet_configuration |
| | 145 | end |
| | 146 | |
| | 147 | end |
| | 148 | |
| | 149 | describe "transaction" do |
| | 150 | |
| | 151 | it "should instance a single PuppetConfiguration" do |
| | 152 | PuppetConfiguration.should_receive(:new).and_return(@puppet_configuration) |
| | 153 | PuppetConfiguration.transaction do |
| | 154 | 3.times do |
| | 155 | PuppetConfiguration.load.should == @puppet_configuration |
| | 156 | end |
| | 157 | end |
| | 158 | end |
| | 159 | |
| | 160 | it "should save once PuppetConfiguration after transaction" do |
| | 161 | PuppetConfiguration.stub!(:new).and_return(@puppet_configuration) |
| | 162 | @puppet_configuration.should_receive(:save) |
| | 163 | PuppetConfiguration.transaction do |
| | 164 | end |
| | 165 | end |
| | 166 | |
| | 167 | end |
| | 168 | |
| 121 | 169 | end |