Example #1
0
def test_load_failure():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name-fail')

    with nose.tools.assert_raises(errors.VCloudNotFoundError):
        driver.load()
Example #2
0
def test_commit():
    mock_client = get_mock_client()
    mock_client.wait_for_task.return_value = True

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()
    driver.commit()
Example #3
0
def test_load():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    assert driver.edge_gateway is not None
    assert driver.config is not None
Example #4
0
def test_commit_failure():
    mock_client = get_mock_client(task_status=400)
    mock_client.wait_for_task.return_value = True

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()
    with nose.tools.assert_raises(errors.VCloudAPIError):
        driver.commit()
Example #5
0
def test_add_service():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()
    service = driver.add_service('TestService')

    assert service is not None
    assert service.IsEnabled == 'true'
    assert hasattr(driver.config, 'TestService')
Example #6
0
def test_add_virtal_server_exists(mock_get_network):
    mock_network = objectify.Element('NetworkRecord')
    mock_network.attrib['name'] = 'test-network'
    mock_network.attrib['href'] = 'test-network-href'
    mock_get_network.return_value = mock_network
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    mock_service_profile = objectify.Element('ServiceProfile')

    # Add virtual server.
    driver.add_virtual_server(
        'test-vs-one', '0.0.0.0', 'test-pool', 'test-network',
        [mock_service_profile])

    # Add virtual server again.
    with nose.tools.assert_raises(errors.VCloudResourceConflict):
        driver.add_virtual_server(
            'test-vs-one', '0.0.0.1', 'test-pool', 'test-network',
            [mock_service_profile])

    # Add virtual server with same IP.
    with nose.tools.assert_raises(errors.VCloudResourceConflict):
        driver.add_virtual_server(
            'test-vs-two', '0.0.0.0', 'test-pool', 'test-network',
            [mock_service_profile])
Example #7
0
def test_add_firewall_rule_exists():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    # Add rule.
    driver.add_firewall_rule('test-rule-one', 'TCP', 'any', 80, 'any')

    # Add rule again.
    with nose.tools.assert_raises(errors.VCloudResourceConflict):
        driver.add_firewall_rule('test-rule-one', 'TCP', 'any', 80, 'any')
Example #8
0
def test_add_firewall_rule():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    # No existing rules.
    driver.add_firewall_rule('test-rule-one', 'TCP', 'any', 80, 'any')
    assert hasattr(driver.config, 'FirewallService')
    assert hasattr(driver.config.FirewallService, 'FirewallRule')

    # Existing rules.
    driver.add_firewall_rule('test-rule-two', 'TCP', 'any', 80, 'any')
    assert len(driver.config.FirewallService.FirewallRule) == 2
Example #9
0
def test_add_pool_exists():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    mock_service_port = objectify.Element('ServicePort')
    mock_member = objectify.Element('Member')

    # Add pool.
    driver.add_pool('test-pool-one', [mock_service_port], [mock_member])

    # Add pool again.
    with nose.tools.assert_raises(errors.VCloudResourceConflict):
        driver.add_pool('test-pool-one', [mock_service_port], [mock_member])
Example #10
0
def test_add_pool():
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    # No existing pools.
    mock_service_port = objectify.Element('ServicePort')
    mock_member = objectify.Element('Member')

    driver.add_pool('test-pool-one', [mock_service_port], [mock_member])
    assert hasattr(driver.config, 'LoadBalancerService')
    assert hasattr(driver.config.LoadBalancerService, 'Pool')

    # Existing rules.
    driver.add_pool('test-pool-two', [mock_service_port], [mock_member])
    assert len(driver.config.LoadBalancerService.Pool) == 2
Example #11
0
def test_add_virtual_server(mock_get_network):
    mock_network = objectify.Element('NetworkRecord')
    mock_network.attrib['name'] = 'test-network'
    mock_network.attrib['href'] = 'test-network-href'
    mock_get_network.return_value = mock_network
    mock_client = get_mock_client()

    driver = EdgeGatewayDriver(mock_client, 'test-name')
    driver.load()

    # No existing virtual servers.
    mock_service_profile = objectify.Element('ServiceProfile')

    driver.add_virtual_server(
        'test-vs-one', '0.0.0.0', 'test-pool', 'test-network',
        [mock_service_profile])
    assert hasattr(driver.config, 'LoadBalancerService')
    assert hasattr(driver.config.LoadBalancerService, 'VirtualServer')

    # Existing virtual servers.
    driver.add_virtual_server(
        'test-vs-two', '0.0.0.1', 'test-pool', 'test-network',
        [mock_service_profile])
    assert len(driver.config.LoadBalancerService.VirtualServer) == 2