def setUpClass(cls):
        cls.prefix = prefix or rand()
        #cls.auth = Auth(user=user, password=password, tenant=tenant)
        #cls.context_public = cls.auth

    # Initialize platform and check access
        cls.platform = QubellPlatform.connect(tenant, user, password)
        #assert cls.platform.authenticate()

        ###cls.platform_public = QubellPlatformPublic(context=cls.context_public)

    # Set default manifest for app creation
        cls.manifest = Manifest(file=os.path.join(os.path.dirname(__file__), 'default.yml'), name='BaseTestManifest')

    # Initialize organization
        cls.organization = cls.platform.organization(name=org)
        ###cls.organization_public = cls.platform_public.organization(name=org)

        if zone:
            z = [x for x in cls.organization.list_zones() if x['name'] == zone]
            if z:
                cls.organization.zoneId = z[0]['id']



    # Initialize environment
        if zone:
            cls.environment = cls.organization.environment(name='default', zone=cls.organization.zoneId)
            cls.environment.set_backend(cls.organization.zoneId)
        else:
            cls.environment = cls.organization.get_environment(name='default')
        """
        def get_unauthenticated_platform(self):
            if not self.unauthenticated_platform:
                assert QUBELL["tenant"], "No platform URL provided. Set QUBELL_TENANT or use --tenant option."

                self.unauthenticated_platform = QubellPlatform.connect(tenant=QUBELL["tenant"])

            return self.unauthenticated_platform
Exemplo n.º 3
0
 def get_platform(self):
     if not self.platform:
         self.platform = QubellPlatform.connect(
             tenant=QUBELL["tenant"],
             user=QUBELL["user"],
             password=QUBELL["password"])
     return self.platform
def prepare_monitor(tenant=tenant,
                    user=user,
                    password=password,
                    organization=organization,
                    zone_name=zone_name):
    """
    :param tenant: tenant url
    :param user: user's email
    :param password: user's password
    :param zone_name: (optional) zone_name
    :return:
    """
    router = PrivatePath(tenant, verify_codes=False)

    payload = {
        "firstName": "AllSeeingEye",
        "lastName": "Monitor",
        "email": user,
        "password": password,
        "accept": "true"
    }
    try:
        router.post_quick_sign_up(data=payload)
    except exceptions.ApiUnauthorizedError:
        pass

    platform = QubellPlatform.connect(tenant=tenant,
                                      user=user,
                                      password=password)
    org = platform.organization(name=organization)
    if zone_name:
        zone = org.zones[zone_name]
    else:
        zone = org.zone
    env = org.environment(name="Monitor for " + zone.name, zone=zone.id)
    env.init_common_services(with_cloud_account=False, zone_name=zone_name)

    # todo: move to env
    policy_name = lambda policy: "{}.{}".format(policy.get('action'),
                                                policy.get('parameter'))
    env_data = env.json()
    key_id = [
        p for p in env_data['policies']
        if 'provisionVms.publicKeyId' == policy_name(p)
    ][0].get('value')

    with env as envbulk:
        envbulk.add_marker('monitor')
        envbulk.add_property('publicKeyId', 'string', key_id)

    monitor = Manifest(file=os.path.join(os.path.dirname(__file__),
                                         './monitor_manifests/monitor.yml'))
    monitor_child = Manifest(file=os.path.join(
        os.path.dirname(__file__), './monitor_manifests/monitor_child.yml'))

    org.application(manifest=monitor_child, name='monitor-child')
    app = org.application(manifest=monitor, name='monitor')

    return platform, org.id, app.id, env.id
 def platform(cls):
     """
     lazy property, to authenticate when needed
     """
     if not cls.__lazy_platform:
         cls.__lazy_platform = QubellPlatform.connect()
         log.info('Authentication succeeded.')
     return cls.__lazy_platform
 def platform(cls):
     """
     lazy property, to authenticate when needed
     """
     if not cls.__lazy_platform:
         cls.__lazy_platform = QubellPlatform.connect(user=qubell_config['user'], password=qubell_config['password'], token=qubell_config['token'])
         log.info('Authentication succeeded.')
     return cls.__lazy_platform
 def get_platform(self):
     if not self.platform:
         assert QUBELL["tenant"], "No platform URL provided. Set QUBELL_TENANT or use --tenant option."
         assert QUBELL["user"], "No username. Set QUBELL_USER or use --user option."
         assert QUBELL["password"], "No password provided. Set QUBELL_PASSWORD or use --password option."
         self.platform = QubellPlatform.connect(
             tenant=QUBELL["tenant"],
             user=QUBELL["user"],
             password=QUBELL["password"])
     return self.platform
Exemplo n.º 8
0
 def platform(cls):
     """
     lazy property, to authenticate when needed
     """
     if not cls.__lazy_platform:
         cls.__lazy_platform = QubellPlatform.connect(
             user=qubell_config['user'],
             password=qubell_config['password'],
             token=qubell_config['token'])
         log.info('Authentication succeeded.')
     return cls.__lazy_platform
Exemplo n.º 9
0
def start():
    # Here we check existance of given credentials and create services if needed
    print "Creating ENV"
    exit = 0
    if not user:
        log.error('No username provided. Set QUBELL_USER env')
        exit = 1
    if not password:
        log.error('No password provided. Set QUBELL_PASSWORD env')
        exit = 1
    if not api:
        log.error('No api url provided. Set QUBELL_API env')
        exit = 1

    if exit:
        sys.exit(1)


# Setup access
    context = Context(user=user, password=password, api=api)

    # Initialize platform and check access
    platform = QubellPlatform(context=context)
    assert platform.authenticate()
    print "Authorization passed"
    # Initialize organization
    organization = platform.organization(name=org)
    print "Using orgainzation %s" % org

    if zone:  # Need to run tests against zones. Create env for each
        z = [x for x in organization.list_zones() if x['name'] == zone]
        if len(z):
            print "Using zone %s" % zone
            create_env(organization, z[0]['id'])

    create_env(organization)
    create_launcher_apps(organization)
    print "ENV created"
Exemplo n.º 10
0
def start():
# Here we check existance of given credentials and create services if needed
    print "Creating ENV"
    exit = 0
    if not user:
        log.error('No username provided. Set QUBELL_USER env')
        exit = 1
    if not password:
        log.error('No password provided. Set QUBELL_PASSWORD env')
        exit = 1
    if not tenant:
        log.error('No api url provided. Set QUBELL_TENANT env')
        exit = 1

    if exit:
        sys.exit(1)

# Setup access
    auth = Auth(user=user, password=password, tenant=tenant)

# Initialize platform and check access
    platform = QubellPlatform(auth=auth)
    assert platform.authenticate()
    print "Authorization passed"
# Initialize organization
    organization = platform.organization(name=org)
    print "Using orgainzation %s" % org

    if zone: # Need to run tests against zones. Create env for each
        z = [x for x in organization.list_zones() if x['name'] == zone]
        if len(z):
            print "Using zone %s" % zone
            create_env(organization, z[0]['id'])

    create_env(organization)
    create_launcher_apps(organization)
    print "ENV created"
Exemplo n.º 11
0
    def setUpClass(cls):
        cls.prefix = prefix or rand()
        cls.context = Context(user=user, password=password, api=api)
        cls.context_public = cls.context

        # Initialize platform and check access
        cls.platform = QubellPlatform(context=cls.context)
        assert cls.platform.authenticate()

        cls.platform_public = QubellPlatformPublic(context=cls.context_public)

        # Set default manifest for app creation
        cls.manifest = Manifest(file=os.path.join(os.path.dirname(__file__),
                                                  'default.yml'),
                                name='BaseTestManifest')

        # Initialize organization
        cls.organization = cls.platform.organization(name=org)
        cls.organization_public = cls.platform_public.organization(name=org)

        if zone:
            z = [x for x in cls.organization.list_zones() if x['name'] == zone]
            if z:
                cls.organization.zoneId = z[0]['id']

    # Initialize environment
        if zone:
            cls.environment = cls.organization.environment(
                name='default', zone=cls.organization.zoneId)
            cls.environment.set_backend(cls.organization.zoneId)
        else:
            cls.environment = cls.organization.environment(name='default')
        cls.environment_public = cls.organization_public.environment(
            id=cls.environment.environmentId)

        cls.shared_service = cls.organization.service(
            name='BaseTestSharedService' + zone)
        cls.wf_service = cls.organization.service(name='Workflow' + zone)
        cls.key_service = cls.organization.service(name='Keystore' + zone)

        # Cannot get services by Name (list not imlpemented)
        cls.shared_service_public = cls.organization_public.service(
            id=cls.shared_service.serviceId)
        cls.wf_service_public = cls.organization_public.service(
            id=cls.wf_service.serviceId)
        cls.key_service_public = cls.organization_public.service(
            id=cls.key_service.serviceId)
Exemplo n.º 12
0
def prepare_monitor(tenant, user, password, organization, zone_name=None):
    """
    :param tenant: tenant url
    :param user: user's email
    :param password: user's password
    :param zone_name: (optional) zone_name
    :return:
    """
    router = PrivatePath(tenant, verify_codes=False)

    payload = {
        "firstName": "AllSeeingEye",
        "lastName": "Monitor",
        "email": user,
        "password": password,
        "accept": "true"
    }
    try:
        router.post_quick_sign_up(data=payload)
    except exceptions.ApiUnauthorizedError:
        pass

    platform = QubellPlatform.connect(tenant=tenant, user=user, password=password)
    org = platform.organization(name=organization)
    if zone_name:
        zone = org.zones[zone_name]
    else:
        zone = org.zone
    env = org.environment(name="Monitor for "+zone.name, zone=zone.id)
    env.init_common_services(with_cloud_account=False, zone_name=zone_name)

    # todo: move to env
    policy_name = lambda policy: "{}.{}".format(policy.get('action'), policy.get('parameter'))
    env_data = env.json()
    key_id = [p for p in env_data['policies'] if 'provisionVms.publicKeyId' == policy_name(p)][0].get('value')

    with env as envbulk:
        envbulk.add_marker('monitor')
        envbulk.add_property('publicKeyId', 'string', key_id)

    monitor = Manifest(file=os.path.join(os.path.dirname(__file__), './monitor_manifests/monitor.yml'))
    monitor_child = Manifest(file=os.path.join(os.path.dirname(__file__), './monitor_manifests/monitor_child.yml'))

    org.application(manifest=monitor_child, name='monitor-child')
    app = org.application(manifest=monitor, name='monitor')

    return platform, org.id, app.id, env.id
Exemplo n.º 13
0
class BaseTestCase(SetupOnce, unittest.TestCase):
    parameters=parameters
    ## TODO: Main preparation should be here
    """ Here we prepare global env. (load config, etc)
    """
    # Set default manifest for app creation
    manifest = Manifest(file=os.path.join(os.path.dirname(__file__), './default.yml'), name='BaseTestManifest')
    platform = QubellPlatform.connect(user=parameters['user'], password=parameters['pass'], tenant=parameters['tenant'], token=parameters['token'])


    def setup_once(self):
        def type_to_app(t):
            return self.organization.applications[system_application_types.get(t, t)]
    # Initialize organization
        if os.getenv("QUBELL_IT_LOCAL"):
            self.parameters['organization'] = self.__class__.__name__
        self.organization = self.platform.organization(name=self.parameters['organization'])

        if zone:
            z = [x for x in self.organization.list_zones() if x['name'] == zone]
            if z:
                self.organization.zoneId = z[0]['id']


    # Initialize environment
        if zone:
            self.environment = self.organization.environment(name='default', zone=self.organization.zoneId)
            self.environment.set_backend(self.organization.zoneId)
        else:
            self.environment = self.organization.get_environment(name='default')

        self.shared_service = self.organization.service(name='BaseTestSharedService',
                                                        application=type_to_app(SHARED_INSTANCE_CATALOG_TYPE),
                                                        environment=self.environment,
                                                        parameters={'configuration.shared-instances': {}})
        self.wf_service, self.key_service, self.cloud_account_service = self.environment.init_common_services()
./restore_env.py
Will use default.env

"""

