def test_mistral_url_https_bad_insecure(self, session_mock,
                                            log_warning_mock):
        fd, path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = self.setup_keystone_mock(
            session_mock
        )

        try:
            client.client(
                mistral_url=MISTRAL_HTTPS_URL,
                user_id=keystone_client_instance.user_id,
                project_id=keystone_client_instance.project_id,
                api_key='password',
                user_domain_name='Default',
                project_domain_name='Default',
                auth_url=AUTH_HTTP_URL_v3,
                cacert=path,
                insecure=True
            )
        finally:
            os.close(fd)
            os.unlink(path)

        self.assertTrue(log_warning_mock.called)
    def test_mistral_url_https_secure(self, http_client_mock, session_mock):
        fd, cert_path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = self.setup_keystone_mock(  # noqa
            session_mock
        )

        expected_args = (
            MISTRAL_HTTPS_URL,
        )

        try:
            client.client(
                mistral_url=MISTRAL_HTTPS_URL,
                username='******',
                project_name='mistral',
                api_key='password',
                user_domain_name='Default',
                project_domain_name='Default',
                auth_url=AUTH_HTTP_URL_v3,
                cacert=cert_path,
                insecure=False
            )
        finally:
            os.close(fd)
            os.unlink(cert_path)

        self.assertTrue(http_client_mock.called)
        self.assertEqual(http_client_mock.call_args[0], expected_args)
        self.assertEqual(http_client_mock.call_args[1]['cacert'], cert_path)
    def test_mistral_url_https_secure(self, mock, keystone_client_mock):
        fd, path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())

        expected_args = (MISTRAL_HTTPS_URL,
                         keystone_client_instance.auth_token,
                         keystone_client_instance.project_id,
                         keystone_client_instance.user_id)

        expected_kwargs = {
            'cacert': path,
            'insecure': False,
            'target_auth_uri': None,
            'target_token': None
        }

        try:
            client.client(mistral_url=MISTRAL_HTTPS_URL,
                          username='******',
                          project_name='mistral',
                          auth_url=AUTH_HTTP_URL_v3,
                          cacert=path,
                          insecure=False)
        finally:
            os.close(fd)
            os.unlink(path)

        self.assertTrue(mock.called)
        self.assertEqual(mock.call_args[0], expected_args)
        self.assertDictEqual(mock.call_args[1], expected_kwargs)
    def test_mistral_url_https_bad_insecure(self, session_mock,
                                            log_warning_mock):
        fd, path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = self.setup_keystone_mock(
            session_mock
        )

        try:
            client.client(
                mistral_url=MISTRAL_HTTPS_URL,
                user_id=keystone_client_instance.user_id,
                project_id=keystone_client_instance.project_id,
                api_key='password',
                user_domain_name='Default',
                project_domain_name='Default',
                auth_url=AUTH_HTTP_URL_v3,
                cacert=path,
                insecure=True
            )
        finally:
            os.close(fd)
            os.unlink(path)

        self.assertTrue(log_warning_mock.called)
    def test_mistral_url_https_insecure(self, mock, keystone_client_mock):
        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())

        expected_args = (
            MISTRAL_HTTPS_URL,
            keystone_client_instance.auth_token,
            keystone_client_instance.project_id,
            keystone_client_instance.user_id
        )

        expected_kwargs = {
            'cacert': None,
            'insecure': True
        }

        client.client(
            mistral_url=MISTRAL_HTTPS_URL,
            username='******',
            project_name='mistral',
            auth_url=AUTH_HTTP_URL,
            cacert=None,
            insecure=True
        )

        self.assertTrue(mock.called)
        self.assertEqual(mock.call_args[0], expected_args)
        self.assertDictEqual(mock.call_args[1], expected_kwargs)
    def test_mistral_url_default(self, mocked, keystone_client_mock):
        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())
        url_for = mock.Mock(side_effect=Exception)
        keystone_client_instance.service_catalog.url_for = url_for

        expected_args = (MISTRAL_HTTP_URL, keystone_client_instance.auth_token,
                         keystone_client_instance.project_id,
                         keystone_client_instance.user_id)

        expected_kwargs = {
            'cacert': None,
            'insecure': False,
            'target_auth_uri': None,
            'target_token': None
        }

        client.client(username='******',
                      project_name='mistral',
                      auth_url=AUTH_HTTP_URL_v3)

        self.assertTrue(mocked.called)
        self.assertEqual(mocked.call_args[0], expected_args)
        self.assertDictEqual(mocked.call_args[1], expected_kwargs)
