rutema_elements 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ === 0.1.3 / 2008-12-04
2
+ * vsdbcmd added to SQLServer module (uses the new VS Database GDR tool)
3
+ * refactored code that handles sqlcmd and mstest
1
4
  === 0.1.2 / 2008-11-04
2
5
  * shared_path handling in mstest fixed
3
6
  === 0.1.1 / 2008-11-03
@@ -9,7 +9,7 @@ module Rutema
9
9
  module Version
10
10
  MAJOR=0
11
11
  MINOR=1
12
- TINY=2
12
+ TINY=3
13
13
  STRING=[ MAJOR, MINOR, TINY ].join( "." )
14
14
  end
15
15
  module Web
@@ -38,19 +38,8 @@ module Rutema
38
38
  raise Rutema::ParserError,"Missing required script attribute in sqlcmd step" unless step.has_script?
39
39
  cfg=@configuration.tools.sqlcmd[:configuration].dup if @configuration.tools.sqlcmd && @configuration.tools.sqlcmd[:configuration]
40
40
  cfg||=Hash.new
41
- if step.has_script_root?
42
- cfg[:script_root]=step.script_root
43
- end
44
- #see if there is a script root directory
45
- if cfg[:script_root]
46
- raise Rutema::ParserError,"Script root directory '#{cfg[:script_root]}' does not exist. Error in the configuration for sqlcmd steps" unless File.exists?(cfg[:script_root])
47
- script_path=File.expand_path(File.join(cfg[:script_root],step.script))
48
- else
49
- script_path=File.expand_path(step.script)
50
- end
51
- #we want a specific DB script to run
52
- step.script=script_path
53
- raise Rutema::ParserError,"Cannot find script file '#{step.script}' for sqlcmd step" unless File.exists?(step.script)
41
+ root_path=script_root_path(cfg,step)
42
+ cfg[:script]=adjust_with_root_path(step.script,root_path,step)
54
43
  #check for overrides
55
44
  cfg[:host] = step.host if step.has_host?
56
45
  cfg[:server] = step.host if step.has_server?
@@ -59,13 +48,81 @@ module Rutema
59
48
  #add the optional attributes
60
49
  cfg[:database] = step.database if step.has_database?
61
50
  cfg[:level] = step.level if step.has_level?
62
- #add the script
63
- cfg[:script]=step.script
64
51
  #get the command object
65
52
  step.cmd=sqlcmd_command(cfg)
66
53
  return step
67
54
  end
