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()
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()
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
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()
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')
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])
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')
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
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])
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
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