Esempio n. 1
0
 def setUp(self):
     config_file = os.environ.get('CIRCONUS_CONFIG')
     cfg = config.load_config(configfile=config_file, nocache=True)
     account = cfg.get('general', 'default_account')
     token = cfg.get('tokens', account)
     api = circonusdata.CirconusData(token)
     self.api = api
    def test_two_merged_config_files(self):
        config_txt_1 = '''
[general]
default_account=sampleaccount
appname=sample appname
'''
        config_txt_2 = '''
[tokens]
sampleaccount=AAAAAAAA-1234-5678-9999-BBBBBBBB
'''
        with NamedTemporaryFile(mode='w+') as tmp_file_1:
            with NamedTemporaryFile(mode='w+') as tmp_file_2:
                tmp_file_1.write(config_txt_1)
                tmp_file_2.write(config_txt_2)
                for cfl in [tmp_file_1, tmp_file_2]:
                    cfl.file.flush()
                    cfl.file.seek(0)
                cfg = config.load_config(
                    configfile=[
                        tmp_file_1.name,
                        tmp_file_2.name
                    ],
                    nocache=True
                )
            self.assertEqual(cfg.get('general', 'appname'), 'sample appname')
            self.assertEqual(cfg.get('tokens', 'sampleaccount'), 'AAAAAAAA-1234-5678-9999-BBBBBBBB')
Esempio n. 3
0
    def test_single_config_file(self):
        with NamedTemporaryFile(mode='w+') as tmp_file:
            tmp_file.file.write('''
[general]
default_account=sampleaccount
appname=sample appname

[tokens]
sampleaccount=AAAAAAAA-1234-5678-9999-BBBBBBBB
''')
            tmp_file.file.flush()
            tmp_file.file.seek(0)
            cfg = config.load_config(configfile=tmp_file.name, nocache=True)
            self.assertEqual(cfg.get('general', 'appname'), 'sample appname')
            cfg_cached = config.load_config()
            self.assertEqual(cfg_cached.get('general', 'appname'),
                             'sample appname')
 def setUp(self):
     config_file = os.environ.get('CIRCONUS_CONFIG')
     cfg = config.load_config(configfile=config_file, nocache=True)
     account = cfg.get('general', 'default_account')
     appname = cfg.get('general', 'appname')
     token = cfg.get('tokens', account)
     api = circonusapi.CirconusAPI(token)
     api.appname = appname
     self.config = cfg
     self.api = api
Esempio n. 5
0
 def setUp(self):
     config_file = os.environ.get('CIRCONUS_CONFIG')
     cfg = config.load_config(configfile=config_file, nocache=True)
     account = cfg.get('general', 'default_account')
     appname = cfg.get('general', 'appname')
     token = cfg.get('tokens', account)
     api = circonusapi.CirconusAPI(token)
     api.appname = appname
     self.config = cfg
     self.api = api
    def test_single_config_file(self):
        with NamedTemporaryFile(mode='w+') as tmp_file:
            tmp_file.file.write(
                '''
[general]
default_account=sampleaccount
appname=sample appname

[tokens]
sampleaccount=AAAAAAAA-1234-5678-9999-BBBBBBBB
'''
            )
            tmp_file.file.flush()
            tmp_file.file.seek(0)
            cfg = config.load_config(
                configfile=tmp_file.name,
                nocache=True
            )
            self.assertEqual(cfg.get('general', 'appname'), 'sample appname')
            cfg_cached = config.load_config()
            self.assertEqual(cfg_cached.get('general', 'appname'), 'sample appname')
Esempio n. 7
0
    def test_two_merged_config_files(self):
        config_txt_1 = '''
[general]
default_account=sampleaccount
appname=sample appname
'''
        config_txt_2 = '''
[tokens]
sampleaccount=AAAAAAAA-1234-5678-9999-BBBBBBBB
'''
        with NamedTemporaryFile(mode='w+') as tmp_file_1:
            with NamedTemporaryFile(mode='w+') as tmp_file_2:
                tmp_file_1.write(config_txt_1)
                tmp_file_2.write(config_txt_2)
                for cfl in [tmp_file_1, tmp_file_2]:
                    cfl.file.flush()
                    cfl.file.seek(0)
                cfg = config.load_config(
                    configfile=[tmp_file_1.name, tmp_file_2.name],
                    nocache=True)
            self.assertEqual(cfg.get('general', 'appname'), 'sample appname')
            self.assertEqual(cfg.get('tokens', 'sampleaccount'),
                             'AAAAAAAA-1234-5678-9999-BBBBBBBB')
Esempio n. 8
0
      resources to the same endpoint).

The content of each resource is sent directly to the API. See the API
documentation for information on what this should contain, or use circonusvi
to take a look at existing resources for examples.
"""
import getopt
import json
import re
import sys

from circonusapi import circonusapi
from circonusapi import config
from circuslib import util

conf = config.load_config()

options = {
    'account': conf.get('general', 'default_account'),
    'debug': False
}

def usage():
    print "Usage:"
    print sys.argv[0], "[options] [FILENAME]"
    print
    print "Reads in a json file with a list of resources to add"
    print
    print "  -a -- Specify which account to use"
    print "  -d -- Enable debug mode"
 def test_no_config_file(self):
     cfg = config.load_config(configfile='nope', nocache=True)
     self.assertEqual(cfg.sections(), [])
Esempio n. 10
0
 def test_no_config_file(self):
     cfg = config.load_config(configfile='nope', nocache=True)
     self.assertEqual(cfg.sections(), [])