Example #1
0
 def sample_obj(self):
     nic = Nic(_test_node(), 'ipmi', '00:11:22:33:44:55')
     project = Project('anvil-nextgen')
     network = Network(project, [project], True, '102', 'hammernet')
     return NetworkingAction(nic=nic,
                             new_network=network,
                             channel='null')
Example #2
0
 def sample_obj(self):
     from hil.ext.obm.ipmi import Ipmi
     nic = Nic(
         Node(label='node-99',
              obm=Ipmi(type=Ipmi.api_name,
                       host="ipmihost",
                       user="******",
                       password="******")), 'ipmi', '00:11:22:33:44:55')
     project = Project('anvil-nextgen')
     network = Network(project, [project], True, '102', 'hammernet')
     return NetworkingAction(nic=nic, new_network=network, channel='null')
Example #3
0
File: model.py Project: vsemp/hil
 def sample_obj(self):
     pj = Project('anvil-nextgen')
     return Network(pj, [pj], True, '102', 'hammernet')
Example #4
0
File: model.py Project: vsemp/hil
 def sample_obj(self):
     return Hnic(Headnode(Project('anvil-nextgen'),
                          'hn-0', 'base-headnode'),
                 'storage')
Example #5
0
File: model.py Project: vsemp/hil
 def sample_obj(self):
     return Headnode(Project('anvil-nextgen'),
                     'hn-example', 'base-headnode')
Example #6
0
File: model.py Project: vsemp/hil
 def sample_obj(self):
     return Project('manhattan')
Example #7
0
def initial_db():
    """Populates the database with a useful set of objects.

    This allows us to avoid some boilerplate in tests which need a few objects
    in the database in order to work.

    Is static to allow database migrations to be tested, if new objects need
    to be added they should be included in additional_db not initial_db.

    Note that this fixture requires the use of the following extensions:

        - hil.ext.switches.mock
        - hil.ext.obm.mock
    """
    for required_extension in 'hil.ext.switches.mock', 'hil.ext.obm.mock':
        assert required_extension in sys.modules, \
            "The 'initial_db' fixture requires the extension %r" % \
            required_extension

    from hil.ext.switches.mock import MockSwitch
    from hil.ext.obm.mock import MockObm

    with app.app_context():
        # Create a couple projects:
        runway = Project("runway")
        manhattan = Project("manhattan")
        for proj in [runway, manhattan]:
            db.session.add(proj)

        # ...including at least one with nothing in it:
        db.session.add(Project('empty-project'))

        # ...A variety of networks:

        networks = [
            {
                'owner': None,
                'access': [],
                'allocated': True,
                'label': 'stock_int_pub',
            },
            {
                'owner': None,
                'access': [],
                'allocated': False,
                'network_id': 'ext_pub_chan',
                'label': 'stock_ext_pub',
            },
            {
                # For some tests, we want things to initially be attached to a
                # network. This one serves that purpose; using the others would
                # interfere with some of the network_delete tests.
                'owner': None,
                'access': [],
                'allocated': True,
                'label': 'pub_default',
            },
            {
                'owner': runway,
                'access': [runway],
                'allocated': True,
                'label': 'runway_pxe'
            },
            {
                'owner': None,
                'access': [runway],
                'allocated': False,
                'network_id': 'runway_provider_chan',
                'label': 'runway_provider',
            },
            {
                'owner': manhattan,
                'access': [manhattan],
                'allocated': True,
                'label': 'manhattan_pxe'
            },
            {
                'owner': None,
                'access': [manhattan],
                'allocated': False,
                'network_id': 'manhattan_provider_chan',
                'label': 'manhattan_provider',
            },
        ]

        for net in networks:
            if net['allocated']:
                net['network_id'] = \
                    get_network_allocator().get_new_network_id()
            db.session.add(Network(**net))

        # ... Two switches. One of these is just empty, for testing deletion:
        db.session.add(
            MockSwitch(label='empty-switch',
                       hostname='empty',
                       username='******',
                       password='******',
                       type=MockSwitch.api_name))

        # ... The other we'll actually attach stuff to for other tests:
        switch = MockSwitch(label="stock_switch_0",
                            hostname='stock',
                            username='******',
                            password='******',
                            type=MockSwitch.api_name)

        # ... Some free ports:
        db.session.add(Port('free_port_0', switch))
        db.session.add(Port('free_port_1', switch))

        # ... Some nodes (with projets):
        nodes = [
            {
                'label': 'runway_node_0',
                'project': runway
            },
            {
                'label': 'runway_node_1',
                'project': runway
            },
            {
                'label': 'manhattan_node_0',
                'project': manhattan
            },
            {
                'label': 'manhattan_node_1',
                'project': manhattan
            },
            {
                'label': 'free_node_0',
                'project': None
            },
            {
                'label': 'free_node_1',
                'project': None
            },
        ]
        for node_dict in nodes:
            obm = MockObm(type=MockObm.api_name,
                          host=node_dict['label'],
                          user='******',
                          password='******')
            node = Node(
                label=node_dict['label'],
                obm=obm,
                obmd_uri='http://obmd.example.com/nodes/' + node_dict['label'],
                obmd_admin_token='secret',
            )
            node.project = node_dict['project']
            db.session.add(Nic(node, label='boot-nic', mac_addr='Unknown'))

            # give it a nic that's attached to a port:
            port_nic = Nic(node, label='nic-with-port', mac_addr='Unknown')
            port = Port(node_dict['label'] + '_port', switch)
            port.nic = port_nic

        # ... Some headnodes:
        headnodes = [
            {
                'label': 'runway_headnode_on',
                'project': runway,
                'on': True
            },
            {
                'label': 'runway_headnode_off',
                'project': runway,
                'on': False
            },
            {
                'label': 'runway_manhattan_on',
                'project': manhattan,
                'on': True
            },
            {
                'label': 'runway_manhattan_off',
                'project': manhattan,
                'on': False
            },
        ]
        for hn_dict in headnodes:
            headnode = Headnode(hn_dict['project'], hn_dict['label'],
                                'base-headnode')
            headnode.dirty = not hn_dict['on']
            hnic = Hnic(headnode, 'pxe')
            db.session.add(hnic)

            # Connect them to a network, so we can test detaching.
            hnic = Hnic(headnode, 'public')
            hnic.network = Network.query \
                .filter_by(label='pub_default').one()

        # ... and at least one node with no nics (useful for testing delete):
        obm = MockObm(type=MockObm.api_name,
                      host='hostname',
                      user='******',
                      password='******')
        db.session.add(
            Node(
                label='no_nic_node',
                obm=obm,
                obmd_uri='http://obmd.example.com/nodes/no_nic_node',
                obmd_admin_token='secret',
            ))

        db.session.commit()
Example #8
0
def load_projects():
    """Add a couple probjects to the database for us to work with"""
    db.session.add(Project("manhattan"))
    db.session.add(Project("runway"))