Skip to content

Commit

Permalink
[bitingsparrow-online_offline_nodes] Fixes merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
katelovescode committed Feb 13, 2018
2 parents dc6fb95 + de3dfae commit 86bee9f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
22 changes: 22 additions & 0 deletions lib/jenkins_api_client/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,28 @@ def delete_all!
list.each { |node| delete(node) unless node == "master" }
end

# This method returns two lists 1) nodes online 2) nodes offline
#
# @param [String] filter a regex to filter node names
# @param [Bool] ignorecase whether to be case sensitive or not
#
def online_offline_lists(filter = nil, ignorecase = true)
@logger.info "Obtaining nodes from jenkins matching filter '#{filter}'"
offline_node_names = []
online_node_names = []
response_json = @client.api_get_request("/computer")
response_json["computer"].each do |computer|
if computer["displayName"] =~ /#{filter}/i
if computer["offline"] == true
offline_node_names << computer["displayName"]
else
online_node_names << computer["displayName"]
end
end
end
return online_node_names, offline_node_names
end

# This method lists all nodes
#
# @param [String] filter a regex to filter node names
Expand Down
23 changes: 18 additions & 5 deletions spec/unit_tests/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@
end
end

describe "#online_offline_lists" do
it "accepts filter and returns one offline list and one online list of nodes matching the filter" do
@client.should_receive(
:api_get_request
).with(
"/computer"
).and_return(
@sample_json_list_response
)
@node.online_offline_lists("slave").class.should == Array
end
end

describe "GeneralAttributes" do
general_attributes = JenkinsApi::Client::Node::GENERAL_ATTRIBUTES
general_attributes.each do |attribute|
Expand Down Expand Up @@ -211,7 +224,7 @@
).and_return(
@offline_slave
)
@node.method("is_offline?").call("slave").should be_truthy
@node.method("is_offline?").call("slave").should be true
end

it "returns false if the node is online" do
Expand All @@ -223,7 +236,7 @@
).and_return(
@online_slave
)
@node.method("is_offline?").call("slave").should be_falsey
@node.method("is_offline?").call("slave").should be false
end

it "returns false if the node is online and have a string value on its attr" do
Expand All @@ -235,7 +248,7 @@
).and_return(
@offline_slave_in_string
)
@node.method("is_offline?").call("slave").should be_truthy
@node.method("is_offline?").call("slave").should be true
end

it "returns false if the node is online and have a string value on its attr" do
Expand All @@ -247,7 +260,7 @@
).and_return(
@online_slave_in_string
)
@node.method("is_offline?").call("slave").should be_falsey
@node.method("is_offline?").call("slave").should be false
end
end

Expand Down Expand Up @@ -314,7 +327,7 @@
@offline_slave,
@online_slave
)
@node.method("toggle_temporarilyOffline").call("slave", "foo bar").should be_falsey
@node.method("toggle_temporarilyOffline").call("slave", "foo bar").should be false
end

it "fails to toggle an offline status of a node" do
Expand Down

0 comments on commit 86bee9f

Please sign in to comment.