예제 #1
0
 def test_correct_arguments_passed_to_client_constructor_noauth_mode(
         self, mock_ks_session, mock_client):
     kwargs = {
         'watcher_url': 'http://watcher.example.org:9322/',
         'os_auth_token': 'USER_AUTH_TOKEN',
         'os_infra_optim_api_version': 'latest',
         'insecure': True,
         'max_retries': 10,
         'retry_interval': 10,
         'os_cacert': 'data'
     }
     watcherclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', 'http://watcher.example.org:9322/', **{
             'os_infra_optim_api_version': 'latest',
             'max_retries': 10,
             'retry_interval': 10,
             'token': 'USER_AUTH_TOKEN',
             'insecure': True,
             'ca_file': 'data',
             'cert_file': None,
             'key_file': None,
             'timeout': None,
             'session': None
         })
     self.assertFalse(mock_ks_session.called)
예제 #2
0
 def test_correct_arguments_passed_to_client_constructor_noauth_mode(
         self, mock_ks_session, mock_client):
     kwargs = {
         'watcher_url': 'http://watcher.example.org:9322/',
         'os_auth_token': 'USER_AUTH_TOKEN',
         'os_infra_optim_api_version': 'latest',
         'insecure': True,
         'max_retries': 10,
         'retry_interval': 10,
         'os_cacert': 'data'
     }
     watcherclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', 'http://watcher.example.org:9322/',
         **{
             'os_infra_optim_api_version': 'latest',
             'max_retries': 10,
             'retry_interval': 10,
             'token': 'USER_AUTH_TOKEN',
             'insecure': True,
             'ca_file': 'data',
             'cert_file': None,
             'key_file': None,
             'timeout': None,
             'session': None
         }
     )
     self.assertFalse(mock_ks_session.called)
예제 #3
0
 def test_get_client_only_session_passed(self):
     session = mock.Mock()
     session.get_endpoint.return_value = 'http://localhost:35357/v2.0'
     kwargs = {
         'session': session,
     }
     watcherclient.get_client('1', **kwargs)
     session.get_endpoint.assert_called_once_with(
         service_type='infra-optim',
         interface='publicURL',
         region_name=None)
예제 #4
0
 def test_get_client_only_session_passed(self):
     session = mock.Mock()
     session.get_endpoint.return_value = 'http://localhost:35357/v2.0'
     kwargs = {
         'session': session,
     }
     watcherclient.get_client('1', **kwargs)
     session.get_endpoint.assert_called_once_with(
         service_type='infra-optim',
         interface='publicURL',
         region_name=None)
예제 #5
0
 def test_correct_arguments_passed_to_client_constructor_session_passed(
         self, mock_ks_session, mock_client):
     session = mock.Mock()
     kwargs = {
         'session': session,
     }
     watcherclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', session.get_endpoint.return_value, **{
             'os_infra_optim_api_version': None,
             'max_retries': None,
             'retry_interval': None,
             'session': session,
         })
     self.assertFalse(mock_ks_session.called)
예제 #6
0
    def _test_get_client(self, mock_ks_loader, mock_ks_session,
                         version=None, auth='password', **kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:9322/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'

        watcherclient.get_client('1', **kwargs)

        mock_ks_loader.assert_called_once_with(auth)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=kwargs.get('timeout'),
            insecure=kwargs.get('insecure'), cert=kwargs.get('cert'),
            cacert=kwargs.get('cacert'), key=kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=kwargs.get('os_service_type') or 'infra-optim',
            interface=kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=kwargs.get('os_region_name'))
예제 #7
0
    def _test_get_client(self, mock_ks_loader, mock_ks_session,
                         version=None, auth='password', **kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:9322/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'

        watcherclient.get_client('1', **kwargs)

        mock_ks_loader.assert_called_once_with(auth)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=kwargs.get('timeout'),
            insecure=kwargs.get('insecure'), cert=kwargs.get('cert'),
            cacert=kwargs.get('cacert'), key=kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=kwargs.get('os_service_type') or 'infra-optim',
            interface=kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=kwargs.get('os_region_name'))
예제 #8
0
 def test_correct_arguments_passed_to_client_constructor_session_passed(
         self, mock_ks_session, mock_client):
     session = mock.Mock()
     kwargs = {
         'session': session,
     }
     watcherclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', session.get_endpoint.return_value,
         **{
             'os_infra_optim_api_version': None,
             'max_retries': None,
             'retry_interval': None,
             'session': session,
         }
     )
     self.assertFalse(mock_ks_session.called)
예제 #9
0
    def test_get_client_with_auth_token_watcher_url(self):
        kwargs = {
            'watcher_url': 'http://watcher.example.org:9322/',
            'os_auth_token': 'USER_AUTH_TOKEN',
        }
        client = watcherclient.get_client('1', **kwargs)

        self.assertEqual('USER_AUTH_TOKEN', client.http_client.auth_token)
        self.assertEqual('http://watcher.example.org:9322/',
                         client.http_client.endpoint)
