Exemple #1
0
    def _initialize_tests(self):
        """Perform final initialization before tests get run."""
        # Access the sentries for inspecting service units
        self.murano_sentry = self.d.sentry['murano'][0]
        self.pxc_sentry = self.d.sentry['percona-cluster'][0]
        self.keystone_sentry = self.d.sentry['keystone'][0]
        self.rabbitmq_sentry = self.d.sentry['rabbitmq-server'][0]
        u.log.debug('openstack release val: {}'.format(
            self._get_openstack_release()))
        u.log.debug('openstack release str: {}'.format(
            self._get_openstack_release_string()))

        # Authenticate admin with keystone endpoint
        self.keystone = u.authenticate_keystone_admin(self.keystone_sentry,
                                                      user='******',
                                                      password='******',
                                                      tenant='admin')

        # Authenticate admin with murano endpoint
        murano_ep = self.keystone.service_catalog.url_for(
            service_type='application-catalog', endpoint_type='publicURL')

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

        auth = keystone_identity.V2Token(auth_url=keystone_ep,
                                         token=self.keystone.auth_token)
        sess = keystone_session.Session(auth=auth)
        self.murano = murano_client.Client(version=1,
                                           session=sess,
                                           endpoint_override=murano_ep)
Exemple #2
0
    def create_client(self, version=None, service_type=None):
        """Return Murano client."""
        from muranoclient import client as murano

        client = murano.Client(self.choose_version(version),
                               endpoint=self._get_endpoint(service_type),
                               token=self.keystone.auth_ref.auth_token)

        return client
Exemple #3
0
def murano_client(conf):
    creds = conf.service_credentials
    mclient = client.Client(
        version='1',
        session=keystone_client.get_session(conf),
        region_name=creds.region_name,
        service_type='application-catalog',
    )
    return mclient
Exemple #4
0
 def setUpClass(cls):
     cls.keystone_client = ksclient.Client(username=cfg.common.user,
                                           password=cfg.common.password,
                                           tenant_name=cfg.common.tenant,
                                           auth_url=cfg.common.keystone_url)
     cls.murano_client = mclient.Client(
         '1', endpoint=cfg.common.murano_url,
         token=cls.keystone_client.auth_token)
     cls.url_prefix = urlparse.urlparse(cfg.common.horizon_url).path or ''
     if cls.url_prefix.endswith('/'):
         cls.url_prefix = cls.url_prefix[:-1]
Exemple #5
0
    def get_murano_client(cls, auth_client=None):
        keystone = auth_client if auth_client else cls._get_auth()
        murano_endpoint = cls._get_endpoint(service_type='application-catalog',
                                            endpoint_type='publicURL')
        cert = auth.BasicAuth.cert_path

        if not cert:
            murano = muranoclient.Client(
                '1',
                endpoint=murano_endpoint,
                token=keystone.auth_token,
            )
        else:
            murano = muranoclient.Client(
                '1',
                endpoint=murano_endpoint,
                token=keystone.auth_token,
                cacert=cert,
            )
        return murano
Exemple #6
0
    def test_create_client_instance(self):

        endpoint = 'http://no-resolved-host:8001'
        test_client = client.Client('1',
                                    endpoint=endpoint,
                                    token='1',
                                    timeout=10)

        self.assertIsNotNone(test_client.environments)
        self.assertIsNotNone(test_client.sessions)
        self.assertIsNotNone(test_client.services)
Exemple #7
0
def muranoclient(token_id):
    endpoint = "http://{murano_host}:{murano_port}".format(
        murano_host=CONF.bind_host, murano_port=CONF.bind_port)
    insecure = False

    LOG.debug('murano client created. Murano::Client <Url: {endpoint}'.format(
        endpoint=endpoint))

    return client.Client(1,
                         endpoint=endpoint,
                         token=token_id,
                         insecure=insecure)
