def test_get_setting_without_config_file(self): if os.path.exists('test_get_setting.conf'): os.remove('test_get_setting.conf') hostlists.hostlists.CONF_FILE = os.path.abspath( 'test_get_setting.conf') result = hostlists.get_setting('key') self.assertIsNone(result)
def expand(value,name='hosttag',method=None): state='ALL' group='False' tags='' templist=[] # Parse the parameters passed temp=value.split(':') if len(temp): tags=temp[0] for index in range(0,len(temp)): temp2=temp[index].split('=') if len(temp2) == 2: if temp2[0].lower() == 'tags': tags=temp2[1] if temp2[0].lower() == 'group': group=temp2[1] else: return [] # Get a list of servers from our settings and try each in turn settings=hostlists.get_setting('hosttag_plugin') for server in settings['servers']: url='http://%s/api/host?tags=%s&group=%s' % (server,tags,group) try: result=json.load(urllib2.urlopen(url)) except urllib2.HTTPError: # Get an error from the server rest api result=[] if len(result): for host in result: templist.append(host['name']) return templist
def test_get_setting_with_config_file(self): expected_dict = {'key': 'value'} with open('test_get_setting.conf', 'w') as tf: json.dump(expected_dict, tf) hostlists.hostlists.CONF_FILE = os.path.abspath( 'test_get_setting.conf') result = hostlists.get_setting('key') os.remove('test_get_setting.conf') self.assertEqual(result, 'value')
def server_setting(server='default', setting=None): if not setting: return None settings = hostlists.get_setting('haproxy_plugin') if not settings: return None if server in settings.keys(): if setting in settings[server].keys(): return settings[server][setting] return None
def test_get_setting_with_config_file(self): expected_dict = { 'key': 'value' } with open('test_get_setting.conf', 'w') as tf: json.dump(expected_dict, tf) hostlists.CONF_FILE = os.path.abspath('test_get_setting.conf') result = hostlists.get_setting('key') os.remove('test_get_setting.conf') self.assertEqual(result, 'value')
def test_get_setting_without_config_file(self): if os.path.exists('test_get_setting.conf'): os.remove('test_get_setting.conf') hostlists.CONF_FILE = os.path.abspath('test_get_setting.conf') result = hostlists.get_setting('key') self.assertIsNone(result)