Example #7
0
    def test_target_parameters_processed(self, http_client_mock,
                                         keystone_client_mock):
        keystone_client_instance = self.setup_keystone_mock(
            keystone_client_mock)

        url_for = mock.Mock(return_value='http://mistral_host:8989/v2')
        keystone_client_instance.service_catalog.url_for = url_for

        client.client(target_username='******',
                      target_project_name='tmistralp',
                      target_auth_url=AUTH_HTTP_URL_v3,
                      target_region_name='tregion')

        self.assertTrue(http_client_mock.called)
        mistral_url_for_http = http_client_mock.call_args[0][0]
        kwargs = http_client_mock.call_args[1]
        self.assertEqual(MISTRAL_HTTP_URL, mistral_url_for_http)

        expected_values = {
            'target_project_id': keystone_client_instance.project_id,
            'target_auth_token': keystone_client_instance.auth_token,
            'target_user_id': keystone_client_instance.user_id,
            'target_auth_url': AUTH_HTTP_URL_v3,
            'target_project_name': 'tmistralp',
            'target_username': '******',
            'target_region_name': 'tregion',
            'target_service_catalog': '"{}"'
        }

        for key in expected_values:
            self.assertEqual(expected_values[key], kwargs[key])
    def test_mistral_url_https_secure(self, http_client_mock, session_mock):
        fd, cert_path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = self.setup_keystone_mock(  # noqa
            session_mock)

        expected_args = (MISTRAL_HTTPS_URL, )

        try:
            client.client(mistral_url=MISTRAL_HTTPS_URL,
                          username='******',
                          project_name='mistral',
                          api_key='password',
                          user_domain_name='Default',
                          project_domain_name='Default',
                          auth_url=AUTH_HTTP_URL_v3,
                          cacert=cert_path,
                          insecure=False)
        finally:
            os.close(fd)
            os.unlink(cert_path)

        self.assertTrue(http_client_mock.called)
        self.assertEqual(http_client_mock.call_args[0], expected_args)
        self.assertEqual(http_client_mock.call_args[1]['cacert'], cert_path)
    def test_mistral_profile_enabled(self, mock, keystone_client_mock):
        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())

        expected_args = (
            MISTRAL_HTTP_URL,
            keystone_client_instance.auth_token,
            keystone_client_instance.project_id,
            keystone_client_instance.user_id
        )

        expected_kwargs = {
            'cacert': None,
            'insecure': False
        }

        client.client(
            username='******',
            project_name='mistral',
            auth_url=AUTH_HTTP_URL,
            profile=PROFILER_HMAC_KEY
        )

        self.assertTrue(mock.called)
        self.assertEqual(mock.call_args[0], expected_args)
        self.assertDictEqual(mock.call_args[1], expected_kwargs)

        profiler = osprofiler.profiler.get()

        self.assertEqual(profiler.hmac_key, PROFILER_HMAC_KEY)
 def test_mistral_url_defult(self, mock, keystone_client_mock):
     client.client(username='******',
                   project_name='misteal',
                   auth_url="http://localhost:35357/v3")
     self.assertTrue(mock.called)
     params = mock.call_args
     self.assertEqual('http://localhost:8989/v2',
                      params[0][0])
    def test_target_parameters_processed(self, http_client_mock, session_mock,
                                         password_mock, catalog_type_mock):

        session = mock.MagicMock()
        target_session = mock.MagicMock()
        session_mock.side_effect = [session, target_session]
        auth = mock.MagicMock()
        target_auth = mock.MagicMock()
        target_auth._plugin.auth_url = AUTH_HTTP_URL_v3

        password_mock.side_effect = [auth, target_auth]

        get_endpoint = mock.Mock(return_value='http://mistral_host:8989/v2')
        session.get_endpoint = get_endpoint

        target_session.get_project_id = mock.Mock(return_value='projectid')
        target_session.get_user_id = mock.Mock(return_value='userid')
        target_session.get_auth_headers = mock.Mock(
            return_value={'X-Auth-Token': 'authtoken'})

        mock_access = mock.MagicMock()
        mock_catalog = mock.MagicMock()
        mock_catalog.catalog = {}
        mock_access.service_catalog = mock_catalog
        auth.get_access = mock.Mock(return_value=mock_access)

        client.client(auth_url=AUTH_HTTP_URL_v3,
                      username='******',
                      api_key='password',
                      user_domain_name='Default',
                      project_domain_name='Default',
                      target_username='******',
                      target_project_name='tmistralp',
                      target_auth_url=AUTH_HTTP_URL_v3,
                      target_api_key='tpassword',
                      target_user_domain_name='Default',
                      target_project_domain_name='Default',
                      target_region_name='tregion')

        self.assertTrue(http_client_mock.called)
        mistral_url_for_http = http_client_mock.call_args[0][0]
        kwargs = http_client_mock.call_args[1]
        self.assertEqual('http://mistral_host:8989/v2', mistral_url_for_http)

        expected_values = {
            'target_project_id': 'projectid',
            'target_auth_token': 'authtoken',
            'target_user_id': 'userid',
            'target_auth_url': AUTH_HTTP_URL_v3,
            'target_project_name': 'tmistralp',
            'target_username': '******',
            'target_region_name': 'tregion',
            'target_service_catalog': "{}"
        }

        for key in expected_values:
            self.assertEqual(expected_values[key], kwargs[key])
    def test_mistral_no_auth(self, get_auth_handler_mock):
        # Test that we don't authenticate if auth url wasn't provided

        client.client(username='******',
                      project_name='mistral',
                      api_key='password',
                      service_type='workflowv2')

        self.assertEqual(0, get_auth_handler_mock.call_count)
    def test_mistral_no_auth(self, get_auth_handler_mock):
        # Test that we don't authenticate if auth url wasn't provided

        client.client(
            username='******',
            project_name='mistral',
            api_key='password',
            service_type='workflowv2'
        )

        self.assertEqual(0, get_auth_handler_mock.call_count)
Example #14
0
    def test_mistral_profile_enabled(self, http_client_mock,
                                     keystone_client_mock):
        keystone_client_instance = self.setup_keystone_mock(  # noqa
            keystone_client_mock)

        client.client(username='******',
                      project_name='mistral',
                      auth_url=AUTH_HTTP_URL_v3,
                      profile=PROFILER_HMAC_KEY)

        self.assertTrue(http_client_mock.called)

        profiler = osprofiler.profiler.get()

        self.assertEqual(profiler.hmac_key, PROFILER_HMAC_KEY)
Example #15
0
    def _create_client(region):
        if not mistralcli:
            LOG.warning(_LW("Mistral client is not available"))
            raise mistral_import_error

        mistral_settings = CONF.mistral

        endpoint_type = mistral_settings.endpoint_type
        service_type = mistral_settings.service_type
        session = auth_utils.get_client_session()

        mistral_url = mistral_settings.url or session.get_endpoint(
            service_type=service_type,
            endpoint_type=endpoint_type,
            region_name=region)
        auth_ref = session.auth.get_access(session)

        return mistralcli.client(mistral_url=mistral_url,
                                 project_id=auth_ref.project_id,
                                 endpoint_type=endpoint_type,
                                 service_type=service_type,
                                 auth_token=auth_ref.auth_token,
                                 user_id=auth_ref.user_id,
                                 insecure=mistral_settings.insecure,
                                 cacert=mistral_settings.ca_cert)
Example #16
0
    def get_workflow_client(self, context):
        mistral_endpoint = keystone_utils.get_endpoint_for_project('mistral')

        mc = mistral_client.client(auth_token=context.auth_token,
                                   mistral_url=mistral_endpoint.url)

        return mc
Example #17
0
    def initialize_app(self, argv):
        self._clear_shell_commands()

        ver = client.determine_client_version(self.options.mistral_version)

        self._set_shell_commands(self._get_commands(ver))

        do_help = ('help' in argv) or ('-h' in argv) or not argv

        # Set default for auth_url if not supplied. The default is not
        # set at the parser to support use cases where auth is not enabled.
        # An example use case would be a developer's environment.
        if not self.options.auth_url:
            if self.options.password or self.options.token:
                self.options.auth_url = 'http://localhost:35357/v3'

        # bash-completion should not require authentification.
        if do_help or ('bash-completion' in argv):
            self.options.auth_url = None

        self.client = client.client(mistral_url=self.options.mistral_url,
                                    username=self.options.username,
                                    api_key=self.options.password,
                                    project_name=self.options.tenant_name,
                                    auth_url=self.options.auth_url,
                                    project_id=self.options.tenant_id,
                                    endpoint_type=self.options.endpoint_type,
                                    service_type=self.options.service_type,
                                    auth_token=self.options.token,
                                    cacert=self.options.cacert)
Example #18
0
    def _create_client(region):
        if not mistralclient:
            raise mistral_import_error

        mistral_settings = CONF.mistral

        endpoint_type = mistral_settings.endpoint_type
        service_type = mistral_settings.service_type
        session = auth_utils.get_client_session()

        mistral_url = mistral_settings.url or session.get_endpoint(
            service_type=service_type,
            endpoint_type=endpoint_type,
            region_name=region)
        auth_ref = session.auth.get_access(session)

        return mistralclient.client(
            mistral_url=mistral_url,
            project_id=auth_ref.project_id,
            endpoint_type=endpoint_type,
            service_type=service_type,
            auth_token=auth_ref.auth_token,
            user_id=auth_ref.user_id,
            insecure=mistral_settings.insecure,
            cacert=mistral_settings.ca_cert
        )