def muranoclient(request):
    endpoint = _get_endpoint(request)
    insecure = getattr(settings, 'MURANO_API_INSECURE', False)

    token_id = request.user.token.id
    LOG.debug('Murano::Client <Url: {0}, '
              'TokenId: {1}>'.format(endpoint, token_id))

    return client.Client(1,
                         endpoint=endpoint,
                         token=token_id,
                         insecure=insecure)
Exemple #9
0
    def initialize_murano_client(cls, auth_client=None):
        ks_client = (auth_client
                     if auth_client else cls.initialize_keystone_client())

        murano_endpoint = cls.get_endpoint(service_type='application-catalog',
                                           endpoint_type='publicURL')

        murano = muranoclient.Client('1',
                                     endpoint=murano_endpoint,
                                     token=ks_client.auth_token)

        return murano
Exemple #10
0
def muranoclient(token_id):
    # TODO(starodubcevna): I guess it can be done better.
    endpoint = "http://{murano_host}:{murano_port}".format(
        murano_host=CONF.bind_host, murano_port=CONF.bind_port)
    insecure = False

    LOG.debug('murano client created. Murano::Client <Url: {endpoint}'.format(
        endpoint=endpoint))

    return client.Client(1,
                         endpoint=endpoint,
                         token=token_id,
                         insecure=insecure)
Exemple #11
0
    def murano(self, version="1"):
        """Return Murano client."""
        from muranoclient import client as murano
        kc = self.keystone()
        murano_url = kc.service_catalog.url_for(
            service_type=consts.ServiceType.APPLICATION_CATALOG,
            endpoint_type=self.endpoint.endpoint_type,
            region_name=self.endpoint.region_name)

        client = murano.Client(version,
                               endpoint=murano_url,
                               token=kc.auth_token)

        return client
Exemple #12
0
def _get_muranoclient(token_id, req):

    artifacts_client = None
    if CONF.engine.packages_service in ['glance', 'glare']:
        artifacts_client = _get_glareclient(token_id, req)

    murano_url = CONF.murano.url or req.endpoints.get('murano')
    if not murano_url:
        LOG.error(_LE('No murano url is specified and no '
                      '"application-catalog" '
                      'service is registered in keystone.'))

    return muranoclient.Client(1, murano_url, token=token_id,
                               artifacts_client=artifacts_client)
Exemple #13
0
    def create_client(self, version=None, service_type=None):
        """Return Murano client."""
        from muranoclient import client as murano
        kc = self.keystone()
        murano_url = kc.service_catalog.url_for(
            service_type=self.choose_service_type(service_type),
            endpoint_type=self.credential.endpoint_type,
            region_name=self.credential.region_name)

        client = murano.Client(self.choose_version(version),
                               endpoint=murano_url,
                               token=kc.auth_token)

        return client
Exemple #14
0
 def murano_client(cls):
     murano_url = cls.get_murano_url()
     if CONF.murano.packages_service == "glare":
         glare_endpoint = "http://127.0.0.1:9494"
         artifacts_client = glare_client.Client(
             endpoint=glare_endpoint,
             token=cls.keystone_client().auth_token,
             insecure=False, key_file=None, ca_file=None, cert_file=None,
             type_name="murano", type_version=1)
     else:
         artifacts_client = None
     return mclient.Client('1',
                           artifacts_client=artifacts_client,
                           endpoint=murano_url,
                           token=cls.keystone_client().auth_token)
Exemple #15
0
def muranoclient(request):
    endpoint = _get_endpoint(request)
    insecure = getattr(settings, 'MURANO_API_INSECURE', False)

    use_artifacts = getattr(settings, 'MURANO_USE_GLARE', False)
    if use_artifacts:
        artifacts = artifactclient(request)
    else:
        artifacts = None

    token_id = request.user.token.id
    LOG.debug('Murano::Client <Url: {0}>'.format(endpoint))

    return client.Client(1, endpoint=endpoint, token=token_id,
                         insecure=insecure, artifacts_client=artifacts,
                         tenant=request.user.tenant_id)
