Browse Source

Validation for cpc_object_id config option

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
Andreas Scheuring 2 years ago
parent
commit
5e74551f60
2 changed files with 30 additions and 7 deletions
  1. 2
    1
      os_dpm/config/config.py
  2. 28
    6
      os_dpm/tests/unit/config/test_config.py

+ 2
- 1
os_dpm/config/config.py View File

@@ -14,6 +14,7 @@
14 14
 
15 15
 from oslo_config import cfg
16 16
 
17
+from os_dpm.config.cfg import DPMObjectIdOpt
17 18
 
18 19
 DPM_GROUP = cfg.OptGroup('dpm',
19 20
                          title='DPM options',
@@ -33,7 +34,7 @@ COMMON_DPM_OPTS = [
33 34
     User name for connection to the HMC"""),
34 35
     cfg.StrOpt('hmc_password', secret=True, help="""
35 36
     Password for connection to the HMC"""),
36
-    cfg.StrOpt('cpc_object_id', help="""
37
+    DPMObjectIdOpt('cpc_object_id', help="""
37 38
     DPM Object-id of the target CPC"""),
38 39
 ]
39 40
 

+ 28
- 6
os_dpm/tests/unit/config/test_config.py View File

@@ -18,19 +18,41 @@ from oslo_config.fixture import Config
18 18
 from oslotest import base
19 19
 
20 20
 from os_dpm.config import config
21
+from os_dpm.tests.unit.config.test_types import VALID_DPM_OBJECT_ID
22
+from os_dpm.tests.unit.config.test_types import VALID_DPM_OBJECT_ID_UC
21 23
 
22 24
 
23 25
 class TestConfig(base.BaseTestCase):
24 26
 
27
+    def setUp(self):
28
+        super(TestConfig, self).setUp()
29
+        self.conf = Config()
30
+
25 31
     def test_register_opts(self):
26
-        conf = Config()
27
-        conf.load_raw_values(group="dpm", hmc='host')
28
-        conf.load_raw_values(group="dpm", hmc_username='username')
29
-        conf.load_raw_values(group="dpm", hmc_password='password')
30
-        conf.load_raw_values(group="dpm", cpc_object_id='uuid')
32
+        self.conf.load_raw_values(group="dpm", hmc='host')
33
+        self.conf.load_raw_values(group="dpm", hmc_username='username')
34
+        self.conf.load_raw_values(group="dpm", hmc_password='password')
35
+        self.conf.load_raw_values(group="dpm",
36
+                                  cpc_object_id=VALID_DPM_OBJECT_ID)
31 37
 
32 38
         config.register_opts()
33 39
         self.assertEqual('host', cfg.CONF.dpm.hmc)
34 40
         self.assertEqual('username', cfg.CONF.dpm.hmc_username)
35 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

Loading…
Cancel
Save