Added documentation & TODOs resource.rb & changed time format in base.erb

This commit is contained in:
Tristan Ancelet 2024-06-29 14:21:36 -05:00
parent a1e223851e
commit 08e132a4d2
2 changed files with 38 additions and 6 deletions

View File

@ -1,15 +1,38 @@
module RubyQA module RubyQA
class Resource class Resource
# This is responsible for data gathering & parsing to provide the test-writers direct access to
# resource information without needing to manually specify them in their code.
attr_reader :name, :data attr_reader :name, :data
# REQUIREMENTS
# This is a Hash that is meant to serve as a way of determining if a resource needs to be
# added to a host. If a key is defined here it will be checked against the information
# configured on the host. If it does not find matching keys it will not be added
#
# If empty it will just be assumed that this resource can be added to the host.
#
# This MUST be defined in each Resourced subclass, as otherwise manager will error when
# adding this resource to host.
REQUIREMENTS = {} REQUIREMENTS = {}
def initialize (host) def initialize (host)
@host = host @host = host
@data = Hash.new @data = Hash.new
@gather_command = "" @gather_command = ""
end end
# TODO: Create validate_host method to replace REQUIREMENTS for a bit more flexiblity on
# determining if a host is valid for this resource to be added to it.
# TODO: Add a discovery method for the resource to find out if the necessary utilities or
# otherwise are on the host
def gather def gather
# Handles gathering the information from the host. Provided the developer has provided a
# @gather_command it will run that command on the remote host & provide the output to the
# user/dev implemented parse command. This can be overwritten by the sublcass to make it all in one in cases
# where something needs to be done differently
if not @gather_command.empty? if not @gather_command.empty?
output = @host.exec(@gather_command) output = @host.exec(@gather_command)
parse(output) parse(output)
@ -19,20 +42,22 @@ module RubyQA
end end
def parse(output) def parse(output)
# Subclass Implemented method that is supposed to handle parsing the gathered data on the remote node.
raise "parse not yet implemented on Resource[#{@name}]" raise "parse not yet implemented on Resource[#{@name}]"
end end
def self.all_resources
## This will allow me to iterate through all subclasses without ## This will allow me to iterate through all subclasses without
## having to manually define them elsewhere ## having to manually define them elsewhere
def self.all_resources
ObjectSpace.each_object(Class).select{|klass| klass < self} ObjectSpace.each_object(Class).select{|klass| klass < self}
end end
end end
## Gathers the facts from the remote machine via the facter utility ## Gathers the facts from the remote machine via the facter utility
require 'json'
class Facts < Resource class Facts < Resource
require 'json'
REQUIREMENTS = {} REQUIREMENTS = {}
def initialize (host) def initialize (host)
super host super host
@ -46,6 +71,8 @@ module RubyQA
end end
class DRDB < Resource class DRDB < Resource
# Handles gathering DRBD related information from the drbdadm utility.
REQUIREMENTS = { REQUIREMENTS = {
:cluster => true :cluster => true
} }
@ -56,6 +83,9 @@ module RubyQA
@gather_command = "sudo drbdadm" @gather_command = "sudo drbdadm"
end end
# TODO: Add a XML parser to requires & have the parse method load the config from the `sudo drbdadm dump-xml`
# command
def parse (output) def parse (output)
@data = output @data = output
end end

View File

@ -1,6 +1,6 @@
RubyQA Test Report RubyQA Test Report
QA Date: <%= Time.now %> QA Date: <%= Time.now.strftime("%Y/%m/%d %l:%M:%S %Z") %>
QA Runner: <%= ENV['USER'] %> QA Runner: <%= ENV['USER'] %>
QA Tests: <%= Manager.tests.count %> QA Tests: <%= Manager.tests.count %>
<% Manager.tests.each do |test| -%> <% Manager.tests.each do |test| -%>
@ -11,8 +11,10 @@ QA Hosts:
- <%= host.name %> (<%= host.data[:ip] %>) - <%= host.name %> (<%= host.data[:ip] %>)
<% end -%> <% end -%>
Tests Begin ###############
----------- # Tests Begin #
###############
<% Manager.tests.each do |test| -%> <% Manager.tests.each do |test| -%>
<%= test.report %> <%= test.report %>
<% end -%> <% end -%>