55
+
56
+ #Calls vsdbcmd to deploy a database schema
57
+ #
58
+ #Requires the dbschema attribute pointing to the dbschema file to deploy.
59
+ #
60
+ #Paths can be relative to the specification file
61
+ #===Configuration
62
+ #Requires a configuration.tool entry with :name=>"vsdbcmd"
63
+ #and a :configuration entry pointing to a hash containing the configuration parameters.
64
+ #Configuration parameters are:
65
+ # :path - the path to the vsdbcmd.exe
66
+ # :cs - the connection string to use
67
+ # :manifest - path to the depploymanifest file to use. If not present then a manifest attribute is expected.
68
+ # :overrides - Optional. Should be a string containing parameters that override vsdbcmd parameters in the format expected by vsdbcmd
69
+ # :script_root - The path relative to which pathnames for scripts are calculated. If it's missing, paths are relative to the specification file. Optional
70
+ #all configuration options apart from :path can be overriden in the element
71
+ #===Example Configuration Entry
72
+ # configuration.tool={:name=>"vsdbcmd",:configuration=>{:path=>"c:/tools/db/vsdbcmd.exe",:cs=>"Data Source=(local);;Initial Catalog=YourDB;Integrated Security=True":overrides=>"/p:AlwaysCreateNewDatabase=True"}}
73
+ #===Extras
74
+ #When overriding the :manifest configuration the path to the file can be relative to the specification file or the :script_root path if defined
75
+ #
76
+ #A .deploymanifest is required because of the number of possible parameters that can be defined in it and it's dependent files. Making every parameter available in the configuration will result in nothing but a mess. In every case a database project in Visual Studio will create a manifest file.
77
+ #
78
+ #Use the :overrides key to override parameter values and provide extra command line parameters. The :overrides value must be in valid vsdbcmd format (see examples)
79
+ #
80
+ #Defining paths in :overrides and handling paths defined in the .deploymanifest can be tricky: All paths will be relative to the specification file.
81
+ #===Example Elements
82
+ # <vsdbcmd dbschema="../yourdb.dbschema"/>
83
+ # <vsdbcmd dbschema="../yourdb.dbschema" overrides="/p:AlwaysCreateNewDatabase=False /p:BlockIncrementalDeploymentIfDataLoss=True"/>
84
+ # <vsdbcmd dbschema="../yourdb.dbschema" overrides="/p:AlwaysCreateNewDatabase=False /DeploymentScriptFile:\"somefile.sql\""/>
85
+ def element_vsdbcmd step
86
+ raise Rutema::ParserError,"Missing tool configuration for vsdbcmd (no configuration.tool entry)" unless @configuration.tools.vsdbcmd && @configuration.tools.vsdbcmd[:configuration]
87
+ raise Rutema::ParserError,"Missing required dbschema attribute in vsdbcmd step" unless step.has_dbschema?
88
+ cfg=@configuration.tools.vsdbcmd[:configuration].dup
89
+ path_to_util=File.expand_path(cfg[:path])
90
+ raise Rutema::ParserError,"Cannot find vsdbcmd in '#{path_to_util}'" unless File.exists?(path_to_util)
91
+ cfg[:dsp]||="sql"
92
+ root_path=script_root_path(cfg,step)
93
+ cfg[:dbschema]=adjust_with_root_path(step.dbschema,root_path,step)
94
+ manifest=cfg[:manifest]
95
+ manifest=step.manifest if step.has_manifest?
96
+ raise Rutema::ParserError,"No manifest file defined for #{step.step_type}" unless manifest
97
+ cfg[:manifest]=adjust_with_root_path(manifest,root_path,step)
98
+ if step.has_overrides?
99
+ cfg[:overrides]=step.overrides
100
+ end
101
+ step.cmd=vsdbcmd_command(cfg)
102
+ return step
103
+ end
68
104
  private
105
+ def script_root_path cfg,step
106
+ root_path=cfg[:script_root]
107
+ if step.has_script_root?
108
+ root_path=step.script_root
109
+ else
110
+ root_path||=Dir.pwd
111
+ end
112
+ return root_path
113
+ end
114
+ #checks the path to use as script root
115
+ def adjust_with_root_path filename,root_path,step
116
+ if File.exists?(filename)
117
+ return File.expand_path(filename)
118
+ else
119
+ #see if there is a script root directory
120
+ raise Rutema::ParserError,"Root directory '#{root_path}' for #{step.step_type} does not exist. Check the configuration or the override in the affected scenario" unless File.exists?(root_path)
121
+ script_path=File.expand_path(File.join(root_path,filename))
122
+ raise Rutema::ParserError,"Cannot find file '#{script_path}' specified in #{step.step_type}" unless File.exists?(script_path)
123
+ return script_path
124
+ end
125
+ end
69
126
  #Returns the Patir::ShellCommand with the correct commandline
70
127
  def sqlcmd_command cfg
71
128
  cmdline="sqlcmd -i \"#{File.expand_path(cfg[:script]).gsub("/","\\\\")}\" -b "
@@ -78,6 +135,16 @@ module Rutema
78
135
  #make sure the script executes at the directory where it is.
79
136
  return Patir::ShellCommand.new(:cmd=>cmdline,:working_directory=>File.dirname(File.expand_path(cfg[:script])))
80
137
  end