Example #19
0
    def run(self, action_parameters):
        client = mistral.client(mistral_url='%s/v2' % self.url)

        # Update workbook definition.
        workbook_name = self.action.pack + '.' + self.action.name
        with open(self.entry_point, 'r') as wbkfile:
            definition = wbkfile.read()
            try:
                wbk = client.workbooks.get(workbook_name)
                if wbk.definition != definition:
                    client.workbooks.update(definition)
            except:
                client.workbooks.create(definition)

        # Setup context for the workflow execution.
        context = self.runner_parameters.get('context', dict())
        context.update(action_parameters)
        endpoint = 'http://%s:%s/actionexecutions' % (cfg.CONF.api.host, cfg.CONF.api.port)
        params = {'st2_api_url': endpoint,
                  'st2_parent': self.action_execution_id}

        # Execute the workflow.
        execution = client.executions.create(self.runner_parameters.get('workflow'),
                                             workflow_input=context, **params)

        # Return status and output.
        output = {
            'id': str(execution.id),
            'state': str(execution.state)
        }

        self.container_service.report_status(ACTIONEXEC_STATUS_RUNNING)
        self.container_service.report_result(output)

        return (str(execution.state) == 'RUNNING')
Example #20
0
    def _initialize_tests(self):
        """Perform final initialization before tests get run."""
        # Access the sentries for inspecting service units
        self.mistral_sentry = self.d.sentry['mistral'][0]
        self.mysql_sentry = self.d.sentry['percona-cluster'][0]
        self.keystone_sentry = self.d.sentry['keystone'][0]
        self.rabbitmq_sentry = self.d.sentry['rabbitmq-server'][0]
        self.mistral_svcs = [
            'mistral-api', 'mistral-engine', 'mistral-executor'
        ]
        # Authenticate admin with keystone endpoint
        self.keystone = u.authenticate_keystone_admin(self.keystone_sentry,
                                                      user='******',
                                                      password='******',
                                                      tenant='admin')
        mistral_ep = self.keystone.service_catalog.url_for(
            service_type='workflowv2', endpoint_type='publicURL')

        keystone_ep = self.keystone.service_catalog.url_for(
            service_type='identity', endpoint_type='publicURL')

        self.mclient = mistral_client.client(username='******',
                                             mistral_url=mistral_ep,
                                             auth_url=keystone_ep,
                                             project_name='admin',
                                             api_key='openstack')
Example #21
0
    def _create_client(region):
        if not mistralcli:
            LOG.warning("Mistral client is not available")
            raise ImportError("Import mistralcliet error")

        mistral_settings = CONF.mistral

        endpoint_type = mistral_settings.endpoint_type
        service_type = mistral_settings.service_type
        session = auth_utils.get_client_session()

        mistral_url = mistral_settings.url or session.get_endpoint(
            service_type=service_type,
            endpoint_type=endpoint_type,
            region_name=region)
        auth_ref = session.auth.get_access(session)

        # TODO(gyurco): use auth_utils.get_session_client_parameters
        return mistralcli.client(
            mistral_url=mistral_url,
            project_id=auth_ref.project_id,
            endpoint_type=endpoint_type,
            service_type=service_type,
            auth_token=auth_ref.auth_token,
            user_id=auth_ref.user_id,
            insecure=mistral_settings.insecure,
            cacert=mistral_settings.cafile
        )
Example #22
0
    def test_mistral_url_https_insecure(self, http_client_mock,
                                        keystone_client_mock):
        keystone_client_instance = self.setup_keystone_mock(  # noqa
            keystone_client_mock)

        expected_args = (MISTRAL_HTTPS_URL, )

        client.client(mistral_url=MISTRAL_HTTPS_URL,
                      username='******',
                      project_name='mistral',
                      auth_url=AUTH_HTTP_URL_v3,
                      cacert=None,
                      insecure=True)

        self.assertTrue(http_client_mock.called)
        self.assertEqual(http_client_mock.call_args[0], expected_args)
        self.assertEqual(http_client_mock.call_args[1]['insecure'], True)
Example #23
0
File: v2.py Project: automotola/st2
 def __init__(self):
     super(MistralWorkflowValidator, self).__init__()
     self._client = mistral.client(
         mistral_url=self.url,
         username=cfg.CONF.mistral.keystone_username,
         api_key=cfg.CONF.mistral.keystone_password,
         project_name=cfg.CONF.mistral.keystone_project_name,
         auth_url=cfg.CONF.mistral.keystone_auth_url)
