def test_public_and_private_networks():
    """Public networks are accessible (within the host), but private ones are
    not.

    """
    pub = sample_network("public", cidr="192.168.0.0/24", public=True)
    dmz = sample_network("dmz", cidr="192.168.1.0/24")
    lan = sample_network("lan", cidr="192.168.3.0/24")

    with pub as pub, dmz as dmz, lan as lan:

        nginx = sample_node(networks=[pub, dmz])
        django = sample_node(networks=[dmz, lan])
        postgresql = sample_node(networks=[lan])

        with nginx as nginx, django as django, postgresql as postgresql:
            assert len(nginx.public_ips) == 1
            addr = nginx.public_ips[0]
            assert addr != pub.host_address
            assert ping(addr)

            assert len(nginx.private_ips) == 1
            addr = nginx.private_ips[0]
            assert not ping(addr)

            assert len(django.public_ips) == 0
            assert len(django.private_ips) == 2
            for addr in django.private_ips:
                assert not ping(addr)

            assert len(postgresql.public_ips) == 0
            assert len(postgresql.private_ips) == 1
            addr = postgresql.private_ips[0]
            assert not ping(addr)
示例#2
0
def test_num_cpus(driver):
    """The Vagrant driver honours the number of CPUs expressed in the nodes'
    size objects.

    """
    size = driver.list_sizes()[0]
    size.extra["cpus"] = 1
    with sample_node(driver, size=size) as node:
        assert num_cpus(node) == 1

    size.extra["cpus"] = 2
    with sample_node(driver, size=size) as node:
        assert num_cpus(node) == 2
示例#3
0
def test_host_interface_cleanup(driver):
    """Host interfaces are removed when their associated networks are
    destroyed.

    """
    with sample_network(driver, "pub", public=True) as pub:
        with sample_node(driver, networks=[pub]):
            iface = pub.host_interface
            assert iface in netifaces.interfaces()
        assert iface in netifaces.interfaces()
    assert iface not in netifaces.interfaces()

    with sample_network(driver, "priv") as priv:
        with sample_node(driver, networks=[priv]):
            assert priv.host_interface is None
示例#4
0
def test_host_interface_cleanup(driver):
    """Host interfaces are removed when their associated networks are
    destroyed.

    """
    with sample_network(driver, "pub", public=True) as pub:
        with sample_node(driver, networks=[pub]):
            iface = pub.host_interface
            assert iface in netifaces.interfaces()
        assert iface in netifaces.interfaces()
    assert iface not in netifaces.interfaces()

    with sample_network(driver, "priv") as priv:
        with sample_node(driver, networks=[priv]):
            assert priv.host_interface is None
def test_with_public_network():
    """Deployment works for nodes with public networks.

    """
    with sample_network("priv", "172.16.0.0/16", public=True) as net:
        with sample_node(networks=[net]) as node:
            deploy_node(node)
def test_public_network():
    with sample_network("public", cidr="192.168.0.0/24", public=True) as pub:
        with sample_node(networks=[pub]) as n:
            assert len(n.public_ips) == 1
            addr = n.public_ips[0]
            assert addr != pub.host_address
            assert ping(addr)
            assert not n.private_ips
def test_move_volume():
    """Attached volumes may be detached and attached to anothe node.

    """
    with sample_node() as n1, sample_node() as n2, sample_volume() as v:
        driver.ex_stop_node(n1)
        driver.ex_stop_node(n2)

        assert driver.attach_volume(n1, v)
        assert v.attached_to == n1.name
        assert not driver.attach_volume(n2, v)

        assert driver.detach_volume(v)
        assert v.attached_to is None
        assert driver.attach_volume(n2, v)
        assert v.attached_to == n2.name
        assert not driver.attach_volume(n1, v)
def test_invalid_device():
    """Volumes may only be attached to ``/dev/sd[a-z]``.

    """
    with sample_node() as node, sample_volume() as volume:
        driver.ex_stop_node(node)
        assert not driver.attach_volume(node, volume, "/dev/sdB")
        assert driver.attach_volume(node, volume, "/dev/sdb")
def test_attach_to_device():
    """It is possible to attach volumes to specific devices.

    """
    with sample_node() as node, sample_volume() as v1, sample_volume() as v2:
        driver.ex_stop_node(node)
        assert driver.attach_volume(node, v1, device="/dev/sdc")
        assert not driver.attach_volume(node, v2, device="/dev/sdc")
        assert driver.attach_volume(node, v2, device="/dev/sdb")
示例#10
0
def test_destroy_network():
    """Networks in use may not be destroyed.

    """
    with sample_network("net1", cidr="192.168.0.0/24") as net1:
        with sample_node(networks=[net1]):
            assert not driver.ex_destroy_network(net1)

        assert driver.ex_destroy_network(net1)
示例#11
0
def test_destroy_node_detaches_volume(driver, volume):
    """Destroying a node detaches all volumes attached to it.

    """
    with sample_node(driver) as node:
        assert driver.attach_volume(node, volume)
        assert volume.attached_to == node.name

    assert get_volume(driver, volume.name).attached_to == None
