Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new model constructs

  • Loading branch information...
commit f4d977b2b25597c4f9ebe8680b1d25abdfad0033 1 parent 73b065a
Nicholas Weaver lynxbat authored
Showing with 353 additions and 165 deletions.
  1. +1 −0  .yardopts
  2. +2 −2 Gemfile
  3. +0 −86 README.rdoc
  4. +1 −0  bin/node/razor.js
  5. +3 −0  bin/razor
  6. +7 −2 lib/common/configuration.rb
  7. +2 −2 lib/common/data.rb
  8. +24 −0 lib/common/engine.rb
  9. +0 −23 lib/common/model.rb
  10. +20 −16 lib/common/node.rb
  11. +3 −2 lib/common/object.rb
  12. +28 −0 lib/common/old_model.rb
  13. +0 −1  lib/common/persist_controller.rb
  14. +1 −0  lib/common/persist_database_object.rb
  15. +9 −2 lib/common/utility.rb
  16. +40 −0 lib/models/model_base.rb
  17. +28 −0 lib/models/ubuntu_oneiric.rb
  18. +16 −4 lib/slices/slice_base.rb
  19. +7 −3 lib/slices/slice_config.rb
  20. +57 −3 lib/slices/slice_model.rb
  21. +23 −4 lib/slices/slice_node.rb
  22. +2 −0  lib/slices/slice_template.rb
  23. +13 −0 lib/systems/system_base.rb
  24. +15 −0 lib/systems/system_puppet.rb
  25. 0  log/README
  26. +7 −6 spec/base/rz_001_persist_controller_spec.rb
  27. +9 −9 spec/base/rz_002_data_spec.rb
  28. +1 −0  spec/base/rz_011_slice_node_spec.rb
  29. +31 −0 spec/base/rz_012_slice_model_spec.rb
  30. +3 −0  todo
