[Ovirt-devel] [PATCH server] Added a link from bonding to a boot type.
Darryl L. Pierce
dpierce at redhat.com
Mon Oct 6 15:30:44 UTC 2008
Previously the bondings had one of two paths: it could either
explicitly set a static IP address or else fallback to an implicit
DHCP boot.
This change will require that bondings be explicitly configured
in the same way as a standard network interface.
Signed-off-by: Darryl L. Pierce <dpierce at redhat.com>
---
src/app/models/bonding.rb | 10 +++++++
src/db/migrate/023_add_boot_type_to_bonding.rb | 31 ++++++++++++++++++++++++
src/test/fixtures/bondings.yml | 1 +
src/test/unit/bonding_test.rb | 20 +++++++++++----
4 files changed, 57 insertions(+), 5 deletions(-)
create mode 100644 src/db/migrate/023_add_boot_type_to_bonding.rb
diff --git a/src/app/models/bonding.rb b/src/app/models/bonding.rb
index 941e2cd..1be2f92 100644
--- a/src/app/models/bonding.rb
+++ b/src/app/models/bonding.rb
@@ -32,12 +32,22 @@
class Bonding < ActiveRecord::Base
validates_presence_of :name,
:message => 'A name is required.'
+
+ validates_presence_of :host_id,
+ :message => 'A host must be specified.'
validates_presence_of :interface_name,
:message => 'An interface name is required.'
+
+ validates_presence_of :boot_type_id,
+ :message => 'A boot type must be specified.'
+
+ validates_presence_of :bonding_type_id,
+ :message => 'A bonding type must be specified.'
belongs_to :host
belongs_to :bonding_type
+ belongs_to :boot_type
has_and_belongs_to_many :nics,
:join_table => 'bondings_nics',
diff --git a/src/db/migrate/023_add_boot_type_to_bonding.rb b/src/db/migrate/023_add_boot_type_to_bonding.rb
new file mode 100644
index 0000000..2947661
--- /dev/null
+++ b/src/db/migrate/023_add_boot_type_to_bonding.rb
@@ -0,0 +1,31 @@
+#
+# Copyright (C) 2008 Red Hat, Inc.
+# Written by Darryl L. Pierce <dpierce at redhat.com>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+
+class AddBootTypeToBonding < ActiveRecord::Migration
+ def self.up
+ add_column :bondings, :boot_type_id, :integer, :null => false
+
+ execute 'alter table bondings add constraint fk_bondings_boot_type
+ foreign key (boot_type_id) references boot_types(id)'
+ end
+
+ def self.down
+ remove_column :bondings, :boot_type_id
+ end
+end
diff --git a/src/test/fixtures/bondings.yml b/src/test/fixtures/bondings.yml
index c2a47b5..29473c7 100644
--- a/src/test/fixtures/bondings.yml
+++ b/src/test/fixtures/bondings.yml
@@ -3,6 +3,7 @@ mailservers_managed_node_bonding:
interface_name: bond0
bonding_type_id: <%= Fixtures.identify(:link_aggregation_bonding_type) %>
host_id: <%= Fixtures.identify(:mailservers_managed_node) %>
+ boot_type_id: <%= Fixtures.identify(:boot_type_static) %>
ip_addr: 172.31.0.15
netmask: 255.255.255.
broadcast: 172.31.0.255
diff --git a/src/test/unit/bonding_test.rb b/src/test/unit/bonding_test.rb
index 4bdb079..bacf2bc 100644
--- a/src/test/unit/bonding_test.rb
+++ b/src/test/unit/bonding_test.rb
@@ -23,15 +23,17 @@ class BondingTest < ActiveSupport::TestCase
fixtures :bondings
fixtures :bonding_types
fixtures :bondings_nics
+ fixtures :boot_types
fixtures :hosts
fixtures :nics
def setup
@bonding = Bonding.new(
- :name => 'Bonding1',
- :interface_name => 'bond0',
- :type_id => bonding_types(:failover_bonding_type),
- :host_id => hosts(:mailservers_managed_node))
+ :name => 'Bonding1',
+ :interface_name => 'bond0',
+ :bonding_type_id => bonding_types(:failover_bonding_type),
+ :boot_type_id => boot_types(:boot_type_dhcp),
+ :host_id => hosts(:mailservers_managed_node))
end
# Ensures that the name is required.
@@ -49,11 +51,19 @@ class BondingTest < ActiveSupport::TestCase
flunk 'Bondings have to have an interface name.' if @bonding.valid?
end
+
+ # Ensures that the bonding requires a boot type.
+ #
+ def test_valid_fails_without_boot_type
+ @bonding.boot_type_id = nil
+
+ flunk 'Bondings have to have a boot type.' if @bonding.valid?
+ end
# Ensures that the bonding type is required.
#
def test_valid_fails_without_type
- @bonding.type_id = nil
+ @bonding.bonding_type_id = nil
flunk 'Bondings have to have a valid type.' if @bonding.valid?
end
--
1.5.5.1
More information about the ovirt-devel
mailing list