138
+ #Returns the Patir::ShellCommand with the correct commandline
139
+ def vsdbcmd_command cfg
140
+ path_to_util=File.expand_path(cfg[:path])
141
+ dbschema=File.expand_path(cfg[:dbschema]).gsub("/","\\\\")
142
+ manifest=File.expand_path(cfg[:manifest]).gsub("/","\\\\")
143
+ cmdline="#{path_to_util} /a:Deploy /dsp:#{cfg[:dsp]} /dd /model:\"#{dbschema}\" /manifest:\"#{manifest}\" #{cfg[:overrides]}"
144
+ @logger.debug("Parsed vsdbcmd call as '#{cmdline}'")
145
+ #make sure the script executes at the specification directory.
146
+ return Patir::ShellCommand.new(:cmd=>cmdline)
147
+ end
81
148
  end
82
149
  #Elements to drive MSTest
83
150
  module MSTest
@@ -111,22 +178,18 @@ module Rutema
111
178
  raise Rutema::ParserError,"Missing required attribute 'assembly'" unless step.has_assembly?
112
179
  raise Rutema::ParserError,"Missing tool configuration for mstest (no configuration.tool entry)" unless @configuration.tools.mstest && @configuration.tools.mstest[:configuration]
113
180
  cfg=@configuration.tools.mstest[:configuration].dup
114
- raise Rutema::ParserError,"Cannot find mstest in '#{@configuration.tools.mstest[:path]}'" unless File.exists?(cfg[:path])
181
+ path_to_util=cfg[:path]
182
+ raise Rutema::ParserError,"Cannot find mstest in '#{path_to_util}'" unless File.exists?(path_to_util)
115
183
  if step.has_assembly_root?
116
184
  cfg[:assembly_root]=step.assembly_root
117
- end
118
- #if there is an assembly root defined than calculate the paths relative to that
119
- if cfg[:assembly_root]
120
- raise Rutema::ParserError, "assembly_root entry '#{cfg[:assembly_root]}' defined for mstest does not exist. Error in the configuration for mstest steps" unless File.exists?(cfg[:assembly_root])
121
- assembly_path=File.expand_path(File.join(cfg[:assembly_root],step.assembly))
122
185
  else
123
- assembly_path=File.expand_path(step.assembly)
186
+ cfg[:assembly_root]=Dir.pwd
124
187
  end
125
- #check that the assembly exists first
126
- raise Rutema::ParserError,"Cannot find assembly file '#{assembly_path}' in mstest step" unless File.exists?(assembly_path)
188
+ #icalculate the paths relative to the assembly_root
189
+ assembly_path=adjust_with_root_path(step.assembly,cfg[:assembly_root],step)
127
190
  #check to see if we apply the workaround
128
- if cfg[:shared_path]
129
- shared_path=cfg[:shared_path]
191
+ shared_path=cfg[:shared_path]
192
+ if shared_path
130
193
  raise Rutema::ParserError,"Missing :share key for shared_path configuration" unless shared_path[:share]
131
194
  raise Rutema::ParserError,"Missing :local key for shared_path configuration" unless shared_path[:local]
132
195
  @logger.debug("Assembly path is '#{assembly_path}'")
@@ -137,11 +200,24 @@ module Rutema
137
200
  #make the path windows compatible
138
201
  assembly_path.gsub!('/',"\\\\")
139
202
  #create the command line and the command instance
140
- cmdline="\"#{cfg[:path]}\" /testcontainer:\"#{assembly_path}\""
203
+ cmdline="\"#{path_to_util}\" /testcontainer:\"#{assembly_path}\""
141
204
  @logger.debug("Parsed mstest call as '#{cmdline}'")
142
205
  step.cmd=Patir::ShellCommand.new(:cmd=>cmdline,:working_directory=>File.dirname(assembly_path))
143
206
  return step
144
207
  end
