rake scheduler:status[login,password,hostname]
rake scheduler:start[login,password,hostname]
rake scheduler:stop[login,password,hostname]
Plus tests for JobScheduler.
---
src/lib/tasks/scheduler.rake | 47 +++++
src/spec/lib/job_scheduler_spec.rb | 60 +++++++
src/spec/vcr/cassettes/job_scheduler.yml | 186 ++++++++++++++++++++
.../vcr/cassettes/job_scheduler_bad_password.yml | 34 ++++
4 files changed, 327 insertions(+), 0 deletions(-)
create mode 100644 src/lib/tasks/scheduler.rake
create mode 100644 src/spec/lib/job_scheduler_spec.rb
create mode 100644 src/spec/vcr/cassettes/job_scheduler.yml
create mode 100644 src/spec/vcr/cassettes/job_scheduler_bad_password.yml
diff --git a/src/lib/tasks/scheduler.rake b/src/lib/tasks/scheduler.rake
new file mode 100644
index 0000000..0f50c3d
--- /dev/null
+++ b/src/lib/tasks/scheduler.rake
@@ -0,0 +1,47 @@
+require 'job_scheduler'
+
+namespace :scheduler do
+ desc 'scheduler status'
+ task :status, [:login, :password, :hostname] => :environment do |t, args|
+ unless args.login && args.password && args.hostname
+ puts "Usage: rake 'scheduler:status[login,password,hostname]'"
+ exit(1)
+ end
+
+ print_status(JobScheduler.status_via_http(args.login, args.password, args.hostname))
+
+ end
+
+ desc 'scheduler start'
+ task :start, [:login, :password, :hostname] => :environment do |t, args|
+ unless args.login && args.password && args.hostname
+ puts "Usage: rake 'scheduler:start[login,password,hostname]'"
+ exit(1)
+ end
+
+ print_status(JobScheduler.start_via_http(args.login, args.password, args.hostname))
+
+ end
+
+ desc 'scheduler stop'
+ task :stop, [:login, :password, :hostname] => :environment do |t, args|
+ unless args.login && args.password && args.hostname
+ puts "Usage: rake 'scheduler:stop[login,password,hostname]'"
+ exit(1)
+ end
+
+ print_status(JobScheduler.stop_via_http(args.login, args.password, args.hostname))
+
+ end
+
+ def print_status(response)
+ if response.strip == "<activated>false</activated>"
+ puts "Job scheduler is off"
+ elsif response.strip == "<activated>true</activated>"
+ puts "Job scheduler is on"
+ else
+ puts "Job scheduler status unknown"
+ end
+ end
+
+end
diff --git a/src/spec/lib/job_scheduler_spec.rb b/src/spec/lib/job_scheduler_spec.rb
new file mode 100644
index 0000000..fdcf27e
--- /dev/null
+++ b/src/spec/lib/job_scheduler_spec.rb
@@ -0,0 +1,60 @@
+#
+# Copyright 2012 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#
http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require 'spec_helper'
+require 'job_scheduler'
+require 'vcr'
+
+describe JobScheduler do
+
+ it "status, start, and stop" do
+ JobScheduler.activated?.should == false
+
+ JobScheduler.start
+ JobScheduler.activated?.should == true
+
+ JobScheduler.stop
+ JobScheduler.activated?.should == false
+ end
+
+ VCR.config do |c|
+ c.cassette_library_dir = 'spec/vcr/cassettes'
+ c.stub_with :webmock
+ end
+
+ login = 'admin'
+ hostname = 'localhost'
+
+ it "status, start, and stop via http" do
+ VCR.use_cassette('job_scheduler', :record => :new_episodes,
:match_requests_on => [:method, :uri, :body, :headers]) do
+ password = 'password'
+ JobScheduler.status_via_http(login, password, hostname).strip.should ==
"<activated>false</activated>"
+
+ JobScheduler.start_via_http(login, password, hostname).strip.should ==
"<activated>true</activated>"
+ JobScheduler.status_via_http(login, password, hostname).strip.should ==
"<activated>true</activated>"
+
+ JobScheduler.stop_via_http(login, password, hostname).strip.should ==
"<activated>false</activated>"
+ JobScheduler.status_via_http(login, password, hostname).strip.should ==
"<activated>false</activated>"
+ end
+ end
+
+ it "start via http with incorrect password" do
+ VCR.use_cassette('job_scheduler_bad_password', :record => :new_episodes,
:match_requests_on => [:method, :uri, :body, :headers]) do
+ password = 'badpassword'
+ JobScheduler.start_via_http(login, password, hostname).strip.should ==
""
+ end
+ end
+end
diff --git a/src/spec/vcr/cassettes/job_scheduler.yml
b/src/spec/vcr/cassettes/job_scheduler.yml
new file mode 100644
index 0000000..77bc80f
--- /dev/null
+++ b/src/spec/vcr/cassettes/job_scheduler.yml
@@ -0,0 +1,186 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost:443/conductor/job_scheduler/
+ body:
+ headers:
+ content-type:
+ - application/xml
+ http-accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Thu, 31 May 2012 01:56:22 GMT
+ x-runtime:
+ - "0.204081"
+ set-cookie:
+ - _session_id=25e894ffb9fe390bc416b8c0f4d602c7; path=/; HttpOnly
+ etag:
+ - "\"8d3b9c1559d5af7ef58d1bd05ecf8c56\""
+ transfer-encoding:
+ - chunked
+ cache-control:
+ - max-age=0, private, must-revalidate
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ content-type:
+ - application/xml; charset=utf-8
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ body: |
+ <activated>false</activated>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost:443/conductor/job_scheduler/new
+ body:
+ headers:
+ content-type:
+ - application/xml
+ http-accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Thu, 31 May 2012 01:56:22 GMT
+ x-runtime:
+ - "0.096482"
+ set-cookie:
+ - _session_id=c9e508e01ff15fcb3de53eae927c19b4; path=/; HttpOnly
+ etag:
+ - "\"fc733921358334b1dbc3735a8cc3723a\""
+ transfer-encoding:
+ - chunked
+ cache-control:
+ - max-age=0, private, must-revalidate
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ content-type:
+ - application/xml; charset=utf-8
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ body: |
+ <activated>true</activated>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost:443/conductor/job_scheduler/
+ body:
+ headers:
+ content-type:
+ - application/xml
+ http-accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Thu, 31 May 2012 01:56:23 GMT
+ x-runtime:
+ - "0.082169"
+ set-cookie:
+ - _session_id=9ce6f06febbf18a1134c2ab8eedc1ed2; path=/; HttpOnly
+ etag:
+ - "\"fc733921358334b1dbc3735a8cc3723a\""
+ transfer-encoding:
+ - chunked
+ cache-control:
+ - max-age=0, private, must-revalidate
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ content-type:
+ - application/xml; charset=utf-8
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ body: |
+ <activated>true</activated>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :delete
+ uri:
https://admin:password@localhost:443/conductor/job_scheduler/1
+ body:
+ headers:
+ content-type:
+ - application/xml
+ http-accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Thu, 31 May 2012 01:56:23 GMT
+ x-runtime:
+ - "0.083348"
+ set-cookie:
+ - _session_id=66e5bf3bcf6916dd906f09dda272542c; path=/; HttpOnly
+ etag:
+ - "\"8d3b9c1559d5af7ef58d1bd05ecf8c56\""
+ transfer-encoding:
+ - chunked
+ cache-control:
+ - max-age=0, private, must-revalidate
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ content-type:
+ - application/xml; charset=utf-8
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ body: |
+ <activated>false</activated>
+
+ http_version: "1.1"
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:password@localhost:443/conductor/job_scheduler/
+ body:
+ headers:
+ content-type:
+ - application/xml
+ http-accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 200
+ message: OK
+ headers:
+ date:
+ - Thu, 31 May 2012 01:56:23 GMT
+ x-runtime:
+ - "0.074150"
+ set-cookie:
+ - _session_id=d03c029ec0f4ac75faba282f787e897c; path=/; HttpOnly
+ etag:
+ - "\"8d3b9c1559d5af7ef58d1bd05ecf8c56\""
+ transfer-encoding:
+ - chunked
+ cache-control:
+ - max-age=0, private, must-revalidate
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ content-type:
+ - application/xml; charset=utf-8
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ body: |
+ <activated>false</activated>
+
+ http_version: "1.1"
diff --git a/src/spec/vcr/cassettes/job_scheduler_bad_password.yml
b/src/spec/vcr/cassettes/job_scheduler_bad_password.yml
new file mode 100644
index 0000000..743374e
--- /dev/null
+++ b/src/spec/vcr/cassettes/job_scheduler_bad_password.yml
@@ -0,0 +1,34 @@
+---
+- !ruby/struct:VCR::HTTPInteraction
+ request: !ruby/struct:VCR::Request
+ method: :get
+ uri:
https://admin:badpassword@localhost:443/conductor/job_scheduler/new
+ body:
+ headers:
+ content-type:
+ - application/xml
+ http-accept:
+ - application/xml
+ response: !ruby/struct:VCR::Response
+ status: !ruby/struct:VCR::ResponseStatus
+ code: 401
+ message: Unauthorized
+ headers:
+ content-type:
+ - application/xml; charset=utf-8
+ x-runtime:
+ - "0.121451"
+ cache-control:
+ - no-cache
+ server:
+ - thin 1.2.11 codename Bat-Shit Crazy
+ x-ua-compatible:
+ - IE=Edge,chrome=1
+ set-cookie:
+ - _session_id=24ad1b8522e903415be0b485bb8dff4b; path=/; HttpOnly
+ date:
+ - Thu, 31 May 2012 01:57:29 GMT
+ transfer-encoding:
+ - chunked
+ body: " "
+ http_version: "1.1"
--
1.7.7.6