if os.getenv("QUBELL_LOG_LEVEL", "info") == "debug":
    logging.getLogger().setLevel(logging.DEBUG)
else:
    logging.getLogger().setLevel(logging.INFO)

default_env = os.path.join(os.path.dirname(__file__), "default.env")

if len(sys.argv) > 1:
    env = sys.argv[1]
else:
    env = default_env

cfg = load_env(env)

# Patch configuration to include provider and org info
cfg["organizations"][0].update({"providers": [PROVIDER_CONFIG]})
if QUBELL["organization"]:
    cfg["organizations"][0].update({"name": QUBELL["organization"]})

platform = QubellPlatform.connect(user=QUBELL["user"], password=QUBELL["password"], tenant=QUBELL["tenant"])
print "Authorization passed"

print "Restoring env: %s" % env
platform.restore(cfg)
print "Restore finished"
      "jcloudsCredential": SECRET_KEY,
      "jcloudsRegions": "us-east-1"
    }
    prov = org.provider(access)
    env.add_provider(prov)
    return org.organizationId


# Define manifest. We take example from documentation.
# TODO: make manifests accessible from docs.qubell.com
app_manifest = Manifest(url="https://raw.github.com/qubell/contrib-python-qubell-client/master/qm/hierarchical-main.yml")
db_manifest = Manifest(url="https://raw.github.com/qubell/contrib-python-qubell-client/master/qm/hierarchical-db.yml")


