Commit 433b8374 by Őry Máté

vm: fix _rename and its tests

parent 07e58f59
from __future__ import absolute_import, unicode_literals
from logging import getLogger
from re import match
from re import search
from django.core.exceptions import PermissionDenied
from django.utils import timezone
......@@ -203,13 +203,15 @@ class SaveAsTemplateOperation(InstanceOperation):
icon = 'save'
def _rename(self, name):
m = match("^(.*)( v(\d+))?$", name)
if is None:
v = 2
def _rename(name):
m = search(r" v(\d+)$", name)
if m:
v = int( + 1
name = search(r"^(.*) v(\d+)$", name).group(1)
v = int(v) + 1
return "%s v%d" % (, v)
v = 1
return "%s v%d" % (name, v)
def _operation(self, activity, user, system, timeout=300,
with_shutdown=True, **kwargs):
......@@ -44,11 +44,12 @@ class SaveAsTemplateOperationTestCase(TestCase):
assert in getattr(Instance, op_reg_name)
def test_rename(self):
assert SaveAsTemplateOperation._rename("foo") == "foo v2"
assert SaveAsTemplateOperation._rename("foo v2") == "foo v3"
assert SaveAsTemplateOperation._rename("foo v") == "foo v v2"
assert SaveAsTemplateOperation._rename("foo v9") == "foo v10"
assert SaveAsTemplateOperation._rename("foo v111") == "foo v112"
self.assertEqual(SaveAsTemplateOperation._rename("foo"), "foo v1")
self.assertEqual(SaveAsTemplateOperation._rename("foo v2"), "foo v3")
self.assertEqual(SaveAsTemplateOperation._rename("foo v"), "foo v v1")
self.assertEqual(SaveAsTemplateOperation._rename("foo v9"), "foo v10")
SaveAsTemplateOperation._rename("foo v111"), "foo v112")
class ShutdownOperationTestCase(TestCase):
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment