Class: Beaker::Subcommand
- Inherits:
-
Thor
- Object
- Thor
- Beaker::Subcommand
- Defined in:
- lib/beaker/subcommand.rb
Constant Summary collapse
- SubcommandUtil =
Beaker::Subcommands::SubcommandUtil
Instance Attribute Summary collapse
-
#cli ⇒ Object
readonly
Returns the value of attribute cli.
Instance Method Summary collapse
- #destroy ⇒ Object
- #exec(resource = nil) ⇒ Object
- #init ⇒ Object
-
#initialize(*args) ⇒ Subcommand
constructor
A new instance of Subcommand.
- #provision ⇒ Object
Constructor Details
#initialize(*args) ⇒ Subcommand
Returns a new instance of Subcommand.
11 12 13 14 15 16 17 |
# File 'lib/beaker/subcommand.rb', line 11 def initialize(*args) super FileUtils.mkdir_p(SubcommandUtil::CONFIG_DIR) FileUtils.touch(SubcommandUtil::SUBCOMMAND_OPTIONS) unless SubcommandUtil::SUBCOMMAND_OPTIONS.exist? FileUtils.touch(SubcommandUtil::SUBCOMMAND_STATE) unless SubcommandUtil::SUBCOMMAND_STATE.exist? @cli = Beaker::CLI.new end |
Instance Attribute Details
#cli ⇒ Object (readonly)
Returns the value of attribute cli.
9 10 11 |
# File 'lib/beaker/subcommand.rb', line 9 def cli @cli end |
Instance Method Details
#destroy ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/beaker/subcommand.rb', line 211 def destroy if [:help] invoke :help, [], ["destroy"] return end state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE) SubcommandUtil.error_with('Please provision an environment') unless state.transaction { state['provisioned'] } @cli. @cli.[:provision] = false @cli.initialize_network_manager @cli.network_manager.cleanup state.transaction do state.delete('provisioned') end end |
#exec(resource = nil) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/beaker/subcommand.rb', line 152 def exec(resource = nil) if [:help] invoke :help, [], ["exec"] return end @cli. @cli.initialize_network_manager if !resource @cli.execute! return end beaker_suites = %i[pre_suite tests post_suite pre_cleanup] resources = resource.split(',') paths = resources.map { |r| Pathname(r) } if paths.all?(&:exist?) # If we determine the resource is a valid file resource, then we empty # all the suites and run that file resource in the tests suite. In the # future, when we have the ability to have custom suites, we should change # this to run in a custom suite. You know, in the future. beaker_suites.each do |suite| @cli.[suite] = [] end @cli.[:tests] = paths.map do |path| if path.directory? Dir.glob("#{path}/**/*.rb") else path.to_s end end.flatten elsif resources.all? { |r| /^(pre-suite|tests|post-suite|pre-cleanup)$/.match?(r) } # The regex match here is loose so that users can supply multiple suites, # such as `beaker exec pre-suite,tests`. beaker_suites.each do |suite| @cli.[suite] = [] unless resource.tr('-', '_').match(suite.to_s) end else raise ArgumentError, "Unable to parse #{resource} with beaker exec" end @cli.execute! return unless ['preserve-state'] @cli.logger.notify 'updating HOSTS key in subcommand_options' hosts = SubcommandUtil.(@cli.) = YAML::Store.new(SubcommandUtil::SUBCOMMAND_OPTIONS) .transaction do ['HOSTS'] = hosts end end |
#init ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/beaker/subcommand.rb', line 78 def init if [:help] invoke :help, [], ["init"] return end @cli. = SubcommandUtil.(@cli.) @cli.logger.notify 'Writing configured options to disk' File.write(SubcommandUtil::SUBCOMMAND_OPTIONS, .to_yaml) @cli.logger.notify "Options written to #{SubcommandUtil::SUBCOMMAND_OPTIONS}" state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE) state.transaction do state['provisioned'] = false end end |
#provision ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/beaker/subcommand.rb', line 105 def provision if [:help] invoke :help, [], ["provision"] return end state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE) SubcommandUtil.error_with('Provisioned SUTs detected. Please destroy and reprovision.') if state.transaction { state['provisioned'] } @cli. @cli.provision # Sanitize the hosts cleaned_hosts = SubcommandUtil.(@cli.) # Update each host provisioned with a flag indicating that it no longer needs # provisioning cleaned_hosts.each do |_host, host_hash| host_hash['provision'] = false end # should we only update the options here with the new host? Or update the settings # with whatever new flags may have been provided with provision? = YAML::Store.new(SubcommandUtil::SUBCOMMAND_OPTIONS) .transaction do @cli.logger.notify 'updating HOSTS key in subcommand_options' ['HOSTS'] = cleaned_hosts ['hosts_preserved_yaml_file'] = @cli.[:hosts_preserved_yaml_file] end @cli.preserve_hosts_file state.transaction do state['provisioned'] = true end end |