# Initialize our qubell platform
platform = QubellPlatform(context=context)

# Try to login
assert platform.authenticate()
print "Authenticate passed"

# Create new organization
org = platform.organization(name="python-qubellclient")

# Use existing organization
# org = platform.organization(id="524f3028e4b0b12cd4de2759")

# Init environment (find by name "default")
env = org.environment(name='default')

# If env is not set up yet, do it. (dirty check)
Exemplo n.º 16
0
def main():
    # Parse arguments
    global qubell
    qubell = cls()
    parser = argparse.ArgumentParser(description='Tool for launching manifests and checking returnvalues')
    parser.add_argument('-c', '--config',
                        help='Use provided configuration file')
    parser.add_argument('-u', '--user',
                        help='User email to access qubell platform')
    parser.add_argument('-p', '--password',
                        help='User password to access qubell platform')
    parser.add_argument('-t', '--tenant',
                        help='Link to qubell api')
    parser.add_argument('-g', '--organization',
                        help='Qubell organization')
    parser.add_argument('-i', '--appid',
                        help='Application ID launch manifest in')
    parser.add_argument('-n', '--appname',
                        help='Application name launch manifest in')
    parser.add_argument('-m', '--manifest',
                        help='Launch single manifest and check it launched')
    parser.add_argument('-o', '--output',
                        help='Write JUnit report to specified file')
    parser.add_argument('-v', '--verbose', help='increase output verbosity',
                        action="store_true")
    parser.add_argument('--debug',
                        action="store_true", help='Show debug info')
    parser.parse_args(namespace=qubell)


    # todo improve cfg loading
    if not qubell.config:
        qubell.config = 'launcher.cfg'
    try:
        cfile = open(qubell.config, 'r')
        config = yaml.load(cfile, OrderedDictYAMLLoader)
        log('Config: %s' % config,'debug')
    except:
        if qubell.manifest:
            config = OrderedDict({'cli-manifest':
                    { 'source': qubell.manifest,
                      'launch':
                            { 'parameters':{},
                                'expected':{},
                            }}})
        else:
            error('No configuration file or manifest provided')

    if 'qubell' in config.keys():
        cfg = config.pop('qubell')
        if not qubell.user:
            qubell.user = cfg['user']
        if not qubell.password:
            qubell.password = cfg['password']
        if not qubell.tenant:
            qubell.tenant = cfg['tenant']
        if not qubell.appid or qubell.appname:
            if cfg.has_key('appid'):
                qubell.appid = cfg['appid']
            elif cfg.has_key('appname'):
                qubell.appname = cfg['appname']
        if qubell.verbose:
            verbosity.append('info')
        if qubell.debug:
            verbosity.append('debug')
            verbosity.append('info')

    #TODO: get qubell organization be app ID

    # Inintialize platform
    platform = QubellPlatform()
    assert platform.connect(tenant=qubell.tenant, user=qubell.user, password=qubell.password)
    qubell.organization = platform.organization(name=qubell.organization)


    process(config)
    exit_code = 0
    for case in test_cases:
        if case.is_error() or case.is_failure():
            exit_code = 1
    if qubell.output:
        publish_result(qubell.output)
        exit(0)
    else:
        publish_result()
        exit(exit_code)
      "jcloudsIdentity": identity,
      "jcloudsCredential": credentials,
      "jcloudsRegions": region
    }

