1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 import unittest
18 from cm_api.endpoints.cms import ClouderaManager
19 from cm_api.endpoints.types import config_to_json, ApiConfig
20 from cm_api_tests import utils
21
22 try:
23 import json
24 except ImportError:
25 import simplejson as json
26
28
30 SUMMARY = """
31 {
32 "items" : [ {
33 "name" : "blacklisted_parcel_products",
34 "value" : "foo,bar"
35 } ]
36 }
37 """
38 FULL = """
39 {
40 "items" : [ {
41 "name" : "blacklisted_parcel_products",
42 "value" : "foo,bar",
43 "required" : false,
44 "default" : "",
45 "displayName" : "Blacklisted Products",
46 "description" : "Parcels for blacklisted products will not be distributed to the host, nor activated for process execution. Already distributed parcels will be undistributed. Already running process will not be affected until the next restart.",
47 "validationState" : "OK"
48 }, {
49 "name" : "rm_enabled",
50 "required" : false,
51 "default" : "false",
52 "displayName" : "Enable Resource Management",
53 "description" : "Enables resource management for all roles on this host.",
54 "validationState" : "OK"
55 } ]
56 }
57 """
58
59 resource = utils.MockResource(self)
60 cms = ClouderaManager(resource)
61
62 resource.expect("GET", "/cm/allHosts/config", retdata=json.loads(SUMMARY))
63 cfg = cms.get_all_hosts_config()
64 self.assertIsInstance(cfg, dict)
65 self.assertEqual(1, len(cfg))
66 self.assertEqual('foo,bar', cfg.get('blacklisted_parcel_products'))
67
68 resource.expect("GET", "/cm/allHosts/config", params={ 'view' : 'full' },
69 retdata=json.loads(FULL))
70 cfg = cms.get_all_hosts_config(view='full')
71 self.assertIsInstance(cfg, dict)
72 self.assertEqual(2, len(cfg))
73 self.assertIsInstance(cfg['blacklisted_parcel_products'], ApiConfig)
74 self.assertFalse(cfg['blacklisted_parcel_products'].required)
75 self.assertEqual('OK', cfg['rm_enabled'].validationState)
76
77 cfg = { 'blacklisted_parcel_products' : 'bar' }
78 resource.expect("PUT", "/cm/allHosts/config", data=config_to_json(cfg),
79 retdata=json.loads(SUMMARY))
80 cms.update_all_hosts_config(cfg)
81