示例#12
0
def test_destroy_node_detaches_volume(driver, volume):
    """Destroying a node detaches all volumes attached to it.

    """
    with sample_node(driver) as node:
        assert driver.attach_volume(node, volume)
        assert volume.attached_to == node.name

    assert get_volume(driver, volume.name).attached_to == None
示例#13
0
def test_public_and_private_networks(driver, public_network, private_network):
    """Public networks are accessible (within the host), but private ones are
    not.

    """
    with sample_node(driver, networks=[public_network, private_network]) as n:
        assert len(n.public_ips) == 1
        assert ping(n.public_ips[0])
        assert len(n.private_ips) == 1
        assert not ping(n.private_ips[0])
示例#14
0
def test_public_and_private_networks(driver, public_network, private_network):
    """Public networks are accessible (within the host), but private ones are
    not.

    """
    with sample_node(driver, networks=[public_network, private_network]) as n:
        assert len(n.public_ips) == 1
        assert ping(n.public_ips[0])
        assert len(n.private_ips) == 1
        assert not ping(n.private_ips[0])
示例#15
0
def test_destroy_network(driver):
    """Networks in use may not be destroyed.

    """
    network = driver.ex_create_network(name="net1", cidr=available_network())
    try:
        with sample_node(driver, networks=[network]):
            assert not driver.ex_destroy_network(network)

    finally:
        assert driver.ex_destroy_network(network)
示例#16
0
def test_node_state(driver):
    """Node state reflects actual VirtualBox status.

    """
    with sample_node(driver) as node:
        assert driver.ex_get_node_state(node) == NodeState.RUNNING

    assert driver.ex_get_node_state(node) == NodeState.UNKNOWN

    node.id = None
    assert driver.ex_get_node_state(node) == NodeState.UNKNOWN
示例#17
0
def test_destroy_network(driver):
    """Networks in use may not be destroyed.

    """
    network = driver.ex_create_network(name="net1", cidr=available_network())
    try:
        with sample_node(driver, networks=[network]):
            assert not driver.ex_destroy_network(network)

    finally:
        assert driver.ex_destroy_network(network)
示例#18
0
def test_create_node(driver):
    """Nodes are created and registered correctly.

    """
    node_name = uuid.uuid4().hex
    assert node_name not in driver.list_nodes()

    with sample_node(driver) as node:
        assert node in driver.list_nodes()

        with driver._catalogue as c:
            assert node.id == c.virtualbox_uuid(node)
示例#19
0
def test_move_volume(driver, node, volume):
    """Attached volumes may be detached and attached to anothe node.

    """
    with sample_node(driver) as other_node:
        assert driver.attach_volume(node, volume)
        assert volume.attached_to == node.name
        assert not driver.attach_volume(other_node, volume)

        assert driver.detach_volume(volume)
        assert volume.attached_to is None
        assert driver.attach_volume(other_node, volume)
        assert volume.attached_to == other_node.name
        assert not driver.attach_volume(node, volume)
示例#20
0
def test_move_volume(driver, node, volume):
    """Attached volumes may be detached and attached to anothe node.

    """
    with sample_node(driver) as other_node:
        assert driver.attach_volume(node, volume)
        assert volume.attached_to == node.name
        assert not driver.attach_volume(other_node, volume)

        assert driver.detach_volume(volume)
        assert volume.attached_to is None
        assert driver.attach_volume(other_node, volume)
        assert volume.attached_to == other_node.name
        assert not driver.attach_volume(node, volume)
示例#21
0
def test_attach_volume():
    """Volumes may be attached to stopped nodes only. Attaching an
    already-attached volume fails.

    """
    with sample_node() as node, sample_volume() as volume:
        assert volume.attached_to is None

        assert node.state == NodeState.RUNNING
        assert not driver.attach_volume(node, volume)

        driver.ex_stop_node(node)
        assert node.state == NodeState.STOPPED
        assert driver.attach_volume(node, volume)
        assert volume.attached_to == node.name
示例#22
0
def node(driver):
    """Return an ephemeral Ubuntu 12.04 node.

    """
    with sample_node(driver) as n:
        yield n
示例#23
0
 def test_reboot_node_response(self):
     with sample_node(self.driver):
         super(ComputeTestCase, self).test_reboot_node_response()
示例#24
0
 def test_list_nodes_response(self):
     with sample_node(self.driver):
         super(ComputeTestCase, self).test_list_nodes_response()
 def test_list_nodes_response(self):
     with sample_node():
         super(ComputeTestCase, self).test_list_nodes_response()
示例#26
0
def node(driver):
    """Return an ephemeral Ubuntu 12.04 node.

    """
    with sample_node(driver) as n:
        yield n
示例#27
0
def test_deploy_without_network():
    """Deployment works for nodes without networks.

    """
    with sample_node() as node:
        deploy_node(node)