# Qubell access info
auth = Auth(user=user, password=password, tenant=tenant)
env = None
if len(sys.argv)>1:
    env = sys.argv[1]
else:
    env = default_env

env_file = open(env)
cfg = yaml.load(env_file)

# Get cloud access info
cfg['organizations'][0].update({'providers': [cloud_access]})
if org:
    cfg['organizations'][0].update({'name': org})

platform = QubellPlatform(auth=auth)

assert platform.authenticate()
print "Authorization passed"

print "Restoring env: %s" % env
platform.restore(cfg)
print "Restore finished"

      "jcloudsCredential": SECRET_KEY,
      "jcloudsRegions": "us-east-1"
    }
    prov = org.provider(access)
    env.providerAdd(prov)
    return org.organizationId


# Define manifest. We take example from documentation.
# TODO: make manifests accessible from docs.qubell.com
app_manifest = Manifest(url="https://raw.github.com/qubell/contrib-python-qubell-client/master/qm/hierarchical-main.yml")
db_manifest = Manifest(url="https://raw.github.com/qubell/contrib-python-qubell-client/master/qm/hierarchical-db.yml")


# Initialize our qubell platform
platform = QubellPlatform(context=context)

# Try to login
assert platform.authenticate()
print "Authenticate passed"

# Create new organization
org = platform.organization(name="python-qubellclient")

