Beispiel #1
0
def add_interfaces(session):
    """ Add a default interface for all HW that has an IP """
    q = session.query(HardwareEntity)
    q = q.filter(~exists().where(Interface.hardware_entity_id == HardwareEntity.id))
    q = q.outerjoin(PrimaryNameAssociation, System, DnsDomain)
    q = q.options(contains_eager('_primary_name_asc'))
    q = q.options(contains_eager('_primary_name_asc.dns_record'))
    q = q.options(contains_eager('_primary_name_asc.dns_record.dns_domain'))
    q = q.filter(System.ip != None)

    hws = q.all()
    count = 0
    for hw in hws:
        if hw.hardware_type == "machine":
            interface = "eth0"
            itype = "public"
        elif hw.hardware_type == "switch":
            interface = "xge"
            itype = "oa"
        else:
            interface = "oa"
            itype = "oa"

        #print "Adding default interface for {0:l}".format(hw)

        dbinterface = Interface(hardware_entity=hw, name=interface,
                                interface_type="oa",
                                comments="Created automatically by upgrade script")
        session.add(dbinterface)
        count += 1

    session.flush()
    print "Added %d interfaces" % count
Beispiel #2
0
def test_create_iface():
    machine = sess.query(Machine).first()

    iface = Interface(hardware_entity=machine,
                      name='eth0',
                      mac=random_mac(),
                      bootable=True,
                      interface_type='public')
    create(sess, iface)
    assert isinstance(iface, Interface), 'no iface created @ %s' % func_name()
Beispiel #3
0
def test_fail_upd_mgmt_iface_to_null_mac():
    machine = sess.query(Machine).first()

    iface = Interface(hardware_entity=machine,
                      name='ipmi',
                      mac=random_mac(),
                      bootable=True,
                      interface_type='management')
    create(sess, iface)
    assert isinstance(iface, Interface), 'no iface created @ %s' % func_name()

    iface.mac = None
    commit(sess)

    assert iface.mac is not None, 'set a management iface to null mac_addr'
Beispiel #4
0
def test_fail_upd_bootable_iface_to_null_mac():
    machine = sess.query(Machine).first()

    iface = Interface(hardware_entity=machine,
                      name='eth1',
                      mac=random_mac(),
                      bootable=True,
                      interface_type='public')
    create(sess, iface)
    assert isinstance(iface, Interface), 'no iface created @ %s' % func_name()

    iface.mac = None
    commit(sess)

    assert iface.mac is not None, 'able to set a bootable interface to null'
Beispiel #5
0
def test_fail_management_iface_with_no_mac_addr():
    machine = sess.query(Machine).first()
    iface = Interface(machine=machine,
                      name='eth2',
                      interface_type='management')
Beispiel #6
0
def test_fail_bootable_iface_with_no_mac_addr():
    machine = sess.query(Machine).first()
    iface = Interface(machine=machine,
                      name='eth3',
                      interface_type='public',
                      bootable=True)