[PATCH] [Kimchi] Issue #1050: Rename template with existing template name

From: Archana Singh <archus@linux.vnet.ibm.com> If template name is change to update and the new template name to be updated already exists then exception is raised stating name already exists. Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- model/templates.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/model/templates.py b/model/templates.py index c3e24e1..e5663ad 100644 --- a/model/templates.py +++ b/model/templates.py @@ -231,6 +231,14 @@ class TemplateModel(object): def update(self, name, params): edit_template = self.lookup(name) + # If new name is not same as existing name + # and new name already exists: raise exception + with self.objstore as session: + if name != params['name'] \ + and params['name'] in session.get_list('template'): + raise InvalidOperation("KCHTMPL0001E", + {'name': params['name']}) + # Valid interfaces interfaces = params.get('interfaces', []) validate_interfaces(interfaces) -- 2.7.4

Reviewed-By: Lucio Correia <luciojhc@linux.vnet.ibm.com> On 23/10/2016 10:38, archus@linux.vnet.ibm.com wrote:
From: Archana Singh <archus@linux.vnet.ibm.com>
If template name is change to update and the new template name to be updated already exists then exception is raised stating name already exists.
Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- model/templates.py | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/model/templates.py b/model/templates.py index c3e24e1..e5663ad 100644 --- a/model/templates.py +++ b/model/templates.py @@ -231,6 +231,14 @@ class TemplateModel(object): def update(self, name, params): edit_template = self.lookup(name)
+ # If new name is not same as existing name + # and new name already exists: raise exception + with self.objstore as session: + if name != params['name'] \ + and params['name'] in session.get_list('template'): + raise InvalidOperation("KCHTMPL0001E", + {'name': params['name']}) + # Valid interfaces interfaces = params.get('interfaces', []) validate_interfaces(interfaces)
-- Lucio Correia Software Engineer IBM LTC Brazil

Hi, Some tests are failing with this patch: ***** Running unit test: test_template... FAILED ====================================================================== FAIL: test_customized_network (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 397, in test_customized_network self.assertEquals(200, resp.status) AssertionError: 200 != 500 ====================================================================== FAIL: test_customized_storagepool (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 459, in test_customized_storagepool self.assertEquals(200, resp.status) AssertionError: 200 != 500 ====================================================================== FAIL: test_customized_tmpl (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 212, in test_customized_tmpl self.assertEquals(200, resp.status) AssertionError: 200 != 500 ====================================================================== FAIL: test_tmpl_integrity (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 516, in test_tmpl_integrity self.assertEquals(204, resp.status) AssertionError: 204 != 400 ---------------------------------------------------------------------- Ran 5 tests in 4.866s On 10/23/2016 10:38 AM, archus@linux.vnet.ibm.com wrote:
From: Archana Singh <archus@linux.vnet.ibm.com>
If template name is change to update and the new template name to be updated already exists then exception is raised stating name already exists.
Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- model/templates.py | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/model/templates.py b/model/templates.py index c3e24e1..e5663ad 100644 --- a/model/templates.py +++ b/model/templates.py @@ -231,6 +231,14 @@ class TemplateModel(object): def update(self, name, params): edit_template = self.lookup(name)
+ # If new name is not same as existing name + # and new name already exists: raise exception + with self.objstore as session: + if name != params['name'] \ + and params['name'] in session.get_list('template'): + raise InvalidOperation("KCHTMPL0001E", + {'name': params['name']}) + # Valid interfaces interfaces = params.get('interfaces', []) validate_interfaces(interfaces)

Hi Aline, The testcases are failing even without this patch applied. Could you please check if the testcases are failing for you too without this patch applied. Thanks, Archana Singh On 10/28/2016 07:26 PM, Aline Manera wrote:
Hi,
Some tests are failing with this patch:
***** Running unit test: test_template... FAILED ====================================================================== FAIL: test_customized_network (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 397, in test_customized_network self.assertEquals(200, resp.status) AssertionError: 200 != 500
====================================================================== FAIL: test_customized_storagepool (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 459, in test_customized_storagepool self.assertEquals(200, resp.status) AssertionError: 200 != 500
====================================================================== FAIL: test_customized_tmpl (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 212, in test_customized_tmpl self.assertEquals(200, resp.status) AssertionError: 200 != 500
====================================================================== FAIL: test_tmpl_integrity (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 516, in test_tmpl_integrity self.assertEquals(204, resp.status) AssertionError: 204 != 400
---------------------------------------------------------------------- Ran 5 tests in 4.866s
On 10/23/2016 10:38 AM, archus@linux.vnet.ibm.com wrote:
From: Archana Singh <archus@linux.vnet.ibm.com>
If template name is change to update and the new template name to be updated already exists then exception is raised stating name already exists.
Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- model/templates.py | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/model/templates.py b/model/templates.py index c3e24e1..e5663ad 100644 --- a/model/templates.py +++ b/model/templates.py @@ -231,6 +231,14 @@ class TemplateModel(object): def update(self, name, params): edit_template = self.lookup(name)
+ # If new name is not same as existing name + # and new name already exists: raise exception + with self.objstore as session: + if name != params['name'] \ + and params['name'] in session.get_list('template'): + raise InvalidOperation("KCHTMPL0001E", + {'name': params['name']}) + # Valid interfaces interfaces = params.get('interfaces', []) validate_interfaces(interfaces)

Hi Archana, On 11/03/2016 02:02 PM, Archana Singh wrote:
Hi Aline,
The testcases are failing even without this patch applied. Could you please check if the testcases are failing for you too without this patch applied.
No! The tests only fail with this patch set applied. Without it, only a test on tests_rest.py fails.
Thanks, Archana Singh
On 10/28/2016 07:26 PM, Aline Manera wrote:
Hi,
Some tests are failing with this patch:
***** Running unit test: test_template... FAILED ====================================================================== FAIL: test_customized_network (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 397, in test_customized_network self.assertEquals(200, resp.status) AssertionError: 200 != 500
====================================================================== FAIL: test_customized_storagepool (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 459, in test_customized_storagepool self.assertEquals(200, resp.status) AssertionError: 200 != 500
====================================================================== FAIL: test_customized_tmpl (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 212, in test_customized_tmpl self.assertEquals(200, resp.status) AssertionError: 200 != 500
====================================================================== FAIL: test_tmpl_integrity (test_template.TemplateTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "test_template.py", line 516, in test_tmpl_integrity self.assertEquals(204, resp.status) AssertionError: 204 != 400
---------------------------------------------------------------------- Ran 5 tests in 4.866s
On 10/23/2016 10:38 AM, archus@linux.vnet.ibm.com wrote:
From: Archana Singh <archus@linux.vnet.ibm.com>
If template name is change to update and the new template name to be updated already exists then exception is raised stating name already exists.
Signed-off-by: Archana Singh <archus@linux.vnet.ibm.com> --- model/templates.py | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/model/templates.py b/model/templates.py index c3e24e1..e5663ad 100644 --- a/model/templates.py +++ b/model/templates.py @@ -231,6 +231,14 @@ class TemplateModel(object): def update(self, name, params): edit_template = self.lookup(name)
+ # If new name is not same as existing name + # and new name already exists: raise exception + with self.objstore as session: + if name != params['name'] \ + and params['name'] in session.get_list('template'): + raise InvalidOperation("KCHTMPL0001E", + {'name': params['name']}) + # Valid interfaces interfaces = params.get('interfaces', []) validate_interfaces(interfaces)

Applied. Thanks. Regards, Aline Manera
participants (4)
-
Aline Manera
-
Archana Singh
-
archus@linux.vnet.ibm.com
-
Lucio Correia