Ejemplo n.º 1
0
 def setUp(self):
     """
     Creates the object patching the actual connection.
     """
     conn_params = {'hostname': 'dummy.host.org',
                    'port': 8822,
                    'username': '******',
                    'key': '~/.ssh/ubuntu_ssh',
                    'timeout': '600'}
     _, self.tmp_file = tempfile.mkstemp()
     os.environ['LIBCLOUD_DEBUG'] = self.tmp_file
     _init_once()
     self.ssh_cli = ParamikoSSHClient(**conn_params)
Ejemplo n.º 2
0
 def setUp(self):
     """
     Creates the object patching the actual connection.
     """
     conn_params = {'hostname': 'dummy.host.org',
                    'port': 8822,
                    'username': '******',
                    'key': '~/.ssh/ubuntu_ssh',
                    'timeout': '600'}
     _, self.tmp_file = tempfile.mkstemp()
     os.environ['LIBCLOUD_DEBUG'] = self.tmp_file
     _init_once()
     self.ssh_cli = ParamikoSSHClient(**conn_params)
Ejemplo n.º 3
0
 def setUp(self):
     """
     Creates the object patching the actual connection.
     """
     conn_params = {
         "hostname": "dummy.host.org",
         "port": 8822,
         "username": "******",
         "key": "~/.ssh/ubuntu_ssh",
         "timeout": "600",
     }
     _, self.tmp_file = tempfile.mkstemp()
     os.environ["LIBCLOUD_DEBUG"] = self.tmp_file
     _init_once()
     self.ssh_cli = ParamikoSSHClient(**conn_params)
Ejemplo n.º 4
0
    def test_init_once_and_debug_mode(self):
        # Debug mode is disabled
        _init_once()

        self.assertEqual(LoggingConnection.log, None)

        if have_paramiko:
            logger = paramiko.util.logging.getLogger()
            paramiko_log_level = logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.WARNING)

        # Enable debug mode
        os.environ['LIBCLOUD_DEBUG'] = '/dev/null'
        _init_once()

        self.assertTrue(LoggingConnection.log is not None)

        if have_paramiko:
            logger = paramiko.util.logging.getLogger()
            paramiko_log_level = logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.DEBUG)
Ejemplo n.º 5
0
    def test_init_once_and_debug_mode(self):
        # Debug mode is disabled
        _init_once()

        self.assertEqual(LoggingHTTPConnection.log, None)
        self.assertEqual(LoggingHTTPSConnection.log, None)

        if have_paramiko:
            logger = paramiko.util.logging.getLogger()
            paramiko_log_level = logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.WARNING)

        # Enable debug mode
        os.environ['LIBCLOUD_DEBUG'] = '/dev/null'
        _init_once()

        self.assertTrue(LoggingHTTPConnection.log is not None)
        self.assertTrue(LoggingHTTPSConnection.log is not None)

        if have_paramiko:
            logger = paramiko.util.logging.getLogger()
            paramiko_log_level = logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.DEBUG)
Ejemplo n.º 6
0
    def test_init_once_and_debug_mode(self):
        if have_paramiko:
            paramiko_logger = logging.getLogger('paramiko')
            paramiko_logger.setLevel(logging.INFO)

        # Debug mode is disabled
        _init_once()

        self.assertIsNone(LoggingConnection.log)

        if have_paramiko:
            paramiko_log_level = paramiko_logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.INFO)

        # Enable debug mode
        os.environ['LIBCLOUD_DEBUG'] = '/dev/null'
        _init_once()

        self.assertTrue(LoggingConnection.log is not None)

        if have_paramiko:
            paramiko_log_level = paramiko_logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.DEBUG)
Ejemplo n.º 7
0
    def test_init_once_and_debug_mode(self):
        if have_paramiko:
            paramiko_logger = logging.getLogger("paramiko")
            paramiko_logger.setLevel(logging.INFO)

        # Debug mode is disabled
        _init_once()

        self.assertIsNone(LoggingConnection.log)

        if have_paramiko:
            paramiko_log_level = paramiko_logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.INFO)

        # Enable debug mode
        _, tmp_path = tempfile.mkstemp()
        os.environ["LIBCLOUD_DEBUG"] = tmp_path
        _init_once()

        self.assertTrue(LoggingConnection.log is not None)

        if have_paramiko:
            paramiko_log_level = paramiko_logger.getEffectiveLevel()
            self.assertEqual(paramiko_log_level, logging.DEBUG)
Ejemplo n.º 8
0
def run_action(cmd_options, required_options, resource, action, callback):
    cmd_options = cmd_options or []
    all_options = GLOBAL_OPTIONS + cmd_options
    required_options = required_options or []
    parser = get_parser()

    def done(result=None):
        if action == 'list':
            print_list(result, options.details)
        elif action == 'create':
            print_success('Resource created. ID: ' + result.id)
        elif action == 'update':
            print_success('Resource has been successfully updated')
        elif action == 'delete':
            if result:
                print_success('Resource deleted')
            else:
                print_success('Resource not deleted')
        elif result:
            pprint(result)

    if action in ACTION_OPTIONS:
        all_options.extend(ACTION_OPTIONS[action])

    for args, kwargs in all_options:
        parser.add_option(*args, **kwargs)

    optcomplete.autocomplete(parser)
    (options, args) = parser.parse_args()

    for option in required_options:
        if not getattr(options, option, None):
            parser.print_help()
            print('\nMissing required options: ' + option)
            sys.exit(1)

    result = get_config()
    username, api_key = result['username'], result['api_key']
    auth_token, api_url = result['auth_token'], result['api_url']
    auth_url = result['auth_url']
    ssl_verify = result['ssl_verify']

    if options.username:
        username = options.username

    if options.api_key:
        api_key = options.api_key

    if options.api_url:
        api_url = options.api_url

    if options.auth_token:
        auth_token = options.auth_token

    if options.auth_url:
        auth_url = options.auth_url

    if (not username or not api_key) and (not auth_token or not api_url):
        print('No username/API key or auth token/API URL provided!')
        print('You need to either put credentials in ~/.raxrc or '
              'pass them to the command using --username/--api-key '
              'or --auth-token/--api-url options')
        sys.exit(1)

    if options.debug:
        os.environ['LIBCLOUD_DEBUG'] = '/dev/stderr'
        _init_once()

    if options.no_ssl_verify or ssl_verify == False:
        libcloud.security.VERIFY_SSL_CERT = False

    instance = get_instance(username, api_key, api_url, auth_url, auth_token)

    if not getattr(options, 'who', None):
        options.who = username

    try:
        callback(instance, options, args, done)
    except Exception:
        traceback.print_exc(file=sys.stderr)
        sys.exit(1)
