From 4aeeaad9660cead4224c63b2a87fcbcbc6c7367c Mon Sep 17 00:00:00 2001 From: Anirvan BASU Date: Wed, 7 Sep 2016 14:47:00 +0200 Subject: [PATCH] Updates to code to remove /deployments from version 4.0 of g5k-api --- README.md | 35 +- app/controllers/deployments_controller.rb | 271 ---------- app/controllers/sites_controller.rb | 2 +- app/models/grid5000/deployment.rb | 310 ------------ config/routes.rb | 3 +- .../20160906203813_remove_deployments.rb | 54 ++ db/schema.rb | 33 +- .../deployments_controller_spec.rb | 270 ---------- spec/controllers/sites_controller_spec.rb | 6 +- spec/factories.rb | 27 - spec/models/grid5000/deployment_spec.rb | 461 ------------------ spec/spec_helper.rb | 2 +- 12 files changed, 80 insertions(+), 1394 deletions(-) delete mode 100644 app/controllers/deployments_controller.rb delete mode 100644 app/models/grid5000/deployment.rb create mode 100644 db/migrate/20160906203813_remove_deployments.rb delete mode 100644 spec/controllers/deployments_controller_spec.rb delete mode 100644 spec/factories.rb delete mode 100644 spec/models/grid5000/deployment_spec.rb diff --git a/README.md b/README.md index e50ea532..d7d5e15c 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ In particular, runtime dependencies of the app include `ruby2.1.5` and `git-core $ DEVELOPER=dmargery OAR_DB_SITE=rennes vagrant up --provision $ vagrant ssh vagrant> cd /vagrant + vagrant> bundle install The vagrant provisionning script will attempt to configure the VM's root and vagrant accounts to be accessible by ssh. By default, it will copy your authorized_keys, but you @@ -52,7 +53,7 @@ In particular, runtime dependencies of the app include `ruby2.1.5` and `git-core are already packaged in the Vagrant box. As this is not trivial a requires some compromises, the development of this application relies strongly on unit tests. - A usefull set of ssh tunnels is created with + A useful set of ssh tunnels is created with vagrant> rake tunnels:setup @@ -89,15 +90,14 @@ In particular, runtime dependencies of the app include `ruby2.1.5` and `git-core * Give access to reference data to expose. The scripts expect you have a checkout version of the reference-repository in a sibling directory to this code that is mounted on /home/vagrant/reference-repository in the - vagrant box. + vagrant box. (g5k-api) $ cd .. - ( ) $ git clone ssh://g5kadmin@git.grid5000.fr/srv/git/repos/reference-repository.git \ - reference-repository + (..) $ git clone ssh://g5kadmin@git.grid5000.fr/srv/git/repos/reference-repository.git reference-repository You might not have admin access to Grid'5000's reference repository. in this case, you - could duplicate the fake repository used for tests, in the spec/fixtures/reference-repository - directory. + could duplicate the fake repository used for tests, in the + spec/fixtures/reference-repository directory. (g5k-api) $ cp -r spec/fixtures/reference-repository .. (g5k-api) $ mv ../reference-repository/git.rename ../reference-repository/.git @@ -117,21 +117,20 @@ In particular, runtime dependencies of the app include `ruby2.1.5` and `git-core information). You should setup an SSH tunnel between your machine and one of the oardb servers of Grid'5000, so that you can access the current jobs: - $ #first create a reverse port from the vagrant machine to - $ #your own machine + $ #first create a reverse port from the vagrant machine to your own machine $ vagrant ssh -- -R 15433:localhost:15433 - $ In an other shell, create a tunnel from your machine to Grid'5000 + $ #In an other shell, create a tunnel from your machine to Grid'5000 $ ssh -NL 15433:oardb.rennes.grid5000.fr:5432 access.grid5000.fr - # finally, edit the development section of app/config/defaults.yml to - oar: - <<: *oar - host: 127.0.0.1 - port: 15433 - username: oarreader - password: read - database: oar2 + $ #finally, edit the development section of config/defaults.yml to + oar: + <<: *oar + host: 127.0.0.1 + port: 15433 + username: oarreader + password: read + database: oar2 ### Wrapping it up to run the server @@ -142,7 +141,7 @@ In particular, runtime dependencies of the app include `ruby2.1.5` and `git-core * If you require traces on the shell, use - $ ./bin/g5k-api server -V start -e development + $ ./bin/g5k-api server -V start -e development * If you need to be authenticated for some development, use: diff --git a/app/controllers/deployments_controller.rb b/app/controllers/deployments_controller.rb deleted file mode 100644 index 9a65b57e..00000000 --- a/app/controllers/deployments_controller.rb +++ /dev/null @@ -1,271 +0,0 @@ -# Copyright (c) 2009-2011 Cyril Rohr, INRIA Rennes - Bretagne Atlantique -# -# 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. - -class DeploymentsController < ApplicationController - LIMIT = 50 - LIMIT_MAX = 500 - - # List deployments - def index - allow :get, :post; vary_on :accept - - offset = [(params[:offset] || 0).to_i, 0].max - limit = [(params[:limit] || LIMIT).to_i, LIMIT_MAX].min - order = "DESC" - order = "ASC" if params[:reverse] && params[:reverse].to_s == "true" - - items = Grid5000::Deployment.order("created_at #{order}") - items = items.where(:user_uid => params[:user]) if params[:user] - items = items.where(:status => params[:status]) if params[:status] - - total = items.count - - items = items.offset(offset).limit(limit) - - items.each{|item| - item.links = links_for_item(item) - } - - result = { - "total" => total, - "offset" => offset, - "items" => items, - "links" => links_for_collection - } - - respond_to do |format| - format.g5kcollectionjson { render :json => result } - format.json { render :json => result } - end - end - - # Display the details of a deployment - def show - allow :get, :delete, :put; vary_on :accept - expires_in 60.seconds - - item = find_item(params[:id]) - item.links = links_for_item(item) - - respond_to do |format| - format.g5kitemjson { render :json => item } - format.json { render :json => item } - end - end - - # Delete a deployment. Client must be authenticated and must own the deployment. - # - # Delegates to the Kadeploy API. - def destroy - ensure_authenticated! - dpl = find_item(params[:id]) - authorize!(dpl.user_uid) - dpl.base_uri = api_path() - dpl.user = @credentials[:cn] - - begin - dpl.cancel! if dpl.can_cancel? - rescue Exception => e - raise ServerError, "Cannot cancel deployment: #{e.message}" - end - - location_uri = uri_to( - resource_path(params[:id]), - :in, :absolute - ) - - render :text => "", - :head => :ok, - :location => location_uri, - :status => 202 - end - - # Create a new Deployment. Client must be authenticated. - # - # Delegates the request to the Kadeploy API. - def create - ensure_authenticated! - - dpl = Grid5000::Deployment.new(payload) - dpl.user_uid = @credentials[:cn] - dpl.site_uid = Rails.whoami - dpl.user = @credentials[:cn] - dpl.base_uri = api_path() - - Rails.logger.info "Received deployment = #{dpl.inspect}" - raise BadRequest, "The deployment you are trying to submit is not valid: #{dpl.errors.to_a.join("; ")}" unless dpl.valid? - - # WARN: this is a blocking call as it creates a file on disk. - # we may want to defer it or implement it natively with EventMachine - files_base_uri = uri_to(parent_path+"/files",:in, :absolute) - dpl.transform_blobs_into_files!(Rails.tmp, files_base_uri) - - begin - dpl.launch || raise(ServerError, - "#{dpl.errors.full_messages.join("; ")}") - rescue Exception => e - raise ServerError, "Cannot launch deployment: #{e.message}" - end - - location_uri = uri_to( - resource_path(dpl.uid), - :in, :absolute - ) - - dpl.links = links_for_item(dpl) - - render_opts = { - #:methods => [:resources_by_type, :assigned_nodes], - :location => location_uri, - :status => 201 - } - respond_to do |format| - format.g5kitemjson { render render_opts.merge(:json => dpl) } - format.json { render render_opts.merge(:json => dpl) } - end - end - - # If the deployment is in the "canceled", "error", or "terminated" state, - # return the deployment from DB. Otherwise, fetches the deployment status - # from the kadeploy-server, and update the result attribute if the - # deployment has finished. - def update - dpl = find_item(params[:id]) - dpl.base_uri = api_path() - dpl.user = 'root' # Ugly hack since no auth is needed for this method on theg5k API - - begin - dpl.touch! if dpl.active? - rescue Exception => e - raise ServerError, e.message - end - - location_uri = uri_to( - resource_path(dpl.uid), - :in, :absolute - ) - - render :text => "", - :head => :ok, - :location => location_uri, - :status => 204 - end - - protected - - def collection_path - site_deployments_path(params[:site_id]) - end - - def parent_path - site_path(params[:site_id]) - end - - def resource_path(id) - File.join(collection_path, id.to_s) - end - - def links_for_item(item) - [ - { - "rel" => "self", - "href" => uri_to(resource_path(item['uid'])), - "type" => media_type(:g5kitemjson) - }, - { - "rel" => "parent", - "href" => uri_to(parent_path), - "type" => media_type(:g5kitemjson) - } - ] - end - - def links_for_collection - [ - { - "rel" => "self", - "href" => uri_to(collection_path), - "type" => media_type(:g5kcollectionjson) - }, - { - "rel" => "parent", - "href" => uri_to(parent_path), - "type" => media_type(:g5kitemjson) - } - ] - end - - def find_item(id) - item = Grid5000::Deployment.find_by_uid(id) - raise NotFound, "Couldn't find #{Grid5000::Deployment} with ID=#{id}" if item.nil? - item - end - - def api_path(path='') - uri_to( - File.join( - site_path(params[:site_id]), - "/internal/kadeployapi/deployment", - path - ), - :out - ) - end - - # Not useful atm -=begin - def wrap_item(item,params,orig=false) - ret = item - item = item.dup - ret.clear - ret['orig'] = item if orig - - ret['uid'] = item['wid'] || item['id'] - ret['site_uid'] = params[:site_id] - ret['user_uid'] = item['user'] - #item['created_at'] = item['start_time'] - if item['nodes'].is_a?(Hash) - nodes = item['nodes'] - ret['nodes'] = [] - ret['result'] = {} - nodes['ok'].each do |node| - ret['nodes'] << node - ret['result'][node] = { 'state' => 'OK' } - end - nodes['processing'].each do |node| - ret['nodes'] << node - ret['result'][node] = { 'state' => 'OK' } - end - nodes['ko'].each do |node| - ret['nodes'] << node - ret['result'][node] = { 'state' => 'KO' } - end - else - ret['nodes'] = item['nodes'] - end - - if item['error'] - ret['status'] = :error - elsif item['done'] - ret['status'] = :terminated - else - ret['status'] = :processing - end - - ret['links'] = links_for_item(ret) - - ret - end -=end -end diff --git a/app/controllers/sites_controller.rb b/app/controllers/sites_controller.rb index 844dda0e..7eac5715 100644 --- a/app/controllers/sites_controller.rb +++ b/app/controllers/sites_controller.rb @@ -61,7 +61,7 @@ class SitesController < ResourcesController def links_for_item(item) links = super(item) - %w{jobs deployments vlans metrics}.each do |rel| + %w{jobs vlans metrics}.each do |rel| # abasu bug #7179 removed deployments links.push({ "rel" => rel, "type" => media_type(:g5kcollectionjson), diff --git a/app/models/grid5000/deployment.rb b/app/models/grid5000/deployment.rb deleted file mode 100644 index 9da413d2..00000000 --- a/app/models/grid5000/deployment.rb +++ /dev/null @@ -1,310 +0,0 @@ -# Copyright (c) 2009-2011 Cyril Rohr, INRIA Rennes - Bretagne Atlantique -# -# 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 'json' -require 'fileutils' - -module Grid5000 - # The Deployment class represents a deployment that is launched using the Kadeploy3 tool. - class Deployment < ActiveRecord::Base - attr_accessor :links - # Ugly hack to make the communication between the controller and the model possible - attr_accessor :base_uri, :user - - SERIALIZED_ATTRIBUTES = [:nodes, :notifications, :result] - - validates_presence_of :user_uid, :site_uid, :environment, :nodes - validates_uniqueness_of :uid - - before_save :json_serialize - after_save :json_deserialize - after_find :json_deserialize - - before_create do - self.created_at ||= Time.now.to_i - end - - before_save do - self.updated_at = Time.now.to_i - errors.add(:uid, "must be set") if uid.nil? - errors.empty? - end - - def to_param - uid - end - - # Experiment states - state_machine :status, :initial => :waiting do - after_transition :processing => :canceled, :do => :deliver_notification - after_transition :processing => :error, :do => :deliver_notification - after_transition :processing => :terminated, :do => :deliver_notification - - before_transition :processing => :canceled, :do => :cancel_workflow! - before_transition :waiting => :processing, :do => :launch_workflow! - - event :launch do - transition :waiting => :processing - end - event :process do - transition :processing => :processing - end - event :cancel do - transition :processing => :canceled - end - event :terminate do - transition :processing => :terminated - end - event :fail do - transition :processing => :error - end - end - - def active? - status?(:processing) - end - - validate do - errors.add :nodes, "must be a non-empty list of node FQDN" unless (nodes.kind_of?(Array) && nodes.length > 0) - errors.add :notifications, "must be a list of notification URIs" unless (notifications.nil? || notifications.kind_of?(Array)) - end - - def processing? - status.nil? || status == "processing" - end - - def deliver_notification - unless notifications.blank? - begin - Grid5000::Notification.new( - notification_message, - :to => notifications - ).deliver! - rescue Exception => e - Rails.logger.warn "Unable to deliver notification to #{notifications.inspect} for deployment ##{uid}: #{e.class.name} - #{e.message} - #{e.backtrace.join("; ")}" - end - end - true - end - - # When some attributes such as :key are passed as text strings, - # we must transform such strings into files - # and replace the attribute value by the HTTP URI - # where the original content can be accessed. - # This is required since Kadeploy3 does not allow to directly - # pass the content string for such attributes. - def transform_blobs_into_files!(storage_path, base_uri) - tmpfiles_dir = File.expand_path(storage_path) - [:key].each do |attribute| - value = send(attribute) - next if value.nil? - scheme = URI.parse(value).scheme rescue nil - if scheme.nil? - filename = [ - user_uid, attribute, Digest::SHA1.hexdigest(value) - ].join("-") - # ensure the directory exists... - FileUtils.mkdir_p(tmpfiles_dir) - # and write the file to that location - File.open("#{tmpfiles_dir}/#{filename}", "w") { |f| f.write(value) } - uri = "#{base_uri}/#{filename}" - send("#{attribute}=".to_sym, uri) - end - end - end # def transform_blobs_into_files! - - def cancel_workflow! - raise "cancel_workflow!" if !user or !base_uri # Ugly hack - - http = EM::HttpRequest.new(File.join(base_uri,uid)).delete( - :timeout => 15, - :head => { - #'Accept' => '*/*', - 'X-Remote-Ident' => user, - } - ) - http.errback{ error("Unable to contact #{File.join(base_uri,uid)}"); raise self.output+"\n" } - - # Not checked since it avoid touch! to cancel the deployment - #unless %w{200 201 202 204}.include?(http.response_header.status.to_s) - # fail - # raise "The deployment no longer exists on the Kadeploy server" - #end - - true - end - - def launch_workflow! - raise "launch_workflow!" if !user or !base_uri # Ugly hack - - params = to_hash - # The environment was specified as an URL to a description file - if params['environment'].empty? - scheme = URI.parse(environment).scheme - case scheme - when 'http','https' - begin - http = EM::HttpRequest.new(environment).get(:timeout=>10) - params['environment'] = YAML.load(http.response) - params['environment']['kind'] = 'anonymous' - rescue Exception => e - raise "Error fetching the image description file: #{e.class.name}, #{e.message}" - end - else - raise "Error fetching the image description file: #{scheme} protocol not supported yet" - end - else - params['environment']['kind'] = 'database' - end - Rails.logger.info "Submitting: #{params.inspect}" - - http = EM::HttpRequest.new(base_uri).post( - :timeout => 20, - :body => params.to_json, - :head => { - 'Content-Type' => Mime::Type.lookup_by_extension(:json).to_s, - 'Accept' => Mime::Type.lookup_by_extension(:json).to_s, - 'X-Remote-Ident' => user, - } - ) - http.errback{ error("Unable to contact #{base_uri}"); raise self.output+"\n" } - - if %w{200 201 202 204}.include?(http.response_header.status.to_s) - update_attribute(:uid, JSON.parse(http.response)['wid']) - else - error(get_kaerror(http.response,http.response_header)) - # Cannot continue since :uid is not set - raise self.output+"\n" - end - - true - end - - def touch! - http = EM::HttpRequest.new(File.join(base_uri,uid)).get( - :timeout => 10, - :head => { - 'Accept' => Mime::Type.lookup_by_extension(:json).to_s, - 'X-Remote-Ident' => user, - } - ) - http.errback{ error("Unable to contact #{File.join(base_uri,uid)}"); raise self.output+"\n" } - - if %w{200 201 202 204}.include?(http.response_header.status.to_s) - item = JSON.parse(http.response) - - unless item['error'] - http = EM::HttpRequest.new(File.join(base_uri,uid,'state')).get( - :timeout => 15, - :head => { - 'Accept' => Mime::Type.lookup_by_extension(:json).to_s, - 'X-Remote-Ident' => user, - } - ) - http.errback{ error("Unable to contact #{File.join(base_uri,uid,'state')}"); raise self.output+"\n" } - res = JSON.parse(http.response) - # Ugly compatibility hack - res.each_pair do |node,stat| - res[node]['state'] = res[node]['state'].upcase - end - self.result = res - else - http = EM::HttpRequest.new(File.join(base_uri,uid,'error')).get( - :timeout => 15, - :head => { - #'Accept' => '*/*', - 'X-Remote-Ident' => user, - } - ) - error(get_kaerror(http.response,http.response_header)) - http.errback{ error("Unable to contact #{File.join(base_uri,uid,'error')}"); raise self.output+"\n" } - return - end - - if item['done'] - terminate - else - process - end - else - error("The deployment no longer exists on the Kadeploy server") - end - end - - def get_kaerror(resp,hdr) - if hdr['X_APPLICATION_ERROR_CODE'] and hdr['X_APPLICATION_ERROR_INFO'] - "Kadeploy error ##{hdr['X_APPLICATION_ERROR_CODE']}: #{Base64.strict_decode64(hdr['X_APPLICATION_ERROR_INFO'])}" - else - "HTTP error ##{hdr.status}: #{resp}" - end - end - - def error(msg) - self.output = msg - - # Delete the workflow from the kadeploy server - cancel_workflow! if uid - - fail - end - - def as_json(*args) - attributes.merge(:links => links).reject{|k,v| v.nil? || k=="id"} - end - - def notification_message - ::JSON.pretty_generate(as_json) - end - - def json_serialize - SERIALIZED_ATTRIBUTES.each do |att| - value = send(att) - if value == [] or ! value.blank? - send("#{att}=".to_sym, value.to_json) - end - end - end - - def json_deserialize - SERIALIZED_ATTRIBUTES.each do |att| - value = send(att) rescue nil - send("#{att}=".to_sym, (JSON.parse(value) rescue value)) unless value.blank? - end - end - - def to_hash - params = { - 'environment' => {} - } - if URI.parse(environment).scheme.nil? - env_name, env_user = environment.split("@") - params['environment'] = { 'name' => env_name } - params['environment']['user'] = env_user if env_user - params['environment']['version'] = version.to_s if version - end - params['ssh_authorized_keys'] = key if key - params['nodes'] = nodes.dup - params['deploy_part'] = partition_number.to_s if partition_number - params['block_device'] = block_device.to_s if block_device - params['reformat_tmp_partition'] = reformat_tmp.to_s if reformat_tmp - params['vlan'] = vlan.to_s if vlan - params['disable_disk_partitioning'] = true if disable_disk_partitioning - params['disable_bootloader_install'] = true if disable_bootloader_install - params['force'] = true if ignore_nodes_deploying - params['hook'] = true - - params - end - end # class Deployment -end diff --git a/config/routes.rb b/config/routes.rb index 39addcf9..42a27941 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -43,7 +43,8 @@ Api::Application.routes.draw do resources :nodes, :only => [:index, :show] end resources :jobs - resources :deployments +# abasu - bug #7179 : remove deployments from g5k-api in v4.0 +# resources :deployments end resources :notifications, :only => [:index, :create] diff --git a/db/migrate/20160906203813_remove_deployments.rb b/db/migrate/20160906203813_remove_deployments.rb new file mode 100644 index 00000000..eb0fec35 --- /dev/null +++ b/db/migrate/20160906203813_remove_deployments.rb @@ -0,0 +1,54 @@ +# Copyright (c) 2009-2011 Cyril Rohr, INRIA Rennes - Bretagne Atlantique +# +# 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. + +# abasu - bug #7179 to remove deployments +class RemoveDeployments < ActiveRecord::Migration + def self.up + drop_table :deployments + end + + def self.down + create_table :deployments, :options => 'ENGINE=InnoDB DEFAULT CHARSET=utf8' do |t| + t.string :uid + t.string :site_uid + t.string :user_uid + t.string :environment, :size => 255 + t.string :version, :size => 10 # environment version + t.string :status, :default => "processing" + t.text :key + t.text :nodes + t.text :notifications + t.text :result + t.text :output + t.integer :partition_number, :size => 3 + t.string :block_device + t.string :reformat_tmp + t.boolean :disable_disk_partitioning, :default => false + t.boolean :disable_bootloader_install, :default => false + t.boolean :ignore_nodes_deploying, :default => false + t.integer :vlan + t.integer :created_at + t.integer :updated_at + end + + add_index :deployments, :uid + add_index :deployments, :environment + add_index :deployments, :site_uid + add_index :deployments, :user_uid + add_index :deployments, :status + add_index :deployments, :created_at + add_index :deployments, :updated_at + end + +end diff --git a/db/schema.rb b/db/schema.rb index 0d2e57b8..c20aaf8c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,37 +11,6 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20110109203813) do - - create_table "deployments", :force => true do |t| - t.string "uid" - t.string "site_uid" - t.string "user_uid" - t.string "environment" - t.string "version" - t.string "status", :default => "processing" - t.text "key" - t.text "nodes" - t.text "notifications" - t.text "result" - t.text "output" - t.integer "partition_number" - t.string "block_device" - t.string "reformat_tmp" - t.boolean "disable_disk_partitioning", :default => false - t.boolean "disable_bootloader_install", :default => false - t.boolean "ignore_nodes_deploying", :default => false - t.integer "vlan" - t.integer "created_at" - t.integer "updated_at" - end - - add_index "deployments", ["created_at"], :name => "index_deployments_on_created_at" - add_index "deployments", ["environment"], :name => "index_deployments_on_environment" - add_index "deployments", ["site_uid"], :name => "index_deployments_on_site_uid" - add_index "deployments", ["status"], :name => "index_deployments_on_status" - add_index "deployments", ["uid"], :name => "index_deployments_on_uid" - add_index "deployments", ["updated_at"], :name => "index_deployments_on_updated_at" - add_index "deployments", ["user_uid"], :name => "index_deployments_on_user_uid" +ActiveRecord::Schema.define(:version => 20160906203813) do end diff --git a/spec/controllers/deployments_controller_spec.rb b/spec/controllers/deployments_controller_spec.rb deleted file mode 100644 index 427214af..00000000 --- a/spec/controllers/deployments_controller_spec.rb +++ /dev/null @@ -1,270 +0,0 @@ -# Copyright (c) 2009-2011 Cyril Rohr, INRIA Rennes - Bretagne Atlantique -# -# 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 DeploymentsController do - render_views - - before do - @now = Time.now - 10.times do |i| - Factory.create(:deployment, :uid => "uid#{i}", :created_at => (@now+i).to_i).should_not be_nil - end - - end - - describe "GET /sites/{{site_id}}/deployments" do - - it "should return the list of deployments with the correct links, in created_at DESC order" do - get :index, :site_id => "rennes", :format => :json - response.status.should == 200 - json['total'].should == 10 - json['offset'].should == 0 - json['items'].length.should == 10 - json['items'].map{|i| i['uid']}.should == (0...10).map{|i| "uid#{i}"}.reverse - - json['items'].all?{|i| i.has_key?('links')}.should be_true - - - json['items'][0]['links'].should == [ - { - "rel"=> "self", - "href"=> "/sites/rennes/deployments/uid9", - "type"=> media_type(:g5kitemjson) - }, - { - "rel"=> "parent", - "href"=> "/sites/rennes", - "type"=> media_type(:g5kitemjson) - } - ] - json['links'].should == [ - { - "rel"=>"self", - "href"=>"/sites/rennes/deployments", - "type"=>media_type(:g5kcollectionjson) - }, - { - "rel"=>"parent", - "href"=>"/sites/rennes", - "type"=>media_type(:g5kitemjson) - } - ] - end - it "should correctly deal with pagination filters" do - get :index, :site_id => "rennes", :offset => 3, :limit => 5, :format => :json - response.status.should == 200 - json['total'].should == 10 - json['offset'].should == 3 - json['items'].length.should == 5 - json['items'].map{|i| i['uid']}.should == (0...10).map{|i| "uid#{i}"}.reverse.slice(3,5) - end - end # describe "GET /sites/{{site_id}}/deployments" - - - describe "GET /sites/{{site_id}}/deployments/{{id}}" do - it "should return 404 if the deployment does not exist" do - get :show, :site_id => "rennes", :id => "doesnotexist", :format => :json - response.status.should == 404 - response.body.should =~ %r{Couldn't find Grid5000::Deployment with ID=doesnotexist} - end - it "should return 200 and the deployment" do - expected_uid = "uid1" - get :show, :site_id => "rennes", :id => expected_uid, :format => :json - response.status.should == 200 - json["uid"].should == expected_uid - json["links"].should be_a(Array) - json.keys.sort.should == ["created_at", "disable_bootloader_install", "disable_disk_partitioning", "environment", "ignore_nodes_deploying", "links", "nodes", "site_uid", "status", "uid", "updated_at", "user_uid"] - end - end # describe "GET /sites/{{site_id}}/deployments/{{id}}" - - - describe "POST /sites/{{site_id}}/deployments" do - before do - @valid_attributes = { - "nodes" => ["paradent-1.rennes.grid5000.fr"], - "environment" => "lenny-x64-base" } - @deployment = Grid5000::Deployment.new(@valid_attributes) - end - - it "should return 403 if the user is not authenticated" do - authenticate_as("") - post :create, :site_id => "rennes", :format => :json - response.status.should == 403 - response.body.should == "You are not authorized to access this resource" - end - - it "should fail if the deployment is not valid" do - authenticate_as("crohr") - send_payload(@valid_attributes.merge("nodes" => []), :json) - - post :create, :site_id => "rennes", :format => :json - - response.status.should == 400 - response.body.should =~ /The deployment you are trying to submit is not valid/ - end - - it "should raise an error if an error occurred when launching the deployment" do - Grid5000::Deployment.should_receive(:new).with(@valid_attributes). - and_return(@deployment) - @deployment.should_receive(:launch_workflow!).and_raise(Exception.new("some error message")) - - authenticate_as("crohr") - send_payload(@valid_attributes, :json) - - post :create, :site_id => "rennes", :format => :json - - response.status.should == 500 - response.body.should == "Cannot launch deployment: some error message" - end - - it "should return 500 if the deploymet cannot be launched" do - Grid5000::Deployment.should_receive(:new).with(@valid_attributes). - and_return(@deployment) - - @deployment.should_receive(:launch_workflow!).and_return(nil) - - authenticate_as("crohr") - send_payload(@valid_attributes, :json) - - post :create, :site_id => "rennes", :format => :json - - response.status.should == 500 - response.body.should == "Cannot launch deployment: Uid must be set" - end - - it "should call transform_blobs_into_files! before sending the deployment, and return 201 if OK" do - Grid5000::Deployment.should_receive(:new).with(@valid_attributes). - and_return(@deployment) - - @deployment.should_receive(:transform_blobs_into_files!). - with( - Rails.tmp, - "http://api-in.local/sites/rennes/files" - ) - - @deployment.should_receive(:launch_workflow!).and_return(true) - @deployment.uid="kadeploy-api-provided-wid" - - authenticate_as("crohr") - send_payload(@valid_attributes, :json) - - post :create, :site_id => "rennes", :format => :json - - response.status.should == 201 - response.headers['Location'].should == "http://api-in.local/sites/rennes/deployments/kadeploy-api-provided-wid" - - json["uid"].should == "kadeploy-api-provided-wid" - json["links"].should be_a(Array) - json.keys.sort.should == ["created_at", "disable_bootloader_install", "disable_disk_partitioning", "environment", "ignore_nodes_deploying", "links", "nodes", "site_uid", "status", "uid", "updated_at", "user_uid"] - - dep = Grid5000::Deployment.find_by_uid("kadeploy-api-provided-wid") - dep.should_not be_nil - dep.status?(:processing).should be_true - end - end # describe "POST /sites/{{site_id}}/deployments" - - - describe "DELETE /sites/{{site_id}}/deployments/{{id}}" do - before do - @deployment = Grid5000::Deployment.first - end - - it "should return 403 if the user is not authenticated" do - authenticate_as("") - delete :destroy, :site_id => "rennes", :id => @deployment.uid, :format => :json - response.status.should == 403 - response.body.should == "You are not authorized to access this resource" - end - - it "should return 404 if the deployment does not exist" do - authenticate_as("crohr") - delete :destroy, :site_id => "rennes", :id => "doesnotexist", :format => :json - response.status.should == 404 - response.body.should == "Couldn't find Grid5000::Deployment with ID=doesnotexist" - end - - it "should return 403 if the requester does not own the deployment" do - authenticate_as(@deployment.user_uid+"whatever") - delete :destroy, :site_id => "rennes", :id => @deployment.uid, :format => :json - response.status.should == 403 - response.body.should == "You are not authorized to access this resource" - end - - it "should do nothing and return 204 if the deployment is not in an active state" do - Grid5000::Deployment.should_receive(:find_by_uid). - with(@deployment.uid). - and_return(@deployment) - - @deployment.should_receive(:can_cancel?).and_return(false) - - authenticate_as(@deployment.user_uid) - - delete :destroy, :site_id => "rennes", :id => @deployment.uid, :format => :json - - response.status.should == 202 - response.headers['Location'].should == "http://api-in.local/sites/rennes/deployments/#{@deployment.uid}" - response.body.should be_empty - end - - it "should call Grid5000::Deployment#cancel! if deployment active" do - Grid5000::Deployment.should_receive(:find_by_uid). - with(@deployment.uid). - and_return(@deployment) - - @deployment.should_receive(:can_cancel?).and_return(true) - @deployment.should_receive(:cancel!).and_return(true) - - authenticate_as(@deployment.user_uid) - - delete :destroy, :site_id => "rennes", :id => @deployment.uid, :format => :json - - response.status.should == 202 - response.body.should be_empty - response.headers['Location'].should == "http://api-in.local/sites/rennes/deployments/#{@deployment.uid}" - end - - end # describe "DELETE /sites/{{site_id}}/deployments/{{id}}" - - describe "PUT /sites/{{site_id}}/deployments/{{id}}" do - before do - @deployment = Grid5000::Deployment.first - end - - it "should return 404 if the deployment does not exist" do - authenticate_as("crohr") - put :update, :site_id => "rennes", :id => "doesnotexist", :format => :json - response.status.should == 404 - response.body.should == "Couldn't find Grid5000::Deployment with ID=doesnotexist" - end - - it "should call Grid5000::Deployment#touch!" do - Grid5000::Deployment.should_receive(:find_by_uid). - with(@deployment.uid). - and_return(@deployment) - - - @deployment.should_receive(:active?).and_return(true) - @deployment.should_receive(:touch!) - - put :update, :site_id => "rennes", :id => @deployment.uid, :format => :json - - response.status.should == 204 - response.body.should be_empty - response.headers['Location'].should == "http://api-in.local/sites/rennes/deployments/#{@deployment.uid}" - end - - end # describe "PUT /sites/{{site_id}}/deployments/{{id}}" -end diff --git a/spec/controllers/sites_controller_spec.rb b/spec/controllers/sites_controller_spec.rb index 6036e084..e4773ce5 100644 --- a/spec/controllers/sites_controller_spec.rb +++ b/spec/controllers/sites_controller_spec.rb @@ -64,7 +64,8 @@ describe SitesController do json['uid'].should == 'rennes' json['links'].map{|l| l['rel']}.sort.should == [ "clusters", - "deployments", +# abasu bug #7179 +# "deployments", "environments", "jobs", "metrics", @@ -92,7 +93,8 @@ describe SitesController do response.status.should == 200 json['links'].map{|l| l['rel']}.sort.should == [ "clusters", - "deployments", +# abasu bug #7179 +# "deployments", "environments", "jobs", "metrics", diff --git a/spec/factories.rb b/spec/factories.rb deleted file mode 100644 index c4a1c7a3..00000000 --- a/spec/factories.rb +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) 2009-2011 Cyril Rohr, INRIA Rennes - Bretagne Atlantique -# -# 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 'digest/sha1' - -Factory.sequence(:uid) do |n| - Digest::SHA1.hexdigest("uid-#{n}") -end - -Factory.define(:deployment, :class => Grid5000::Deployment) do |e| - e.uid { Factory.next(:uid) } - e.environment "lenny-x64-base" - e.nodes ["paradent-1.rennes.grid5000.fr", "parapluie-1.rennes.grid5000.fr"] - e.user_uid "crohr" - e.site_uid "rennes" -end diff --git a/spec/models/grid5000/deployment_spec.rb b/spec/models/grid5000/deployment_spec.rb deleted file mode 100644 index da78f017..00000000 --- a/spec/models/grid5000/deployment_spec.rb +++ /dev/null @@ -1,461 +0,0 @@ -# Copyright (c) 2009-2011 Cyril Rohr, INRIA Rennes - Bretagne Atlantique -# -# 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 Grid5000::Deployment do - - before(:each) do - @now = Time.now - Time.stub!(:now).and_return(@now) - @deployment = Grid5000::Deployment.new({ - :environment => "lenny-x64-base", - :user_uid => "crohr", - :site_uid => "rennes", - :nodes => ["paradent-1.rennes.grid5000.fr"] - }) - end - - - describe "validations" do - it "should be valid" do - @deployment.should be_valid - end - - [[], nil, ""].each do |value| - it "should not be valid if :nodes is set to #{value.inspect}" do - @deployment.nodes = value - @deployment.should_not be_valid - @deployment.errors[:nodes]. - should == ["can't be blank", "must be a non-empty list of node FQDN"] - end - end - - [nil, ""].each do |value| - it "should not be valid if :environment is set to #{value.inspect}" do - @deployment.environment = value - @deployment.should_not be_valid - @deployment.errors[:environment]. - should == ["can't be blank"] - end - it "should not be valid if :user_uid is set to #{value.inspect}" do - @deployment.user_uid = value - @deployment.should_not be_valid - @deployment.errors[:user_uid]. - should == ["can't be blank"] - end - it "should not be valid if :site_uid is set to #{value.inspect}" do - @deployment.site_uid = value - @deployment.should_not be_valid - @deployment.errors[:site_uid]. - should == ["can't be blank"] - end - end - - it "should not be valid if :notifications is not null but is not a list" do - @deployment.notifications = "" - @deployment.should_not be_valid - @deployment.errors[:notifications]. - should == ["must be a list of notification URIs"] - end - end # describe "validations" - - - describe "export to hash" do - - it "should correctly export the attributes to an array [simple]" do - @deployment.to_hash.should == { - "environment" => { - "name" => "lenny-x64-base", - }, - "nodes" => ["paradent-1.rennes.grid5000.fr"], - "hook"=>true - } - end - - it "should work [many nodes]" do - @deployment.nodes = [ - "paradent-1.rennes.grid5000.fr", - "paramount-10.rennes.grid5000.fr" - ] - @deployment.to_hash.should == { - "environment" => { - "name" => "lenny-x64-base", - }, - "nodes" => [ - "paradent-1.rennes.grid5000.fr", - "paramount-10.rennes.grid5000.fr", - ], - "hook"=>true - } - end - - it "should work [environment description file]" do - @deployment.environment = "http://server.com/some/file.dsc" - @deployment.to_hash.should == { - "environment"=>{}, - "nodes"=>["paradent-1.rennes.grid5000.fr"], - "hook"=>true - } - end - - it "should work [environment associated to a specific user]" do - @deployment.environment = "lenny-x64-base@crohr" - @deployment.to_hash.should == { - "environment" => { - "name" => "lenny-x64-base", - "user" => "crohr", - }, - "nodes" => ["paradent-1.rennes.grid5000.fr"], - "hook" => true - } - end - - it "should work [environment version]" do - @deployment.version = 3 - @deployment.to_hash.should == { - "environment" => { - "name" => "lenny-x64-base", - "version" => "3", - }, - "nodes" => ["paradent-1.rennes.grid5000.fr"], - "hook" => true - } - end - - it "should work [optional parameters]" do - @deployment.partition_number = 4 - @deployment.block_device = "whatever" - @deployment.vlan = 3 - @deployment.reformat_tmp = "ext2" - @deployment.ignore_nodes_deploying = true - @deployment.disable_bootloader_install = true - @deployment.disable_disk_partitioning = true - @deployment.to_hash.should == { - "environment" => { - "name" => "lenny-x64-base", - }, - "nodes" => ["paradent-1.rennes.grid5000.fr"], - "deploy_part" => "4", - "block_device" => "whatever", - "reformat_tmp_partition" => "ext2", - "vlan" => "3", - "disable_disk_partitioning" => true, - "disable_bootloader_install" => true, - "force" => true, - "hook" => true - } - end - end # describe "export to array" - - - describe "transform blobs into files" do - it "should transform a plain text key into a URI pointing to a physical file that contains the key content" do - expected_filename = "crohr-key-d971f6c5dfeeaf64c9699e2a81f6d4cb5532ed96" - @deployment.key = "ssh-dsa XMKSFNJCNJSJNJDNJSBCJSJ" - @deployment.transform_blobs_into_files!( - Rails.tmp, - "https://api.grid5000.fr/sid/grid5000/sites/rennes/files") - @deployment.key.should == "https://api.grid5000.fr/sid/grid5000/sites/rennes/files/#{expected_filename}" - File.read( - File.join(Rails.tmp, expected_filename) - ).should == "ssh-dsa XMKSFNJCNJSJNJDNJSBCJSJ" - end - - it "should do nothing if the key is already a URI" do - @deployment.key = "http://public.rennes.grid5000.fr/~crohr/my-key.pub" - @deployment.transform_blobs_into_files!( - Rails.tmp, - "https://api.grid5000.fr/sid/grid5000/sites/rennes/files") - @deployment.key. - should == "http://public.rennes.grid5000.fr/~crohr/my-key.pub" - end - end # describe "transform blobs into files" - - - describe "serialization" do - before do - @deployment.uid = "1234" - @deployment.notifications = [ - "xmpp:crohr@jabber.grid5000.fr", - "mailto:cyril.rohr@irisa.fr" - ] - @deployment.result = { - "paradent-1.rennes.grid5000.fr" => { - "state" => "OK" - } - } - @deployment.save.should_not be_false - @deployment.reload - end - - it "should correctly serialize the to-be-serialized attributes" do - @deployment.nodes.should == [ - "paradent-1.rennes.grid5000.fr" - ] - @deployment.notifications.should == [ - "xmpp:crohr@jabber.grid5000.fr", - "mailto:cyril.rohr@irisa.fr" - ] - @deployment.result.should == { - "paradent-1.rennes.grid5000.fr" => { - "state" => "OK" - } - } - end - - it "correctly build the attributes hash for JSON export" do - @deployment.as_json.should == {"created_at"=>@now.to_i, "disable_bootloader_install"=>false, "disable_disk_partitioning"=>false, "environment"=>"lenny-x64-base", "ignore_nodes_deploying"=>false, "nodes"=>["paradent-1.rennes.grid5000.fr"], "notifications"=>["xmpp:crohr@jabber.grid5000.fr", "mailto:cyril.rohr@irisa.fr"], "result"=>{"paradent-1.rennes.grid5000.fr"=>{"state"=>"OK"}}, "site_uid"=>"rennes", "status"=>"waiting", "uid"=>"1234", "updated_at"=>@now.to_i, "user_uid"=>"crohr"} - end - - it "should correctly export to json" do - export = JSON.parse(@deployment.to_json) - export['nodes'].should == [ - "paradent-1.rennes.grid5000.fr"] - export['notifications'].should == [ - "xmpp:crohr@jabber.grid5000.fr", - "mailto:cyril.rohr@irisa.fr"] - export['result'].should == { - "paradent-1.rennes.grid5000.fr"=>{"state"=>"OK"} - } - end - end # describe "serialization" - - - describe "creation" do - it "should not allow to create a deployment if uid is nil" do - @deployment.uid.should be_nil - @deployment.save.should be_false - @deployment.errors[:uid].should == ["must be set"] - end - - it "should not allow to create a deployment if uid already exists" do - @deployment.uid = "whatever" - @deployment.save - dep = Grid5000::Deployment.new(@deployment.attributes) - dep.uid = "whatever" - dep.save.should_not be_true - dep.errors[:uid].should == ["has already been taken"] - end - - it "should set the :created_at and :updated_at attributes" do - @deployment.uid = "1234" - @deployment.save.should be_true - @deployment.reload - @deployment.uid.should == "1234" - @deployment.created_at.should == @now.to_i - @deployment.updated_at.should == @now.to_i - end - end - - describe "state transitions" do - before do - @deployment.uid = "some-uid" - @deployment.save! - end - it "should be able to go from waiting to processing" do - @deployment.status?(:waiting).should be_true - @deployment.should_not_receive(:deliver_notification) - @deployment.should_receive(:launch_workflow!).and_return(true) - @deployment.launch.should be_true - @deployment.status?(:processing).should be_true - end - it "should not be able to go from waiting to processing if an exception is raised when launch_workflow" do - @deployment.should_not_receive(:deliver_notification) - @deployment.should_receive(:launch_workflow!). - and_raise(Exception.new("some error")) - @deployment.status?(:waiting).should be_true - lambda{ - @deployment.launch! - }.should raise_error(Exception, "some error") - @deployment.status?(:processing).should be_false - end - - describe "once it is in the :processing state" do - before do - @deployment.stub!(:launch_workflow!).and_return(true) - @deployment.launch! - @deployment.status?(:processing).should be_true - end - it "should be able to go from processing to processing" do - @deployment.should_not_receive(:deliver_notification) - @deployment.process.should be_true - @deployment.status?(:processing).should be_true - end - it "should be able to go from processing to terminated, and should call :deliver_notification" do - @deployment.should_receive(:deliver_notification) - @deployment.terminate.should be_true - @deployment.status?(:terminated).should be_true - end - it "should be able to go from processing to canceled, and should call :deliver_notification" do - @deployment.should_receive(:cancel_workflow!).and_return(true) - @deployment.should_receive(:deliver_notification) - @deployment.cancel.should be_true - @deployment.status?(:canceled).should be_true - end - it "should not be able to go from processing to canceled if an exception is raised when cancel_workflow" do - @deployment.should_receive(:cancel_workflow!). - and_raise(Exception.new("some error")) - @deployment.should_not_receive(:deliver_notification) - lambda{ - @deployment.cancel - }.should raise_error(Exception, "some error") - @deployment.status?(:canceled).should be_false - end - it "should be able to go from processing to error, and should call :deliver_notification" do - @deployment.should_receive(:deliver_notification) - @deployment.fail.should be_true - @deployment.status?(:error).should be_true - end - it "should not be able to go from canceled to terminated" do - @deployment.update_attribute(:status, "canceled") - @deployment.terminate.should be_false - @deployment.status?(:canceled).should be_true - end - end - end - -# No more Kadeploy lib -=begin - describe "calls to kadeploy server" do - before do - @kserver = Kadeploy::Server.new - Kadeploy::Server.stub!(:new).and_return(@kserver) - end - - describe "launch_workflow!" do - it "should raise an exception if an error occurred when trying to contact the kadeploy server" do - @kserver.should_receive(:submit!). - and_raise(Exception.new("some error")) - lambda { - @deployment.launch_workflow! - }.should raise_error(Exception, "some error") - @deployment.uid.should be_nil - end - it "should return the deployment uid if submission successful" do - @kserver.should_receive(:submit!). - and_return("some-uid") - @deployment.launch_workflow!.should == "some-uid" - end - end - - describe "with a deployment in the :processing state" do - - before do - @deployment.stub!(:launch_workflow!).and_return("some-uid") - @deployment.launch! - @deployment.status?(:processing).should be_true - end - - describe "cancel_workflow!" do - it "should raise an exception if an error occurred when trying to contact the kadeploy server" do - @kserver.should_receive(:cancel!). - and_raise(Exception.new("some error")) - lambda { - @deployment.cancel_workflow! - }.should raise_error(Exception, "some error") - end - it "should return true if correctly canceled on the kadeploy-server" do - @kserver.should_receive(:cancel!).and_return(true) - @deployment.cancel_workflow!.should be_true - end - it "should transition to the error state if not correctly canceled on the kadeploy-server" do - @kserver.should_receive(:cancel!).and_return(false) - @deployment.cancel_workflow!.should be_true - @deployment.reload.status?(:error).should be_true - end - end - - describe "touch!" do - before do - @result = {"x" => "y"} - @output = "some string" - end - - it "should raise an exception if an error occurred when trying to contact the kadeploy server" do - @kserver.should_receive(:touch!). - and_raise(Exception.new("some error")) - lambda { - @deployment.touch! - }.should raise_error(Exception, "some error") - end - - it "should set the status to :terminated if deployment is finished" do - @kserver.should_receive(:touch!). - and_return([:terminated, @result, @output]) - @deployment.touch!.should be_true - @deployment.reload - @deployment.status.should == "terminated" - @deployment.result.should == @result - @deployment.output.should == @output - end - it "should set the status to :error if an error occurred while trying to fetch the results from the kadeploy server" do - @kserver.should_receive(:touch!). - and_return([:error, nil, @output]) - - @deployment.touch!.should be_true - @deployment.reload - @deployment.status.should == "error" - @deployment.output.should == @output - end - it "should set the status to :error if the deployment no longer exist on the kadeploy server" do - @kserver.should_receive(:touch!). - and_return([:canceled, nil, @output]) - - @deployment.touch!.should be_true - @deployment.reload - @deployment.status.should == "error" - @deployment.output.should == @output - end - - end # describe "touch!" - end # describe "with a deployment in the :processing state" - end # describe "calls to kadeploy server" -=end - - describe "notification delivery" do - - it "should not deliver a notification if notifications is blank" do - @deployment.notifications = nil - Grid5000::Notification.should_not_receive(:new) - @deployment.deliver_notification.should be_true - end - - it "should deliver a notification if notifications is not empty" do - @deployment.notifications = ["xmpp:crohr@jabber.grid5000.fr"] - @deployment.stub!(:notification_message).and_return(msg = "msg") - Grid5000::Notification.should_receive(:new). - with(msg, :to => ["xmpp:crohr@jabber.grid5000.fr"]). - and_return(notif = mock("notif")) - notif.should_receive(:deliver!).and_return(true) - @deployment.deliver_notification.should be_true - end - - it "should always return true even if the notification delivery failed" do - @deployment.notifications = ["xmpp:crohr@jabber.grid5000.fr"] - @deployment.stub!(:notification_message).and_return(msg = "msg") - Grid5000::Notification.should_receive(:new). - with(msg, :to => ["xmpp:crohr@jabber.grid5000.fr"]). - and_return(notif = mock("notif")) - notif.should_receive(:deliver!).and_raise(Exception.new("message")) - @deployment.deliver_notification.should be_true - end - - it "build the correct notification message" do - @deployment.notifications = ["xmpp:crohr@jabber.grid5000.fr"] - @deployment.notification_message.should == JSON.pretty_generate(@deployment.as_json) - end - end - -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2a50d180..ea1e2982 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -92,7 +92,7 @@ RSpec.configure do |config| @now = Time.now Time.stub!(:now).and_return(@now) - Grid5000::Deployment.delete_all +# Grid5000::Deployment.delete_all @json = nil end -- GitLab