Пример #1
0
def test_host_in_two_clusters():
    """
        create 2 new clusters and add a host to both. check Host.cluster.
    """
    per = sess.query(Personality).select_from(join(
        Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                 Personality.name == 'generic')).one()

    for i in xrange(3):
        ec = EsxCluster(name='%s%s' % (CLUSTER_NAME, i), personality=per)
        add(sess, ec)
    commit(sess)

    c1 = sess.query(EsxCluster).filter_by(name='%s1' % (CLUSTER_NAME)).one()
    c2 = sess.query(EsxCluster).filter_by(name='%s2' % (CLUSTER_NAME)).one()

    assert c1
    assert c2
    print 'clusters in host in 2 cluster test are %s and %s' % (c1, c2)

    host = h_factory.next()

    sess.autoflush = False
    hcm1 = HostClusterMember(host=host, cluster=c1)
    create(sess, hcm1)
    assert host in c1.hosts
    print 'c1 hosts are %s' % (c1.hosts)

    c2.hosts.append(host)
    sess.autoflush = True
    commit(sess)
Пример #2
0
    def render(self, session, logger, cluster, **arguments):
        dbcluster = EsxCluster.get_unique(session, cluster, compel=True)
        cluster = str(dbcluster.name)
        if dbcluster.virtual_machines:
            machines = ", ".join([m.label for m in dbcluster.virtual_machines])
            raise ArgumentError("%s is still in use by virtual machines: %s." % (format(dbcluster), machines))

        return CommandDelCluster.render(self, session=session, logger=logger, cluster=cluster, **arguments)
Пример #3
0
def test_vm_append():
    machines = sess.query(Machine).filter(Machine.label.like(VM_NAME+'%')).all()
    ec = EsxCluster.get_unique(sess, CLUSTER_NAME)
    assert ec

    ec.machines.append(machines[12])
    commit(sess)
    assert len(ec.machines) is 11
    print 'now, there are %s machines in the cluster: %s'% (len(ec.machines),
                                                            ec.machines)
Пример #4
0
    def render(self, session, logger, cluster, **arguments):
        dbcluster = EsxCluster.get_unique(session, cluster, compel=True)
        cluster = str(dbcluster.name)
        if dbcluster.machines:
            machines = ", ".join([m.label for m in dbcluster.machines])
            raise ArgumentError("%s is still in use by virtual machines: %s." %
                                (format(dbcluster), machines))

        return CommandDelCluster.render(self, session=session, logger=logger,
                                        cluster=cluster, **arguments)
Пример #5
0
def test_vm_append():
    machines = sess.query(Machine).filter(Machine.label.like(VM_NAME +
                                                             '%')).all()
    ec = EsxCluster.get_unique(sess, CLUSTER_NAME)
    assert ec

    ec.machines.append(machines[12])
    commit(sess)
    assert len(ec.machines) is 11
    print 'now, there are %s machines in the cluster: %s' % (len(
        ec.machines), ec.machines)
