[PATCH aeolus-image-rubygem 0/2] Katello API client
by Matt Wagner
Howdy,
This is a client for the Katello API that I've been working on.
Aeolus is going to need to be able to fetch system templates from Katello. Those belongs to environments, which belong to organizations, so you end up having to make some nested calls. This got very painful to try to code up manually, so base.rb implements some quick nesting capabilities.
It's worth noting that ActiveResource has a patch adding more robust associations upstream, but it's not in any released version yet, much less the 3.0.10 version that's in Fedora.
I'm not convinced that this belongs in aeolus-image-rubygem; it has litte to do with images. However, aeolus-image-rubygem was a library pulling various API clients into Conductor, and the reason I'm writing the Katello API was to fetch image templates, so it isn't too big of a leap. Let me know if you think this belongs elsewhere.
-- Matt
11 years, 11 months
Updates for the Aeolus "Get It" page, for RHEL/CentOS version?
by Justin Clift
Realised today that our "Get It" page still has instructions on it to enable
the "Optional" repo in RHEL/RHN/equiv.
Going to remove that, as it doesn't seem to be needed.
Did notice one hiccup though, specific to the RHEL6 version. We seem to be
missing the mustache rubygem:
Error: Package: aeolus-conductor-0.9.0-0.20120504193224gita8a4c66.el6_2.noarch (rhel-aeolus-testing)
Requires: rubygem(mustache) >= 0.99.4
You could try using --skip-broken to work around the problem
You could try running: rpm -Va --nofiles --nodigest
The EPEL repo has the requested mustache rubygem rpm in it, which lets installation
proceed.
I'm wondering if we should add the EPEL repo to our install instructions.
i.e. swap the "Optional" repo dependency for the EPEL repo
Anyone know if that would be a good/bad/otherwise thing to do?
Regards and best wishes,
Justin Clift
--
Aeolus Community Manager
http://www.aeolusproject.org
11 years, 11 months
New wiki page -> our git branches
by Justin Clift
Hey all,
We don't yet have a listing of our git branches, showing what each is for.
So, created one here:
https://www.aeolusproject.org/redmine/projects/aeolus/wiki/GitHub_Branche...
The purpose of some branches is really obvious, so it was easy to write
descriptions for them. Need help with the non-obvious ones though: :)
* admin_ui -
* common_header -
* feature-providers-api -
* fix_iwhd_tests -
* gelato -
* gelato_reorder -
* initscript_cleanup -
* min_unified_ui -
* readme -
* unified_ui -
* master - [what's the best way to describe "master"?]
* 0.3.x - Our 0.3.x release series
* 0.4.x - Our 0.4.x release series
* 0.5.x - Our 0.5.x release series
* 0.6.x - Our 0.6.x release series
* 0.7.x - Our 0.7.x release series
* 0.8.x - Our 0.8.x release series
* 0.9-maint - Our 0.9.x release series
* 0_2_0 - Our 0.2.x release series
If you know what a branch is for, please reply back with its description
so it can be included. (updating the wiki page directly is also ok) :)
Regards and best wishes,
Justin Clift
--
Aeolus Community Manager
http://www.aeolusproject.org
11 years, 11 months
[PATCH conductor] Moving the service parameter type attr off the parameter tag
by Dan Radez
reposting this patch after a couple updates to issues found in the cucumber tests
Service parameters have an attribute named type on them that conductor uses to decided whether or not to preset a text box as a password or not when collecting parameter values from the user at launch time. This type attr is only relevant to parameters that have a child value tag.
This patch moves the type attribute to the value tag and throws warnings to the user when the type attribute is still passed on the parameter tag.
radez
11 years, 11 months
[PATCH conductor 2/2] rake tasks to control the scheduler
by Richard Su
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
11 years, 11 months
[PATCH conductor 1/2] rufus scheduler integration - RM 3273
by Richard Su
https://www.aeolusproject.org/redmine/issues/3273
REST api to turn the rufus scheduler on (:new) and off (:destroy)
and to check its status (:index).
A singleton class JobScheduler encapsulates the rufus scheduler
so that only a single scheduler instance runs at any time.
Only users who have the ROLE view and modify permissions may
control the scheduler.
---
aeolus-conductor.spec.in | 2 +
src/app/controllers/job_scheduler_controller.rb | 45 ++++++++++
src/app/views/job_scheduler/destroy.xml.haml | 2 +
src/app/views/job_scheduler/index.xml.haml | 2 +
src/app/views/job_scheduler/new.xml.haml | 2 +
src/config/routes.rb | 2 +
src/lib/job_scheduler.rb | 93 ++++++++++++++++++++
.../controllers/job_scheduler_controller_spec.rb | 84 ++++++++++++++++++
8 files changed, 232 insertions(+), 0 deletions(-)
create mode 100644 src/app/controllers/job_scheduler_controller.rb
create mode 100644 src/app/views/job_scheduler/destroy.xml.haml
create mode 100644 src/app/views/job_scheduler/index.xml.haml
create mode 100644 src/app/views/job_scheduler/new.xml.haml
create mode 100644 src/lib/job_scheduler.rb
create mode 100644 src/spec/controllers/job_scheduler_controller_spec.rb
diff --git a/aeolus-conductor.spec.in b/aeolus-conductor.spec.in
index a40d517..6cca32f 100644
--- a/aeolus-conductor.spec.in
+++ b/aeolus-conductor.spec.in
@@ -47,6 +47,7 @@ Requires: rubygem(oauth)
Requires: rubygem(rake)
Requires: rubygem(delayed_job) >= 2.1.4
Requires: rubygem(paranoia)
+Requires: rubygem(rufus-scheduler)
Requires: postgresql
Requires: postgresql-server
Requires: system-logos
@@ -189,6 +190,7 @@ haml="app/views/hardware_profiles app/views/realm_mappings \
app/views/deployables app/views/catalogs \
app/views/provider_types app/views/api/images \
app/views/config_servers app/views/provider_realms \
+ app/views/job_scheduler \
app/views/logs \
app/views/api/hooks \
app/views/api \
diff --git a/src/app/controllers/job_scheduler_controller.rb b/src/app/controllers/job_scheduler_controller.rb
new file mode 100644
index 0000000..b1a2701
--- /dev/null
+++ b/src/app/controllers/job_scheduler_controller.rb
@@ -0,0 +1,45 @@
+#
+# 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 'job_scheduler'
+
+class JobSchedulerController < ApplicationController
+ before_filter :require_user_api
+ respond_to :xml
+ layout :false
+
+ # GET /jobscheduler
+ # GET /jobscheduler.xml
+ def index
+ require_privilege(Privilege::PERM_VIEW)
+ respond_with(JobScheduler.activated?)
+ end
+
+ # GET /jobscheduler/new
+ # GET /jobscheduler/new.xml
+ def new
+ require_privilege(Privilege::PERM_SET)
+ respond_with(JobScheduler.start)
+ end
+
+ # DELETE /jobscheduler/1
+ # DELETE /jobscheduler/1.xml
+ def destroy
+ require_privilege(Privilege::PERM_SET)
+ respond_with(JobScheduler.stop)
+ end
+
+end
diff --git a/src/app/views/job_scheduler/destroy.xml.haml b/src/app/views/job_scheduler/destroy.xml.haml
new file mode 100644
index 0000000..18e796d
--- /dev/null
+++ b/src/app/views/job_scheduler/destroy.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+%activated=JobScheduler.activated?
\ No newline at end of file
diff --git a/src/app/views/job_scheduler/index.xml.haml b/src/app/views/job_scheduler/index.xml.haml
new file mode 100644
index 0000000..b5c75d6
--- /dev/null
+++ b/src/app/views/job_scheduler/index.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+%activated=JobScheduler.activated?
diff --git a/src/app/views/job_scheduler/new.xml.haml b/src/app/views/job_scheduler/new.xml.haml
new file mode 100644
index 0000000..18e796d
--- /dev/null
+++ b/src/app/views/job_scheduler/new.xml.haml
@@ -0,0 +1,2 @@
+!!! XML
+%activated=JobScheduler.activated?
\ No newline at end of file
diff --git a/src/config/routes.rb b/src/config/routes.rb
index 265f752..518b013 100644
--- a/src/config/routes.rb
+++ b/src/config/routes.rb
@@ -238,6 +238,8 @@ Conductor::Application.routes.draw do
resources :provider_images
end
+ resources :job_scheduler, :only => [:index, :new, :destroy]
+
get 'api', :controller => 'api/entrypoint', :action => 'index'
namespace :api do
resources :images do
diff --git a/src/lib/job_scheduler.rb b/src/lib/job_scheduler.rb
new file mode 100644
index 0000000..f30ff2d
--- /dev/null
+++ b/src/lib/job_scheduler.rb
@@ -0,0 +1,93 @@
+#
+# 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 'curb'
+
+class JobScheduler
+
+ @@scheduler = nil
+
+ def self.initialize
+ self.start
+ end
+
+ def self.start
+ if @(a)scheduler.nil?
+ @@scheduler = Rufus::Scheduler::PlainScheduler.start_new
+ schedule_tasks(@@scheduler)
+ end
+ end
+
+ def self.stop
+ if @@scheduler
+ @(a)scheduler.stop
+ @@scheduler = nil
+ end
+ end
+
+ def self.activated?
+ if @@scheduler
+ true
+ else
+ false
+ end
+ end
+
+ def self.status_via_http(login, password, hostname)
+ curl = self.curl_request(login, password)
+ curl.url = job_scheduler_url(hostname, '')
+ curl.http_get
+ curl.body_str.to_s
+ end
+
+ def self.start_via_http(login, password, hostname)
+ curl = self.curl_request(login, password)
+ curl.url = job_scheduler_url(hostname, 'new')
+ curl.http_get
+ curl.body_str.to_s
+ end
+
+ def self.stop_via_http(login, password, hostname)
+ curl = self.curl_request(login, password)
+ curl.url = job_scheduler_url(hostname, '1')
+ curl.http_delete
+ curl.body_str.to_s
+ end
+
+ private
+
+ def self.schedule_tasks(scheduler)
+ scheduler.every("1m") do
+ puts "job scheduler is running"
+ end
+ end
+
+ def self.job_scheduler_url(hostname, suffix)
+ # TODO: is there a better way to generate this url?
+ url = "https://#{hostname}/conductor/#{JobSchedulerController.controller_path}/#{suffix}"
+ end
+
+ def self.curl_request(login, password)
+ curl = Curl::Easy.new
+ curl.username = login
+ curl.password = password
+ curl.headers['HTTP_ACCEPT'] = 'application/xml'
+ curl.headers['CONTENT_TYPE'] = 'application/xml'
+ curl.http_auth_types = :basic
+ return curl
+ end
+
+end
diff --git a/src/spec/controllers/job_scheduler_controller_spec.rb b/src/spec/controllers/job_scheduler_controller_spec.rb
new file mode 100644
index 0000000..75726ec
--- /dev/null
+++ b/src/spec/controllers/job_scheduler_controller_spec.rb
@@ -0,0 +1,84 @@
+#
+# 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'
+
+describe JobSchedulerController do
+ render_views
+
+ context "when authenticated as admin" do
+
+ before(:each) do
+ @admin_permission = FactoryGirl.create :admin_permission
+ @admin = @admin_permission.user
+ mock_warden(@admin)
+ end
+
+ describe "scheduler controls" do
+
+ it "scheduler status from 'GET index'" do
+ send_and_accept_xml
+ get :index
+ response.should be_success
+ response.body.strip.should == "<activated>false</activated>"
+ end
+
+ it "turn on scheduler by 'GET new'" do
+ send_and_accept_xml
+ get :new
+ response.should be_success
+ response.body.strip.should == "<activated>true</activated>"
+ end
+
+ it "turn off scheduler by 'POST destroy'" do
+ send_and_accept_xml
+ post :destroy, :id => 1
+ response.should be_success
+ response.body.strip.should == "<activated>false</activated>"
+ end
+
+ it "turn scheduler on and then off" do
+ send_and_accept_xml
+ get :index
+ response.should be_success
+ response.body.strip.should == "<activated>false</activated>"
+ get :new
+ response.should be_success
+ response.body.strip.should == "<activated>true</activated>"
+ post :destroy, :id => 1
+ response.should be_success
+ response.body.strip.should == "<activated>false</activated>"
+ end
+ end
+ end
+
+ context "when not authenticated as admin" do
+
+ before(:each) do
+ @non_admin_permission = FactoryGirl.create :pool_user_permission
+ @user = @non_admin_permission.user
+ mock_warden(@user)
+ end
+
+ it "requests should be denied" do
+ send_and_accept_xml
+ get :index
+ response.should_not be_success
+ end
+
+ end
+
+end
--
1.7.7.6
11 years, 11 months
[PATCH conductor 2/2] rake tasks to control the scheduler
by Richard Su
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
11 years, 11 months