def main():
    sc = client.client(**creds())
    workflow = sc.workflows.get("sosreport_test")
    trigger = sc.event_triggers.create("map_sosreport_test",
                                       workflow_id=workflow.id,
                                       exchange="openstack",
                                       topic="notifications",
                                       event="new_sosreport")
Example #25
0
    def get_workflow_client(self, context):
        mistral_endpoint = keystone_utils.get_endpoint_for_project(
            context, 'mistral')

        mc = mistral_client.client(auth_token=context.auth_token,
                                   mistral_url=mistral_endpoint.url)

        return mc
Example #26
0
 def __init__(self):
     super(MistralWorkflowValidator, self).__init__()
     self._client = mistral.client(
         mistral_url=self.url,
         username=cfg.CONF.mistral.keystone_username,
         api_key=cfg.CONF.mistral.keystone_password,
         project_name=cfg.CONF.mistral.keystone_project_name,
         auth_url=cfg.CONF.mistral.keystone_auth_url)
Example #27
0
    def _create(self):
        endpoint_type = self._get_client_option("mistral", "endpoint_type")
        endpoint = self.url_for(service_type=self.WORKFLOW_V2, endpoint_type=endpoint_type)

        args = {"mistral_url": endpoint, "auth_token": self.auth_token}

        client = mistral_client.client(**args)
        return client
Example #28
0
    def _get_workflow_client(self):
        ctx = context.ctx()
        mistral_endpoint = keystone_utils.get_endpoint_for_project('mistral')

        mc = mistral_client.client(auth_token=ctx.auth_token,
                                   mistral_url=mistral_endpoint.url)

        return mc
    def test_mistral_url_default(self, http_client_mock, session_mock):
        session = mock.Mock()
        session_mock.side_effect = [session]

        get_endpoint = mock.Mock(side_effect=Exception)
        session.get_endpoint = get_endpoint

        client.client(username='******',
                      project_name='mistral',
                      api_key='password',
                      user_domain_name='Default',
                      project_domain_name='Default',
                      auth_url=AUTH_HTTP_URL_v3)

        self.assertTrue(http_client_mock.called)
        mistral_url_for_http = http_client_mock.call_args[0][0]
        self.assertEqual(MISTRAL_HTTP_URL, mistral_url_for_http)
Example #30
0
    def create_client(self, service_type=None):
        """Return Mistral client."""
        from mistralclient.api import client as mistral

        client = mistral.client(
            mistral_url=self._get_endpoint(service_type),
            service_type=self.choose_service_type(service_type),
            auth_token=self.keystone.auth_ref.auth_token)
        return client
Example #31
0
    def get_workflow_client(self, context):
        security_ctx = context.security
        mistral_endpoint = keystone_utils.get_endpoint_for_project(
            security_ctx, 'mistral')

        mc = mistral_client.client(auth_token=security_ctx.auth_token,
                                   mistral_url=mistral_endpoint.url)

        return mc
Example #32
0
    def create_client(self, service_type=None):
        """Return Mistral client."""
        from mistralclient.api import client as mistral

        client = mistral.client(
            mistral_url=self._get_endpoint(service_type),
            service_type=self.choose_service_type(service_type),
            auth_token=self.keystone.auth_ref.auth_token)
        return client
Example #33
0
 def __init__(self, id, *args, **kwargs):
     super(MistralResultsQuerier, self).__init__(*args, **kwargs)
     self._base_url = get_url_without_trailing_slash(cfg.CONF.mistral.v2_base_url)
     self._client = mistral.client(
         mistral_url=self._base_url,
         username=cfg.CONF.mistral.keystone_username,
         api_key=cfg.CONF.mistral.keystone_password,
         project_name=cfg.CONF.mistral.keystone_project_name,
         auth_url=cfg.CONF.mistral.keystone_auth_url)
Example #34
0
    def _create(self):
        endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')
        endpoint = self.url_for(service_type=self.WORKFLOW_V2,
                                endpoint_type=endpoint_type)

        args = {'mistral_url': endpoint, 'auth_token': self.auth_token}

        client = mistral_client.client(**args)
        return client
    def test_mistral_url_default(self, http_client_mock, session_mock):
        session = mock.Mock()
        session_mock.side_effect = [session]

        get_endpoint = mock.Mock(side_effect=Exception)
        session.get_endpoint = get_endpoint

        client.client(
            username='******',
            project_name='mistral',
            api_key='password',
            user_domain_name='Default',
            project_domain_name='Default',
            auth_url=AUTH_HTTP_URL_v3
        )

        self.assertTrue(http_client_mock.called)
        mistral_url_for_http = http_client_mock.call_args[0][0]
        self.assertEqual(MISTRAL_HTTP_URL, mistral_url_for_http)
