While using the mock driver for a while I noticed that my
instances started having weird names. I eventually figured
out that the mock driver is auto-assigning instance names
based on the instances that already exist. However, it does
this using the string "succ" method, which means that after
you get to inst9, the next instance is actually insu0. Fix
it so that we only increment the number part of the name.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
.../lib/deltacloud/drivers/mock/mock_driver.rb | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
b/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
index e22a615..1e16235 100644
--- a/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
+++ b/server/libexec/lib/deltacloud/drivers/mock/mock_driver.rb
@@ -152,7 +152,15 @@ class MockDriver < Deltacloud::BaseDriver
def create_instance(credentials, image_id, opts)
check_credentials( credentials )
ids = Dir[ "#{STORAGE_ROOT}/instances/*.yml" ].collect{|e| File.basename(
e, ".yml" )}
- next_id = ids.sort.last.succ
+
+ count = 0
+ while true
+ next_id = "inst" + count.to_s
+ if not ids.include?(next_id)
+ break
+ end
+ count = count + 1
+ end
realm_id = opts[:realm_id]
if ( realm_id.nil? )
--
1.6.6