예제 #1
0
파일: test_common.py 프로젝트: henn/hil
    def collect_nodes(self):
        """Add 4 available nodes with nics to the project.

        If there are not enough nodes, this will rais an api.AllocationError.
        """
        free_nodes = Node.query.filter_by(project_id=None).all()
        nodes = []
        for node in free_nodes:
            if len(node.nics) > 0:
                api.project_connect_node("anvil-nextgen", node.label)
                nodes.append(node)
                if len(nodes) >= 4:
                    break

        # If there are not enough nodes with nics, raise an exception
        if len(nodes) < 4:
            raise api.AllocationError(
                (
                    "At least 4 nodes with at least "
                    + "1 NIC are required for this test. Only %d node(s) were "
                    + "provided."
                )
                % len(nodes)
            )
        return nodes
예제 #2
0
파일: stress.py 프로젝트: kylehogan/haas
def test_many_http_queries():
    """Put a few objects in the db, then bombard the api with queries.

    This is intended to shake out problems like the resource leak discussed
    in issue #454.
    """
    # NOTE: Now that the session is managed by Flask-SQLAlchemy, failures here
    # are unlikely to be regressions of the issue that #454 fixed; we're no
    # longer managing the lifecycle of the session ourselves. It's not obvious
    # that this is more than clutter now, but let's not be too trigger happy
    # about deleting tests.
    with rest.app.test_request_context():
        rest.init_auth()
        api.node_register('node-99', obm={
            "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
            "host": "ipmihost",
            "user": "******",
            "password": "******"})
        api.node_register('node-98', obm={
            "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
            "host": "ipmihost",
            "user": "******",
            "password": "******"})
        api.node_register('node-97', obm={
            "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
            "host": "ipmihost",
            "user": "******",
            "password": "******"})
        api.node_register_nic('node-99', 'eth0', 'DE:AD:BE:EF:20:14')
        api.node_register_nic('node-98', 'eth0', 'DE:AD:BE:EF:20:15')
        api.node_register_nic('node-97', 'eth0', 'DE:AD:BE:EF:20:16')
        api.project_create('anvil-nextgen')
        api.project_create('anvil-legacy')
        api.project_connect_node('anvil-nextgen', 'node-99')
        api.project_connect_node('anvil-legacy', 'node-98')

    client = rest.app.test_client()

    def _show_nodes(path):
        """Helper for the loop below.

        This does a GET on path, which must return a json list of names of
        nodes. It will then query the state of each node. If any request does
        not return 200 or has a body which is not valid json, the test will
        fail.
        """
        resp = client.get(path)
        assert resp.status_code == 200
        for node in json.loads(resp.get_data()):
            resp = client.get('/nodes/%s' % node)
            assert resp.status_code == 200
            # At least make sure the body parses:
            json.loads(resp.get_data())

    for i in range(100):
        _show_nodes('/nodes/free')
        resp = client.get('/projects')
        assert resp.status_code == 200
        for project in json.loads(resp.get_data()):
            _show_nodes('/project/%s/nodes' % project)
예제 #3
0
def create_pending_actions_db():
    """Create database objects including a pending NetworkingAction.

    The first version of this function was used to create the dump
    'pending-networking-actions.sql'.
    """
    # At a minimum we need a project, node, nic, switch, port, and network:
    api.project_create('runway')
    api.node_register(
        'node-1',
        obm={
            'type': MOCK_OBM_TYPE,
            'user': '******',
            'host': 'host',
            'password': '******',
        },
    )
    api.node_register_nic('node-1', 'pxe', 'de:ad:be:ef:20:16')
    api.switch_register(
        'sw0',
        type=MOCK_SWITCH_TYPE,
        username='******',
        hostname='host',
        password='******',
    )
    api.switch_register_port('sw0', 'gi1/0/4')
    api.port_connect_nic('sw0', 'gi1/0/4', 'node-1', 'pxe')
    api.project_connect_node('runway', 'node-1')
    api.network_create('runway_pxe', 'runway', 'runway', '')

    # Queue up a networking action. Importantly, we do *not* call
    # deferred.apply_networking, as that would flush the action and
    # remove it from the database.
    api.node_connect_network('node-1', 'pxe', 'runway_pxe')