Example #36
0
    def _create(self):
        endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')
        endpoint = self.url_for(service_type=self.WORKFLOW_V2,
                                endpoint_type=endpoint_type)
        args = {
            'mistral_url': endpoint,
            'auth_token': self.context.keystone_session.get_token()
        }

        client = mistral_client.client(**args)
        return client
Example #37
0
    def test_mistral_url_default(self, http_client_mock, keystone_client_mock):
        keystone_client_instance = self.setup_keystone_mock(
            keystone_client_mock)

        url_for = mock.Mock(side_effect=Exception)
        keystone_client_instance.service_catalog.url_for = url_for

        client.client(username='******',
                      project_name='mistral',
                      auth_url=AUTH_HTTP_URL_v3)

        self.assertTrue(http_client_mock.called)
        mistral_url_for_http = http_client_mock.call_args[0][0]
        kwargs = http_client_mock.call_args[1]
        self.assertEqual(MISTRAL_HTTP_URL, mistral_url_for_http)
        self.assertEqual(keystone_client_instance.auth_token,
                         kwargs['auth_token'])
        self.assertEqual(keystone_client_instance.project_id,
                         kwargs['project_id'])
        self.assertEqual(keystone_client_instance.user_id, kwargs['user_id'])
Example #38
0
File: v2.py Project: mikeatm/st2
 def __init__(self, runner_id):
     super(MistralRunner, self).__init__(runner_id=runner_id)
     self._on_behalf_user = cfg.CONF.system_user.user
     self._notify = None
     self._skip_notify_tasks = []
     self._client = mistral.client(
         mistral_url=self.url,
         username=cfg.CONF.mistral.keystone_username,
         api_key=cfg.CONF.mistral.keystone_password,
         project_name=cfg.CONF.mistral.keystone_project_name,
         auth_url=cfg.CONF.mistral.keystone_auth_url)
    def test_mistral_profile_enabled(self, http_client_mock, session_mock):
        keystone_client_instance = self.setup_keystone_mock(  # noqa
            session_mock
        )

        client.client(
            username='******',
            project_name='mistral',
            api_key='password',
            user_domain_name='Default',
            project_domain_name='Default',
            auth_url=AUTH_HTTP_URL_v3,
            profile=PROFILER_HMAC_KEY
        )

        self.assertTrue(http_client_mock.called)

        profiler = osprofiler.profiler.get()

        self.assertEqual(profiler.hmac_key, PROFILER_HMAC_KEY)
Example #40
0
 def __init__(self, runner_id):
     super(MistralRunner, self).__init__(runner_id=runner_id)
     self._on_behalf_user = cfg.CONF.system_user.user
     self._notify = None
     self._skip_notify_tasks = []
     self._client = mistral.client(
         mistral_url=self.url,
         username=cfg.CONF.mistral.keystone_username,
         api_key=cfg.CONF.mistral.keystone_password,
         project_name=cfg.CONF.mistral.keystone_project_name,
         auth_url=cfg.CONF.mistral.keystone_auth_url)
Example #41
0
    def _create(self):
        endpoint_type = self._get_client_option(CLIENT_NAME, 'endpoint_type')
        endpoint = self.url_for(service_type=self.WORKFLOW_V2,
                                endpoint_type=endpoint_type)
        args = {
            'mistral_url': endpoint,
            'session': self.context.keystone_session,
            'region_name': self._get_region_name()
        }

        client = mistral_client.client(**args)
        return client
Example #42
0
    def test_mistral_url_https_bad_insecure(self, keystone_client_mock,
                                            log_warning_mock):
        fd, path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())

        try:
            client.client(mistral_url=MISTRAL_HTTPS_URL,
                          username='******',
                          project_name='mistral',
                          auth_url=AUTH_HTTP_URL_v3,
                          cacert=path,
                          insecure=True)
        finally:
            os.close(fd)
            os.unlink(path)

        self.assertTrue(log_warning_mock.called)
Example #43
0
    def _create(self):
        endpoint_type = self._get_client_option('mistral', 'endpoint_type')
        endpoint = self.url_for(service_type=self.WORKFLOW_V2,
                                endpoint_type=endpoint_type)

        args = {
            'mistral_url': endpoint,
            'auth_token': self.auth_token
        }

        client = mistral_client.client(**args)
        return client
Example #44
0
File: clients.py Project: ed-/solum
    def mistral(self):
        if self._mistral:
            return self._mistral

        args = {
            'auth_token': self.auth_token,
        }
        endpoint_type = self._get_client_option('mistral', 'endpoint_type')
        endpoint = self.url_for(service_type='workflow',
                                endpoint_type=endpoint_type)
        self._mistral = mistralclient.client(mistral_url=endpoint, **args)

        return self._mistral