# Use existing organization
# org = platform.organization(id="524f3028e4b0b12cd4de2759")

# Init environment (find by name "default")
env = org.environment(name='default')

# If env is not set up yet, do it. (dirty check)
      "jcloudsCredential": credentials,
      "jcloudsRegions": region
    }


env = None
if len(sys.argv)>1:
    env = sys.argv[1]
else:
    env = default_env

env_file = open(env)
cfg = yaml.load(env_file)

# Get cloud access info
cfg['organizations'][0].update({'providers': [cloud_access]})
if org:
    cfg['organizations'][0].update({'name': org})

platform = QubellPlatform()

platform.connect(user=user, password=password, tenant=tenant)
print "Authorization passed"

import pprint
pprint.pprint(cfg)
print "Restoring env: %s" % env
platform.restore(cfg)
print "Restore finished"

Exemplo n.º 20
0
parameters = {
    'organization': os.getenv('QUBELL_ORGANIZATION', None),
    'user': os.environ['QUBELL_USER'],
    'pass': os.environ['QUBELL_PASS'],
    'tenant': os.environ['QUBELL_TENANT'],
    'provider_name': os.getenv('PROVIDER_NAME', "test-provider"),
    'provider_type': os.environ['PROVIDER_TYPE'],
    'provider_identity': os.environ['PROVIDER_IDENTITY'],
    'provider_credential': os.environ['PROVIDER_CREDENTIAL'],
    'provider_region': os.environ['PROVIDER_REGION']
}

context = Context(user=parameters['user'],
                  password=parameters['pass'],
                  api=parameters['tenant'])
platform = QubellPlatform(context=context)
assert platform.authenticate()


class BaseComponentTestCase(BaseTestCase):
    platform = platform
    parameters = parameters
    apps = []

    @classmethod
    def timeout(cls):
        return 40

    @classmethod
    def environment(cls, organization):
        base_env = super(BaseComponentTestCase, cls).environment(organization)
Exemplo n.º 21
0
from qubell.api.private.testing import BaseTestCase

parameters = {
    'organization': os.getenv('QUBELL_ORGANIZATION', None),
    'user': os.environ['QUBELL_USER'],
    'pass': os.environ['QUBELL_PASS'],
    'tenant': os.environ['QUBELL_TENANT'],
    'provider_name': os.getenv('PROVIDER_NAME', "test-provider"),
    'provider_type': os.environ['PROVIDER_TYPE'],
    'provider_identity': os.environ['PROVIDER_IDENTITY'],
    'provider_credential': os.environ['PROVIDER_CREDENTIAL'],
    'provider_region': os.environ['PROVIDER_REGION']
}

context = Context(user=parameters['user'], password=parameters['pass'], api=parameters['tenant'])
platform = QubellPlatform(context=context)
assert platform.authenticate()


class BaseComponentTestCase(BaseTestCase):
    platform = platform
    parameters = parameters
    apps = []

    @classmethod
    def environment(cls, organization):
        base_env = super(BaseComponentTestCase, cls).environment(organization)

        base_env['applications'] = cls.apps

        return base_env
"""

if os.getenv('QUBELL_LOG_LEVEL', 'info') == 'debug':
    logging.getLogger().setLevel(logging.DEBUG)
else:
    logging.getLogger().setLevel(logging.INFO)

default_env = os.path.join(os.path.dirname(__file__), 'default.env')

if len(sys.argv) > 1:
    env = sys.argv[1]
else:
    env = default_env

cfg = load_env(env)

# Patch configuration to include provider and org info
cfg['organizations'][0].update({'providers': [PROVIDER_CONFIG]})
if QUBELL['organization']:
    cfg['organizations'][0].update({'name': QUBELL['organization']})

platform = QubellPlatform.connect(user=QUBELL['user'],
                                  password=QUBELL['password'],
                                  tenant=QUBELL['tenant'])
print "Authorization passed"

print "Restoring env: %s" % env
platform.restore(cfg)
print "Restore finished"