Skip to content
Browse files

remove old quota manager calls

Change-Id: I13e104407736432ab4e40a12634b164e1830fc38
  • Loading branch information...
1 parent 8a23c4f commit 55d051c8e59315087c223e546fa86ed7754c7543 @pbozeman pbozeman committed Nov 6, 2012
View
6 config/cloud_controller.yml
@@ -42,12 +42,6 @@ uaa:
resource_id: "cloud_controller"
symmetric_secret: "tokensecret"
-quota_manager:
- policy: "MoneyMakerApproval" # can also be BlindApproval
- base_url: "http://localhost:31004/v1/quota"
- auth_token: "testtoken"
- http_timeout_sec: 2
-
cc_partition: ng
bulk_api:
View
34 lib/cloud_controller/api/app.rb
@@ -35,22 +35,6 @@ module VCAP::CloudController
query_parameters :name, :space_guid, :organization_guid, :framework_guid, :runtime_guid
- def create_quota_token_request(obj)
- ret = quota_token_request("post", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def update_quota_token_request(obj)
- ret = quota_token_request("put", obj)
- ret[:body][:audit_data] = request_attrs
- ret
- end
-
- def delete_quota_token_request(obj)
- quota_token_request("delete", obj)
- end
-
def after_update(app, changes)
AppStager.stage_app(app) if app.needs_staging?
@@ -78,24 +62,6 @@ def self.translate_validation_exception(e, attributes)
private
- def quota_token_request(op, obj)
- {
- :path => obj.space.organization_guid,
- :body => {
- :op => op,
- :user_id => user.guid,
- :object => "application",
- :object_id => obj.guid,
- :object_name => obj.name,
- :space_id => obj.space_guid,
- :memory => obj.memory,
- :instances => obj.instances,
- :production => obj.production,
- :audit_data => obj.to_hash
- }
- }
- end
-
def after_modify(app)
if app.dea_update_pending?
DeaClient.update_uris(app)
View
34 lib/cloud_controller/api/domain.rb
@@ -19,25 +19,6 @@ module VCAP::CloudController
query_parameters :name, :owning_organization_guid, :space_guid
- def create_quota_token_request(obj)
- return unless obj.owning_organization
- ret = quota_token_request("post", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def update_quota_token_request(obj)
- return unless obj.owning_organization
- ret = quota_token_request("put", obj)
- ret[:body][:audit_data] = request_attrs
- ret
- end
-
- def delete_quota_token_request(obj)
- return unless obj.owning_organization
- quota_token_request("delete", obj)
- end
-
def self.translate_validation_exception(e, attributes)
name_errors = e.errors.on(:name)
if name_errors && name_errors.include?(:unique)
@@ -46,20 +27,5 @@ def self.translate_validation_exception(e, attributes)
Errors::DomainInvalid.new(e.errors.full_messages)
end
end
-
- private
-
- def quota_token_request(op, obj)
- {
- :path => obj.owning_organization_guid,
- :body => {
- :op => op,
- :user_id => user.guid,
- :object => "domain",
- :name => obj.name,
- :object_id => obj.guid
- }
- }
- end
end
end
View
15 lib/cloud_controller/api/organization.rb
@@ -26,21 +26,6 @@ module VCAP::CloudController
:user_guid, :manager_guid, :billing_manager_guid,
:auditor_guid
- def update_quota_token_request(org)
- # TODO: sync payload with ilia
- {
- :path => "#{org.guid}",
- :body => {
- :op => "put",
- :user_id => user.guid,
- :object => "org",
- :object_id => org.guid,
- :object_name => request_attrs["name"] || org.name,
- :audit_data => request_attrs
- }
- }
- end
-
def self.translate_validation_exception(e, attributes)
name_errors = e.errors.on(:name)
if name_errors && name_errors.include?(:unique)
View
32 lib/cloud_controller/api/route.rb
@@ -20,22 +20,6 @@ module VCAP::CloudController
query_parameters :host, :domain_guid
- def create_quota_token_request(obj)
- ret = quota_token_request("post", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def update_quota_token_request(obj)
- ret = quota_token_request("put", obj)
- ret[:body][:audit_data] = request_attrs
- ret
- end
-
- def delete_quota_token_request(obj)
- quota_token_request("delete", obj)
- end
-
def self.translate_validation_exception(e, attributes)
name_errors = e.errors.on([:host, :domain_id])
if name_errors && name_errors.include?(:unique)
@@ -44,21 +28,5 @@ def self.translate_validation_exception(e, attributes)
Errors::RouteInvalid.new(e.errors.full_messages)
end
end
-
- private
-
- def quota_token_request(op, obj)
- {
- :path => obj.space.organization_guid,
- :body => {
- :op => op,
- :user_id => user.guid,
- :object => "route",
- :host => obj.host,
- :object_id => obj.guid,
- :domain_id => obj.domain.guid
- }
- }
- end
end
end
View
35 lib/cloud_controller/api/service_binding.rb
@@ -18,23 +18,6 @@ module VCAP::CloudController
query_parameters :app_guid, :service_instance_guid
- def create_quota_token_request(obj)
- ret = quota_token_request("post", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def update_quota_token_request(obj)
- ret = quota_token_request("put", obj)
- ret[:body][:audit_data] = request_attrs
- ret
- end
-
- def delete_quota_token_request(obj)
- quota_token_request("delete", obj)
- end
-
-
def self.translate_validation_exception(e, attributes)
unique_errors = e.errors.on([:app_id, :service_instance_id])
if unique_errors && unique_errors.include?(:unique)
@@ -44,23 +27,5 @@ def self.translate_validation_exception(e, attributes)
Errors::ServiceBindingInvalid.new(e.errors.full_messages)
end
end
-
- private
-
- # Tim might need to tweak this. I'm not really sure what info the bizops
- # guys want here.
- def quota_token_request(op, obj)
- {
- :path => obj.app.space.organization_guid,
- :body => {
- :op => op,
- :user_id => user.guid,
- :object => "service_binding",
- :object_id => obj.guid,
- :app_id => obj.app.guid,
- :service_instance_id => obj.service_instance.guid
- }
- }
- end
end
end
View
37 lib/cloud_controller/api/service_instance.rb
@@ -18,22 +18,6 @@ module VCAP::CloudController
query_parameters :name, :space_guid, :service_plan_guid, :service_binding_guid
- def create_quota_token_request(obj)
- ret = quota_token_request("post", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def update_quota_token_request(obj)
- ret = quota_token_request("put", obj)
- ret[:body][:audit_data] = request_attrs
- ret
- end
-
- def delete_quota_token_request(obj)
- quota_token_request("delete", obj)
- end
-
def self.translate_validation_exception(e, attributes)
space_and_name_errors = e.errors.on([:space_id, :name])
if space_and_name_errors && space_and_name_errors.include?(:unique)
@@ -42,26 +26,5 @@ def self.translate_validation_exception(e, attributes)
Errors::ServiceInstanceInvalid.new(e.errors.full_messages)
end
end
-
- private
-
- def quota_token_request(op, obj)
- {
- :path => obj.space.organization_guid,
- :body => {
- :op => op,
- :user_id => user.guid,
- :object => "service",
- :object_id => obj.guid,
- :space_id => obj.space.guid,
- :object_name => obj.name,
- :plan_name => obj.service_plan.name,
- :service_label => obj.service_plan.service.label,
- :service_provider => obj.service_plan.service.provider,
- :service_version => obj.service_plan.service.version
- }
- }
- end
-
end
end
View
31 lib/cloud_controller/api/space.rb
@@ -24,22 +24,6 @@ module VCAP::CloudController
query_parameters :name, :organization_guid, :developer_guid, :app_guid
- def create_quota_token_request(obj)
- ret = quota_token_request("post", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def update_quota_token_request(obj)
- ret = quota_token_request("put", obj)
- ret[:body][:audit_data] = obj.to_hash
- ret
- end
-
- def delete_quota_token_request(obj)
- quota_token_request("delete", obj)
- end
-
def self.translate_validation_exception(e, attributes)
name_errors = e.errors.on([:organization_id, :name])
if name_errors && name_errors.include?(:unique)
@@ -48,20 +32,5 @@ def self.translate_validation_exception(e, attributes)
Errors::SpaceInvalid.new(e.errors.full_messages)
end
end
-
- private
-
- def quota_token_request(op, obj)
- {
- :path => obj.organization_guid,
- :body => {
- :op => op,
- :user_id => user.guid,
- :object => "space",
- :object_id => obj.guid,
- :object_name => obj.name
- }
- }
- end
end
end
View
7 lib/cloud_controller/config.rb
@@ -28,12 +28,6 @@ class VCAP::CloudController::Config < VCAP::Config
:symmetric_secret => String
},
- :quota_manager => {
- :base_url => String,
- :auth_token => String,
- optional(:http_timeout_sec) => Integer
- },
-
:logging => {
:level => String, # debug, info, etc.
optional(:file) => String, # Log file to use
@@ -100,7 +94,6 @@ def self.configure(config)
# via per instance constructor. Remove that in favor of this
# method as there will be more along these lines.
VCAP::CloudController::MessageBus.configure(config)
- VCAP::CloudController::RestController::QuotaManager.configure(config)
VCAP::CloudController::AccountCapacity.configure(config)
VCAP::CloudController::ResourcePool.configure(config)
VCAP::CloudController::FilesystemPool.configure(config)
View
1 lib/cloud_controller/rest_controller.rb
@@ -4,7 +4,6 @@
require "cloud_controller/rest_controller/messages"
require "cloud_controller/rest_controller/object_serialization"
require "cloud_controller/rest_controller/paginator"
-require "cloud_controller/rest_controller/quota_manager"
require "cloud_controller/rest_controller/routes"
require "cloud_controller/rest_controller/base"
require "cloud_controller/rest_controller/model_controller"
View
30 lib/cloud_controller/rest_controller/model_controller.rb
@@ -6,16 +6,6 @@ module VCAP::CloudController::RestController
class ModelController < Base
include Routes
- # By default, operations do not require quota enformcement.
- # Endpoints are expected to override this method if they need
- # quota enforcement.
- #
- # TODO: once quota is implemented verywhere, take these out
- # for safety. Err on the side of requring quota check.
- def create_quota_token_request(obj); end
- def update_quota_token_request(obj); end
- def delete_quota_token_request(obj); end
-
# Create operation
def create
json_msg = self.class::CreateMessage.decode(body)
@@ -26,12 +16,11 @@ def create
logger.debug "create: #{request_attrs}"
obj = model.create_from_hash(request_attrs)
validate_access(:create, obj, user)
-
- QuotaManager.with_quota_enforcement(create_quota_token_request(obj)) do
- [HTTP::CREATED,
- { "Location" => "#{self.class.path}/#{obj.guid}" },
- serialization.render_json(self.class, obj, @opts)]
- end
+ [
+ HTTP::CREATED,
+ { "Location" => "#{self.class.path}/#{obj.guid}" },
+ serialization.render_json(self.class, obj, @opts)
+ ]
end
end
@@ -55,7 +44,7 @@ def update(id)
logger.debug "update: #{id} #{request_attrs}"
changes = {}
- QuotaManager.with_quota_enforcement(update_quota_token_request(obj)) do
+ model.db.transaction do
obj.update_from_hash(request_attrs)
changes = obj.previous_changes || {}
obj.save
@@ -72,11 +61,8 @@ def update(id)
def delete(id)
logger.debug "delete: #{id}"
obj = find_id_and_validate_access(:delete, id)
-
- QuotaManager.with_quota_enforcement(delete_quota_token_request(obj)) do
- obj.destroy
- [HTTP::NO_CONTENT, nil]
- end
+ obj.destroy
+ [ HTTP::NO_CONTENT, nil ]
end
# Enumerate operation
View
294 lib/cloud_controller/rest_controller/quota_manager.rb
@@ -1,294 +0,0 @@
-# Copyright (c) 2009-2012 VMware, Inc.
-
-require "httpclient"
-require "steno"
-
-module VCAP::CloudController::RestController
- module QuotaManager
- class << self
- # Set the configuration for the QuotaManager
- #
- # The most important attribute is the :policy attribute.
- # This can be either "MoneyMaker" or "BlindApproval"
- #
- # If MoneyMaker, the QuotaManager will attempt to get
- # quota approval from the account manger portion of the
- # MoneyMaker/Billing System.
- def configure(config)
- c = config[:quota_manager]
- policy_name = c[:policy] || "MoneyMaker"
- @policy = QuotaManager.const_get(policy_name)
- MoneyMakerClient.configure(c)
- end
-
- # Common managment of quota enforcement.
- #
- # @param [Hash] quota_request_body Hash of the request to send to the
- # remote quota manager. If nil, indicates that quota enformcement
- # is not necessary.
- #
- # @param [Block] &blk The block to execute with quota enforcement.
- #
- # @return Results of calling the provided block.
- def with_quota_enforcement(quota_request_body, &blk)
- begin
- token = fetch_quota_token(quota_request_body)
- rescue VCAP::CloudController::Errors::QuotaDeclined => e
- raise e
- end
-
- begin
- ret = blk.call
- rescue Exception => e
- token.abandon(e.message) unless token.nil?
- raise e
- end
-
- begin
- token.commit
- rescue Exception => e
- logger.error "failed to commit token #{token.inspect} #{e}"
- end
-
- return ret
- end
-
- # Fetch a quota token. If the policy decision is denied,
- # an exception is raised.
- #
- # @param [Hash] quota_request. There should be a :path entry
- # that is appened to the base url for the approval request. The :body
- # entry is encoded as json and passed directly to the quota server.
- #
- # @return [QuotaManager::ApprovalToken] The caller should call commit
- # or abandon on the returned token.
- def fetch_quota_token(quota_request)
- p = quota_request ? @policy : BlindApproval
- logger.debug "@policy: #{p}"
- token = p.fetch_quota_token(quota_request)
- unless token.approved?
- raise VCAP::CloudController::Errors::QuotaDeclined.new(token.reason)
- end
- logger.debug "token: #{token.inspect}"
- token
- end
-
- def logger
- @logger ||= Steno.logger("cc.qm")
- end
- end
-
- # BlindApprovalTokens are basically no-op tokens.
- class BlindApprovalToken
-
- # Perform a rollback with the quota system.
- #
- # @param [String] Error string indicating why the operation failed.
- def abandon(reason)
- logger.debug "blind abandon: #{reason}"
- end
-
- # Commit
- #
- # @param [String] Error string indicating why the operation failed.
- def commit
- logger.debug "blind commit"
- end
-
- # Approval check
- #
- # @return [Bool] True if the quota manager approved the quota check
- def approved?
- true
- end
-
- # Reason the quota manager denied the quota check
- #
- # @return [String] Reason the quota manager denied the quota check
- def reason
- end
-
- private
-
- def logger
- QuotaManager.logger
- end
- end
-
- # Blind Approval policy
- class BlindApproval
- def self.fetch_quota_token(quota_request)
- BlindApprovalToken.new
- end
- end
-
- # Approval token from the MoneyMaker quota manager. Commit/abandon
- # result in a follow up call to the quota manager to complete
- # the processing of the token.
- class MoneyMakerApprovalToken
- def initialize(token_id, approved, reason = nil)
- @token_id = token_id
- @approved = approved
- @reason = reason
- end
-
- def approved?
- @approved
- end
-
- def reason
- @reason
- end
-
- def abandon(reason)
- MoneyMakerClient.abandon_token(@token_id, reason)
- end
-
- def commit
- MoneyMakerClient.commit_token(@token_id)
- end
- end
-
- # Money Maker approval policy
- class MoneyMakerApproval
- def self.fetch_quota_token(quota_request)
- resp = MoneyMakerClient.request_token(quota_request)
- MoneyMakerApprovalToken.new(resp["token"],
- resp["approved"] == "yes",
- resp["reason"])
- rescue MoneyMakerClient::MoneyMakerError => e
- logger.warn "BLIND APPROVAL: #{e}"
- BlindApprovalToken.new
- end
-
- def self.logger
- QuotaManager.logger
- end
- end
-
-
- # Money Maker rest client
- class MoneyMakerClient
- class MoneyMakerError < StandardError; end
-
- DEFAULT_HTTP_TIMEOUT_SEC = 2
-
- class << self
- def configure(config)
- @base_url = config[:base_url]
- @auth_token = config[:auth_token]
- @http_timeout = config[:http_timeout_sec]
- end
-
- def request_token(quota_request)
- begin
- url = quota_manager_url(quota_request[:path])
- response = post(url, quota_request[:body])
- rescue SystemCallError,
- OpenSSL::SSL::SSLError,
- HTTPClient::BadResponseError,
- HTTPClient::TimeoutError => e
- raise MoneyMakerError.new("http error #{e}")
- end
-
- case response.code
- when 200..201
- return parse_token(response.body)
- when 204
- raise MoneyMakerError.new("204 response no token received")
- else
- raise MoneyMakerError.new("unexpected error #{response.code}")
- end
- end
-
- def abandon_token(token_id, reason)
- post(token_url(token_id, "abandon"), :abandon_reason => reason)
- end
-
- def commit_token(token_id)
- post(token_url(token_id, "commit"))
- end
-
- private
-
- def parse_token(json)
- raise MoneyMakerError.new("no response body") unless json
-
- hash = Yajl::Parser.parse(json)
- unless hash["approved"]
- raise MoneyMakerError.new("missing 'approved' entry '#{json}'")
- end
-
- hash["approved"].downcase!
-
- unless ["yes", "no"].include?(hash["approved"])
- raise MoneyMakerError.new("malformed 'approved' entry '#{json}'")
- end
-
- if hash["approved"] == "yes" && hash["token"].nil?
- raise MoneyMakerError.new("missing 'token' entry '#{json}'")
- end
-
- hash
- end
-
- def post(url, body = nil)
- request(:post, url, body)
- end
-
- def put(url, body = nil)
- request(:put, url, body)
- end
-
- def delete(url, body = nil)
- request(:delete, url, body)
- end
-
- def request(method, url, body)
- headers = {
- "accept" => :json,
- "x-bs-auth-token" => auth_token,
- "x-vcap-request-id" => Thread.current[:vcap_request_id]
- }
- headers["content-type"] = :json unless body.nil?
- encoded = Yajl::Encoder.encode(body)
-
- logger.debug "req: #{method} #{url} #{headers} #{body}"
- response = http_client.request(method, url,
- :body => encoded,
- :header => headers)
- logger.debug "resp: #{response.code} #{response.body}"
- response
- end
-
- def http_client
- c = HTTPClient.new
- c.send_timeout = http_timeout
- c.receive_timeout = http_timeout
- c.connect_timeout = http_timeout
- c
- end
-
- def auth_token
- @auth_token
- end
-
- def quota_manager_url(path)
- "#{@base_url}/#{path}"
- end
-
- def http_timeout
- @http_timeout
- end
-
- def token_url(token_id, action)
- quota_manager_url("#{action}/#{token_id}")
- end
-
- def logger
- QuotaManager.logger
- end
- end
- end
- end
-end
View
45 spec/api/app_spec.rb
@@ -426,50 +426,5 @@ module VCAP::CloudController
end
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
- let(:app_obj) { Models::App.make }
-
- describe "create" do
- it "should fetch a quota token" do
- should_receive_quota_call
- post "/v2/apps", Yajl::Encoder.encode(:name => Sham.name,
- :space_guid => app_obj.space_guid,
- :framework_guid => app_obj.framework_guid,
- :runtime_guid => app_obj.runtime_guid),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- RestController::QuotaManager.should_not_receive(:fetch_quota_token)
- get "/v2/apps/#{app_obj.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "update" do
- it "should fetch a quota token" do
- should_receive_quota_call
- put("/v2/apps/#{app_obj.guid}",
- Yajl::Encoder.encode(:name => "#{app_obj.name}_renamed"),
- headers_for(cf_admin)
- )
- last_response.status.should == 201
- end
- end
-
- describe "delete" do
- it "should fetch a quota token" do
- should_receive_quota_call
- delete "/v2/apps/#{app_obj.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
end
end
View
45 spec/api/domain_spec.rb
@@ -186,50 +186,5 @@ module VCAP::CloudController
end
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
- let(:org) { Models::Organization.make }
- let(:domain) { Models::Domain.make }
-
- describe "create" do
- it "should fetch a quota token" do
- should_receive_quota_call
- post "/v2/domains",
- Yajl::Encoder.encode(:name => Sham.domain,
- :owning_organization_guid => org.guid,
- :wildcard => true),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- get "/v2/domains/#{domain.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "update" do
- it "should fetch a quota token" do
- should_receive_quota_call
- put "/v2/domains/#{domain.guid}",
- Yajl::Encoder.encode(:name => Sham.domain),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "delete" do
- it "should fetch a quota token" do
- should_receive_quota_call
- delete "/v2/domains/#{domain.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
-
end
end
View
38 spec/api/organization_spec.rb
@@ -211,43 +211,5 @@ module VCAP::CloudController
end
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
-
- describe "create" do
- it "should not fetch a quota token" do
- should_receive_nil_quota_call
- post "/v2/organizations", Yajl::Encoder.encode(:name => "some org"), headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- get "/v2/organizations/#{org.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "update" do
- it "should fetch a quota token" do
- should_receive_quota_call
- put "/v2/organizations/#{org.guid}",
- Yajl::Encoder.encode(:name => "#{org.name}_renamed"),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "delete" do
- it "should not fetch a quota token" do
- should_receive_nil_quota_call
- delete "/v2/organizations/#{org.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
end
end
View
49 spec/api/route_spec.rb
@@ -218,55 +218,6 @@ module VCAP::CloudController
include_examples "route permissions"
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
- let(:domain) { Models::Domain.make(:wildcard => true) }
- let(:space) {
- s = Models::Space.make(:organization => domain.owning_organization)
- s.add_domain(domain)
- s
- }
- let(:route) { Models::Route.make(:domain => domain, :space => space) }
-
- describe "create" do
- it "should fetch a quota token" do
- should_receive_quota_call
- post "/v2/routes",
- Yajl::Encoder.encode(:host => Sham.host,
- :domain_guid => domain.guid,
- :space_guid => space.guid),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- get "/v2/routes/#{route.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "update" do
- it "should fetch a quota token" do
- should_receive_quota_call
- put "/v2/routes/#{route.guid}",
- Yajl::Encoder.encode(:host => Sham.host),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "delete" do
- it "should fetch a quota token" do
- should_receive_quota_call
- delete "/v2/routes/#{route.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
end
describe "on app change" do
View
38 spec/api/service_binding_spec.rb
@@ -190,43 +190,5 @@ module VCAP::CloudController
end
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
- let(:app_obj) { Models::App.make }
- let(:service_instance) { Models::ServiceInstance.make(:space => app_obj.space) }
- let(:service_binding) do
- Models::ServiceBinding.make(:app => app_obj,
- :service_instance => service_instance)
- end
-
- describe "create" do
- it "should fetch a quota token" do
- should_receive_quota_call
- post "/v2/service_bindings",
- Yajl::Encoder.encode(:app_guid => app_obj.guid,
- :service_instance_guid => service_instance.guid),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- get "/v2/service_bindings/#{service_binding.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "delete" do
- it "should fetch a quota token" do
- should_receive_quota_call
- delete "/v2/service_bindings/#{service_binding.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
-
end
end
View
44 spec/api/service_instance_spec.rb
@@ -141,49 +141,5 @@ module VCAP::CloudController
end
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
- let(:service_instance) { Models::ServiceInstance.make }
-
- describe "create" do
- it "should fetch a quota token" do
- should_receive_quota_call
- post "/v2/service_instances",
- Yajl::Encoder.encode(:name => Sham.name,
- :space_guid => service_instance.space_guid,
- :service_plan_guid => service_instance.service_plan_guid),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- get "/v2/service_instances/#{service_instance.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "update" do
- it "should fetch a quota token" do
- should_receive_quota_call
- put "/v2/service_instances/#{service_instance.guid}",
- Yajl::Encoder.encode(:name => "#{service_instance.name}_renamed"),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "delete" do
- it "should fetch a quota token" do
- should_receive_quota_call
- delete "/v2/service_instances/#{service_instance.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
-
end
end
View
42 spec/api/space_spec.rb
@@ -154,47 +154,5 @@ module VCAP::CloudController
end
end
end
-
- describe "quota" do
- let(:cf_admin) { Models::User.make(:admin => true) }
- let(:org) { Models::Organization.make }
- let(:space) { Models::Space.make }
-
- describe "create" do
- it "should fetch a quota token" do
- should_receive_quota_call
- post "/v2/spaces", Yajl::Encoder.encode(:name => Sham.name,
- :organization_guid => org.guid),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "get" do
- it "should not fetch a quota token" do
- should_not_receive_quota_call
- get "/v2/spaces/#{space.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 200
- end
- end
-
- describe "update" do
- it "should fetch a quota token" do
- should_receive_quota_call
- put "/v2/spaces/#{space.guid}",
- Yajl::Encoder.encode(:name => "#{space.name}_renamed"),
- headers_for(cf_admin)
- last_response.status.should == 201
- end
- end
-
- describe "delete" do
- it "should fetch a quota token" do
- should_receive_quota_call
- delete "/v2/spaces/#{space.guid}", {}, headers_for(cf_admin)
- last_response.status.should == 204
- end
- end
- end
end
end
View
21 spec/api/spec_helper.rb
@@ -74,27 +74,6 @@ def entity
decoded_response["entity"]
end
- def should_not_receive_quota_call
- RestController::QuotaManager.should_not_receive(:fetch_quota_token).with(nil)
- end
-
- def should_receive_nil_quota_call
- t = RestController::QuotaManager::BlindApprovalToken.new
- t.should_receive(:commit)
- RestController::QuotaManager.should_receive(:fetch_quota_token).with(nil).and_return(t)
- end
-
- def should_receive_quota_call
- RestController::QuotaManager.should_not_receive(:fetch_quota_token).with(nil)
- RestController::QuotaManager.should_receive(:fetch_quota_token) do |arg|
- arg[:path].should_not be_nil
- arg[:body].should_not be_nil
- audit_data = arg[:body][:audit_data]
- audit_data.should be_a_kind_of(Hash) if audit_data
- RestController::QuotaManager::BlindApprovalToken.new
- end
- end
-
shared_examples "a CloudController API" do |opts|
[:required_attributes, :unique_attributes, :basic_attributes,
:extra_attributes, :sensitive_attributes,
View
104 spec/quota_manager_spec.rb
@@ -1,104 +0,0 @@
-# Copyright (c) 2009-2012 VMware, Inc.
-
-require File.expand_path("../spec_helper", __FILE__)
-
-module VCAP::CloudController
- describe VCAP::CloudController::RestController::QuotaManager do
- describe "with_quota_enforcement" do
- # since we are mocking the fetch, we don't really need a body
- let (:quota_body) { {:foo => "bar"} }
-
- context "Errors::QuotaDeclined returned from fetch_quota_token" do
- it "should raise a QuotaDeclined error" do
- body_called = false
-
- RestController::QuotaManager.should_receive(:fetch_quota_token).
- and_raise(Errors::QuotaDeclined.new("over limit"))
-
- expect do
- RestController::QuotaManager.with_quota_enforcement(quota_body) do
- body_called = true
- end
- end.to raise_error(Errors::QuotaDeclined, /over limit/)
-
- body_called.should be_false
- end
- end
-
- context "a token returned erom fetch_quota_token" do
- it "should call the supplied block and commit the token" do
- token = mock(:token)
- token.should_receive(:commit)
-
- RestController::QuotaManager.should_receive(:fetch_quota_token).
- and_return(token)
-
- body_called = false
- ret = RestController::QuotaManager.with_quota_enforcement(quota_body) do
- body_called = true
- 123
- end
- body_called.should be_true
- ret.should == 123
- end
- end
-
- context "error during block processing" do
- it "should call token.abandon and re-raise the error" do
- token = mock(:token)
- token.should_receive(:abandon).with("boom")
-
- RestController::QuotaManager.should_receive(:fetch_quota_token).
- and_return(token)
-
- expect do
- RestController::QuotaManager.with_quota_enforcement(quota_body) do
- raise "boom"
- end
- end.to raise_error("boom")
- end
- end
-
- context "error while commiting the token" do
- it "should log an error but not call token.abandon" do
- RestController::QuotaManager.logger.should_receive(:error)
-
- token = mock(:token)
- token.should_receive(:commit).and_raise("bang")
-
- RestController::QuotaManager.should_receive(:fetch_quota_token).
- and_return(token)
-
- RestController::QuotaManager.with_quota_enforcement(quota_body) {}
- end
- end
- end
- end
-
- describe VCAP::CloudController::RestController::QuotaManager::MoneyMakerClient do
- describe "request" do
- it "should send X-VCAP-Request_ID" do
- request_guid = SecureRandom.uuid
- Thread.current[:vcap_request_id] = request_guid
-
- client = mock(:http_client)
- url = "http://some/url"
- body = { :foo => "bar" }
-
- client.should_receive(:request) do |m, u, opts|
- m.should == :post
- u.should == url
- opts[:body].should == Yajl::Encoder.encode(body)
- opts[:header]["x-vcap-request-id"].should == request_guid
- OpenStruct.new(:code => 200, :body => "")
- end
-
- RestController::QuotaManager::MoneyMakerClient.
- should_receive(:http_client).and_return(client)
-
- RestController::QuotaManager::MoneyMakerClient.
- send(:request, :post, url, body)
- end
- end
- end
-end
View
1 spec/spec_helper.rb
@@ -82,7 +82,6 @@ def config
config_file = File.expand_path("../../config/cloud_controller.yml", __FILE__)
c = VCAP::CloudController::Config.from_file(config_file)
c[:nginx][:use_nginx] = true
- c[:quota_manager][:policy] = "BlindApproval"
c = c.merge(@config_override || {})
VCAP::CloudController::Config.configure(c)
c

0 comments on commit 55d051c

Please sign in to comment.
Something went wrong with that request. Please try again.