Example #45
0
def get_mistralclinet_from_env():
    username = env("OS_USERNAME", default=None)
    password = env("OS_PASSWORD", default=None)
    project_name = env("OS_TENANT_NAME", "OS_PROJECT_NAME", default=None)
    auth_url = env("OS_AUTH_URL", default=None)
    mistral_url = env("OS_MISTRAL_URL", default=None)
    mistralclient = client.client(
        mistral_url=mistral_url,
        username=username,
        api_key=password,
        project_name=project_name,
        auth_url=auth_url)
    return mistralclient
Example #46
0
def mistralclient(request):
    return mistral_client.client(
        username=request.user.username,
        auth_token=request.user.token.id,
        project_id=request.user.tenant_id,
        # Ideally, we should get it from identity endpoint, but since
        # python-mistralclient is not supporting v2.0 API it might create
        # additional troubles for those who still rely on v2.0 stack-wise.
        auth_url=getattr(settings, 'OPENSTACK_KEYSTONE_URL'),
        # Todo: add SECONDARY_ENDPOINT_TYPE support
        endpoint_type=getattr(settings, 'OPENSTACK_ENDPOINT_TYPE',
                              'internalURL'),
        service_type=SERVICE_TYPE)
Example #47
0
    def initialize_app(self, argv):
        self._clear_shell_commands()
        self._set_shell_commands(self._get_commands(
            client.determine_client_version(self.options.mistral_url)))

        self.client = client.client(mistral_url=self.options.mistral_url,
                                    username=self.options.username,
                                    api_key=self.options.password,
                                    project_name=self.options.tenant_name,
                                    auth_url=self.options.auth_url,
                                    project_id=self.options.tenant_id,
                                    endpoint_type='publicURL',
                                    service_type='workflow',
                                    auth_token=self.options.token)
Example #48
0
    def mistral(self):
        """Return Mistral client."""
        from mistralclient.api import client
        kc = self.keystone()

        mistral_url = kc.service_catalog.url_for(
            service_type="workflowv2",
            endpoint_type=self.endpoint.endpoint_type,
            region_name=self.endpoint.region_name)

        client = client.client(mistral_url=mistral_url,
                               service_type="workflowv2",
                               auth_token=kc.auth_token)
        return client
Example #49
0
    def test_mistral_url_from_catalog_v2(self, keystone_client_mock):
        keystone_client_instance = self.setup_keystone_mock(
            keystone_client_mock)

        url_for = mock.Mock(return_value='http://mistral_host:8989/v2')
        keystone_client_instance.service_catalog.url_for = url_for

        mistralclient = client.client(username='******',
                                      project_name='mistral',
                                      auth_url=AUTH_HTTP_URL_v2_0,
                                      service_type='workflowv2')

        self.assertEqual('http://mistral_host:8989/v2',
                         mistralclient.actions.http_client.base_url)
Example #50
0
    def _update_action_execution(cls, url, data):
        action_execution_id = get_action_execution_id_from_url(url)

        LOG.info('Sending callback to %s with data %s.', url, data)

        client = mistral.client(
            mistral_url=cfg.CONF.mistral.v2_base_url,
            username=cfg.CONF.mistral.keystone_username,
            api_key=cfg.CONF.mistral.keystone_password,
            project_name=cfg.CONF.mistral.keystone_project_name,
            auth_url=cfg.CONF.mistral.keystone_auth_url)

        manager = action_executions.ActionExecutionManager(client)
        manager.update(action_execution_id, **data)
Example #51
0
    def mistral(self):
        """Return Mistral client."""
        from mistralclient.api import client
        kc = self.keystone()

        mistral_url = kc.service_catalog.url_for(
            service_type="workflowv2",
            endpoint_type=self.endpoint.endpoint_type,
            region_name=self.endpoint.region_name)

        client = client.client(mistral_url=mistral_url,
                               service_type="workflowv2",
                               auth_token=kc.auth_token)
        return client
    def test_mistral_url_https_bad_insecure(self, keystone_client_mock,
                                            log_warning_mock):
        fd, path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())

        try:
            client.client(
                mistral_url=MISTRAL_HTTPS_URL,
                username='******',
                project_name='mistral',
                auth_url=AUTH_HTTP_URL,
                cacert=path,
                insecure=True
            )
        finally:
            os.close(fd)
            os.unlink(path)

        self.assertTrue(log_warning_mock.called)
