Example #1
0
 def nic(self):
     """Create a Nic object (and associated Node) to work with."""
     return model.Nic(
         model.Node(label='node-99'),
         'ipmi',
         '00:11:22:33:44:55',
     )
Example #2
0
def new_nic(name):
    """Create a new nic named ``name``, and an associated Node + Obm."""
    from hil.ext.obm.mock import MockObm
    return model.Nic(
        model.Node(label='node-99',
                   obm=MockObm(
                       type="http://schema.massopencloud.org/haas/v0/obm/mock",
                       host="ipmihost",
                       user="******",
                       password="******")), name, '00:11:22:33:44:55')
Example #3
0
def test_obmd_migrate(tmpdir):
    """The test proper.

    Create some nodes, run the script, and verify that it has done the right
    thing.
    """
    from hil.ext.obm.ipmi import Ipmi

    # Add some objects to the hil database:
    with app.app_context():
        for i in range(4):
            node = model.Node(label='node-%d' % i,
                              obm=Ipmi(user='******',
                                       host='10.0.0.%d' % (100 + i),
                                       password='******'))
            model.db.session.add(node)
        model.db.session.commit()

    check_call([
        'hil-admin', 'migrate-ipmi-info',
        '--obmd-base-url', OBMD_BASE_URL,
        '--obmd-admin-token', ADMIN_TOKEN,
    ])

    with app.app_context():
        for node in model.Node.query.all():

            # Check that the db info was updated correctly:
            assert node.obmd_admin_token == ADMIN_TOKEN, (
                "Node %s{label}'s admin token was incorrect: %s{token}"
                .format(
                    label=node.label,
                    token=node.obmd_admin_token,
                )
            )
            assert node.obmd_uri == OBMD_BASE_URL + '/node/' + node.label, (
                "Node %s{label}'s obmd_uri was incorrect: %s{uri}"
                .format(
                    label=node.label,
                    uri=node.obmd_uri,
                )
            )

            # Make sure obmd thinks the nodes are there; if so it should be
            # possible to get a token:
            sess = requests.Session()
            sess.auth = ('admin', ADMIN_TOKEN)
            resp = sess.post(node.obmd_uri + '/token')
            assert resp.ok, (
                "Failure getting token for node %s{label} from obmd; "
                "response: %s{resp}".format(
                    label=node.label,
                    resp=resp,
                )
            )
Example #4
0
File: brocade.py Project: vsemp/hil
 def nic(self):
     """Create a Nic object (and associated Node) to work with."""
     from hil.ext.obm.ipmi import Ipmi
     return model.Nic(
         model.Node(
             label='node-99',
             obm=Ipmi(
                 type="http://schema.massopencloud.org/haas/v0/obm/ipmi",
                 host="ipmihost",
                 user="******",
                 password="******")), 'ipmi', '00:11:22:33:44:55')
Example #5
0
def new_nic(name):
    """Create a new nic named ``name``, and an associated Node + Obm.
    The new nic is attached to a new node each time, and the node is added to
    the project named 'anvil-nextgen' """

    from hil.ext.obm.mock import MockObm
    project = model.Project('anvil-nextgen')
    node = model.Node(
        label=str(uuid.uuid4()),
        obm=MockObm(type="http://schema.massopencloud.org/haas/v0/obm/mock",
                    host="ipmihost",
                    user="******",
                    password="******"))
    if node.project is None:
        project.nodes.append(node)
    return model.Nic(node, name, '00:11:22:33:44:55')
Example #6
0
def new_nic(name):
    """Create a new nic named ``name``, and an associated Node + Obm.
    The new nic is attached to a new node each time, and the node is added to
    the project named 'anvil-nextgen-####' """

    unique_id = str(uuid.uuid4())
    project = model.Project('anvil-nextgen-' + unique_id)
    label = str(uuid.uuid4())
    node = model.Node(
        label=label,
        obmd_uri='http://obmd.example.com/nodes/' + label,
        obmd_admin_token='secret',
    )
    if node.project is None:
        project.nodes.append(node)
    return model.Nic(node, name, '00:11:22:33:44:55')
Example #7
0
def node_register(node, **kwargs):
    """Create node.

    If the node already exists, a DuplicateError will be raised.
    The node is initially registered with no nics; see the method
    node_register_nic.
    """
    get_auth_backend().require_admin()
    absent_or_conflict(model.Node, node)
    obm_type = kwargs['obm']['type']
    cls = concrete_class_for(model.Obm, obm_type)
    if cls is None:
        raise errors.BadArgumentError('%r is not a valid OBM type.' % obm_type)
    cls.validate(kwargs['obm'])
    node_obj = model.Node(label=node, obm=cls(**kwargs['obm']))
    if 'metadata' in kwargs:
        for label, value in kwargs['metadata'].items():
            metadata_obj = model.Metadata(label, json.dumps(value), node_obj)
            db.session.add(metadata_obj)
    db.session.add(node_obj)
    db.session.commit()
