Package cm_api_tests :: Module test_cms
[hide private]
[frames] | no frames]

Source Code for Module cm_api_tests.test_cms

 1  # Licensed to Cloudera, Inc. under one 
 2  # or more contributor license agreements.  See the NOTICE file 
 3  # distributed with this work for additional information 
 4  # regarding copyright ownership.  Cloudera, Inc. licenses this file 
 5  # to you under the Apache License, Version 2.0 (the 
 6  # "License"); you may not use this file except in compliance 
 7  # with the License.  You may obtain 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, 
13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14  # See the License for the specific language governing permissions and 
15  # limitations under the License. 
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   
27 -class TestCMS(unittest.TestCase):
28
29 - def test_all_hosts_config(self):
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