208
+ private
209
+ #checks the path to use as script root
210
+ def adjust_with_root_path filename,root_path,step
211
+ if File.exists?(filename)
212
+ return File.expand_path(filename)
213
+ else
214
+ #see if there is a script root directory
215
+ raise Rutema::ParserError,"Root directory '#{root_path}' for #{step.step_type} does not exist. Check the configuration or the override in the affected scenario" unless File.exists?(root_path)
216
+ script_path=File.expand_path(File.join(root_path,filename))
217
+ raise Rutema::ParserError,"Cannot find file '#{script_path}' specified in #{step.step_type}" unless File.exists?(script_path)
218
+ return script_path
219
+ end
220
+ end
145
221
  end
146
222
  #Elements to drive IIS
147
223
  module IIS
data/test/test_sqlcmd.rb CHANGED
@@ -26,8 +26,8 @@ class TestSqlcmd <Test::Unit::TestCase
26
26
  def mock_simple_step
27
27
  step=mock()
28
28
  step.expects(:has_script?).returns(true)
29
- step.expects(:script).returns(File.join(File.dirname(__FILE__),"data","sample.sql")).times(3)
30
- step.expects(:script=)
29
+ step.expects(:has_script_root?).returns(false)
30
+ step.expects(:script).returns(File.join(File.dirname(__FILE__),"data","sample.sql"))
31
31
  step.expects(:has_database?).returns(false)
32
32
  step.expects(:has_host?).returns(false)
33
33
  step.expects(:has_server?).returns(false)
@@ -0,0 +1,46 @@
1
+ $:.unshift File.join(File.dirname(__FILE__),"..","lib")
2
+ require 'test/unit'
3
+ require 'rutema/elements/win32'
4
+ require 'rubygems'
5
+ require 'mocha'
6
+
7
+ class TestSqlcmd <Test::Unit::TestCase
8
+ include Rutema::Elements::SQLServer
9
+ def test_missing_configuration
10
+ cmd_conf=mock()
11
+ cmd_conf.expects(:vsdbcmd).returns(nil)
12
+ @configuration=mock()
13
+ @configuration.expects(:tools).returns(cmd_conf)
14
+ step=mock()
15
+ assert_raise(Rutema::ParserError) { element_vsdbcmd(step) }
16
+ end
17
+ def test_empty_configuration
18
+ cmd_conf=mock()
19
+ cmd_conf.expects(:vsdbcmd).returns({}).times(2)
20
+ @configuration=mock()
21
+ @configuration.expects(:tools).returns(cmd_conf).times(2)
22
+ step=mock()
23
+ assert_raise(Rutema::ParserError) { element_vsdbcmd(step) }
24
+ end
25
+ def test_normal_flow
26
+ cmd_conf=mock()
27
+ cmd_conf.expects(:vsdbcmd).returns(:configuration=>{:path=>"data/sample.dbschema"}).times(3)
28
+ @configuration=mock()
29
+ @configuration.expects(:tools).returns(cmd_conf).times(3)
30
+ step=mock_simple_step
31
+ assert_nothing_raised() { element_vsdbcmd(step) }
32
+ end
33
+ private
34
+ def mock_simple_step
35
+ step=mock()
36
+ step.expects(:has_script?).returns(true)
37
+ step.expects(:has_script_root?).returns(false)
38
+ step.expects(:has_dbschema?).returns(true)
39
+ step.expects(:dbschema).returns(File.join(File.dirname(__FILE__),"data","sample.dbschema"))
40
+ step.expects(:has_manifest?).returns(true)
41
+ step.expects(:manifest).returns(File.join("data","sample.dbschema"))
42
+ step.expects(:has_overrides?).returns(false)
43
+ step.expects(:cmd=)
44
+ return step
45
+ end
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rutema_elements
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vassilis Rizopoulos
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-04 00:00:00 +01:00
12
+ date: 2008-12-03 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -95,3 +95,4 @@ test_files:
95
95
  - test/test_selenium.rb
96
96
  - test/test_sqlcmd.rb
97
97
  - test/test_standard.rb
98
+ - test/test_vsdbcmd.rb