def test_subnet_add_invalid_network(self, mock_connection): ovn_north = OvnNorth() rest_data = { SubnetMapper.REST_SUBNET_NAME: 'subnet_name', SubnetMapper.REST_SUBNET_CIDR: '1.1.1.0/24', SubnetMapper.REST_SUBNET_NETWORK_ID: 7, SubnetMapper.REST_SUBNET_DNS_NAMESERVERS: ['1.1.1.1'], SubnetMapper.REST_SUBNET_GATEWAY_IP: '1.1.1.0', } with pytest.raises(SubnetConfigError): ovn_north.add_subnet(rest_data)
def test_subnet_add_duplicate_network(self, mock_connection): ovn_north = OvnNorth() rest_data = { SubnetMapper.REST_SUBNET_NAME: 'subnet_name', SubnetMapper.REST_SUBNET_CIDR: '1.1.1.0/24', SubnetMapper.REST_SUBNET_NETWORK_ID: str(TestOvnNorth.NETWORK_ID10), SubnetMapper.REST_SUBNET_GATEWAY_IP: '1.1.1.0', } with pytest.raises(SubnetConfigError): ovn_north.add_subnet(rest_data)
def test_subnet_dhcp_enabled_false(self, mock_connection): ovn_north = OvnNorth() rest_data = { SubnetMapper.REST_SUBNET_NAME: 'subnet_name', SubnetMapper.REST_SUBNET_CIDR: '1.1.1.0/24', SubnetMapper.REST_SUBNET_NETWORK_ID: '', SubnetMapper.REST_SUBNET_DNS_NAMESERVERS: ['1.1.1.1'], SubnetMapper.REST_SUBNET_GATEWAY_IP: '1.1.1.0', SubnetMapper.REST_SUBNET_ENABLE_DHCP: False } with pytest.raises(UnsupportedDataValueError): ovn_north.add_subnet(rest_data)
def test_add_subnet(self, mock_setoptions_command, mock_add_command, mock_dbset_command, mock_connection): add_execute = mock_add_command.return_value.execute add_execute.return_value = TestOvnNorth.SUBNET_102 subnet_cidr = '1.1.1.0/24' ovn_north = OvnNorth() rest_data = { SubnetMapper.REST_SUBNET_NAME: 'subnet_name', SubnetMapper.REST_SUBNET_CIDR: subnet_cidr, SubnetMapper.REST_SUBNET_NETWORK_ID: str(TestOvnNorth.NETWORK_ID10), SubnetMapper.REST_SUBNET_DNS_NAMESERVERS: ['1.1.1.1'], SubnetMapper.REST_SUBNET_GATEWAY_IP: '1.1.1.0', } result = ovn_north.add_subnet(rest_data) assert result['id'] == str(TestOvnNorth.SUBNET_ID102) assert mock_dbset_command.call_count == 1 assert mock_add_command.call_count == 1 assert mock_setoptions_command.call_count == 1 expected_dbset_call = mock.call( ovn_north.idl, ovnconst.TABLE_LS, str(TestOvnNorth.NETWORK_ID10), (ovnconst.ROW_LS_OTHER_CONFIG, { NetworkMapper.OVN_SUBNET: subnet_cidr }), ) assert mock_dbset_command.mock_calls[0] == expected_dbset_call expected_add_call = mock.call(ovn_north.idl, subnet_cidr, ovirt_name='subnet_name', ovirt_network_id=str( TestOvnNorth.NETWORK_ID10)) assert mock_add_command.mock_calls[0] == expected_add_call expected_options_call = mock.call(ovn_north.idl, TestOvnNorth.SUBNET_ID102, dns_server='1.1.1.1', lease_time=dhcp_lease_time(), router='1.1.1.0', server_id='1.1.1.0', server_mac=dhcp_server_mac(), mtu=dhcp_mtu()) assert mock_setoptions_command.mock_calls[0] == expected_options_call
def test_add_subnet_no_dns(self, mock_setoptions_command, mock_add_command, mock_dbset_command, mock_connection): add_execute = mock_add_command.return_value.execute add_execute.return_value = TestOvnNorth.SUBNET_102 subnet_cidr = '1.1.1.0/24' ovn_north = OvnNorth() rest_data = { SubnetMapper.REST_SUBNET_NAME: 'subnet_name', SubnetMapper.REST_SUBNET_CIDR: subnet_cidr, SubnetMapper.REST_SUBNET_NETWORK_ID: str(TestOvnNorth.NETWORK_ID10), SubnetMapper.REST_SUBNET_DNS_NAMESERVERS: [], SubnetMapper.REST_SUBNET_GATEWAY_IP: '1.1.1.0', } result = ovn_north.add_subnet(rest_data) assert result['id'] == str(TestOvnNorth.SUBNET_ID102) assert mock_dbset_command.call_count == 1 assert mock_add_command.call_count == 1 assert mock_setoptions_command.call_count == 1