Example #53
0
    def _update_action_execution(cls, url, data):
        action_execution_id = get_action_execution_id_from_url(url)

        LOG.info('Sending callback to %s with data %s.', url, data)

        client = mistral.client(
            mistral_url=cfg.CONF.mistral.v2_base_url,
            username=cfg.CONF.mistral.keystone_username,
            api_key=cfg.CONF.mistral.keystone_password,
            project_name=cfg.CONF.mistral.keystone_project_name,
            auth_url=cfg.CONF.mistral.keystone_auth_url)

        manager = action_executions.ActionExecutionManager(client)
        manager.update(action_execution_id, **data)
    def test_mistral_url_https_insecure(self, http_client_mock, session_mock):
        keystone_client_instance = self.setup_keystone_mock(  # noqa
            session_mock
        )

        expected_args = (
            MISTRAL_HTTPS_URL,
        )

        client.client(
            mistral_url=MISTRAL_HTTPS_URL,
            username='******',
            project_name='mistral',
            api_key='password',
            user_domain_name='Default',
            project_domain_name='Default',
            auth_url=AUTH_HTTP_URL_v3,
            cacert=None,
            insecure=True
        )

        self.assertTrue(http_client_mock.called)
        self.assertEqual(http_client_mock.call_args[0], expected_args)
        self.assertEqual(http_client_mock.call_args[1]['insecure'], True)
    def test_mistral_url_https_secure(self, mock, keystone_client_mock):
        fd, path = tempfile.mkstemp(suffix='.pem')

        keystone_client_instance = keystone_client_mock.return_value
        keystone_client_instance.auth_token = str(uuid.uuid4())
        keystone_client_instance.project_id = str(uuid.uuid4())
        keystone_client_instance.user_id = str(uuid.uuid4())

        expected_args = (
            MISTRAL_HTTPS_URL,
            keystone_client_instance.auth_token,
            keystone_client_instance.project_id,
            keystone_client_instance.user_id
        )

        expected_kwargs = {
            'cacert': path,
            'insecure': False
        }

        try:
            client.client(
                mistral_url=MISTRAL_HTTPS_URL,
                username='******',
                project_name='mistral',
                auth_url=AUTH_HTTP_URL,
                cacert=path,
                insecure=False
            )
        finally:
            os.close(fd)
            os.unlink(path)

        self.assertTrue(mock.called)
        self.assertEqual(mock.call_args[0], expected_args)
        self.assertDictEqual(mock.call_args[1], expected_kwargs)
Example #56
0
    def mistral(self):
        if self._mistral:
            return self._mistral

        args = {
            'auth_token': self.auth_token,
        }
        endpoint_type = get_client_option('mistral', 'endpoint_type')
        region_name = get_client_option('mistral', 'region_name')
        endpoint = self.url_for(service_type='workflow',
                                endpoint_type=endpoint_type,
                                region_name=region_name)
        self._mistral = mistralclient.client(mistral_url=endpoint, **args)

        return self._mistral
Example #57
0
        def factory(keystone_client, auth_token):
            mistral_settings = CONF.mistral

            endpoint_type = mistral_settings.endpoint_type
            service_type = mistral_settings.service_type

            mistral_url = keystone_client.service_catalog.url_for(
                service_type=service_type,
                endpoint_type=endpoint_type)

            return mistralclient.client(mistral_url=mistral_url,
                                        project_id=keystone_client.tenant_id,
                                        endpoint_type=endpoint_type,
                                        service_type=service_type,
                                        auth_token=auth_token,
                                        user_id=keystone_client.user_id)
Example #58
0
    def initialize_app(self, argv):
        self._clear_shell_commands()

        ver = client.determine_client_version(self.options.mistral_version)

        self._set_shell_commands(self._get_commands(ver))

        do_help = ('help' in argv) or ('-h' in argv) or not argv

        # Set default for auth_url if not supplied. The default is not
        # set at the parser to support use cases where auth is not enabled.
        # An example use case would be a developer's environment.
        if not self.options.auth_url:
            if self.options.password or self.options.token:
                self.options.auth_url = 'http://localhost:35357/v3'

        # bash-completion should not require authentification.
        if do_help or ('bash-completion' in argv):
            self.options.auth_url = None

        self.client = client.client(
            mistral_url=self.options.mistral_url,
            username=self.options.username,
            api_key=self.options.password,
            project_name=self.options.tenant_name,
            auth_url=self.options.auth_url,
            project_id=self.options.tenant_id,
            endpoint_type=self.options.endpoint_type,
            service_type=self.options.service_type,
            auth_token=self.options.token,
            cacert=self.options.cacert,
            insecure=self.options.insecure,
            profile=self.options.profile,
            auth_type=self.options.auth_type,
            client_id=self.options.client_id,
            client_secret=self.options.client_secret,
        )

        # Adding client_manager variable to make mistral client work with
        # unified OpenStack client.
        ClientManager = type(
            'ClientManager',
            (object,),
            dict(workflow_engine=self.client)
        )

        self.client_manager = ClientManager()