Commit 07e58f59 by Őry Máté

Merge branch 'feature-operations-view'

parents 21a68f69 24bad338
......@@ -112,6 +112,7 @@ class VmOperationViewTestCase(unittest.TestCase):
view.as_view()(request, pk=1234).render().status_code, 200)
def FakeRequestFactory(*args, **kwargs):
''' FakeRequestFactory, FakeMessages and FakeRequestContext are good for
mocking out django views; they are MUCH faster than the Django test client.
from __future__ import absolute_import, unicode_literals
from logging import getLogger
from re import match
from django.core.exceptions import PermissionDenied
from django.utils import timezone
......@@ -202,7 +203,15 @@ class SaveAsTemplateOperation(InstanceOperation):
icon = 'save'
def _operation(self, activity, name, user, system, timeout=300,
def _rename(self, name):
m = match("^(.*)( v(\d+))?$", name)
if is None:
v = 2
v = int(v) + 1
return "%s v%d" % (, v)
def _operation(self, activity, user, system, timeout=300,
with_shutdown=True, **kwargs):
if with_shutdown:
......@@ -219,7 +228,7 @@ class SaveAsTemplateOperation(InstanceOperation):
'description': self.instance.description,
'lease':, # Can be problem in new VM
'max_ram_size': self.instance.max_ram_size,
'name': name,
'name': self._rename(,
'num_cores': self.instance.num_cores,
'owner': user,
'parent': self.instance.template, # Can be problem
......@@ -43,6 +43,13 @@ class SaveAsTemplateOperationTestCase(TestCase):
def test_operation_registered(self):
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"
class ShutdownOperationTestCase(TestCase):
def test_operation_registered(self):
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