You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by mf...@redhat.com on 2013/01/16 12:58:32 UTC
[PATCH core 7/8] Added validation to database models
From: Michal Fojtik <mf...@redhat.com>
Signed-off-by: Michal fojtik <mf...@redhat.com>
---
server/lib/db.rb | 7 +++++--
server/lib/db/address_template.rb | 7 +++++++
server/lib/db/machine_template.rb | 2 ++
server/lib/db/volume_configuration.rb | 2 ++
server/lib/db/volume_template.rb | 2 ++
5 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/server/lib/db.rb b/server/lib/db.rb
index c441021..6dc32c3 100644
--- a/server/lib/db.rb
+++ b/server/lib/db.rb
@@ -4,8 +4,11 @@ module Deltacloud
ENV['RACK_ENV'] == 'test'
end
- require 'sequel' unless test_environment?
- require 'logger'
+ unless test_environment?
+ require 'sequel'
+ require 'logger'
+ Sequel::Model.plugin :validation_class_methods
+ end
DATABASE_LOCATION = ENV['DATABASE_LOCATION'] ||
'sqlite://'+File.join('/', 'var', 'tmp', "deltacloud-mock-#{ENV['USER']}", 'db.sqlite')
diff --git a/server/lib/db/address_template.rb b/server/lib/db/address_template.rb
index 8586255..55771d1 100644
--- a/server/lib/db/address_template.rb
+++ b/server/lib/db/address_template.rb
@@ -2,6 +2,13 @@ module Deltacloud
module Database
class AddressTemplate < Entity
+ validates_presence_of :ip
+ validates_presence_of :hostname
+ validates_presence_of :allocation
+ validates_presence_of :default_gateway
+ validates_presence_of :dns
+ validates_presence_of :protocol
+ validates_presence_of :mask
end
end
diff --git a/server/lib/db/machine_template.rb b/server/lib/db/machine_template.rb
index 1b34161..61f57c1 100644
--- a/server/lib/db/machine_template.rb
+++ b/server/lib/db/machine_template.rb
@@ -2,6 +2,8 @@ module Deltacloud
module Database
class MachineTemplate < Entity
+ validates_presence_of :machine_config
+ validates_presence_of :machine_image
end
end
diff --git a/server/lib/db/volume_configuration.rb b/server/lib/db/volume_configuration.rb
index aa956ce..ebf59c2 100644
--- a/server/lib/db/volume_configuration.rb
+++ b/server/lib/db/volume_configuration.rb
@@ -2,6 +2,8 @@ module Deltacloud
module Database
class VolumeConfiguration < Entity
+ validates_presence_of :format
+ validates_presence_of :capacity
end
end
diff --git a/server/lib/db/volume_template.rb b/server/lib/db/volume_template.rb
index 0d876bf..8a4953a 100644
--- a/server/lib/db/volume_template.rb
+++ b/server/lib/db/volume_template.rb
@@ -2,6 +2,8 @@ module Deltacloud
module Database
class VolumeTemplate < Entity
+ validates_presence_of :volume_config
+ validates_presence_of :volume_Image
end
end
--
1.8.0.2