예제 #10
0
    def test_get_client_with_auth_token_watcher_url(self):
        kwargs = {
            'watcher_url': 'http://watcher.example.org:9322/',
            'os_auth_token': 'USER_AUTH_TOKEN',
        }
        client = watcherclient.get_client('1', **kwargs)

        self.assertEqual('USER_AUTH_TOKEN', client.http_client.auth_token)
        self.assertEqual('http://watcher.example.org:9322/',
                         client.http_client.endpoint)
예제 #11
0
    def _test_loader_arguments_passed_correctly(
            self, mock_ks_loader, mock_ks_session,
            passed_kwargs, expected_kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:9322/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'

        watcherclient.get_client('1', **passed_kwargs)

        mock_ks_loader.return_value.load_from_options.assert_called_once_with(
            **expected_kwargs)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=passed_kwargs.get('timeout'),
            insecure=passed_kwargs.get('insecure'),
            cert=passed_kwargs.get('cert'),
            cacert=passed_kwargs.get('cacert'), key=passed_kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=passed_kwargs.get('os_service_type') or 'infra-optim',
            interface=passed_kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=passed_kwargs.get('os_region_name'))
예제 #12
0
    def _test_loader_arguments_passed_correctly(
            self, mock_ks_loader, mock_ks_session,
            passed_kwargs, expected_kwargs):
        session = mock_ks_session.return_value.load_from_options.return_value
        session.get_endpoint.return_value = 'http://localhost:9322/v1/f14b4123'
        mock_ks_loader.return_value.load_from_options.return_value = 'auth'

        watcherclient.get_client('1', **passed_kwargs)

        mock_ks_loader.return_value.load_from_options.assert_called_once_with(
            **expected_kwargs)
        mock_ks_session.return_value.load_from_options.assert_called_once_with(
            auth='auth', timeout=passed_kwargs.get('timeout'),
            insecure=passed_kwargs.get('insecure'),
            cert=passed_kwargs.get('cert'),
            cacert=passed_kwargs.get('cacert'), key=passed_kwargs.get('key'))
        session.get_endpoint.assert_called_once_with(
            service_type=passed_kwargs.get('os_service_type') or 'infra-optim',
            interface=passed_kwargs.get('os_endpoint_type') or 'publicURL',
            region_name=passed_kwargs.get('os_region_name'))
예제 #13
0
 def test_correct_arguments_passed_to_client_constructor_session_created(
         self, mock_ks_session, mock_client):
     session = mock_ks_session.return_value.load_from_options.return_value
     kwargs = {
         'os_auth_url': 'http://localhost:35357/v3',
         'os_region_name': 'REGIONONE',
         'os_project_id': '1000',
         'os_username': '******',
         'os_password': '******',
         'os_project_domain_name': 'domain1',
         'os_user_domain_name': 'domain1'
     }
     watcherclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', session.get_endpoint.return_value, **{
             'os_infra_optim_api_version': None,
             'max_retries': None,
             'retry_interval': None,
             'session': session,
         })
예제 #14
0
 def test_correct_arguments_passed_to_client_constructor_session_created(
         self, mock_ks_session, mock_client):
     session = mock_ks_session.return_value.load_from_options.return_value
     kwargs = {
         'os_auth_url': 'http://localhost:35357/v3',
         'os_region_name': 'REGIONONE',
         'os_project_id': '1000',
         'os_username': '******',
         'os_password': '******',
         'os_project_domain_name': 'domain1',
         'os_user_domain_name': 'domain1'
     }
     watcherclient.get_client('1', **kwargs)
     mock_client.assert_called_once_with(
         '1', session.get_endpoint.return_value,
         **{
             'os_infra_optim_api_version': None,
             'max_retries': None,
             'retry_interval': None,
             'session': session,
         }
     )
예제 #15
0
def watcherclient(request, password=None):
    api_version = "1"
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    ca_file = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
    insert_watcher_policy_file()

    endpoint = base.url_for(request, WATCHER_SERVICE)

    LOG.debug(
        'watcherclient connection created using token "%s" and url "%s"' %
        (request.user.token.id, endpoint))

    client = wc.get_client(api_version,
                           watcher_url=endpoint,
                           insecure=insecure,
                           ca_file=ca_file,
                           username=request.user.username,
                           password=password,
                           os_auth_token=request.user.token.id)
    return client
예제 #16
0
def watcherclient(request, password=None):
    api_version = "1"
    insecure = getattr(settings, 'OPENSTACK_SSL_NO_VERIFY', False)
    ca_file = getattr(settings, 'OPENSTACK_SSL_CACERT', None)
    insert_watcher_policy_file()

    endpoint = base.url_for(request, WATCHER_SERVICE)

    LOG.debug('watcherclient connection created using token "%s" and url "%s"'
              % (request.user.token.id, endpoint))

    client = wc.get_client(
        api_version,
        watcher_url=endpoint,
        insecure=insecure,
        ca_file=ca_file,
        username=request.user.username,
        password=password,
        os_auth_token=request.user.token.id
    )
    return client
예제 #17
0
 def create_client(self, args):
     client = watcherclient.get_client('1', **args.__dict__)
     return client
예제 #18
0
 def create_client(self, args):
     client = watcherclient.get_client('1', **args.__dict__)
     return client