def cfg_init(): Linode.cfg = ConfigParser.ConfigParser() try: # READ CONFIGURATION FILE if Linode.cfg.read(Linode.SETTINGS_FILENAME) == []: log( "fatal", "Unable to open configuration file: No such file `%s' in the current directory." % (Linode.SETTINGS_FILENAME)) # VALIDATE MAIN SECTION Linode.validate_main_section() # ENABLE/DISABLE DEBUG if Linode.cfg.has_option("main", "debug") and Linode.cfg.getboolean( "main", "debug") == True: Linode.debug = True if Linode.cfg.has_option("main", "api_debug") and Linode.cfg.getboolean( "main", "api_debug") == True: libcloud.enable_debug(sys.stdout) except ConfigParser.Error as parsererr: log("fatal", "Unable to parse configuration file: %s" % parsererr) except Exception: log("fatal", extract_tb()) else: log("debug", "Configuration initialized.")
def main(argv=sys.argv[1:]): if '--debug' in argv: # TODO: improve --debug support, done here very early so we can # see everything possible. file_path = '/dev/stderr' file_handle = open(file_path, 'a') libcloud.enable_debug(file_handle) logging.basicConfig(filename=file_path, filemode='w', level=logging.DEBUG) myapp = RaxCliApp() return myapp.run(argv)
def test_debug_log_class_handles_request(self): with StringIO() as fh: libcloud.enable_debug(fh) conn = Connection(url='http://test.com/') conn.connect() self.assertEqual(conn.connection.host, 'http://test.com') with requests_mock.mock() as m: m.get('http://test.com/test', text='data') conn.request('/test') log = fh.getvalue() self.assertTrue(isinstance(conn.connection, LoggingConnection)) self.assertIn('-i -X GET', log) self.assertIn('data', log)
def test_debug_log_class_handles_request(self): with StringIO() as fh: libcloud.enable_debug(fh) conn = Connection(url="http://test.com/") conn.connect() self.assertEqual(conn.connection.host, "http://test.com") with requests_mock.mock() as m: m.get("http://test.com/test", text="data") conn.request("/test") log = fh.getvalue() self.assertTrue(isinstance(conn.connection, LoggingConnection)) self.assertIn("-i -X GET", log) self.assertIn("data", log)
def test_debug_log_class_handles_request_with_compression(self): request = zlib.compress(b'data') with StringIO() as fh: libcloud.enable_debug(fh) conn = Connection(url='http://test.com/') conn.connect() self.assertEqual(conn.connection.host, 'http://test.com') with requests_mock.mock() as m: m.get('http://test.com/test', content=request, headers={'content-encoding': 'zlib'}) conn.request('/test') log = fh.getvalue() self.assertTrue(isinstance(conn.connection, LoggingConnection)) self.assertIn('-i -X GET', log)
def test_debug_log_class_handles_request_with_compression(self): request = zlib.compress(b"data") with StringIO() as fh: libcloud.enable_debug(fh) conn = Connection(url="http://test.com/") conn.connect() self.assertEqual(conn.connection.host, "http://test.com") with requests_mock.mock() as m: m.get( "http://test.com/test", content=request, headers={"content-encoding": "zlib"}, ) conn.request("/test") log = fh.getvalue() self.assertTrue(isinstance(conn.connection, LoggingConnection)) self.assertIn("-i -X GET", log)
def test_debug_method_uses_log_class(self): with StringIO() as fh: libcloud.enable_debug(fh) conn = Connection(timeout=10) conn.connect() self.assertTrue(isinstance(conn.connection, LoggingConnection))
def test_nodes(self): """ Test that you can list nodes and that the responding objects match basic values, list (ip), and dict (extra). """ nodes = self.instance.list_nodes() for node in NODES: match = [n for n in nodes if n.id == node['id']] self.assertTrue(len(match) == 1) match = match[0] self.assertEqual(match.id, node['id']) self.assertEqual(match.name, node['name']) self.assertEqual(match.private_ips, node['private_ips']) self.assertEqual(match.public_ips, node['public_ips']) self.assertEqual(match.extra, node['extra']) def test_ex_report_data(self): """ Test that a raw request can correctly return the data """ data = self.instance.ex_report_data() self.assertEqual(data, REPORT_DATA) if __name__ == '__main__': import libcloud with open('/tmp/testing.log', 'w') as f: libcloud.enable_debug(f) sys.exit(unittest.main())
def debug(): """ Enable vcloud/libcloud logging """ libcloud.enable_debug(sys.stdout)
import os, sys import libcloud from libcloud.storage.types import Provider from libcloud.storage.providers import get_driver libcloud.enable_debug(sys.stdout) class Cloudy(object): def cloudy(self): S3_ACCESS_ID = os.getenv('AWS_ACCESS_KEY_ID') S3_SECRET_KEY = os.getenv('AWS_SECRET_ACCESS_KEY') Driver = get_driver(Provider.S3) conn = Driver(S3_ACCESS_ID, S3_SECRET_KEY) containers = conn.list_containers() print('%d containers:' % len(containers)) for container in containers: print(' - %s' % container.name) if __name__ == '__main__': Cloudy().cloudy()