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
Esempio 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
Esempio 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
Esempio n. 9
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
Esempio n. 10
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": 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"

"""

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"
Esempio n. 14
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)