Ejemplo n.º 9
0
def run_action(cmd_options, required_options, resource, action, callback):
    cmd_options = cmd_options or []
    all_options = GLOBAL_OPTIONS + cmd_options
    required_options = required_options or []
    parser = get_parser()

    def done(result=None):
        if action == 'list':
            print_list(result, options.details)
        elif action == 'create':
            print_success('Resource created. ID: ' + result.id)
        elif action == 'update':
            print_success('Resource has been successfully updated')
        elif action == 'delete':
            if result:
                print_success('Resource deleted')
            else:
                print_success('Resource not deleted')
        elif result:
            pprint(result)

    if action in ACTION_OPTIONS:
        all_options.extend(ACTION_OPTIONS[action])

    for args, kwargs in all_options:
        parser.add_option(*args, **kwargs)

    optcomplete.autocomplete(parser)
    (options, args) = parser.parse_args()

    for option in required_options:
        if not getattr(options, option, None):
            parser.print_help()
            print('\nMissing required options: ' + option)
            sys.exit(1)

    result = get_config()
    username, api_key = result['username'], result['api_key']
    auth_token, api_url = result['auth_token'], result['api_url']
    auth_url = result['auth_url']
    ssl_verify = result['ssl_verify']

    if options.username:
        username = options.username

    if options.api_key:
        api_key = options.api_key

    if options.api_url:
        api_url = options.api_url

    if options.auth_token:
        auth_token = options.auth_token

    if options.auth_url:
        auth_url = options.auth_url

    if (not username or not api_key) and (not auth_token or not api_url):
        print('No username/API key or auth token/API URL provided!')
        print('You need to either put credentials in ~/.raxrc or '
              'pass them to the command using --username/--api-key '
              'or --auth-token/--api-url options')
        sys.exit(1)

    if options.debug:
        os.environ['LIBCLOUD_DEBUG'] = '/dev/stderr'
        _init_once()

    if options.no_ssl_verify or ssl_verify == False:
        libcloud.security.VERIFY_SSL_CERT = False

    instance = get_instance(username, api_key, api_url, auth_url, auth_token)

    if not getattr(options, 'who', None):
        options.who = username

    try:
        callback(instance, options, args, done)
    except Exception:
        traceback.print_exc(file=sys.stderr)
Ejemplo n.º 10
0
def run_action(cmd_options, required_options, resource, action, callback):
    cmd_options = cmd_options or []
    all_options = GLOBAL_OPTIONS + cmd_options
    required_options = required_options or []
    parser = get_parser()

    def done(result):
        if action == 'list':
            print_list(result, options.details)
        elif action == 'create':
            print_success('Resource created. ID: ' + result.id)
        elif action == 'update':
            print_success('Resource has been successfully updated')
        elif action == 'delete':
            if result:
                print_success('Resource deleted')
            else:
                print_success('Resource not deleted')
        else:
            pprint(result)

    if action in ACTION_OPTIONS:
        all_options.extend(ACTION_OPTIONS[action])

    for args, kwargs in all_options:
        parser.add_option(*args, **kwargs)

    optcomplete.autocomplete(parser)
    (options, args) = parser.parse_args()

    for option in required_options:
        if not getattr(options, option, None):
            raise Exception('Missing required option: ' + option)

    username, api_key, api_url = get_credentials()

    if options.username:
        username = options.username

    if options.api_key:
        api_key = options.api_key

    api_url = api_url or API_URL_ADDRESS

    if options.api_url:
        api_url = options.api_url

    if not username or not api_key:
        print('No username and API key provided!')
        print('You need to either put credentials in ~/.raxrc or ' +
              'pass them to the command using --username and --api-key option')
        sys.exit(1)

    if options.debug:
        os.environ['LIBCLOUD_DEBUG'] = '/dev/stderr'
        _init_once()

    if options.no_ssl_verify:
        libcloud.security.VERIFY_SSL_CERT = False

    instance = get_instance(username, api_key, api_url, options.auth_url)

    if not getattr(options, 'who', None):
        options.who = username

    try:
        callback(instance, options, args, done)
    except Exception:
        traceback.print_exc(file=sys.stderr)
Ejemplo n.º 11
0
 def test_init_once_correct_chardet_version(self, *args):
     _init_once()
Ejemplo n.º 12
0
 def test_init_once_detects_bad_yum_install_requests(self, *args):
     expected_msg = "Known bad version of requests detected"
     with self.assertRaisesRegex(AssertionError, expected_msg):
         _init_once()