Exemple #16
0
    def setUp(self):
        super(MuranoTestsCore, self).setUp()
        self.keystone = keystoneclient.Client(username=CONF.murano.user,
                                              password=CONF.murano.password,
                                              tenant_name=CONF.murano.tenant,
                                              auth_url=CONF.murano.auth_url)
        self.heat = heatclient.Client('1',
                                      endpoint=self.heat_url,
                                      token=self.keystone.auth_token)
        self.murano = muranoclient.Client('1',
                                          endpoint=self.murano_url,
                                          token=self.keystone.auth_token)
        self.headers = {
            'X-Auth-Token': self.murano.auth_token,
            'content-type': 'application/json'
        }

        self.environments = []
Exemple #17
0
    def setUpClass(cls):
        super(MuranoBase, cls).setUpClass()

        cfg.load_config()

        keystone_client = ksclient.Client(username=CONF.murano.user,
                                          password=CONF.murano.password,
                                          tenant_name=CONF.murano.tenant,
                                          auth_url=CONF.murano.auth_url)

        heat_url = keystone_client.service_catalog.url_for(
            service_type='orchestration', endpoint_type='publicURL')

        cls.heat_client = heatclient.Client('1',
                                            endpoint=heat_url,
                                            token=keystone_client.auth_token)

        url = CONF.murano.murano_url
        murano_url = url if 'v1' not in url else "/".join(
            url.split('/')[:url.split('/').index('v1')])

        cls.muranoclient = mclient.Client('1',
                                          endpoint=murano_url,
                                          token=keystone_client.auth_token)

        cls.linux = CONF.murano.linux_image

        cls.pkgs_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), os.path.pardir,
                         'murano-app-incubator'))

        def upload_package(package_name, body, app):

            files = {'%s' % package_name: open(app, 'rb')}

            return cls.muranoclient.packages.create(body, files)

        upload_package(
            'PostgreSQL', {
                "categories": ["Databases"],
                "tags": ["tag"]
            }, os.path.join(cls.pkgs_path,
                            'io.murano.databases.PostgreSql.zip'))
        upload_package(
            'SqlDatabase', {
                "categories": ["Databases"],
                "tags": ["tag"]
            },
            os.path.join(cls.pkgs_path, 'io.murano.databases.SqlDatabase.zip'))
        upload_package(
            'Apache', {
                "categories": ["Application Servers"],
                "tags": ["tag"]
            },
            os.path.join(cls.pkgs_path,
                         'io.murano.apps.apache.ApacheHttpServer.zip'))
        upload_package(
            'Tomcat', {
                "categories": ["Application Servers"],
                "tags": ["tag"]
            }, os.path.join(cls.pkgs_path, 'io.murano.apps.apache.Tomcat.zip'))
        upload_package(
            'Telnet', {
                "categories": ["Web"],
                "tags": ["tag"]
            }, os.path.join(cls.pkgs_path, 'io.murano.apps.linux.Telnet.zip'))