Пример #6
0
def test_no_host_threshold():
    """ ensure down_hosts_threshold must exist """
    br = Branch.get_unique(sess, 'ny-prod', compel=True)
    np = Building.get_unique(sess, name='np', compel=True)

    per = sess.query(Personality).select_from(join(
        Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                 Personality.name == 'generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME,
                    location_constraint=np,
                    personality=per,
                    branch=br)
    add(sess, ec)
    commit(sess)
Пример #7
0
def test_add_cluster_host():
    """ test adding a host to the cluster """
    vm_host = h_factory.next()
    ec = EsxCluster.get_unique(sess, CLUSTER_NAME)

    sess.autoflush=False
    hcm = HostClusterMember(host=vm_host, cluster=ec)
    sess.autoflush=True

    create(sess, hcm)

    assert hcm
    print hcm

    assert ec.hosts
    assert len(ec.hosts) is 1
    print 'cluster members: %s'%(ec.hosts)
Пример #8
0
def test_add_cluster_host():
    """ test adding a host to the cluster """
    vm_host = h_factory.next()
    ec = EsxCluster.get_unique(sess, CLUSTER_NAME)

    sess.autoflush = False
    hcm = HostClusterMember(host=vm_host, cluster=ec)
    sess.autoflush = True

    create(sess, hcm)

    assert hcm
    print hcm

    assert ec.hosts
    assert len(ec.hosts) is 1
    print 'cluster members: %s' % (ec.hosts)
Пример #9
0
def test_add_machines():
    a = sess.query(MachineClusterMember).all()
    if a:
        print '%s machines are already in existence'

    machines = sess.query(Machine).filter(Machine.label.like(VM_NAME+'%')).all()
    ec = EsxCluster.get_unique(sess, CLUSTER_NAME)
    assert ec

    sess.autoflush=False
    for vm in machines[0:10]:
        mcm = MachineClusterMember(cluster=ec, machine=vm)
        add(sess, mcm)
    commit(sess)
    sess.autoflush=True

    assert len(ec.machines) is 10
    print 'there are %s machines in the cluster: %s'%(len(ec.machines), ec.machines)
Пример #10
0
def test_create_cluster():
    #TODO: make this a reusable function in test_cluster and import
    np = sess.query(Building).filter_by(name='np').one()
    dmn = sess.query(Domain).first()
    assert dmn, 'No domain found in %s' % func_name()
    per = sess.query(Personality).select_from(join(
        Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                 Personality.name == 'generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME,
                    location_constraint=np,
                    personality=per,
                    domain=dmn)

    create(sess, ec)

    assert ec, "No EsxCluster created by %s" % func_name()
    print ec
Пример #11
0
def test_add_machines():
    a = sess.query(MachineClusterMember).all()
    if a:
        print '%s machines are already in existence'

    machines = sess.query(Machine).filter(Machine.label.like(VM_NAME +
                                                             '%')).all()
    ec = EsxCluster.get_unique(sess, CLUSTER_NAME)
    assert ec

    sess.autoflush = False
    for vm in machines[0:10]:
        mcm = MachineClusterMember(cluster=ec, machine=vm)
        add(sess, mcm)
    commit(sess)
    sess.autoflush = True

    assert len(ec.machines) is 10
    print 'there are %s machines in the cluster: %s' % (len(
        ec.machines), ec.machines)
Пример #12
0
def test_create_esx_cluster():
    """ tests the creation of an EsxCluster """
    np = Building.get_unique(sess, name='np', compel=True)
    br = Branch.get_unique(sess, 'ny-prod', compel=True)
    per = sess.query(Personality).select_from(join(
        Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                 Personality.name == 'generic')).one()

    ec = EsxCluster(name=CLUSTER_NAME,
                    location_constraint=np,
                    personality=per,
                    down_hosts_threshold=2,
                    branch=br)
    create(sess, ec)

    assert ec
    print ec

    assert ec.max_hosts is 8
    print 'esx cluster max members = %s' % ec.max_hosts
Пример #13
0
def test_create_clusters():
    np = sess.query(Building).filter_by(name='np').one()
    br = Branch.get_unique(sess, 'ny-prod', compel=True)

    per = sess.query(Personality).select_from(
            join(Archetype, Personality)).filter(
            and_(Archetype.name == 'windows',
                Personality.name == 'generic')).one()

    for i in xrange(NUM_CLUSTERS):
        ec = EsxCluster(name='%s%s' % (CLUSTER_NAME, i),
                        location_constraint=np, branch=br,
                        personality=per, down_hosts_threshold=2)
        add(sess, ec)
    commit(sess)

    ecs = sess.query(EsxCluster).all()
    assert len(ecs) is NUM_CLUSTERS
    print ecs[0]

    assert ecs[0].max_hosts is 8
    print 'esx cluster max hosts = %s' % (ecs[0].max_hosts)