From f9eb15f30cc3360daa7dd418f79a1ea353a7e347 Mon Sep 17 00:00:00 2001
From: Jochen Schalanda
+ <%= f.label :name %>
+ <%= f.label :path %>
+ <%= f.label :operatingsystem_id %> Currently used by <%= @medium.hosts.count %> hosts <%= f.submit "Submit" %>
+ <%= link_to "View All", media_path %>
+ <%= link_to "New Medium", new_medium_path %> <%= link_to "Back to List", media_path %>
- <%= f.label :name %>
- <%= f.label :path %>
- <%= f.label :operatingsystem_id %> Currently used by <%= @media.hosts.count %> hosts <%= f.submit "Submit" %>
- <%= link_to "View All", medias_path %>
- <%= link_to "New Media", new_media_path %> <%= link_to "Back to List", medias_path %>
+ <%= f.text_field :name %>
+
+ <%= f.text_field :path %>
+
+ for example http://mirror.averse.net/centos/$version/os/$arch where $arch will be substituted for the host's actual OS architecture
+ and $version, $major and $minor will be substituted for the version of the operating system.
+
+
+ <%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %>
+
+
+
+
+
+ <% for medium in @media %>
+ Name
+ Path
+ Operating system
+
+
+ <% end %>
+<%= link_to h(medium), edit_medium_path(medium) %>
+ <%=h medium.path %>
+ <%=h medium.operatingsystem %>
+ <%= link_to "Destroy", medium, :confirm => 'Are you sure?', :method => :delete %>
+
- <%= f.text_field :name %>
-
- <%= f.text_field :path %>
-
- for example http://mirror.averse.net/centos/$version/os/$arch where $arch will be substituted for the host's actual OS architecture
- and $version, $major and $minor will be substituted for the version of the operating system.
-
-
- <%= f.collection_select :operatingsystem_id, Operatingsystem.all, :id, :to_label %>
-
-
-
-
-
- <% for media in @medias %>
- Name
- Path
- Operatingsystem
-
-
- <% end %>
-<%= link_to h(media), edit_media_path(media) %>
- <%=h media.path %>
- <%=h media.operatingsystem %>
- <%= link_to "Destroy", media, :confirm => 'Are you sure?', :method => :delete %>
-
- <% field_set_tag("Installation Medias") do %> - <%= edit_habtm @operatingsystem, Media %> + <% field_set_tag("Installation Media") do %> + <%= edit_habtm @operatingsystem, Medium %> <% end -%>
diff --git a/app/views/unattended/kickstart.rhtml b/app/views/unattended/kickstart.rhtml index 7a64e65..9f48c76 100644 --- a/app/views/unattended/kickstart.rhtml +++ b/app/views/unattended/kickstart.rhtml @@ -1,5 +1,5 @@ install -<%= @mediapath %> +<%= @mediumpath %> lang en_US.UTF-8 <%= "langsupport --default en_US.UTF-8 en_GB.UTF-8 en_US.UTF-8\n" if @osver < 5 -%> <%= "mouse generic3usb --device input/mice\n" if @osver == 3 -%> diff --git a/config/routes.rb b/config/routes.rb index 3474bc7..2e9e8ed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,7 +24,7 @@ ActionController::Routing::Routes.draw do |map| map.connect "/lookup", :controller => "lookup_keys", :action => "q" map.resources :domains map.resources :operatingsystems - map.resources :medias + map.resources :media map.resources :models map.resources :architectures map.resources :puppetclasses, :member => { :assign => :post }, :collection => {:import_environments => :get} diff --git a/db/migrate/20100523075526_drop_medias.rb b/db/migrate/20100523075526_drop_medias.rb new file mode 100644 index 0000000..d22fb20 --- /dev/null +++ b/db/migrate/20100523075526_drop_medias.rb @@ -0,0 +1,16 @@ +class DropMedias < ActiveRecord::Migration + def self.up + drop_table :medias + end + + def self.down + create_table :medias do |t| + t.string :name, :limit => 50, :default => "", :null => false + t.string :path, :limit => 100, :default => "", :null => false + t.references :operatingsystem + t.timestamps + end + Media.create :name => "CentOS 5 mirror", :path => "http://mirror.averse.net/centos/5.3/os/$arch" + Media.create :name => "Fedora 11 Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/11/Fedora/$arch/os/" + end +end diff --git a/db/migrate/20100523075701_create_media.rb b/db/migrate/20100523075701_create_media.rb new file mode 100644 index 0000000..4510057 --- /dev/null +++ b/db/migrate/20100523075701_create_media.rb @@ -0,0 +1,16 @@ +class CreateMedia < ActiveRecord::Migration + def self.up + create_table :media do |t| + t.string :name, :limit => 50, :default => "", :null => false + t.string :path, :limit => 100, :default => "", :null => false + t.references :operatingsystem + t.timestamps + end + Medium.create :name => "CentOS 5 mirror", :path => "http://mirror.averse.net/centos/5.3/os/$arch" + Medium.create :name => "Fedora 11 Mirror", :path => "http://mirror.nus.edu.sg/fedora/releases/11/Fedora/$arch/os/" + end + + def self.down + drop_table :media + end +end diff --git a/db/migrate/20100523080255_remove_index_from_host.rb b/db/migrate/20100523080255_remove_index_from_host.rb new file mode 100644 index 0000000..ff95fad --- /dev/null +++ b/db/migrate/20100523080255_remove_index_from_host.rb @@ -0,0 +1,9 @@ +class RemoveIndexFromHost < ActiveRecord::Migration + def self.up + remove_index "hosts", :name => 'host_media_id_ix' + end + + def self.down + add_index "hosts", :media_id, :name => 'host_media_id_ix' + end +end diff --git a/db/migrate/20100523080316_change_host_media_id.rb b/db/migrate/20100523080316_change_host_media_id.rb new file mode 100644 index 0000000..a8721e5 --- /dev/null +++ b/db/migrate/20100523080316_change_host_media_id.rb @@ -0,0 +1,13 @@ +class ChangeHostMediaId < ActiveRecord::Migration + def self.up + change_table :hosts do |t| + t.rename :media_id, :medium_id + end + end + + def self.down + change_table :hosts do |t| + t.rename :medium_id, :media_id + end + end +end diff --git a/db/migrate/20100523080344_add_index_media_id_to_host.rb b/db/migrate/20100523080344_add_index_media_id_to_host.rb new file mode 100644 index 0000000..3be3688 --- /dev/null +++ b/db/migrate/20100523080344_add_index_media_id_to_host.rb @@ -0,0 +1,9 @@ +class AddIndexMediaIdToHost < ActiveRecord::Migration + def self.up + add_index "hosts", :medium_id, :name => 'host_medium_id_ix' + end + + def self.down + remove_index "hosts", :name => 'host_medium_id_ix' + end +end diff --git a/lib/family.rb b/lib/family.rb index f034cb7..0d1f6a4 100644 --- a/lib/family.rb +++ b/lib/family.rb @@ -14,8 +14,8 @@ module Family FAMILIES.map{|e| OpenStruct.new(:name => e, :value => FAMILIES.index(e)) } end - def media_uri host, url = nil - url ||= host.media.path + def medium_uri host, url = nil + url ||= host.medium.path URI.parse(url.gsub('$arch',host.architecture.name). gsub('$major', host.os.major). gsub('$minor', host.os.minor). @@ -27,20 +27,20 @@ module Family include Family def preseed_server host - media_uri(host).select(:host, :port).compact.join(':') + medium_uri(host).select(:host, :port).compact.join(':') end def preseed_path host - media_uri(host).select(:path, :query).compact.join('?') + medium_uri(host).select(:path, :query).compact.join('?') end end module RedHat include Family - # outputs kickstart installation media based on the media type (NFS or URL) + # outputs kickstart installation medium based on the medium type (NFS or URL) # it also convert the $arch string to the current host architecture - def mediapath host - uri = media_uri(host) + def mediumpath host + uri = medium_uri(host) server = uri.select(:host, :port).compact.join(':') dir = uri.select(:path, :query).compact.join('?') unless uri.scheme == 'ftp' @@ -67,7 +67,7 @@ module Family else return "" end - return "su -c 'rpm -Uvh #{media_uri(host, epel_url)}'" + return "su -c 'rpm -Uvh #{medium_uri(host, epel_url)}'" end def yumrepo host diff --git a/test/fixtures/media.yml b/test/fixtures/media.yml new file mode 100644 index 0000000..d10755a --- /dev/null +++ b/test/fixtures/media.yml @@ -0,0 +1,6 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html + +one: + name: CentOS 5.4 + path: http://mirror.averse.net/centos/6.0/os/$arch + operatingsystem_id: 1 diff --git a/test/fixtures/medias.yml b/test/fixtures/medias.yml deleted file mode 100644 index d10755a..0000000 --- a/test/fixtures/medias.yml +++ /dev/null @@ -1,6 +0,0 @@ -# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html - -one: - name: CentOS 5.4 - path: http://mirror.averse.net/centos/6.0/os/$arch - operatingsystem_id: 1 diff --git a/test/functional/media_controller_test.rb b/test/functional/media_controller_test.rb new file mode 100644 index 0000000..78b9e2f --- /dev/null +++ b/test/functional/media_controller_test.rb @@ -0,0 +1,49 @@ +require 'test_helper' + +class MediaControllerTest < ActionController::TestCase + def test_index + get :index, {}, set_session_user + assert_template 'index' + end + + def test_new + get :new, {}, set_session_user + assert_template 'new' + end + + def test_create_invalid + Medium.any_instance.stubs(:valid?).returns(false) + post :create, {}, set_session_user + assert_template 'new' + end + + def test_create_valid + Medium.any_instance.stubs(:valid?).returns(true) + post :create, {}, set_session_user + assert_redirected_to media_url + end + + def test_edit + get :edit, {:id => Medium.first}, set_session_user + assert_template 'edit' + end + + def test_update_invalid + Medium.any_instance.stubs(:valid?).returns(false) + put :update, {:id => Medium.first}, set_session_user + assert_template 'edit' + end + + def test_update_valid + Medium.any_instance.stubs(:valid?).returns(true) + put :update, {:id => Medium.first}, set_session_user + assert_redirected_to media_url + end + + def test_destroy + medium = Medium.first + delete :destroy, {:id => medium}, set_session_user + assert_redirected_to media_url + assert !Medium.exists?(medium.id) + end +end diff --git a/test/functional/medias_controller_test.rb b/test/functional/medias_controller_test.rb deleted file mode 100644 index 04ff7ae..0000000 --- a/test/functional/medias_controller_test.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'test_helper' - -class MediasControllerTest < ActionController::TestCase - def test_index - get :index, {}, set_session_user - assert_template 'index' - end - - def test_new - get :new, {}, set_session_user - assert_template 'new' - end - - def test_create_invalid - Media.any_instance.stubs(:valid?).returns(false) - post :create, {}, set_session_user - assert_template 'new' - end - - def test_create_valid - Media.any_instance.stubs(:valid?).returns(true) - post :create, {}, set_session_user - assert_redirected_to medias_url - end - - def test_edit - get :edit, {:id => Media.first}, set_session_user - assert_template 'edit' - end - - def test_update_invalid - Media.any_instance.stubs(:valid?).returns(false) - put :update, {:id => Media.first}, set_session_user - assert_template 'edit' - end - - def test_update_valid - Media.any_instance.stubs(:valid?).returns(true) - put :update, {:id => Media.first}, set_session_user - assert_redirected_to medias_url - end - - def test_destroy - media = Media.first - delete :destroy, {:id => media}, set_session_user - assert_redirected_to medias_url - assert !Media.exists?(media.id) - end -end diff --git a/test/unit/helpers/media_helper_test.rb b/test/unit/helpers/media_helper_test.rb deleted file mode 100644 index e02628b..0000000 --- a/test/unit/helpers/media_helper_test.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'test_helper' - -class MediaHelperTest < ActionView::TestCase -end diff --git a/test/unit/helpers/medium_helper_test.rb b/test/unit/helpers/medium_helper_test.rb new file mode 100644 index 0000000..ef1219f --- /dev/null +++ b/test/unit/helpers/medium_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class MediumHelperTest < ActionView::TestCase +end diff --git a/test/unit/media_test.rb b/test/unit/media_test.rb deleted file mode 100644 index 89aebf3..0000000 --- a/test/unit/media_test.rb +++ /dev/null @@ -1,55 +0,0 @@ -require 'test_helper' - -class MediaTest < ActiveSupport::TestCase - test "name can't be blank" do - media = Media.new :name => " ", :path => "http://www.google.com" - assert media.name.strip.empty? - assert !media.save - end - - test "name can't contain white spaces" do - media = Media.new :name => " Archlinux mirror thing ", :path => "http://www.google.com" - assert !media.name.strip.squeeze(" ").empty? - assert !media.save - - media.name.strip!.squeeze!(" ") - assert media.save! - end - - test "name must be unique" do - media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com" - assert media.save! - - other_media = Media.new :name => "Archlinux mirror", :path => "http://www.youtube.com" - assert !other_media.save - end - - test "path can't be blank" do - media = Media.new :name => "Archlinux mirror", :path => " " - assert media.path.strip.empty? - assert !media.save - end - - test "path must be unique" do - media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com" - assert media.save! - - other_media = Media.new :name => "Ubuntu mirror", :path => "http://www.google.com" - assert !other_media.save - end - - test "should not destroy while using" do - media = Media.new :name => "Archlinux mirror", :path => "http://www.google.com" - assert media.save! - - host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03", - :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first, - :architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition", - :ptable => Ptable.first - assert host.save! - - media.hosts << host - - assert !media.destroy - end -end diff --git a/test/unit/medium_test.rb b/test/unit/medium_test.rb new file mode 100644 index 0000000..7846b9f --- /dev/null +++ b/test/unit/medium_test.rb @@ -0,0 +1,55 @@ +require 'test_helper' + +class MediumTest < ActiveSupport::TestCase + test "name can't be blank" do + medium = Medium.new :name => " ", :path => "http://www.google.com" + assert medium.name.strip.empty? + assert !medium.save + end + + test "name can't contain white spaces" do + medium = Medium.new :name => " Archlinux mirror thing ", :path => "http://www.google.com" + assert !medium.name.strip.squeeze(" ").empty? + assert !medium.save + + medium.name.strip!.squeeze!(" ") + assert medium.save! + end + + test "name must be unique" do + medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com" + assert medium.save! + + other_medium = Medium.new :name => "Archlinux mirror", :path => "http://www.youtube.com" + assert !other_medium.save + end + + test "path can't be blank" do + medium = Medium.new :name => "Archlinux mirror", :path => " " + assert medium.path.strip.empty? + assert !medium.save + end + + test "path must be unique" do + medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com" + assert medium.save! + + other_medium = Medium.new :name => "Ubuntu mirror", :path => "http://www.google.com" + assert !other_medium.save + end + + test "should not destroy while using" do + medium = Medium.new :name => "Archlinux mirror", :path => "http://www.google.com" + assert medium.save! + + host = Host.new :name => "myfullhost", :mac => "aabbecddeeff", :ip => "123.05.02.03", + :domain => Domain.find_or_create_by_name("company.com"), :operatingsystem => Operatingsystem.first, + :architecture => Architecture.first, :environment => Environment.first, :disk => "empty partition", + :ptable => Ptable.first + assert host.save! + + medium.hosts << host + + assert !medium.destroy + end +end -- 1.6.3.3