예제 #4
0
        def create_networks():
            # Add up to 4 available nodes with nics to the project
            free_nodes = db.query(model.Node).filter_by(project_id=None).all()
            nodes = []
            for node in free_nodes:
                if len(node.nics) > 0:
                    api.project_connect_node('anvil-nextgen', node.label)
                    nodes.append(node)
                    if len(nodes) >= 4:
                        break

            # If there are not enough nodes with nics, raise an exception
            if len(nodes) < 4:
                raise api.AllocationError(('At least 4 nodes with at least ' +
                    '1 NIC are required for this test. Only %d node(s) were ' +
                    'provided.') % len(nodes))

            # Create two networks
            network_create_simple('net-0', 'anvil-nextgen')
            network_create_simple('net-1', 'anvil-nextgen')

            # Convert each node to a dict for ease of access
            nodes = [{'label': n.label,
                      'nic': n.nics[0].label,
                      'port': n.nics[0].port.label}
                     for n in nodes]

            # Assert that n0 and n1 are not on any network
            vlan_cfgs = get_switch_vlans()

            assert get_network(nodes[0]['port'], vlan_cfgs) == []
            assert get_network(nodes[1]['port'], vlan_cfgs) == []

            # Connect n0 and n1 to net-0 and net-1 respectively
            api.node_connect_network(nodes[0]['label'], nodes[0]['nic'], 'net-0')
            api.node_connect_network(nodes[1]['label'], nodes[1]['nic'], 'net-1')
            deferred.apply_networking()

            # Assert that n0 and n1 are on isolated networks
            vlan_cfgs = get_switch_vlans()
            assert get_network(nodes[0]['port'], vlan_cfgs) == [nodes[0]['port']]
            assert get_network(nodes[1]['port'], vlan_cfgs) == [nodes[1]['port']]

            # Add n2 and n3 to the same networks as n0 and n1 respectively
            api.node_connect_network(nodes[2]['label'], nodes[2]['nic'], 'net-0')
            api.node_connect_network(nodes[3]['label'], nodes[3]['nic'], 'net-1')
            deferred.apply_networking()

            # Assert that n2 and n3 have been added to n0 and n1's networks
            # respectively
            vlan_cfgs = get_switch_vlans()
            assert sorted(get_network(nodes[0]['port'], vlan_cfgs)) == sorted([nodes[0]['port'], nodes[2]['port']])
            assert sorted(get_network(nodes[1]['port'], vlan_cfgs)) == sorted([nodes[1]['port'], nodes[3]['port']])
예제 #5
0
파일: stress.py 프로젝트: starbops/haas
def test_many_http_queries():
    """Put a few objects in the db, then bombard the api with queries.

    This is intended to shake out problems like the resource leak discussed
    in issue #454.
    """
    with rest.RequestContext():
        api.node_register('node-99', obm={
                  "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                  "host": "ipmihost",
                  "user": "******",
                  "password": "******"})
        api.node_register('node-98', obm={
                  "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                  "host": "ipmihost",
                  "user": "******",
                  "password": "******"})
        api.node_register('node-97', obm={
                  "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                  "host": "ipmihost",
                  "user": "******",
                  "password": "******"})
        api.node_register_nic('node-99', 'eth0', 'DE:AD:BE:EF:20:14')
        api.node_register_nic('node-98', 'eth0', 'DE:AD:BE:EF:20:15')
        api.node_register_nic('node-97', 'eth0', 'DE:AD:BE:EF:20:16')
        api.project_create('anvil-nextgen')
        api.project_create('anvil-legacy')
        api.project_connect_node('anvil-nextgen', 'node-99')
        api.project_connect_node('anvil-legacy', 'node-98')

    def _show_nodes(path):
        """Helper for the loop below.

        This does a GET on path, which must return a json list of names of
        nodes. It will then query the state of each node. If any request does
        not return 200 or has a body which is not valid json, the test will
        fail.
        """
        resp = do_request('GET', path)
        assert resp.status_code == 200
        for node in json.loads(resp.get_data()):
            resp = do_request('GET', '/node/%s' % node)
            assert resp.status_code == 200
            # At least make sure the body parses:
            json.loads(resp.get_data())

    for i in range(100):
        _show_nodes('/free_nodes')
        resp = do_request('GET', '/projects')
        assert resp.status_code == 200
        for project in json.loads(resp.get_data()):
            _show_nodes('/project/%s/nodes' % project)
예제 #6
0
def test_test():

    api.node_register('node-99',
                      obm={
                          "type":
                          "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                          "host": "ipmihost",
                          "user": "******",
                          "password": "******"
                      })
    api.project_create('anvil-nextgen')
    api.project_connect_node('anvil-nextgen', 'node-99')
    api.project_detach_node('anvil-nextgen', 'node-99')
    api.project_delete('anvil-nextgen')
예제 #7
0
    def collect_nodes(self):
        """Add 4 available nodes with nics to the project.

        If there are not enough nodes, this will rais an api.AllocationError.
        """
        free_nodes = Node.query.filter_by(project_id=None).all()
        nodes = []
        for node in free_nodes:
            if len(node.nics) > 0:
                api.project_connect_node('anvil-nextgen', node.label)
                nodes.append(node)
                if len(nodes) >= 4:
                    break

        # If there are not enough nodes with nics, raise an exception
        if len(nodes) < 4:
            raise api.AllocationError(
                ('At least 4 nodes with at least ' +
                 '1 NIC are required for this test. Only %d node(s) were ' +
                 'provided.') % len(nodes))
        return nodes
