summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Scheuring <andreas.scheuring@de.ibm.com>2017-03-08 09:49:12 +0100
committerAndreas Scheuring <andreas.scheuring@de.ibm.com>2017-04-20 11:34:44 +0200
commit5e74551f60115684f24c62fc3695dc48d6d7281e (patch)
treed73d607f601645f1f18af6ac6a4e4eb7bae8b97f
parentb66d960537b8dbba421125b49e5c541ccfde47bc (diff)
Validation for cpc_object_id config option1.1.0
This patch uses the newly created DPMObjectId config object to introduce validation for the cpc_object_id config option. The config option still accepts both, upper and lower case, but takes care of converting that value to lower case when used in the code. The HMC web services only supports lower case object-ids. Change-Id: I63bd5cdc699bde64151a7bf047e1349a7f509f3f Closes-Bug: #1663369
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:23 +0000 Reviewed-on: https://review.openstack.org/443022 Project: openstack/os-dpm Branch: refs/heads/master
-rwxr-xr-xos_dpm/config/config.py3
-rw-r--r--os_dpm/tests/unit/config/test_config.py34
2 files changed, 30 insertions, 7 deletions
diff --git a/os_dpm/config/config.py b/os_dpm/config/config.py
index c4847f2..811e2f5 100755
--- a/os_dpm/config/config.py
+++ b/os_dpm/config/config.py
@@ -14,6 +14,7 @@
14 14
15from oslo_config import cfg 15from oslo_config import cfg
16 16
17from os_dpm.config.cfg import DPMObjectIdOpt
17 18
18DPM_GROUP = cfg.OptGroup('dpm', 19DPM_GROUP = cfg.OptGroup('dpm',
19 title='DPM options', 20 title='DPM options',
@@ -33,7 +34,7 @@ COMMON_DPM_OPTS = [
33 User name for connection to the HMC"""), 34 User name for connection to the HMC"""),
34 cfg.StrOpt('hmc_password', secret=True, help=""" 35 cfg.StrOpt('hmc_password', secret=True, help="""
35 Password for connection to the HMC"""), 36 Password for connection to the HMC"""),
36 cfg.StrOpt('cpc_object_id', help=""" 37 DPMObjectIdOpt('cpc_object_id', help="""
37 DPM Object-id of the target CPC"""), 38 DPM Object-id of the target CPC"""),
38] 39]
39 40
diff --git a/os_dpm/tests/unit/config/test_config.py b/os_dpm/tests/unit/config/test_config.py
index 5e5d501..6988abe 100644
--- a/os_dpm/tests/unit/config/test_config.py
+++ b/os_dpm/tests/unit/config/test_config.py
@@ -18,19 +18,41 @@ from oslo_config.fixture import Config
18from oslotest import base 18from oslotest import base
19 19
20from os_dpm.config import config 20from os_dpm.config import config
21from os_dpm.tests.unit.config.test_types import VALID_DPM_OBJECT_ID
22from os_dpm.tests.unit.config.test_types import VALID_DPM_OBJECT_ID_UC
21 23
22 24
23class TestConfig(base.BaseTestCase): 25class TestConfig(base.BaseTestCase):
24 26
27 def setUp(self):
28 super(TestConfig, self).setUp()
29 self.conf = Config()
30
25 def test_register_opts(self): 31 def test_register_opts(self):
26 conf = Config() 32 self.conf.load_raw_values(group="dpm", hmc='host')
27 conf.load_raw_values(group="dpm", hmc='host') 33 self.conf.load_raw_values(group="dpm", hmc_username='username')
28 conf.load_raw_values(group="dpm", hmc_username='username') 34 self.conf.load_raw_values(group="dpm", hmc_password='password')
29 conf.load_raw_values(group="dpm", hmc_password='password') 35 self.conf.load_raw_values(group="dpm",
30 conf.load_raw_values(group="dpm", cpc_object_id='uuid') 36 cpc_object_id=VALID_DPM_OBJECT_ID)
31 37
32 config.register_opts() 38 config.register_opts()
33 self.assertEqual('host', cfg.CONF.dpm.hmc) 39 self.assertEqual('host', cfg.CONF.dpm.hmc)
34 self.assertEqual('username', cfg.CONF.dpm.hmc_username) 40 self.assertEqual('username', cfg.CONF.dpm.hmc_username)
35 self.assertEqual('password', cfg.CONF.dpm.hmc_password) 41 self.assertEqual('password', cfg.CONF.dpm.hmc_password)
36 self.assertEqual('uuid', cfg.CONF.dpm.cpc_object_id) 42 self.assertEqual(VALID_DPM_OBJECT_ID, cfg.CONF.dpm.cpc_object_id)
43
44 def test_register_opts_cpc_object_id_upper_case(self):
45 self.conf.load_raw_values(group="dpm",
46 cpc_object_id=VALID_DPM_OBJECT_ID_UC)
47 config.register_opts()
48 self.assertEqual(VALID_DPM_OBJECT_ID, cfg.CONF.dpm.cpc_object_id)
49
50 def test_invalid_opt(self):
51 self.conf.load_raw_values(group="dpm", cpc_object_id="foo")
52 config.register_opts()
53 # self.assertRaises can only be used with method calls
54 try:
55 cfg.CONF.dpm.cpc_object_id
56 self.fail()
57 except ValueError:
58 pass