summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Scheuring <andreas.scheuring@de.ibm.com>2017-03-08 09:35:00 +0100
committerAndreas Scheuring <andreas.scheuring@de.ibm.com>2017-04-20 11:34:44 +0200
commitb66d960537b8dbba421125b49e5c541ccfde47bc (patch)
tree9d9d817dced1d95437e0ab1f60e96fd4e7590e17
parenta915761d304e83915531482de3f7731892107627 (diff)
Add DPMObjectId configuration object
This patch adds a new DPMObjectId configuraiton object and corresponding type to os-dpm. This new configuration object represents a DPM object id. It inlcudes validation if the given config value has the correct object-id format. It allows upper and lower case values to be defined, however internally it converts everything to lower case (which is required by the hmc webservices). Example for a valid object-id: fa1f2466-12df-311a-804c-4ed2cc1d656b Change-Id: I6b446f9634a018e005e112cf1e3f9cc7f6fb4a1b
Notes
Notes (review): Code-Review+1: Andreas Maier <maiera@de.ibm.com> Code-Review+2: Andreas Scheuring <andreas.scheuring@de.ibm.com> Workflow+1: Andreas Scheuring <andreas.scheuring@de.ibm.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 10 Jul 2017 13:46:21 +0000 Reviewed-on: https://review.openstack.org/443021 Project: openstack/os-dpm Branch: refs/heads/master
-rw-r--r--os_dpm/config/cfg.py30
-rw-r--r--os_dpm/config/types.py36
-rw-r--r--os_dpm/constants.py17
-rw-r--r--os_dpm/tests/unit/config/test_cfg.py26
-rw-r--r--os_dpm/tests/unit/config/test_types.py48
5 files changed, 157 insertions, 0 deletions
diff --git a/os_dpm/config/cfg.py b/os_dpm/config/cfg.py
new file mode 100644
index 0000000..65a82d9
--- /dev/null
+++ b/os_dpm/config/cfg.py
@@ -0,0 +1,30 @@
1# Copyright 2017 IBM Corp. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from oslo_config import cfg
16
17from os_dpm.config.types import DPMObjectIdType
18
19
20class DPMObjectIdOpt(cfg.Opt):
21 def __init__(self, name, help=None):
22 """Option with DPM Object-Id type
23
24 Option with ``type`` :class:`DPMObjectIdType`
25
26 :param name: the option's name
27 :param help: an explanation of how the option is used
28 """
29 super(DPMObjectIdOpt, self).__init__(name, type=DPMObjectIdType(),
30 help=help)
diff --git a/os_dpm/config/types.py b/os_dpm/config/types.py
new file mode 100644
index 0000000..63ca482
--- /dev/null
+++ b/os_dpm/config/types.py
@@ -0,0 +1,36 @@
1# Copyright 2017 IBM Corp. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16from oslo_config import cfg
17
18from os_dpm import constants as const
19
20
21class DPMObjectIdType(cfg.types.String):
22 def __init__(self):
23 """DPM Object-Id Type.
24
25 DPM Object-Id values are returned as lower case str objects.
26 If the configuration value is provided as upper case, this type
27 converts it to lower case.
28 """
29
30 super(DPMObjectIdType, self).__init__(
31 type_name='DPM Object-Id value', ignore_case=True, max_length=36,
32 regex="^" + const.OBJECT_ID_REGEX + "$")
33
34 def __call__(self, value):
35 val = super(DPMObjectIdType, self).__call__(value)
36 return val.lower()
diff --git a/os_dpm/constants.py b/os_dpm/constants.py
new file mode 100644
index 0000000..259ff2f
--- /dev/null
+++ b/os_dpm/constants.py
@@ -0,0 +1,17 @@
1# Copyright (c) 2017 IBM Corp.
2#
3# All Rights Reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may
6# not use this file except in compliance with the License. You may obtain
7# a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations
15# under the License.
16
17OBJECT_ID_REGEX = "[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}"
diff --git a/os_dpm/tests/unit/config/test_cfg.py b/os_dpm/tests/unit/config/test_cfg.py
new file mode 100644
index 0000000..980283a
--- /dev/null
+++ b/os_dpm/tests/unit/config/test_cfg.py
@@ -0,0 +1,26 @@
1# Copyright 2017 IBM Corp. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15
16from oslotest import base
17
18from os_dpm.config import cfg
19
20
21class TestDPMObjectIdOpt(base.BaseTestCase):
22 def test_object_id_opt(self):
23 opt = cfg.DPMObjectIdOpt("foo-name", help="foo-help")
24 self.assertEqual("foo-help", opt.help)
25 self.assertEqual("foo-name", opt.name)
26 self.assertEqual(cfg.DPMObjectIdType, type(opt.type))
diff --git a/os_dpm/tests/unit/config/test_types.py b/os_dpm/tests/unit/config/test_types.py
new file mode 100644
index 0000000..b4beae2
--- /dev/null
+++ b/os_dpm/tests/unit/config/test_types.py
@@ -0,0 +1,48 @@
1# Copyright 2017 IBM Corp. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15from oslotest import base
16
17from os_dpm.config import types
18
19VALID_DPM_OBJECT_ID = "fa1f2466-12df-311a-804c-4ed2cc1d656b"
20VALID_DPM_OBJECT_ID_UC = "FA1F2466-12DF-311A-804C-4ED2CC1D656B"
21
22
23class TestDPMObjectIdType(base.BaseTestCase):
24 conf_type = types.DPMObjectIdType()
25
26 def test_empty_value_fail(self):
27 self.assertRaises(ValueError, self.conf_type, '')
28
29 def test_invalid_value_fail(self):
30 self.assertRaises(ValueError, self.conf_type, 'foobar')
31
32 def test_valid_object_id(self):
33 self.assertEqual(VALID_DPM_OBJECT_ID,
34 self.conf_type(VALID_DPM_OBJECT_ID))
35
36 def test_valid_object_id_ignore_case(self):
37 self.assertEqual(VALID_DPM_OBJECT_ID,
38 self.conf_type(VALID_DPM_OBJECT_ID_UC))
39
40 def test_object_id_too_long(self):
41 self.assertRaises(ValueError, self.conf_type,
42 VALID_DPM_OBJECT_ID + "1")
43
44 def test_repr(self):
45 t = types.DPMObjectIdType()
46 self.assertEqual(
47 "String(regex='^[a-f0-9]{8}-([a-f0-9]{4}-){3}[a-f0-9]{12}$')",
48 repr(t))