Permalink
Browse files

Enable turning new stager on by email

Adds support for enabling new stager use by user email as well as by
percent.

Test plan:
- New unit test
- Enabled for my email addr, verified that I was using the new stager.
  Ran BVTs, verified they were not using the new stager.
- Ran BVTs on my deployment

Change-Id: I4c1e55c1d7fb33e608a0626db34c4b49695fa147
  • Loading branch information...
1 parent 8edb56c commit 921a91d804ea298e12493b1512ea983497c9888b mpage committed Sep 8, 2011
@@ -109,8 +109,9 @@ def no_more_apps?
def uses_new_stager?(cfg=AppConfig)
- if cfg[:staging][:new_stager_percent] \
- && ((self.id % 100) < cfg[:staging][:new_stager_percent])
+ stg = cfg[:staging]
+ if (stg[:new_stager_percent] && ((self.id % 100) < stg[:new_stager_percent])) \
+ || (stg[:new_stager_email_regexp] && stg[:new_stager_email_regexp].match(self.email))
true
else
false
@@ -2,7 +2,6 @@
# Once we know which Rails environment we are in, we can fail fast in production
# mode by checking that flag. This code runs too early to know for sure if
# we are starting in production mode.
-
require 'vcap/common'
require 'vcap/staging/plugin/common'
@@ -158,7 +157,11 @@
exit 1
end
-if AppConfig[:staging][:new_stager_percent] && !AppConfig[:redis]
+if AppConfig[:staging][:new_stager_email_regexp]
+ AppConfig[:staging][:new_stager_email_regexp] = Regexp.new(AppConfig[:staging][:new_stager_email_regexp])
+end
+
+if (AppConfig[:staging][:new_stager_percent] || AppConfig[:staging][:new_stager_email_regexp]) && !AppConfig[:redis]
$stderr.puts "You must supply a redis config to use the new stager"
exit 1
end
@@ -100,7 +100,7 @@
u.uses_new_stager?({:staging => {}}).should be_false
end
- it 'should correctly identify which users should have the new stager enabled' do
+ it 'should correctly identify which users should have the new stager enabled by percent' do
u = User.new(:email => 'foo@bar.com')
cfg = {:staging => {:new_stager_percent => 2}}
@@ -116,6 +116,15 @@
u.id = 101
u.uses_new_stager?(cfg).should be_true
end
+
+ it 'should correctly identify which users should have the new stager enabled by email' do
+ u1 = User.new(:email => 'mpage@vmware.com')
+ u2 = User.new(:email => 'bar@foo.com')
+ cfg = {:staging => {:new_stager_email_regexp => Regexp.new('.*@vmware\.com')}}
+
+ u1.uses_new_stager?(cfg).should be_true
+ u2.uses_new_stager?(cfg).should be_false
+ end
end
def create_user(email, pw)

0 comments on commit 921a91d

Please sign in to comment.