Exemple #18
0
    def main(self, argv):
        # Parse args once to find version
        parser = self.get_base_parser(argv)
        (options, args) = parser.parse_known_args(argv)
        self._setup_logging(options.debug)

        # build available subcommands based on version
        api_version = options.murano_api_version
        subcommand_parser = self.get_subcommand_parser(api_version, argv)
        self.parser = subcommand_parser

        keystone_session = None
        keystone_auth = None

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line.
        if (not args and options.help) or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected.
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        if not args.os_username and not args.os_auth_token:
            raise exc.CommandError("You must provide a username via"
                                   " either --os-username or env[OS_USERNAME]"
                                   " or a token via --os-auth-token or"
                                   " env[OS_AUTH_TOKEN]")

        if args.murano_packages_service == 'glance':
            args.murano_packages_service = 'glare'

        if args.os_no_client_auth:
            if not args.murano_url:
                raise exc.CommandError(
                    "If you specify --os-no-client-auth"
                    " you must also specify a Murano API URL"
                    " via either --murano-url or env[MURANO_URL]")
            if (not args.glare_url
                    and args.murano_packages_service == 'glare'):
                raise exc.CommandError(
                    "If you specify --os-no-client-auth and"
                    " set murano-packages-service to 'glare'"
                    " you must also specify a glare API URL"
                    " via either --glare-url or env[GLARE_API]")
            if (not any([args.os_tenant_id, args.os_project_id])
                    and args.murano_packages_service == 'glare'):
                # TODO(kzaitsev): see if we can use project's name here
                # NOTE(kzaitsev): glare v0.1 needs project_id to operate
                # correctly
                raise exc.CommandError(
                    "If you specify --os-no-client-auth and"
                    " set murano-packages-service to 'glare'"
                    " you must also specify your project's id"
                    " via either --os-project-id or env[OS_PROJECT_ID] or"
                    " --os-tenant-id or env[OS_TENANT_ID]")

        else:
            # Tenant name or ID is needed to make keystoneclient retrieve a
            # service catalog, it's not required if os_no_client_auth is
            # specified, neither is the auth URL.
            if not any([
                    args.os_tenant_name, args.os_tenant_id, args.os_project_id,
                    args.os_project_name
            ]):
                raise exc.CommandError("You must provide a project name or"
                                       " project id via --os-project-name,"
                                       " --os-project-id, env[OS_PROJECT_ID]"
                                       " or env[OS_PROJECT_NAME]. You may"
                                       " use os-project and os-tenant"
                                       " interchangeably.")
            if not args.os_auth_url:
                raise exc.CommandError("You must provide an auth url via"
                                       " either --os-auth-url or via"
                                       " env[OS_AUTH_URL]")

        endpoint_type = args.os_endpoint_type or 'publicURL'
        endpoint = args.murano_url
        glance_endpoint = args.glance_url

        if args.os_no_client_auth:
            # Authenticate through murano, don't use session
            kwargs = {
                'username': args.os_username,
                'password': args.os_password,
                'auth_token': args.os_auth_token,
                'auth_url': args.os_auth_url,
                'token': args.os_auth_token,
                'insecure': args.insecure,
                'timeout': args.api_timeout,
                'tenant': args.os_project_id or args.os_tenant_id,
            }
            glance_kwargs = kwargs.copy()

            if args.os_region_name:
                kwargs['region_name'] = args.os_region_name
                glance_kwargs['region_name'] = args.os_region_name
        else:
            # Create a keystone session and keystone auth
            keystone_session = ksession.Session.load_from_cli_options(args)

            args.os_project_name = args.os_project_name or args.os_tenant_name
            args.os_project_id = args.os_project_id or args.os_tenant_id

            # make args compatible with DefaultCLI/AuthCLI
            args.os_token = args.os_auth_token
            args.os_endpoint = ''
            # avoid password prompt if no password given
            args.os_password = args.os_password or '<no password>'
            (v2_auth_url, v3_auth_url) = self._discover_auth_versions(
                keystone_session, args.os_auth_url)
            if v3_auth_url:
                if (not args.os_user_domain_id
                        and not args.os_user_domain_name):
                    args.os_user_domain_name = 'default'

                if (not args.os_project_domain_id
                        and not args.os_project_domain_name):
                    args.os_project_domain_name = 'default'

            keystone_auth = AuthCLI.load_from_argparse_arguments(args)

            service_type = args.os_service_type or 'application-catalog'

            if not endpoint:
                endpoint = keystone_auth.get_endpoint(
                    keystone_session,
                    service_type=service_type,
                    interface=endpoint_type,
                    region_name=args.os_region_name)

            kwargs = {
                'session': keystone_session,
                'auth': keystone_auth,
                'service_type': service_type,
                'region_name': args.os_region_name,
            }
            glance_kwargs = kwargs.copy()

            # glance doesn't need endpoint_type
            kwargs['endpoint_type'] = endpoint_type
            kwargs['tenant'] = keystone_auth.get_project_id(keystone_session)

        if args.api_timeout:
            kwargs['timeout'] = args.api_timeout

        if not glance_endpoint:
            try:
                glance_endpoint = keystone_auth.get_endpoint(
                    keystone_session,
                    service_type='image',
                    interface=endpoint_type,
                    region_name=args.os_region_name)
            except Exception:
                pass

        glance_client = None
        if glance_endpoint:
            try:
                # TODO(starodubcevna): switch back to glance APIv2 when it will
                # be ready for use.
                glance_client = glanceclient.Client('1', glance_endpoint,
                                                    **glance_kwargs)
            except Exception:
                pass
        if glance_client:
            kwargs['glance_client'] = glance_client
        else:
            logger.warning("Could not initialize glance client. "
                           "Image creation will be unavailable.")
            kwargs['glance_client'] = None

        if args.murano_packages_service == 'glare':
            glare_endpoint = args.glare_url

            if not glare_endpoint:
                # no glare_endpoint and we requested to store packages in glare
                # let's check keystone
                try:
                    glare_endpoint = keystone_auth.get_endpoint(
                        keystone_session,
                        service_type='artifact',
                        interface=endpoint_type,
                        region_name=args.os_region_name)
                except Exception:
                    raise exc.CommandError(
                        "You set murano-packages-service to {}"
                        " but there is not 'artifact' endpoint in keystone"
                        " Either register one or specify endpoint "
                        " via either --glare-url or env[GLARE_API]".format(
                            args.murano_packages_service))

            auth_token = \
                args.os_auth_token or keystone_auth.get_token(keystone_session)

            artifacts_client = art_client.Client(endpoint=glare_endpoint,
                                                 type_name='murano',
                                                 type_version=1,
                                                 token=auth_token,
                                                 insecure=args.insecure)
            kwargs['artifacts_client'] = artifacts_client

        client = murano_client.Client(api_version, endpoint, **kwargs)

        args.func(client, args)
