Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

almost done

  • Loading branch information...
commit 75df07fd0b8b0c0cdcedf03c92783301c73e2256 1 parent e29eb4e
@atmos authored
View
26 lib/pars/xen/ast.rb
@@ -1,9 +1,29 @@
module XenConfigFile
module AST
- class Comment
- attr_reader :contents
+ class ConfigFile
+ attr_accessor :disks, :vars, :comments
def initialize(contents)
- @contents = contents
+ @comments = contents.delete(:comments)
+ @disks = Disk.build(contents.delete(:disk))
+ @vars = contents.dup
+ end
+ end
+
+ class Disk
+ attr_accessor :volume, :device, :mode
+ def self.build(contents)
+ contents.map do |disk|
+ volume, device, mode = disk.split(/,/)
+ new(volume, device, mode)
+ end unless contents.nil?
+ end
+ def initialize(volume, device, mode)
+ @volume, @device, @mode = volume, device, mode
+ end
+ end
+
+ module Visitor
+ class Printer
end
end
end
View
2  lib/pars/xen/xen_config_file_you_shouldnt_use_node_classes.rb
@@ -9,7 +9,7 @@ def eval(env={})
pp "ZOMFG #{exception.message}"
end
end
- env
+ XenConfigFile::AST::ConfigFile.new(env)
end
end
View
48 spec/integration/xen_spec.rb
@@ -19,40 +19,62 @@
before(:all) do
@evaluated_result = @result.eval
end
- it "should return a hash of the evaluated string" do
- @evaluated_result.should be_a_kind_of(Hash)
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
end
- describe " variables defined" do
+ describe " variables " do
before(:all) do
@vars = @evaluated_result
end
+
it "should know the cpu_cap" do
- @vars[:cpu_cap].should == 100
+ @vars.vars[:cpu_cap].should == 100
end
it "should know the root disk" do
- @vars[:root].should == '/dev/sda1 ro'
+ @vars.vars[:root].should == '/dev/sda1 ro'
end
it "should know the name for the domain" do
- @vars[:name].should == "ey00-s00348"
+ @vars.vars[:name].should == "ey00-s00348"
end
it "should know the kernel for the domain" do
- @vars[:kernel].should == "/boot/vmlinuz-2.6.18-xenU"
+ @vars.vars[:kernel].should == "/boot/vmlinuz-2.6.18-xenU"
end
it "should know the vcpu count for the domain" do
- @vars[:vcpus].should == 1
+ @vars.vars[:vcpus].should == 1
end
it "should know the maxmem settings for the domain" do
- @vars[:maxmem].should == 4096
+ @vars.vars[:maxmem].should == 4096
end
it "should know the virtual interfaces" do
- @vars[:vif].should == ["bridge=xenbr0"]
+ @vars.vars[:vif].should == ["bridge=xenbr0"]
end
it "should know the memory allocated for the domain" do
- @vars[:memory].should == 712
+ @vars.vars[:memory].should == 712
end
- it "should know about the disks exposed to the domain" do
- @vars[:disk].should == ["phy:/dev/ey00-data4/root-s00348,sda1,w", "phy:/dev/ey00-data4/swap-s00348,sda2,w", "phy:/dev/ey00-data4/gfs-00218,sdb1,w!"]
+
+ describe "disks" do
+ before(:all) do
+ @disks = @vars.disks
+ end
+ it "should know about the disks exposed to the domain" do
+ @disks.should have(3).entries
+ end
+
+ describe "variables" do
+ before(:all) do
+ @disk = @disks.first
+ end
+ it "should know the volume" do
+ @disk.volume.should == 'phy:/dev/ey00-data4/root-s00348'
+ end
+ it "should know the device" do
+ @disk.device.should == 'sda1'
+ end
+ it "should know the mode" do
+ @disk.mode.should == 'w'
+ end
+ end
end
end
end
View
16 spec/xen/array_spec.rb
@@ -22,11 +22,14 @@
before(:all) do
@evaluated_result = @result.eval({})
end
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
+ end
it "should return the first value of the array assignment" do
- @evaluated_result[:cpu_environment].first.should == 348
+ @evaluated_result.vars[:cpu_environment].first.should == 348
end
it "should return the second value of the array assignment" do
- @evaluated_result[:cpu_environment].last.should == 349
+ @evaluated_result.vars[:cpu_environment].last.should == 349
end
end
end
@@ -44,14 +47,17 @@
before(:all) do
@evaluated_result = @result.eval({})
end
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
+ end
it "should return the value of the single quoted string as the first element" do
- @evaluated_result[:cpu_environment].first.should == "ey00-s00348"
+ @evaluated_result.vars[:cpu_environment].first.should == "ey00-s00348"
end
it "should return the value of the number as the second element" do
- @evaluated_result[:cpu_environment][1].should == 42
+ @evaluated_result.vars[:cpu_environment][1].should == 42
end
it "should return the value of the single quoted string as the first element" do
- @evaluated_result[:cpu_environment].last.should == "James Brown"
+ @evaluated_result.vars[:cpu_environment].last.should == "James Brown"
end
end
end
View
39 spec/xen/ast_spec.rb
@@ -0,0 +1,39 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe XenConfigFile::AST::ConfigFile do
+ before(:all) do
+
+ end
+end
+
+describe XenConfigFile::AST::Disk do
+ describe "initialize" do
+ before(:all) do
+ @disk = XenConfigFile::AST::Disk.new('phy:/dev/ey00-data4/root-s00348', 'sda1', 'w')
+ end
+ it "should create successfully" do
+ @disk.should_not be_nil
+ end
+ it "should assign the volume" do
+ @disk.volume.should == 'phy:/dev/ey00-data4/root-s00348'
+ end
+ it "should assign the device" do
+ @disk.device.should == 'sda1'
+ end
+ it "should assign the mode" do
+ @disk.mode.should == 'w'
+ end
+ end
+ describe "build" do
+ before(:all) do
+ @params = ["phy:/dev/ey00-data4/root-s00348,sda1,w", "phy:/dev/ey00-data4/swap-s00348,sda2,w", "phy:/dev/ey00-data4/gfs-00218,sdb1,w!"]
+ @disks = XenConfigFile::AST::Disk.build(@params)
+ end
+ it "should build successfully" do
+ @disks.should_not be_nil
+ end
+ it "should have three elements" do
+ @disks.should have(3).entries
+ end
+ end
+end
View
5 spec/xen/comment_spec.rb
@@ -22,8 +22,11 @@
before(:all) do
@evaluated_result = @result.eval({})
end
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
+ end
it "should return the value of the assignment" do
- @evaluated_result.should == {:comments => [" zomg comment"]}
+ @evaluated_result.comments.should == [" zomg comment"]
end
end
end
View
6 spec/xen/number_assignment_spec.rb
@@ -22,8 +22,12 @@
before(:all) do
@evaluated_result = @result.eval({})
end
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
+ end
+
it "should return the value of the assignment" do
- @evaluated_result[:cpu_number].should == 348
+ @evaluated_result.vars[:cpu_number].should == 348
end
end
end
View
10 spec/xen/string_assignment_spec.rb
@@ -22,8 +22,11 @@
before(:all) do
@evaluated_result = @result.eval({})
end
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
+ end
it "should return the value of the assignment" do
- @evaluated_result[:cpu_environment].should == "ey00-s00348"
+ @evaluated_result.vars[:cpu_environment].should == "ey00-s00348"
end
end
end
@@ -41,8 +44,11 @@
before(:all) do
@evaluated_result = @result.eval({})
end
+ it "should return an AST instance of the config file" do
+ @evaluated_result.should be_a_kind_of(XenConfigFile::AST::ConfigFile)
+ end
it "should return the value of the assignment" do
- @evaluated_result[:cpu_environment].should == "ey00-s00348"
+ @evaluated_result.vars[:cpu_environment].should == "ey00-s00348"
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.