1  .yardopts
View
@@ -0,0 +1 @@
+--no-private --protected ./lib/**/*.rb
4 Gemfile
View
@@ -1,13 +1,13 @@
# A sample Gemfile
source "http://rubygems.org"
-gem "mongo" # You need to install the newest per the README.rdoc
+#gem "mongo" # You need to install the newest per the README.rdoc
gem "bson"
gem "bson_ext"
gem "rspec"
gem "syntax"
gem "uuid"
-gem "log4r"
+gem "logger"
gem "extlib" # used for full_const_get method
gem "json"
gem "colored"
86 README.rdoc
View
@@ -1,86 +0,0 @@
-# Project Razor
-
-## Introduction
-
-Project Razor is a power control, provisioning, and management application designed
-to deploy both bare-metal and virtual compute resources with tight integration to
-DevOps-style tool sets.
-
-## Authors
-
-[Nicholas Weaver](https://github.com/lynxbat)
-[Tom McSweeney](https://github.com/tjmcs)
-
-## Installation
-
-### Node.js:
-[Node.js install with package manager](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager)
-[Node Package Manager(NPM)](http://npmjs.org/)
-[Express install via NPM](http://expressjs.com/guide.html)
-
-### Database
-
-#### Mongo
-
-_todo_
-
-## Prereqs
-
-* Ruby >= 1.9.3
-* Assorted gems - see (Gemfile)
-* Node.js >= 0.6.10
-* Node.js Express package
-
-
-## Environment Variables
-* $RAZOR_HOME
- >Root directory for Razor install
-
-* $RAZOR_RSPEC_WEBPATH
- >Root directory for dropping RSpec html _(optional)_
-
-* $RAZOR_LOG_PATH
->Path for razor logs _(optional)_l
->>Default = $RAZOR_HOME/log
-
-* $RAZOR_LOG_LEVEL
- > Verbosity for logs _(optional)_
- >> 0 = Debug
- >> 1 = Info
- >> 2 = Warn
- >> 3 = Error (default)
- >> 4 = Fatal
- >> 5 = Unknown
-
-
-## Directory structure
- ./bin - control scripts
- ./conf - configuration YAML files
- ./doc - Documentation (YARD)
- ./images - default images directory
- ./install - installation bits
- ./lib - root library folder
- ./test_scripts - testing scripts
- ./rspec - unit tests (RSpec)
-
-## Starting services
-
-Start Razor API with:
-
- cd $RAZOR_HOME/bin/node
- node razor.js
-
-
-## Notes
-
-Use the newest mongo ruby driver build as there is a bug with connect_timeout scoping error
-that hasn't been merged into available gem yet
-
-The fix below is assuming RVM as Ruby environment manager. If using global RVM gems make sure
-and 'rvm use ruby-1.9.3@global' before installing updated mongo driver.
-
- wget https://github.com/mongodb/mongo-ruby-driver/zipball/master
- unzip master
- cd mongodb-mongo-ruby-driver-99d9dfd/
- gem build mongo.gemspec
- gem install mongo-1.5.2.gem
1  bin/node/razor.js
View
@@ -83,6 +83,7 @@ function getConfig() {
}
// TODO Add catch for if razor.js is already running on port
+// Start our server if we can get a valid config
function startServer(json_config) {
config = JSON.parse(json_config);
if (config['@api_port'] != null) {
3  bin/razor
View
@@ -28,6 +28,7 @@ def load_slices
get_slices_loaded
end
+# Call the slice
def call_razor_slice
if is_slice?
razor_module = Object.full_const_get(SLICE_PREFIX + @namespace.capitalize).new(@args)
@@ -44,6 +45,7 @@ def call_razor_slice
end
end
+# Load slices
def get_slices_loaded
temp_hash = {}
ObjectSpace.each_object do
@@ -58,6 +60,7 @@ def get_slices_loaded
@slice_array = @slice_array.each_value.collect {|x| x}
end
+# Validate slice
def is_slice?
@slice_array.each { |slice| return true if @namespace.downcase == slice.downcase }
false
9 lib/common/configuration.rb
View
@@ -28,11 +28,12 @@ class Configuration
attr_accessor :checkin_offset
attr_accessor :register_timeout
+ # init
def initialize
use_defaults
end
-
+ # Set defaults
def use_defaults
@persist_mode = :mongo
@persist_host = "127.0.0.1"
@@ -41,7 +42,11 @@ def use_defaults
@admin_port = 8017
@api_port = 8026
- @logpath = "#{ENV['RAZOR_HOME']}/log/"
+ @logpath = "#{ENV['RAZOR_HOME']}/log"
+
+ @checkin_sleep = 60
+ @checkin_offset = 5
+ @register_timeout = 120
end
4 lib/common/data.rb
View
@@ -184,9 +184,9 @@ def reset_config
new_conf = Razor::Configuration.new
# Very important that we only write the file if it doesn't exist as we may not be the only thread using it
- if !File.exist?(CONFIG_PATH)
+ unless File.exist?(CONFIG_PATH)
begin
- new_conf_file = File.new(CONFIG_PATH,'w+')
+ new_conf_file = File.new(CONFIG_PATH, 'w+')
new_conf_file.write(("#{new_conf_header}#{YAML.dump(new_conf)}"))
new_conf_file.close
logger.info "Default config saved to (#{CONFIG_PATH})"
24 lib/common/engine.rb
View
@@ -0,0 +1,24 @@
+# This adds Razor Common lib path to the load path for this child proc
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+# Root Razor namespace
+# @author Nicholas Weaver
+module Razor
+
+ # Used for all event-driven commands and policy resolution
+ # @author Nicholas Weaver
+ class Engine
+
+ # TODO policy resolve
+
+
+ # TODO tag rules resolve
+
+
+
+
+
+
+
+ end
+end
23 lib/common/model.rb
View
@@ -1,23 +0,0 @@
-# This adds Razor Common lib path to the load path for this child proc
-$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
-
-require "object"
-
-module Razor
-class Model < Razor::Object
- attr_accessor :name
- attr_accessor :model_type
- attr_accessor :values_hash
-
-
- # @param hash [Hash]
- def initialize(hash)
- @name = nil
- @model_type = nil
- @values_hash = nil
- super()
- @_collection = :model
- from_hash(hash)
- end
-end
- end
36 lib/common/node.rb
View
@@ -3,23 +3,27 @@
require "object"
-# Razor class representing Nodes
-#noinspection RubyResolve
+# Root Razor namespace
+# @author Nicholas Weaver
module Razor
-class Node < Razor::Object
- attr_accessor :name
- attr_accessor :attributes_hash
- attr_accessor :timestamp
- attr_accessor :last_state
- attr_accessor :current_state
- attr_accessor :next_state
- # @param hash [Hash]
- def initialize(hash)
- super()
- @_collection = :node
- @attributes_hash = {}
- from_hash(hash)
+ # Root Razor::Node namespace
+ # @author Nicholas Weaver
+ class Node < Razor::Object
+ attr_accessor :name
+ attr_accessor :attributes_hash
+ attr_accessor :timestamp
+ attr_accessor :last_state
+ attr_accessor :current_state
+ attr_accessor :next_state
+
+ # init
+ # @param hash [Hash]
+ def initialize(hash)
+ super()
+ @_collection = :node
+ @attributes_hash = {}
+ from_hash(hash)
+ end
end
-end
end
5 lib/common/object.rb
View
@@ -4,7 +4,8 @@
require "utility"
require "logging"
-
+# Root Razor namespace
+# @author Nicholas Weaver
module Razor
# Common object for all base Razor objects
# @abstract
@@ -48,7 +49,7 @@ def update_self
true
end
-
+ # Get logger object
def get_logger
logger
end
28 lib/common/old_model.rb
View
@@ -0,0 +1,28 @@
+# This adds Razor Common lib path to the load path for this child proc
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+require "object"
+
+# Root Razor namespace
+# @author Nicholas Weaver
+module Razor
+ # Root Model object
+ # @author Nicholas Weaver
+ # @abstract
+ class Model < Razor::Object
+ attr_accessor :name
+ attr_accessor :model_type
+ attr_accessor :values_hash
+
+ # init
+ # @param hash [Hash]
+ def initialize(hash)
+ @name = nil
+ @model_type = nil
+ @values_hash = nil
+ super()
+ @_collection = :model
+ from_hash(hash)
+ end
+ end
+end
1  lib/common/persist_controller.rb
View
@@ -3,7 +3,6 @@
require "configuration"
require "persist_database_mongo"
-require "model"
require "logging"
# Persistence Controller for Razor
1  lib/common/persist_database_object.rb
View
@@ -7,6 +7,7 @@
# This adds Razor Common lib path to the load path for this child proc
$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+# @author Nicholas Weaver
module Razor
module Persist
module Database
11 lib/common/utility.rb
View
@@ -1,9 +1,14 @@
require "yaml"
+# Root Razor namespace
+# @author Nicholas Weaver
module Razor
+
+ # Razor::Utility namespace
+ # @author Nicholas Weaver
module Utility
- # returns a hash array of instance variable symbol and instance variable value for self
+ # Returns a hash array of instance variable symbol and instance variable value for self
# will ignore instance variables that start with '_'
def to_hash
hash = {}
@@ -15,8 +20,9 @@ def to_hash
hash
end
- # sets instance variables
+ # Sets instance variables
# will not include any that start with "_" (Mongo specific)
+ # @param [Hash] hash
def from_hash(hash)
hash.each_pair {|key, value| self.instance_variable_set(key,value) unless key.to_s.start_with?("_")}
end
@@ -29,6 +35,7 @@ def validate_instance_vars
end
# Returns the version number as [String] from ./conf/version
+ # @return [String]
def get_razor_version
file = File.open("#{ENV['RAZOR_HOME']}/conf/version", "rb")
version = file.read
40 lib/models/model_base.rb
View
@@ -0,0 +1,40 @@
+# This adds Razor Common lib path to the load path for this child proc
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+require "object"
+
+# Root Razor namespace
+# @author Nicholas Weaver
+module Razor::Model
+ # Root Model object
+ # @author Nicholas Weaver
+ # @abstract
+ class Base < Razor::Object
+ attr_accessor :name
+ attr_accessor :model_type
+ attr_accessor :model_description
+ attr_accessor :values_hash
+
+ # init
+ # @param hash [Hash]
+ def initialize(hash)
+ @name = nil
+ @model_type = :base
+ @model_description = "Base model type"
+ @values_hash = {}
+ super()
+ @_collection = :model
+ from_hash(hash) unless hash == nil
+ end
+
+
+ def define_values_hash
+ @values_hash = {
+ :hostname => "",
+ :root_account => "",
+ :root_password => "",
+ :ssh_pub_key => ""
+ }
+ end
+ end
+end
28 lib/models/ubuntu_oneiric.rb
View
@@ -0,0 +1,28 @@
+# This adds Razor Common lib path to the load path for this child proc
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/models"
+
+require "model_base"
+
+# Root Razor namespace
+# @author Nicholas Weaver
+module Razor::Model
+ # Root Model object
+ # @author Nicholas Weaver
+ # @abstract
+ class UbuntuOneiric < Razor::Model::Base
+
+ def initialize(hash)
+ super(hash)
+ @model_type = :ubuntu_oneiric
+ @model_description = "Ubuntu Oneiric 11.10"
+
+
+ end
+
+ def define_values_hash
+ @values_hash
+ end
+
+ end
+end
20 lib/slices/slice_base.rb
View
@@ -15,18 +15,21 @@ module Slice
class Base
include(Razor::Logging)
+ # Bool for indicating whether this was driven from Node.js
attr_accessor :web_command
- # [Array] @command_array
- # [Hash] @slice_commands
+
+ # Initializes the Slice Base
+ # @param [Array] args
def initialize(args)
@command_array = args
@slice_commands = {}
@web_command = false
end
- # Default call method for a slice. Used by {razor.rb}.
+ # Default call method for a slice
+ # Used by {./bin/razor}
+ # Parses the #command_array and determines the action based on #slice_commands for child object
def slice_call
-
# First var in array should be our root command
@command = @command_array.shift
# check command and route based on it
@@ -49,6 +52,9 @@ def slice_call
end
end
+ # Called when slice action is successful
+ # Returns a json string representing a [Hash] with metadata and response
+ # @param [Hash] response
def slice_success(response)
return_hash = {}
return_hash["resource"] = self.class.to_s
@@ -66,6 +72,9 @@ def slice_success(response)
logger.debug "(#{return_hash["resource"]} #{return_hash["command"]} #{return_hash["result"]})"
end
+ # Called when a slice action triggers an error
+ # Returns a json string representing a [Hash] with metadata including error code and message
+ # @param [Hash] error
def slice_error(error)
@command = "null" if @command == nil
@@ -82,6 +91,8 @@ def slice_error(error)
logger.error "Slice error: #{return_hash.inspect}"
end
+ # Prints available commands to CLI for slice
+ # @param [Hash] return_hash
def available_commands(return_hash)
print "\nAvailable commands for [#{@slice_name}]:\n"
@slice_commands.each do
@@ -97,6 +108,7 @@ def available_commands(return_hash)
end
end
+ # Initializes [Razor::Data] in not already instantiated
def setup_data
@data = Razor::Data.new unless @data.class == Razor::Data
end
10 lib/slices/slice_config.rb
View
@@ -11,16 +11,20 @@ module Razor::Slice
# @author Nicholas Weaver
class Config < Razor::Slice::Base
+ # init
+ # @param [Array] args
def initialize(args)
super(args)
# Define your commands and help text
- @slice_commands = {"read" => "read_config"}
- @slice_commands_help = {"read" => "config [read]"}
+ @slice_commands = {:read => "read_config",
+ :default => "read_config"}
+ @slice_commands_help = {:read => "config [read]"}
@slice_name = "Config"
end
+ # Reads the Razor config
def read_config
- setup_data # inits our Razor::Data if it doesn't exist
+ setup_data
if @web_command # is this a web command
print @data.config.to_hash.to_json
else
60 lib/slices/slice_model.rb
View
@@ -1,12 +1,66 @@
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/slices"
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/models"
+MODEL_TYPE_PATH = "#{ENV['RAZOR_HOME']}/lib/models"
+MODEL_PREFIX = "Razor::Model::"
+require "data"
+require "model_base"
require "slice_base"
+require "json"
+require "logging"
+require "yaml"
# Root Razor namespace
# @author Nicholas Weaver
module Razor::Slice
- # Razor Slice Model
- # @author Nicholas Weaver
- class Model < Razor::Slice::Base
+ # Razor Slice Model
+ # @author Nicholas Weaver
+ class Model < Razor::Slice::Base
+ include(Razor::Logging)
+ # Initializes Razor::Slice::Model including #slice_commands, #slice_commands_help, & #slice_name
+ # @param [Array] args
+ def initialize(args)
+ super(args)
+ load_model_types # load our model types
+
+ # Here we create a hash of the command string to the method it corresponds to for routing.
+ @slice_commands = {:default => "query_models",
+ :type => "query_model_types",
+ :create => "create_model",
+ :remove => "remove_node",
+ :list => "query_model"}
+ @slice_commands_help = {:list => "model list",
+ :default => "model"}
+ @slice_name = "Node"
+ end
+
+
+ def query_model_types
+ temp_hash = {}
+ ObjectSpace.each_object do
+ |object_class|
+
+ if object_class.to_s.start_with?(MODEL_PREFIX) && object_class.to_s != MODEL_PREFIX
+ temp_hash[object_class.to_s] = object_class.to_s.sub(MODEL_PREFIX,"").strip
+ end
+ end
+ @slice_array = {}
+ temp_hash.each_value {|x| @slice_array[x] = x}
+ @slice_array = @slice_array.each_value.collect {|x| x}
+
+ @slice_array.each do
+ |x|
+ o = Object.full_const_get(MODEL_PREFIX + x).new(nil)
+ puts o.model_description
+ end
+ end
+
+
+ def load_model_types
+ Dir.glob("#{MODEL_TYPE_PATH}/*.{rb}") do |file|
+ require "#{file}"
+ end
end
+ end
end
27 lib/slices/slice_node.rb
View
@@ -24,6 +24,8 @@ class Node < Razor::Slice::Base
# TODO fill out comments
+ # Initializes Razor::Slice::Node including #slice_commands, #slice_commands_help, & #slice_name
+ # @param [Array] args
def initialize(args)
super(args)
# Here we create a hash of the command string to the method it corresponds to for routing.
@@ -36,6 +38,7 @@ def initialize(args)
@slice_name = "Node"
end
+ # Runs a node checkin returning appropriate command
def checkin_node
# TODO this needs to be wired to the *future* Razor::Engine
@@ -70,7 +73,7 @@ def checkin_node
else
setup_data
- if (node.timestamp - old_timestamp) > @data.config.register_timeout
+ if (node.timestamp - old_timestamp) > @data.config.register_timeout
logger.debug "Checkin acknowledged: #{forced_action.to_s}"
slice_success(get_command(:register, {}))
else
@@ -96,6 +99,10 @@ def checkin_node
end
end
+ # Builds a command for a checkin
+ # @param [String] command_name
+ # @param [Hash] command_param
+ # @return [Hash]
def get_command(command_name, command_param)
command_response = {}
command_response['command_name'] = command_name
@@ -103,6 +110,9 @@ def get_command(command_name, command_param)
command_response
end
+ # Checks if node exists in DB returns node object or false
+ # @param [String] uuid
+ # @return [Razor::Node, false]
def node_exist?(uuid)
setup_data
node = @data.fetch_object_by_uuid(:node, uuid)
@@ -110,6 +120,7 @@ def node_exist?(uuid)
false
end
+ # Registers node
def register_node
logger.debug "Register node called"
@command_name = "register_node"
@@ -142,15 +153,20 @@ def register_node
end
end
+ # Removes node
def remove_node
slice_error("NotImplemented")
end
+ # Inserts node using hash
+ # @param [Hash] node_hash
+ # @return [Razor::Node]
def insert_node(node_hash)
setup_data
@data.persist_object(Razor::Node.new(node_hash))
end
+ # Queries [Array] of nodes matching filter if supplied in command
def query_node
logger.debug "Query nodes called"
@@ -169,7 +185,7 @@ def query_node
else
slice_error("InvalidFilter")
end
- rescue StandardError=>e
+ rescue StandardError => e
slice_error(e.message)
end
else
@@ -181,11 +197,14 @@ def query_node
end
end
+ # Returns all nodes in DB from slice
def return_all_nodes
setup_data
print_node(@data.fetch_all_objects(:node))
end
+ # Return node matching uuid from Slice
+ # @param [String] uuid
def return_node_by_uuid(uuid)
setup_data
node = @data.fetch_object_by_uuid(:node, uuid)
@@ -193,9 +212,9 @@ def return_node_by_uuid(uuid)
print_node([node])
end
+ # Handles printing of node details to CLI or REST
+ # @param [Hash] node_array
def print_node(node_array)
-
-
unless @web_command
puts "Nodes:"
2  lib/slices/slice_template.rb
View
@@ -11,6 +11,8 @@ module Razor::Slice
# @author Nicholas Weaver
class Template < Razor::Slice::Base
+ # init
+ # @param [Array] args
def initialize(args)
super(args)
# Define your commands and help text
13 lib/systems/system_base.rb
View
@@ -0,0 +1,13 @@
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+# Root namespace for Razor
+# @author Nicholas Weaver
+module Razor::System
+
+ # Root namespace for Systems defined in Razor for node handoff
+ # @author Nicholas Weaver
+ # @abstract
+ class Base
+
+ end
+end
15 lib/systems/system_puppet.rb
View
@@ -0,0 +1,15 @@
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/systems"
+
+require "system_base"
+
+# Root namespace for Razor
+# @author Nicholas Weaver
+module Razor::System
+
+ # Root namespace for Systems defined in Razor for node handoff
+ # @author Nicholas Weaver
+ class PuppetAgent < Razor::System::Base
+
+ end
+end
0  log/README
View
No changes.
13 spec/base/rz_001_persist_controller_spec.rb
View
@@ -2,11 +2,12 @@
# This adds Razor Common lib path to the load path for this child proc
$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/models"
$LOAD_PATH << "#{ENV['RAZOR_HOME']}/spec/base"
require "configuration"
require "persist_controller"
-require "model"
+require "model_base"
require "policy"
require "node"
require "rz_rspec_matchers"
@@ -75,17 +76,17 @@
#create junk models with random updates
(0..rand(10)).each do
|x|
- temp_model = Razor::Model.new({:@name => "rspec_junk#{x}", :@model_type => "base", :@values_hash => {"junk" => "1"}})
+ temp_model = Razor::Model::Base.new({:@name => "rspec_junk#{x}", :@model_type => "base", :@values_hash => {"junk" => "1"}})
temp_model._persist_ctrl = @persist
(0..rand(10)).each do
@persist.object_hash_update(temp_model.to_hash, :model)
end
end
- @model1 = Razor::Model.new({:@name => "rspec_modelname01", :@model_type => "base", :@values_hash => {"a" => "1"}})
+ @model1 = Razor::Model::Base.new({:@name => "rspec_modelname01", :@model_type => "base", :@values_hash => {"a" => "1"}})
@model1._persist_ctrl = @persist
- @model2 = Razor::Model.new({:@name => "rspec_modelname02", :@uuid => @model1.uuid , :@model_type => "base", :@values_hash => {"a" => "454"}})
+ @model2 = Razor::Model::Base.new({:@name => "rspec_modelname02", :@uuid => @model1.uuid , :@model_type => "base", :@values_hash => {"a" => "454"}})
@model2._persist_ctrl = @persist
- @model3 = Razor::Model.new({:@name => "rspec_modelname03", :@uuid => @model1.uuid , :@model_type => "base", :@values_hash => {"a" => "1000"}})
+ @model3 = Razor::Model::Base.new({:@name => "rspec_modelname03", :@uuid => @model1.uuid , :@model_type => "base", :@values_hash => {"a" => "1000"}})
@model3._persist_ctrl = @persist
end
@@ -127,7 +128,7 @@
describe ".Policy" do
before(:all) do
#create junk policies with random updates
- temp_model = Razor::Model.new({:@name => "rspec_modelname01", :@model_type => "base", :@values_hash => {"a" => "1"}})
+ temp_model = Razor::Model::Base.new({:@name => "rspec_modelname01", :@model_type => "base", :@values_hash => {"a" => "1"}})
(0..rand(10)).each do
|x|
temp_policy = Razor::Policy.new({:@name => "rspec_policy_junk#{x}", :@model => temp_model.to_hash, :@policy_type => :unique})
18 spec/base/rz_002_data_spec.rb
View
@@ -275,7 +275,7 @@ def write_config(config)
(1..NODE_COUNT).each do
|x|
- temp_model = Razor::Model.new({:@name => "rspec_model_junk#{x}", :@model_type => :base, :@values_hash => {}})
+ temp_model = Razor::Model::Base.new({:@name => "rspec_model_junk#{x}", :@model_type => :base, :@values_hash => {}})
temp_model = @data.persist_object(temp_model)
@last_uuid = temp_model.uuid
#(0..rand(10)).each do
@@ -296,14 +296,14 @@ def write_config(config)
it "should get a single model by UUID" do
model = @data.fetch_object_by_uuid(:model, @last_uuid)
- model.is_a?(Razor::Model).should == true
+ model.is_a?(Razor::Model::Base).should == true
model = @data.fetch_object_by_uuid(:model, "12345")
model.is_a?(NilClass).should == true
end
it "should be able to add a new Model (does not exist) and update" do
- temp_model = Razor::Model.new({:@name => "rspec_model_junk_new", :@last_state => :idle, :@current_state => :idle, :@next_state => :policy_applied})
+ temp_model = Razor::Model::Base.new({:@name => "rspec_model_junk_new", :@last_state => :idle, :@current_state => :idle, :@next_state => :policy_applied})
temp_model = @data.persist_object(temp_model)
temp_model.update_self
@@ -312,7 +312,7 @@ def write_config(config)
end
it "should be able to delete a specific Model by uuid" do
- temp_model = Razor::Model.new({:@name => "rspec_model_junk_delete_uuid", :@last_state => :idle, :@current_state => :idle, :@next_state => :policy_applied})
+ temp_model = Razor::Model::Base.new({:@name => "rspec_model_junk_delete_uuid", :@last_state => :idle, :@current_state => :idle, :@next_state => :policy_applied})
temp_model = @data.persist_object(temp_model)
temp_model.update_self
@@ -324,7 +324,7 @@ def write_config(config)
end
it "should be able to delete a specific Model by object" do
- temp_model = Razor::Model.new({:@name => "rspec_model_junk_delete_object", :@last_state => :idle, :@current_state => :idle, :@next_state => :policy_applied})
+ temp_model = Razor::Model::Base.new({:@name => "rspec_model_junk_delete_object", :@last_state => :idle, :@current_state => :idle, :@next_state => :policy_applied})
temp_model = @data.persist_object(temp_model)
temp_model.update_self
@@ -337,7 +337,7 @@ def write_config(config)
it "should be able to update Model attributes for existing Model" do
model = @data.fetch_object_by_uuid(:model, @last_uuid)
- model.is_a?(Razor::Model).should == true
+ model.is_a?(Razor::Model::Base).should == true
model.values_hash = {:hostname => "nick_weaver", :ip_address => "1.1.1.1", :iq => 160}
model.update_self
model.values_hash["hostname"].should == "nick_weaver"
@@ -345,7 +345,7 @@ def write_config(config)
model.values_hash["iq"].should == 160
model_confirm = @data.fetch_object_by_uuid(:model, @last_uuid)
- model_confirm.is_a?(Razor::Model).should == true
+ model_confirm.is_a?(Razor::Model::Base).should == true
model_confirm.values_hash["hostname"].should == "nick_weaver"
model_confirm.values_hash["ip_address"].should == "1.1.1.1"
model_confirm.values_hash["iq"].should == 160
@@ -353,13 +353,13 @@ def write_config(config)
it "should be able to update the LastState for existing Model" do
model = @data.fetch_object_by_uuid(:model, @last_uuid)
- model.is_a?(Razor::Model).should == true
+ model.is_a?(Razor::Model::Base).should == true
model.model_type = :nick
model.update_self
model.model_type.should == :nick
model_confirm = @data.fetch_object_by_uuid(:model, @last_uuid)
- model_confirm.is_a?(Razor::Model).should == true
+ model_confirm.is_a?(Razor::Model::Base).should == true
model_confirm.model_type = :nick
end
1  spec/base/rz_011_slice_node_spec.rb
View
@@ -17,6 +17,7 @@
end
after(:all) do
+ @data.delete_all_objects(:node)
end
31 spec/base/rz_012_slice_model_spec.rb
View
@@ -0,0 +1,31 @@
+$LOAD_PATH << "#{ENV['RAZOR_HOME']}/lib/common"
+
+require "rspec"
+require "net/http"
+require "json"
+require "data"
+
+describe "Razor::Slice::Model" do
+
+ describe ".RESTful Interface" do
+
+ it "should get a list of models object types" do
+ uri = URI "http://127.0.0.1:#{@config.api_port}/razor/api/model/type"
+
+ res = Net::HTTP.get(uri)
+ response_hash = JSON.parse(res)
+
+ response_hash['errcode'].should == 0
+ nodes = response_hash['response']
+ nodes.count.should > 0
+ nodes.each do
+ |node|
+ node['@uuid'].should_not == nil
+ end
+ end
+
+ it "should get a list of model objects"
+
+ end
+
+end
3  todo
View
@@ -0,0 +1,3 @@
+-- add tagging for nodes from policy (engine generated?)
+--- user tagging / ui / cli / rest
+---
Please sign in to comment.
Something went wrong with that request. Please try again.