Exemple #19
0
    def main(self, argv):
        # Parse args once to find version
        parser = self.get_base_parser()
        (options, args) = parser.parse_known_args(argv)
        self._setup_logging(options.debug)

        # build available subcommands based on version
        api_version = options.murano_api_version
        subcommand_parser = self.get_subcommand_parser(api_version)
        self.parser = subcommand_parser

        keystone_session = None
        keystone_auth = None

        # Handle top-level --help/-h before attempting to parse
        # a command off the command line.
        if (not args and options.help) or not argv:
            self.do_help(options)
            return 0

        # Parse args again and call whatever callback was selected.
        args = subcommand_parser.parse_args(argv)

        # Short-circuit and deal with help command right away.
        if args.func == self.do_help:
            self.do_help(args)
            return 0
        elif args.func == self.do_bash_completion:
            self.do_bash_completion(args)
            return 0

        if not args.os_username and not args.os_auth_token:
            raise exc.CommandError("You must provide a username via"
                                   " either --os-username or env[OS_USERNAME]"
                                   " or a token via --os-auth-token or"
                                   " env[OS_AUTH_TOKEN]")

        if not any([
                args.os_tenant_name, args.os_tenant_id, args.os_project_id,
                args.os_project_name
        ]):
            raise exc.CommandError("You must provide a project name or"
                                   " project id via --os-project-name,"
                                   " --os-project-id, env[OS_PROJECT_ID]"
                                   " or env[OS_PROJECT_NAME]. You may"
                                   " use os-project and os-tenant"
                                   " interchangeably.")

        if args.os_no_client_auth:
            if not args.murano_url:
                raise exc.CommandError(
                    "If you specify --os-no-client-auth"
                    " you must also specify a Murano API URL"
                    " via either --murano-url or env[MURANO_URL]")
        else:
            # Tenant name or ID is needed to make keystoneclient retrieve a
            # service catalog, it's not required if os_no_client_auth is
            # specified, neither is the auth URL.
            if not (args.os_tenant_id or args.os_tenant_name):
                raise exc.CommandError(
                    "You must provide a tenant name "
                    "or tenant id via --os-tenant-name, "
                    "--os-tenant-id, env[OS_TENANT_NAME] "
                    "or env[OS_TENANT_ID] OR a project name "
                    "or project id via --os-project-name, "
                    "--os-project-id, env[OS_PROJECT_ID] or "
                    "env[OS_PROJECT_NAME]")

            if not args.os_auth_url:
                raise exc.CommandError("You must provide an auth url via"
                                       " either --os-auth-url or via"
                                       " env[OS_AUTH_URL]")

        kwargs = {
            'username': args.os_username,
            'password': args.os_password,
            'token': args.os_auth_token,
            'tenant_id': args.os_tenant_id,
            'tenant_name': args.os_tenant_name,
            'auth_url': args.os_auth_url,
            'service_type': args.os_service_type,
            'endpoint_type': args.os_endpoint_type,
            'insecure': args.insecure,
            'cacert': args.os_cacert,
            'include_pass': args.include_password
        }
        glance_kwargs = kwargs
        glance_kwargs = kwargs.copy()

        endpoint = args.murano_url
        glance_endpoint = args.glance_url

        if args.os_no_client_auth:
            # Authenticate through murano, don't use session
            kwargs = {
                'username': args.os_username,
                'password': args.os_password,
                'auth_token': args.os_auth_token,
                'auth_url': args.os_auth_url,
                'token': args.os_auth_token,
                'insecure': args.insecure,
                'timeout': args.api_timeout
            }
            glance_kwargs = kwargs.copy()

            if args.os_region_name:
                kwargs['region_name'] = args.os_region_name
                glance_kwargs['region_name'] = args.os_region_name
        else:
            # Create a keystone session and keystone auth
            keystone_session = ksession.Session.load_from_cli_options(args)
            project_id = args.os_project_id or args.os_tenant_id
            project_name = args.os_project_name or args.os_tenant_name

            keystone_session = ksession.Session.load_from_cli_options(args)

            keystone_auth = self._get_keystone_auth(
                keystone_session,
                args.os_auth_url,
                username=args.os_username,
                user_id=args.os_user_id,
                user_domain_id=args.os_user_domain_id,
                user_domain_name=args.os_user_domain_name,
                password=args.os_password,
                auth_token=args.os_auth_token,
                project_id=project_id,
                project_name=project_name,
                project_domain_id=args.os_project_domain_id,
                project_domain_name=args.os_project_domain_name)

            endpoint_type = args.os_endpoint_type or 'publicURL'
            service_type = args.os_service_type or 'application-catalog'

            if not endpoint:
                endpoint = keystone_auth.get_endpoint(
                    keystone_session,
                    service_type=service_type,
                    region_name=args.os_region_name)

            kwargs = {
                'session': keystone_session,
                'auth': keystone_auth,
                'service_type': service_type,
                'endpoint_type': endpoint_type,
                'region_name': args.os_region_name,
            }
            glance_kwargs = kwargs.copy()
            del glance_kwargs['endpoint_type']

        if args.api_timeout:
            kwargs['timeout'] = args.api_timeout

        if not glance_endpoint:
            try:
                glance_endpoint = keystone_auth.get_endpoint(
                    keystone_session,
                    service_type='image',
                    region_name=args.os_region_name)
            except Exception:
                pass

        glance_client = None
        if glance_endpoint:
            try:
                glance_client = glanceclient.Client('2', glance_endpoint,
                                                    **glance_kwargs)
            except Exception:
                pass
        if glance_client:
            kwargs['glance_client'] = glance_client
        else:
            logger.warning("Could not initialise glance client. "
                           "Image creation will be unavailable.")
            kwargs['glance_client'] = None

        client = murano_client.Client(api_version, endpoint, **kwargs)

        args.func(client, args)
Exemple #20
0
 def murano_client(cls):
     murano_url = cls.get_murano_url()
     return mclient.Client('1',
                           endpoint=murano_url,
                           token=cls.keystone_client().auth_token)