Validation logic for partition name will fail if the host name has '-'

The validation logic for Instance name fails
if the host name has '-' character.

https://github.com/openstack/nova-dpm/blob/1.0.0/nova_dpm/virt/dpm/vm.py#L69-L87

closes-Bug: 1670949

Change-Id: I82bf4313e46dc273e7307900549fa488cf43b5bd
Signed-off-by: Prabhat Ranjan <pranjank@in.ibm.com>
This commit is contained in:
Prabhat Ranjan
2017-04-11 18:50:35 +05:30
parent f10f0b4519
commit 74e8e972a2
2 changed files with 60 additions and 9 deletions

View File

@@ -0,0 +1,51 @@
# Copyright 2016 IBM Corp. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from nova.test import TestCase
from nova_dpm.virt.dpm import vm
class ValidPartitionNameTestCase(TestCase):
def setUp(self):
super(ValidPartitionNameTestCase, self).setUp()
def test_is_valid_partition_name(self):
# All name should be in this format
# OpenStack-hostname-[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}
# where hostname is basically host of 'self.flags(host='foo').
self.flags(host='foo')
name1 = 'OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c3'
self.assertTrue(vm.is_valid_partition_name(name1))
self.flags(host='foo-bar')
name2 = 'OpenStack-foo-bar-6511ee0f-0d64-4392-b9e0-cdbea10a17c3'
self.assertTrue(vm.is_valid_partition_name(name2))
self.flags(host='foo-bar')
name3 = 'invalid_name'
self.assertFalse(vm.is_valid_partition_name(name3))
self.flags(host='foo')
name4 = 'fooOpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c3'
self.assertFalse(vm.is_valid_partition_name(name4))
self.flags(host='foo')
# Name should be in this format
# OpenStack-hostname-[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}
# but name5 is in
# OpenStack-hostname-[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{13}
# See at last instead of 12 character it is 13 character.
name5 = 'OpenStack-foo-6511ee0f-0d64-4392-b9e0-cdbea10a17c31'
self.assertFalse(vm.is_valid_partition_name(name5))

View File

@@ -36,8 +36,6 @@ from zhmcclient._exceptions import NotFound
CONF = conf.CONF
OPENSTACK_PREFIX = 'OpenStack'
CPCSUBSET_PREFIX = 'CPCSubset='
UUID_PATTERN = re.compile(
r'^[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}$', re.IGNORECASE)
DPM_TO_NOVA_STATE = {
@@ -72,17 +70,19 @@ def is_valid_partition_name(name):
which is managed by openstack
The valid format is
'OpenStack-Instance-6511ee0f-0d64-4392-b9e0-cdbea10a17c3'
'OpenStack-hostname-6511ee0f-0d64-4392-b9e0-cdbea10a17c3'
where hostname is CONF.host
:param name: name of partition
:return: bool
"""
split_name = name.split('-', 2)
if len(split_name) > 2:
if split_name[0] == OPENSTACK_PREFIX:
if split_name[1] == CONF.host:
if UUID_PATTERN.match(split_name[2]):
return True
partition_name_regx = (
re.compile(r"^" + OPENSTACK_PREFIX +
"-" +
CONF.host +
"-[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}$"))
if partition_name_regx.match(name):
return True
return False