Beispiel #1
0
    def test_pod_emptydir(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = utils.create_container(name=container_name, image=container_image)

        vol_name = "emptydir"
        vol_type = "emptyDir"
        vol_mount = "/test-emptydir"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        container.add_volume_mount(volume)

        pod_name = "nginx"
        pod = utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if utils.is_reachable(pod.config.api_host):
            pod.create()
            vols = pod.model.model['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = pod.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(1, len(pod.model.model['spec']['containers']))

            mounts = pod.model.model['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(1, len(pod.model.pod_spec.model['containers']))

            mounts = pod.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
Beispiel #2
0
    def test_rc_aws_ebs(self):
        # http://kubernetes.io/docs/user-guide/volumes/#awselasticblockstore
        # - the nodes on which pods are running must be AWS EC2 instances
        # - those instances need to be in the same region and availability-zone as the EBS volume
        # - EBS only supports a single EC2 instance mounting a volume

        # Pod creation will timeout waiting for readiness if not on AWS; unschedulable.

        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        volume_id = "vol-0e3056a2"
        vol_name = "ebs"
        vol_type = "awsElasticBlockStore"
        vol_mount = "/test-aws-ebs"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_volume_id(volume_id)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['template']['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(2, len(rc.model.model['spec']['template']['spec']['containers']))

                mounts = rc.model.model['spec']['template']['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(2, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Beispiel #3
0
    def test_rc_gce_pd(self):
        # http://kubernetes.io/docs/user-guide/volumes/#gcepersistentdisk
        # - the nodes on which pods are running must be GCE VMs
        # - those VMs need to be in the same GCE project and zone as the PD

        # Pod creation will timeout waiting for readiness if not on GCE; unschedulable.

        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        pd_name = "kubernetes-py-test-pd"
        vol_name = "persistent"
        vol_type = "gcePersistentDisk"
        vol_mount = "/test-gce-pd"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount, read_only=True)
        volume.set_pd_name(pd_name)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(1, len(rc.model.model['spec']['containers']))

                mounts = rc.model.model['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(1, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Beispiel #4
0
    def test_rc_git_repo(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        vol_name = "git-repo"
        vol_type = "gitRepo"
        vol_mount = "/test-git-repo"
        repo = "https://*****:*****@git-lab1.mtl.mnubo.com/ops/traffic-analyzer.git"
        revision = "e42d3dca1541ba085f34ce282feda1109a707c7b"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_git_repository(repo)
        volume.set_git_revision(revision)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(1, len(rc.model.model['spec']['containers']))

                mounts = rc.model.model['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(1, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Beispiel #5
0
    def test_rc_nfs(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        vol_name = "nfs"
        vol_type = "nfs"
        vol_mount = "/test-nfs"
        server = "howard.mtl.mnubo.com"
        path = "/fs1/test-nfs"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_server(server)
        volume.set_path(path)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "nginx-{0}".format(str(uuid.uuid4()))
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(3)

        if utils.is_reachable(rc.config.api_host):
            try:
                rc.create()

                vols = rc.model.model['spec']['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)

                vols = rc.model.pod_spec.model['volumes']
                volnames = [x['name'] for x in vols]
                self.assertIn(vol_name, volnames)
                self.assertEqual(1, len(rc.model.model['spec']['containers']))

                mounts = rc.model.model['spec']['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)
                self.assertEqual(1, len(rc.model.pod_spec.model['containers']))

                mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
                mountnames = [x['name'] for x in mounts]
                self.assertIn(vol_name, mountnames)

            except Exception as err:
                self.assertIsInstance(err, TimedOutException)
Beispiel #6
0
    def test_rc_secret(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        secret_name = "yosecret"
        secret = utils.create_secret(name=secret_name)
        k = ".secret-file"
        v = "dmFsdWUtMg0KDQo="
        secret.set_data(k, v)

        vol_name = "secret"
        vol_type = "secret"
        vol_mount = "/test-secret"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_secret_name(secret)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "app"
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(1)

        if utils.is_reachable(rc.config.api_host):
            secret.create()
            rc.create()
            vols = rc.model.model['spec']['template']['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = rc.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(2, len(rc.model.model['spec']['template']['spec']['containers']))

            mounts = rc.model.model['spec']['template']['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(2, len(rc.model.pod_spec.model['containers']))

            mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
def execute_stress_incremental():
    """
    Executes incremental profile of stress.
    Various parameters are configured on config.py
    Creates a table, loads data, does autosetup; before moving to next table.
    Parallelism is achieved based on number of volumes.
    :return:
    """
    logging.debug("Executing incremental profile")

    remote_path = "/"
    if config.remote_cluster_name is not None:
        remote_path += "mapr/" + config.remote_cluster_name + "/"
    if config.remote_volume_name is not None:
        remote_path += config.remote_volume_name
    local_path = "/"
    if config.local_replica_volume_name is not None:
        local_path += config.local_replica_volume_name

    logging.info("Replica path prefix: " + remote_path)

    # Create volumes
    logging.debug("Creating " + str(config.num_src_vols) + " Volumes.. ")
    volume_list = utils.create_volume(volume_path_prefix="/" +
                                      config.src_volume_prefix,
                                      num_volumes=config.num_src_vols,
                                      start_idx=config.vol_start_index)

    get_chunks = lambda l, n: [l[x:x + n] for x in xrange(0, len(l), n)]
    num_sublist = (len(volume_list) / utils.g_thread_count) + 1
    volume_sublist = get_chunks(volume_list, num_sublist)

    threads = [
        Thread(target=utils.do_incremental_setup,
               args=(volume_sublist[i], config.src_table_prefix,
                     config.num_src_tables, config.table_start_index,
                     config.num_cfs, config.num_cols, config.num_rows,
                     remote_path, local_path, config.num_replica))
        for i in xrange(0, len(volume_sublist))
    ]

    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()

    logging.debug("Done")
Beispiel #8
0
    def test_rc_hostpath(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container_nginx = utils.create_container(name=container_name, image=container_image)

        container_name = "redis"
        container_image = "redis:3.0.7"
        container_redis = utils.create_container(name=container_name, image=container_image)

        vol_name = "hostpath"
        vol_type = "hostPath"
        vol_mount = "/test-hostpath"
        hostpath = "/var/lib/docker"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_path(hostpath)
        container_nginx.add_volume_mount(volume)
        container_redis.add_volume_mount(volume)

        rc_name = "app"
        rc = utils.create_rc(name=rc_name)
        rc.add_volume(volume)
        rc.add_container(container_nginx)
        rc.add_container(container_redis)
        rc.set_replicas(1)

        if utils.is_reachable(rc.config.api_host):
            rc.create()
            vols = rc.model.model['spec']['template']['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = rc.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(2, len(rc.model.model['spec']['template']['spec']['containers']))

            mounts = rc.model.model['spec']['template']['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(2, len(rc.model.pod_spec.model['containers']))

            mounts = rc.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
Beispiel #9
0
    def test_pod_secret(self):
        container_name = "nginx"
        container_image = "nginx:1.7.9"
        container = utils.create_container(name=container_name, image=container_image)

        secret_name = "yosecret"
        secret = utils.create_secret(name=secret_name)
        k = ".secret-file"
        v = "dmFsdWUtMg0KDQo="
        secret.set_data(k, v)

        vol_name = "secret"
        vol_type = "secret"
        vol_mount = "/test-secret"
        volume = utils.create_volume(name=vol_name, type=vol_type, mount_path=vol_mount)
        volume.set_secret_name(secret)
        container.add_volume_mount(volume)

        pod_name = "nginx"
        pod = utils.create_pod(name=pod_name)
        pod.add_volume(volume)
        pod.add_container(container)

        if utils.is_reachable(pod.config.api_host):
            secret.create()
            pod.create()
            vols = pod.model.model['spec']['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)

            vols = pod.model.pod_spec.model['volumes']
            volnames = [x['name'] for x in vols]
            self.assertIn(vol_name, volnames)
            self.assertEqual(1, len(pod.model.model['spec']['containers']))

            mounts = pod.model.model['spec']['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
            self.assertEqual(1, len(pod.model.pod_spec.model['containers']))

            mounts = pod.model.pod_spec.model['containers'][0]['volumeMounts']
            mountnames = [x['name'] for x in mounts]
            self.assertIn(vol_name, mountnames)
Beispiel #10
0
def main():
    f = open('log_test_values_cider.txt', 'w')
    original = sys.stdout
    sys.stdout = utils.Tee(sys.stdout, f)

    token = 0
    domain_id, production_project_id, cms_project_id, atlas_project_id = (
        0, ) * 4
    computing_project_id, visualisation_project_id, services_project_id = (
        0, ) * 3
    operations_project_id = 0
    try:
        token_json = utils.default_token_json('admin', 'demo')
        token = utils.get_token(token_json)
        print '======================================================================='
        print 'This script will use the follow hierarchy to validate the quota values'
        print 'related to Nested Quotas on Cinder'
        print '======================================================================='
        print 'Hierarchy:'
        print '                            Domain_X          '
        print '                               |'
        print '                          ProductionIT - Mike'
        print '                     /                  \ '
        print '          Jay - CMS                       ATLAS - John'
        print '             /       \                   /       \ '
        print '      Computing   Visualisation   Operations   Services  '
        print '       Walter        Duncan          Eric         Xing'
        print ''
        print 'Actors:'
        print ''
        print 'Mike - Cloud Admin (i.e. role:cloud-admin) of ProductionIT'
        print 'Jay - Manager (i.e. role: project-admin) of Project CMS'
        print 'John - Manager (i.e. role: project-admin) of Project ATLAS'
        print 'Eric - Manager (i.e. role: project-admin) of Project Operations'
        print 'Xing - Manager (i.e. role: project-admin) of Project Services'
        print 'Walter - Manager (i.e. role: project-admin) of Project Computing'
        print 'Duncan - Manager (i.e. role: project-admin) of Project Visualisation'
        print '======================================================================='

        # Create a new domain
        print 'Creating the domain...'
        domain = utils.domain_json()
        domain_id = utils.create_domain(domain, token)
        print 'Domain created: %s' % domain_id
        print '======================================================================='
        print 'Creating the projects...'

        # Create project ProductionIT
        production_project_json = utils.project_json('ProductionIT', domain_id)
        production_project_id = utils.create_project(production_project_json,
                                                     token)
        print "ProductionIT created: %s" % production_project_id
        print '======================================================================='

        # Create Project CMS
        cms_project_json = utils.project_json('CMS', domain_id,
                                              production_project_id)
        cms_project_id = utils.create_project(cms_project_json, token)
        print "CMS created: %s" % cms_project_id
        print '======================================================================='

        # Create Project Atlas
        atlas_project_json = utils.project_json('ATLAS', domain_id,
                                                production_project_id)
        atlas_project_id = utils.create_project(atlas_project_json, token)
        print "ATLAS created: %s" % atlas_project_id
        print '======================================================================='

        # Create Project computing
        computing_project_json = utils.project_json('computing', domain_id,
                                                    cms_project_id)
        computing_project_id = utils.create_project(computing_project_json,
                                                    token)
        print "Computing created: %s" % computing_project_id
        print '======================================================================='

        # Create Project visualisation
        visual_project_json = utils.project_json('visualisation', domain_id,
                                                 cms_project_id)
        visualisation_project_id = utils.create_project(
            visual_project_json, token)
        print "Visualisation created: %s" % visualisation_project_id
        print '======================================================================='

        # Create Project services
        services_project_json = utils.project_json('services', domain_id,
                                                   atlas_project_id)
        services_project_id = utils.create_project(services_project_json,
                                                   token)
        print "Services created: %s" % services_project_id
        print '======================================================================='

        # Create Project operations
        operations_project_json = utils.project_json('operations', domain_id,
                                                     atlas_project_id)
        operations_project_id = utils.create_project(operations_project_json,
                                                     token)
        print "Operations created: %s" % operations_project_id
        print '======================================================================='

        admin_role = utils.get_role(token, 'admin')
        # Creating users
        # Creating and grant admin role to mike in production
        print 'Creating the users...'
        mike = utils.create_user(token, 'Mike', domain_id)
        print "Mike: %s" % mike
        utils.grant_user_role(token, mike, admin_role, [production_project_id])
        print '======================================================================='

        # Creating and grant admin role to jay in cms
        jay = utils.create_user(token, 'Jay', domain_id)
        print "Jay: %s" % jay
        utils.grant_user_role(token, jay, admin_role, [cms_project_id])
        print '======================================================================='

        # Creating and grant admin role to john in atlas
        john = utils.create_user(token, 'John', domain_id)
        print "John: %s" % john
        utils.grant_user_role(token, john, admin_role, [atlas_project_id])
        print '======================================================================='

        # Creating and grant admin role to eric in operations
        eric = utils.create_user(token, 'Eric', domain_id)
        print "Eric: %s" % eric
        utils.grant_user_role(token, eric, admin_role, [operations_project_id])
        print '======================================================================='

        # Creating and grant admin role to xing in services
        xing = utils.create_user(token, 'Xing', domain_id)
        print "Xing: %s" % xing
        utils.grant_user_role(token, xing, admin_role, [services_project_id])
        print '======================================================================='

        # Creating and grant admin role to walter in computing
        walter = utils.create_user(token, 'Walter', domain_id)
        print "Walter: %s" % walter
        utils.grant_user_role(token, walter, admin_role,
                              [computing_project_id])
        print '======================================================================='

        # Creating and grant admin role to duncan in visualisation
        duncan = utils.create_user(token, 'Duncan', domain_id)
        print "Ducnan: %s" % duncan
        utils.grant_user_role(token, duncan, admin_role,
                              [visualisation_project_id])
        print '======================================================================='
        print 'Now, we will get a token for Mike in ProductionIT (root project)'
        print 'and show that the quota calculation in the hierarchy works well.'
        print '======================================================================='
        # Get a token for Mike in ProductionIT
        mike_token_json = utils.get_token_json('Mike', production_project_id)
        mike_token = utils.get_token(mike_token_json)
        print 'Token for mike: %s' % mike_token
        print '======================================================================='

        # Update the Prduction Quota to 100
        print 'Updating the ProductionIT quota for 100...'
        quota_value = 100
        production_quota = utils.update_quota(mike_token,
                                              production_project_id,
                                              production_project_id,
                                              quota_value)
        quota_show_production = utils.quota_show(mike_token,
                                                 production_project_id,
                                                 production_project_id)
        print '======================================================================='
        print "Production Quota: %s" % quota_show_production
        print '======================================================================='
        # Update the CMS Quota to 40
        print 'Updating the CMS quota for 40...'
        quota_value = 40
        cms_quota = utils.update_quota(mike_token, production_project_id,
                                       cms_project_id, quota_value)
        quota_show_production = utils.quota_show(mike_token,
                                                 production_project_id,
                                                 production_project_id)
        quota_show_cms = utils.quota_show(mike_token, production_project_id,
                                          cms_project_id)
        print 'Verify that allocated ProductionIT quota was updated to 40'
        print "Production Quota: %s" % quota_show_production
        print "CMS Quota: %s" % quota_show_cms
        print '======================================================================='
        # Update the Atlas Quota to 30
        print 'Updating the Atlas quota for 30...'
        quota_value = 30
        atlas_quota = utils.update_quota(mike_token, production_project_id,
                                         atlas_project_id, quota_value)
        quota_show_production = utils.quota_show(mike_token,
                                                 production_project_id,
                                                 production_project_id)
        quota_show_atlas = utils.quota_show(mike_token, production_project_id,
                                            atlas_project_id)
        print 'Verify that allocated ProductionIT quota was updated to 70'
        print "Production Quota: %s" % quota_show_production
        print "Atlas Quota: %s" % quota_show_atlas
        print '======================================================================='

        # Update the Computing Quota to 15
        print 'Updating the Computing quota for 15...'
        quota_value = 15
        computing_quota = utils.update_quota(mike_token, production_project_id,
                                             computing_project_id, quota_value)
        quota_show_cms = utils.quota_show(mike_token, production_project_id,
                                          cms_project_id)
        quota_show_computing = utils.quota_show(mike_token,
                                                production_project_id,
                                                computing_project_id)
        print 'Verify that allocated CMS quota was updated to 15'
        print "CMS Quota: %s" % quota_show_cms
        print "Computing Quota: %s" % quota_show_computing
        print '======================================================================='

        # Update the visualisaton Quota to 15
        print 'Updating the Visualisation quota for 15...'
        quota_value = 15
        visualisation_quota = utils.update_quota(mike_token,
                                                 production_project_id,
                                                 visualisation_project_id,
                                                 quota_value)
        quota_show_cms = utils.quota_show(mike_token, production_project_id,
                                          cms_project_id)
        quota_show_visualisation = utils.quota_show(mike_token,
                                                    production_project_id,
                                                    visualisation_project_id)
        print 'Verify that allocated CMS quota was updated to 30'
        print "CMS Quota: %s" % quota_show_cms
        print "Visualisation Quota: %s" % quota_show_visualisation
        print '======================================================================='

        print 'Updating the Services quota for 10...'
        # Update the services Quota to 10
        quota_value = 10
        services_quota = utils.update_quota(mike_token, production_project_id,
                                            services_project_id, quota_value)
        quota_show_atlas = utils.quota_show(mike_token, production_project_id,
                                            atlas_project_id)
        quota_show_services = utils.quota_show(mike_token,
                                               production_project_id,
                                               services_project_id)
        print 'Verify that allocated Atlas quota was updated to 10'
        print "Atlas Quota: %s" % quota_show_atlas
        print "Service Quota: %s" % quota_show_services
        print '======================================================================='

        # Update the operations Quota to 10
        quota_value = 10
        operations_quota = utils.update_quota(mike_token,
                                              production_project_id,
                                              operations_project_id,
                                              quota_value)
        quota_show_atlas = utils.quota_show(mike_token, production_project_id,
                                            atlas_project_id)
        quota_show_operations = utils.quota_show(mike_token,
                                                 production_project_id,
                                                 operations_project_id)
        print 'Verify that allocated Atlas quota was updated to 20'
        print "Atlas Quota: %s" % quota_show_atlas
        print "Operations Quota: %s" % quota_show_operations
        print '======================================================================='
        # Update the CMS Quota to 40
        quota_value = 71
        print 'Trying update the CMS quota for 71...'
        cms_quota = utils.update_quota(mike_token, production_project_id,
                                       cms_project_id, quota_value)
        print "Error: %s" % cms_quota
        print '======================================================================='
        print "Creating 10 Volumes in CMS..."
        # Get a token for Jay in CMS
        jay_token_json = utils.get_token_json('Jay', cms_project_id)
        jay_token = utils.get_token(jay_token_json)

        for i in range(0, 10):
            utils.create_volume(jay_token, cms_project_id)
        quota_show_cms = utils.quota_show(jay_token, cms_project_id,
                                          cms_project_id)
        print "CMS Quota: %s" % quota_show_cms
        print 'Now, we dont have free quota in CMS'
        print '======================================================================='
        print "Trying update the computing quota to 16 (subproject for CMS)..."
        quota_value = 16
        computing_quota = utils.update_quota(mike_token, production_project_id,
                                             computing_project_id, quota_value)
        print "Error: %s" % computing_quota
        print '======================================================================='
        print 'Clean up...'

    except Exception as e:
        print 'Error'
        tear_down(token, [
            production_project_id, cms_project_id, atlas_project_id,
            computing_project_id, visualisation_project_id,
            services_project_id, operations_project_id
        ], domain_id)
        f.close()
        print e
    tear_down(token, [
        production_project_id, cms_project_id, atlas_project_id,
        computing_project_id, visualisation_project_id, services_project_id,
        operations_project_id
    ], domain_id)
    f.close()
Beispiel #11
0
    # incremental stress profile
    stress_incr_parser = stress_sub_parser.add_parser(
        'increment', help='Incremental profile of stress')

    args = parser.parse_args()
    print args

    if args.cmd_name == 'create':
        logging.debug('Create command')
        if args.obj_type == 'table':
            utils.create_table(table_path_prefix=args.prefix,
                               start_idx=args.startidx,
                               num_tables=args.numtables)
        elif args.obj_type == 'volume':
            utils.create_volume(volume_path_prefix=args.prefix,
                                start_idx=args.startidx,
                                num_volumes=args.numvolumes)
        else:
            logging.error('Unrecognized object. Cannot create.')
            sys.exit(-1)
    elif args.cmd_name == 'delete':
        logging.debug('Delete command')
        if args.obj_type == 'table':
            utils.delete_table(table_path_prefix=args.prefix,
                               start_idx=args.startidx,
                               num_tables=args.numtables)
        elif args.obj_type == 'volume':
            utils.delete_volume(volume_path_prefix=args.prefix,
                                start_idx=args.startidx,
                                num_volumes=args.numvolumes)
        else:
def execute_stress_bulk():
    """
    Executes bulk profile of stress.
    Various parameters are configured on config.py
    Creates all the tables with data first and does autosetup in bulk.
    :return:
    """
    logging.debug("Executing bulk profile")

    remote_path = "/"
    if config.remote_cluster_name is not None:
        remote_path += "mapr/" + config.remote_cluster_name + "/"
    if config.remote_volume_name is not None:
        remote_path += config.remote_volume_name
    local_path = "/"
    if config.local_replica_volume_name is not None:
        local_path += config.local_replica_volume_name

    logging.info("Replica path prefix: " + remote_path)

    # Create volumes
    logging.debug("Creating " + str(config.num_src_vols) + " Volumes.. ")
    volume_list = utils.create_volume(volume_path_prefix="/" +
                                      config.src_volume_prefix,
                                      num_volumes=config.num_src_vols,
                                      start_idx=config.vol_start_index)

    # Create tables
    table_path_prefix_list = [
        volume + "/" + config.src_table_prefix for volume in volume_list
    ]
    logging.info(table_path_prefix_list)
    utils.create_tables_multithread(
        table_path_prefix_list=table_path_prefix_list,
        num_tables=config.num_src_tables,
        start_idx=config.table_start_index)

    # Load tables
    for volume in volume_list:
        utils.load_volume_tables_multithread(volume_path=volume,
                                             num_cfs=config.num_cfs,
                                             num_cols=config.num_cols,
                                             num_rows=config.num_rows,
                                             is_json=False)

    # Autosetup replica
    for volume in volume_list:
        utils.autosetup_replica_table_multithread(
            volume_path=volume,
            replica_parent=remote_path,
            num_replica=config.num_replica,
            is_multimaster=False)

        utils.autosetup_replica_table_multithread(volume_path=volume,
                                                  replica_parent=local_path,
                                                  num_replica=config.num_local,
                                                  is_multimaster=False)

        utils.autosetup_replica_table_multithread(
            volume_path=volume,
            replica_parent=remote_path,
            num_replica=config.num_replica,
            is_multimaster=True)
def main():
    f = open('log_test_values_cider.txt', 'w')
    original = sys.stdout
    sys.stdout = utils.Tee(sys.stdout, f)

    token = 0
    domain_id, production_project_id, cms_project_id, atlas_project_id = (0, )*4
    computing_project_id, visualisation_project_id, services_project_id = (0, )*3
    operations_project_id = 0
    try:
	token_json = utils.default_token_json('admin', 'demo')
        token = utils.get_token(token_json)
	print '======================================================================='
        print 'This script will use the follow hierarchy to validate the quota values' 
	print 'related to Nested Quotas on Cinder'
	print '======================================================================='
	print 'Hierarchy:'
	print '                            Domain_X          '
	print '                               |'
	print '                          ProductionIT - Mike' 
	print '                     /                  \ '
	print '          Jay - CMS                       ATLAS - John'
	print '             /       \                   /       \ '
	print '      Computing   Visualisation   Operations   Services  '
	print '       Walter        Duncan          Eric         Xing'
	print ''
	print 'Actors:'
	print ''
	print 'Mike - Cloud Admin (i.e. role:cloud-admin) of ProductionIT'
	print 'Jay - Manager (i.e. role: project-admin) of Project CMS'
	print 'John - Manager (i.e. role: project-admin) of Project ATLAS'
	print 'Eric - Manager (i.e. role: project-admin) of Project Operations'
	print 'Xing - Manager (i.e. role: project-admin) of Project Services'
	print 'Walter - Manager (i.e. role: project-admin) of Project Computing'
	print 'Duncan - Manager (i.e. role: project-admin) of Project Visualisation'
	print '======================================================================='
     
        # Create a new domain
 	print 'Creating the domain...'    
        domain = utils.domain_json()
        domain_id = utils.create_domain(domain, token)
        print 'Domain created: %s' % domain_id
	print '======================================================================='
 	print 'Creating the projects...'    
     
        # Create project ProductionIT
        production_project_json = utils.project_json('ProductionIT', domain_id)
        production_project_id = utils.create_project(production_project_json,
						     token)
        print "ProductionIT created: %s" % production_project_id
	print '======================================================================='
        
        # Create Project CMS 
        cms_project_json = utils.project_json('CMS', domain_id,
					      production_project_id)
        cms_project_id = utils.create_project(cms_project_json, token)
        print "CMS created: %s" % cms_project_id
	print '======================================================================='
        
        # Create Project Atlas
        atlas_project_json = utils.project_json('ATLAS',
					        domain_id,
						production_project_id)
        atlas_project_id = utils.create_project(atlas_project_json, token)
        print "ATLAS created: %s" % atlas_project_id
	print '======================================================================='
        
        # Create Project computing
        computing_project_json = utils.project_json('computing',
						    domain_id,
					            cms_project_id)
        computing_project_id = utils.create_project(computing_project_json,
						    token)
        print "Computing created: %s" % computing_project_id
	print '======================================================================='
     
        # Create Project visualisation
        visual_project_json = utils.project_json('visualisation',
	            			         domain_id,
					         cms_project_id)
        visualisation_project_id = utils.create_project(visual_project_json,
						        token)
        print "Visualisation created: %s" % visualisation_project_id
	print '======================================================================='
     
        # Create Project services
        services_project_json = utils.project_json('services',
						   domain_id,
						   atlas_project_id)
        services_project_id = utils.create_project(services_project_json,
						   token)
        print "Services created: %s" % services_project_id
	print '======================================================================='
     
        # Create Project operations
        operations_project_json = utils.project_json('operations',
						     domain_id,
					             atlas_project_id)
        operations_project_id = utils.create_project(operations_project_json,
						     token)
        print "Operations created: %s" % operations_project_id
	print '======================================================================='
     
	admin_role = utils.get_role(token, 'admin')
        # Creating users
	# Creating and grant admin role to mike in production
 	print 'Creating the users...'    
        mike = utils.create_user(token, 'Mike', domain_id)
	print "Mike: %s" % mike
        utils.grant_user_role(token, mike,
			      admin_role, [production_project_id])
	print '======================================================================='

	# Creating and grant admin role to jay in cms
	jay = utils.create_user(token, 'Jay', domain_id)
	print "Jay: %s" % jay 
        utils.grant_user_role(token, jay,
			      admin_role, [cms_project_id])
	print '======================================================================='

	# Creating and grant admin role to john in atlas
	john = utils.create_user(token, 'John', domain_id)
	print "John: %s" % john 
        utils.grant_user_role(token, john,
			      admin_role, [atlas_project_id])
	print '======================================================================='

	# Creating and grant admin role to eric in operations
	eric = utils.create_user(token, 'Eric', domain_id)
	print "Eric: %s" % eric 
        utils.grant_user_role(token, eric,
			      admin_role, [operations_project_id])
	print '======================================================================='

	# Creating and grant admin role to xing in services
	xing = utils.create_user(token, 'Xing', domain_id)
	print "Xing: %s" % xing 
        utils.grant_user_role(token, xing,
			      admin_role, [services_project_id])
	print '======================================================================='

	# Creating and grant admin role to walter in computing
	walter = utils.create_user(token, 'Walter', domain_id)
	print "Walter: %s" % walter 
        utils.grant_user_role(token, walter,
			      admin_role, [computing_project_id])
	print '======================================================================='

	# Creating and grant admin role to duncan in visualisation
	duncan = utils.create_user(token, 'Duncan', domain_id)
	print "Ducnan: %s" % duncan 
        utils.grant_user_role(token, duncan,
			      admin_role, [visualisation_project_id])
	print '======================================================================='
	print 'Now, we will get a token for Mike in ProductionIT (root project)'
	print 'and show that the quota calculation in the hierarchy works well.'
	print '======================================================================='
	# Get a token for Mike in ProductionIT
	mike_token_json = utils.get_token_json('Mike',
					       production_project_id)
        mike_token = utils.get_token(mike_token_json)
	print 'Token for mike: %s' % mike_token
	print '======================================================================='

	# Update the Prduction Quota to 100
	print 'Updating the ProductionIT quota for 100...'
	quota_value = 100 
	production_quota = utils.update_quota(mike_token, 
					      production_project_id,
					      production_project_id,
					      quota_value)
	quota_show_production = utils.quota_show(mike_token,
						 production_project_id,
						 production_project_id)
	print '======================================================================='
	print "Production Quota: %s" % quota_show_production
	print '======================================================================='
	# Update the CMS Quota to 40
	print 'Updating the CMS quota for 40...'
	quota_value = 40 
	cms_quota = utils.update_quota(mike_token, 
				       production_project_id,
				       cms_project_id,
				       quota_value)
	quota_show_production = utils.quota_show(mike_token,
						 production_project_id, 
						 production_project_id)
	quota_show_cms = utils.quota_show(mike_token, production_project_id, cms_project_id)
	print 'Verify that allocated ProductionIT quota was updated to 40'
	print "Production Quota: %s" % quota_show_production
	print "CMS Quota: %s" % quota_show_cms
	print '======================================================================='
	# Update the Atlas Quota to 30 
	print 'Updating the Atlas quota for 30...'
	quota_value = 30 
	atlas_quota = utils.update_quota(mike_token, 
				         production_project_id,
				         atlas_project_id,
				         quota_value)
	quota_show_production = utils.quota_show(mike_token,
						 production_project_id,
						 production_project_id)
	quota_show_atlas = utils.quota_show(mike_token,
					    production_project_id,
					    atlas_project_id)
	print 'Verify that allocated ProductionIT quota was updated to 70'
	print "Production Quota: %s" % quota_show_production
	print "Atlas Quota: %s" % quota_show_atlas
	print '======================================================================='

	# Update the Computing Quota to 15 
	print 'Updating the Computing quota for 15...'
	quota_value = 15 
	computing_quota = utils.update_quota(mike_token, 
				             production_project_id,
				             computing_project_id,
				             quota_value)
	quota_show_cms = utils.quota_show(mike_token,
					  production_project_id,
					  cms_project_id)
	quota_show_computing = utils.quota_show(mike_token,
					        production_project_id,
					        computing_project_id)
	print 'Verify that allocated CMS quota was updated to 15'
	print "CMS Quota: %s" % quota_show_cms
	print "Computing Quota: %s" % quota_show_computing
	print '======================================================================='

	# Update the visualisaton Quota to 15 
	print 'Updating the Visualisation quota for 15...'
	quota_value = 15 
	visualisation_quota = utils.update_quota(mike_token, 
				            	 production_project_id,
				             	 visualisation_project_id,
				             	 quota_value)
	quota_show_cms = utils.quota_show(mike_token,
					  production_project_id,
					  cms_project_id)
	quota_show_visualisation = utils.quota_show(mike_token,
						    production_project_id,
						    visualisation_project_id)
	print 'Verify that allocated CMS quota was updated to 30'
	print "CMS Quota: %s" % quota_show_cms
	print "Visualisation Quota: %s" % quota_show_visualisation
	print '======================================================================='

	print 'Updating the Services quota for 10...'
	# Update the services Quota to 10 
	quota_value = 10 
	services_quota = utils.update_quota(mike_token, 
				           production_project_id,
				           services_project_id,
				           quota_value)
	quota_show_atlas = utils.quota_show(mike_token,
					    production_project_id,
					    atlas_project_id)
	quota_show_services = utils.quota_show(mike_token,
					       production_project_id,
					       services_project_id)
	print 'Verify that allocated Atlas quota was updated to 10'
	print "Atlas Quota: %s" % quota_show_atlas
	print "Service Quota: %s" % quota_show_services
	print '======================================================================='

	# Update the operations Quota to 10 
	quota_value = 10 
	operations_quota = utils.update_quota(mike_token, 
				           production_project_id,
				           operations_project_id,
				           quota_value)
	quota_show_atlas = utils.quota_show(mike_token,
					    production_project_id,
					    atlas_project_id)
	quota_show_operations = utils.quota_show(mike_token,
						 production_project_id,
						 operations_project_id)
	print 'Verify that allocated Atlas quota was updated to 20'
	print "Atlas Quota: %s" % quota_show_atlas
	print "Operations Quota: %s" % quota_show_operations
	print '======================================================================='
	# Update the CMS Quota to 40
	quota_value = 71 
	print 'Trying update the CMS quota for 71...'
	cms_quota = utils.update_quota(mike_token, 
				       production_project_id,
				       cms_project_id,
				       quota_value)
	print "Error: %s" % cms_quota
	print '======================================================================='
	print "Creating 10 Volumes in CMS..."
	# Get a token for Jay in CMS
	jay_token_json = utils.get_token_json('Jay', cms_project_id)
        jay_token = utils.get_token(jay_token_json)

	for i in range(0,10):
	    utils.create_volume(jay_token, cms_project_id)
	quota_show_cms = utils.quota_show(jay_token, cms_project_id, cms_project_id)
	print "CMS Quota: %s" % quota_show_cms
	print 'Now, we dont have free quota in CMS'
	print '======================================================================='
	print "Trying update the computing quota to 16 (subproject for CMS)..."
	quota_value = 16 
	computing_quota = utils.update_quota(mike_token, 
				       production_project_id,
				       computing_project_id,
				       quota_value)
	print "Error: %s" % computing_quota
	print '======================================================================='
	print 'Clean up...'

    except Exception as e:
	print 'Error'
        tear_down(token, [production_project_id,
	          cms_project_id, 
                  atlas_project_id,
                  computing_project_id,
                  visualisation_project_id,
                  services_project_id,
                  operations_project_id], domain_id)
    	f.close()
        print e 
    tear_down(token, [production_project_id,    
              cms_project_id, 
              atlas_project_id,
	      computing_project_id,
	      visualisation_project_id,
	      services_project_id,
	      operations_project_id], domain_id)
    f.close()