Example #8
0
def new_nic(name):
    """Create a new nic named ``name``, and an associated Node + Obm.
    The new nic is attached to a new node each time, and the node is added to
    the project named 'anvil-nextgen-####' """

    from hil.ext.obm.mock import MockObm
    unique_id = str(uuid.uuid4())
    project = model.Project('anvil-nextgen-' + unique_id)
    label = str(uuid.uuid4())
    node = model.Node(
        label=label,
        obm=MockObm(
            type="http://schema.massopencloud.org/haas/v0/obm/mock",
            host="ipmihost",
            user="******",
            password="******",
        ),
        obmd_uri='http://obmd.example.com/nodes/' + label,
        obmd_admin_token='secret',
    )
    if node.project is None:
        project.nodes.append(node)
    return model.Nic(node, name, '00:11:22:33:44:55')
Example #9
0
def create_bigint_db():
    """Create database objects used in 'after-PK-bigint.sql'"""
    from hil.ext.switches.n3000 import DellN3000
    from hil.ext.switches.dell import PowerConnect55xx
    from hil.ext.switches.brocade import Brocade
    from hil.ext.switches.nexus import Nexus
    from hil.ext.switches.mock import MockSwitch
    from hil.ext.obm.ipmi import Ipmi
    from hil.ext.obm.mock import MockObm
    from hil.ext.auth.database import User
    from hil.ext.auth import database as dbauth
    with app.app_context():
        db.session.add(
            DellN3000(label='sw-n3000',
                      hostname='host',
                      username='******',
                      password='******',
                      dummy_vlan='5',
                      type=DellN3000.api_name))
        dell1 = PowerConnect55xx(label='sw-dell',
                                 hostname='host',
                                 username='******',
                                 password='******',
                                 type=PowerConnect55xx.api_name)
        db.session.add(dell1)
        db.session.add(
            Nexus(label='sw-nexus',
                  hostname='host',
                  username='******',
                  password='******',
                  dummy_vlan='5',
                  type=Nexus.api_name))
        db.session.add(
            Brocade(label='sw-brocade',
                    hostname='host',
                    username='******',
                    password='******',
                    interface_type='4',
                    type=Brocade.api_name))
        db.session.add(
            MockSwitch(label='sw0',
                       hostname='host',
                       username='******',
                       password='******',
                       type=MockSwitch.api_name))
        proj = model.Project(label='runway')
        db.session.add(proj)
        headnode1 = model.Headnode(label='runway_headnode',
                                   project=proj,
                                   base_img='image1')
        db.session.add(headnode1)
        db.session.add(model.Hnic(label='hnic1', headnode=headnode1))
        ipmi = Ipmi(host='host', user='******', password='******')
        db.session.add(ipmi)
        mock_obm = MockObm(host='host', user='******', password='******')
        db.session.add(mock_obm)
        node1 = model.Node(label='node-1', obm=ipmi)
        db.session.add(node1)

        db.session.add(
            model.Metadata(label='meta',
                           value="it is a true value",
                           node=node1))
        network1 = model.Network(owner=None,
                                 access=[proj],
                                 allocated=False,
                                 network_id="networking network",
                                 label='hil wireless')
        db.session.add(network1)
        nic1 = model.Nic(node=node1, label='pxe', mac_addr='ff:ff:ff:ff:ff:fe')
        model.Port(label='A fine port', switch=dell1)
        db.session.add(nic1)
        db.session.add(
            model.NetworkAttachment(nic=nic1, network_id=1,
                                    channel='vlan/100'))
        db.session.add(
            model.NetworkingAction(type='modify_port',
                                   nic=nic1,
                                   new_network=network1,
                                   channel='vlan/100'))
        jim = User(label='jim', password='******', is_admin=True)
        db.session.add(jim)

        local.auth = dbauth.User.query.filter_by(label='jim').one()

        dbauth.user_add_project('jim', 'runway')

        db.session.commit()

        # Original password is "pass"
        db.session.query(User).get(1).hashed_password = \
            ('$6$rounds=656000$iTyrApYTUhMx4b4g$YcaMExV'
             'YtS0ut2yXWrT64OggFpE4lLg12QsAuyMA3YKX6Czth'
             'XeisA47dJZW9GwU2q2CTIVrsbpxAVT64Pih2/')
        db.session.commit()