예제 #8
0
def test_many_http_queries():
    """Put a few objects in the db, then bombard the api with queries.

    This is intended to shake out problems like the resource leak discussed
    in issue #454.
    """
    # NOTE: Now that the session is managed by Flask-SQLAlchemy, failures here
    # are unlikely to be regressions of the issue that #454 fixed; we're no
    # longer managing the lifecycle of the session ourselves. It's not obvious
    # that this is more than clutter now, but let's not be too trigger happy
    # about deleting tests.
    with rest.app.test_request_context():
        rest.init_auth()
        api.node_register(
            'node-99',
            obm={
                "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                "host": "ipmihost",
                "user": "******",
                "password": "******"
            })
        api.node_register(
            'node-98',
            obm={
                "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                "host": "ipmihost",
                "user": "******",
                "password": "******"
            })
        api.node_register(
            'node-97',
            obm={
                "type": "http://schema.massopencloud.org/haas/v0/obm/ipmi",
                "host": "ipmihost",
                "user": "******",
                "password": "******"
            })
        api.node_register_nic('node-99', 'eth0', 'DE:AD:BE:EF:20:14')
        api.node_register_nic('node-98', 'eth0', 'DE:AD:BE:EF:20:15')
        api.node_register_nic('node-97', 'eth0', 'DE:AD:BE:EF:20:16')
        api.project_create('anvil-nextgen')
        api.project_create('anvil-legacy')
        api.project_connect_node('anvil-nextgen', 'node-99')
        api.project_connect_node('anvil-legacy', 'node-98')

    client = rest.app.test_client()

    def _show_nodes(path):
        """Helper for the loop below.

        This does a GET on path, which must return a json list of names of
        nodes. It will then query the state of each node. If any request does
        not return 200 or has a body which is not valid json, the test will
        fail.
        """
        resp = client.get(path)
        assert resp.status_code == 200
        for node in json.loads(resp.get_data()):
            resp = client.get('/nodes/%s' % node)
            assert resp.status_code == 200
            # At least make sure the body parses:
            json.loads(resp.get_data())

    for i in range(100):
        _show_nodes('/nodes/free')
        resp = client.get('/projects')
        assert resp.status_code == 200
        for project in json.loads(resp.get_data()):
            _show_nodes('/project/%s/nodes' % project)
예제 #9
0
        def create_networks():
            # Add up to 4 available nodes with nics to the project
            free_nodes = db.query(model.Node).filter_by(project_id=None).all()
            nodes = []
            for node in free_nodes:
                if len(node.nics) > 0:
                    api.project_connect_node('anvil-nextgen', node.label)
                    nodes.append(node)
                    if len(nodes) >= 4:
                        break

            # If there are not enough nodes with nics, raise an exception
            if len(nodes) < 4:
                raise api.AllocationError(
                    ('At least 4 nodes with at least ' +
                     '1 NIC are required for this test. Only %d node(s) were '
                     + 'provided.') % len(nodes))

            # Create two networks
            network_create_simple('net-0', 'anvil-nextgen')
            network_create_simple('net-1', 'anvil-nextgen')

            # Convert each node to a dict for ease of access
            nodes = [{
                'label': n.label,
                'nic': n.nics[0].label,
                'port': n.nics[0].port.label
            } for n in nodes]

            # Assert that n0 and n1 are not on any network
            vlan_cfgs = get_switch_vlans()

            assert get_network(nodes[0]['port'], vlan_cfgs) == []
            assert get_network(nodes[1]['port'], vlan_cfgs) == []

            # Connect n0 and n1 to net-0 and net-1 respectively
            api.node_connect_network(nodes[0]['label'], nodes[0]['nic'],
                                     'net-0')
            api.node_connect_network(nodes[1]['label'], nodes[1]['nic'],
                                     'net-1')
            deferred.apply_networking()

            # Assert that n0 and n1 are on isolated networks
            vlan_cfgs = get_switch_vlans()
            assert get_network(nodes[0]['port'],
                               vlan_cfgs) == [nodes[0]['port']]
            assert get_network(nodes[1]['port'],
                               vlan_cfgs) == [nodes[1]['port']]

            # Add n2 and n3 to the same networks as n0 and n1 respectively
            api.node_connect_network(nodes[2]['label'], nodes[2]['nic'],
                                     'net-0')
            api.node_connect_network(nodes[3]['label'], nodes[3]['nic'],
                                     'net-1')
            deferred.apply_networking()

            # Assert that n2 and n3 have been added to n0 and n1's networks
            # respectively
            vlan_cfgs = get_switch_vlans()
            assert sorted(get_network(nodes[0]['port'], vlan_cfgs)) == sorted(
                [nodes[0]['port'], nodes[2]['port']])
            assert sorted(get_network(nodes[1]['port'], vlan_cfgs)) == sorted(
                [nodes[1]['port'], nodes[3]['port']])