{"action":"created","comment":{"url":"https://api.github.com/repos/theforeman/foreman/pulls/comments/61550858","id":61550858,"diff_hunk":"@@ -0,0 +1,90 @@\n+require 'test_helper'\n+\n+class IPAMTest < ActiveSupport::TestCase\n+  test 'should raise an exception if given mac is invalid' do\n+    s = FactoryGirl.build(:subnet_ipv6, :network => '2001:db8::')\n+    exception = assert_raise Foreman::Exception do\n+      IPAM::Eui64.new(:subnet => s, :mac => 'invalid')\n+    end\n+    assert_includes exception.message, 'not a valid MAC address'\n+  end\n+\n+  context 'dhcp' do\n+    test \"should find unused IP on proxy if proxy is set\" do\n+      subnet = FactoryGirl.create(:subnet_ipv4, :ipam_dhcp, :name => 'my_subnet', :network => '192.168.1.0')\n+      subnet.stubs(:dhcp? => true)\n+      subnet.stubs(:dhcp => mock('attribute', :url => 'proxy.example.com'))\n+      fake_proxy = mock(\"dhcp_proxy\")\n+      fake_proxy.stubs(:unused_ip => {'ip' => '192.168.1.25'})\n+      subnet.stubs(:dhcp_proxy => fake_proxy)\n+      ipam = IPAM::Dhcp.new(:subnet => subnet, :mac => '00:11:22:33:44:55')\n+      assert_equal '192.168.1.25', ipam.suggest_ip\n+    end\n+  end\n+\n+  context 'internal db' do\n+    test \"should find unused IP in internal DB if proxy is not set\" do\n+      host = FactoryGirl.create(:host)","path":"test/unit/ipam_test.rb","position":27,"original_position":27,"commit_id":"da066ffa75b7d4241480882d689119b50a9cb00b","original_commit_id":"da066ffa75b7d4241480882d689119b50a9cb00b","user":{"login":"dLobatog","id":598891,"avatar_url":"https://avatars.githubusercontent.com/u/598891?v=3","gravatar_id":"","url":"https://api.github.com/users/dLobatog","html_url":"https://github.com/dLobatog","followers_url":"https://api.github.com/users/dLobatog/followers","following_url":"https://api.github.com/users/dLobatog/following{/other_user}","gists_url":"https://api.github.com/users/dLobatog/gists{/gist_id}","starred_url":"https://api.github.com/users/dLobatog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dLobatog/subscriptions","organizations_url":"https://api.github.com/users/dLobatog/orgs","repos_url":"https://api.github.com/users/dLobatog/repos","events_url":"https://api.github.com/users/dLobatog/events{/privacy}","received_events_url":"https://api.github.com/users/dLobatog/received_events","type":"User","site_admin":false},"body":"Actually I think this is testing too much. By creating hosts, we're testing `.known_ips` and stuff we shouldn't be testing here. [That's tested somewhere else already](https://github.com/theforeman/foreman/blob/develop/test/unit/subnet/ipv4_test.rb#L287). We just want to get a free IP from the db. So two options to offload this test are: \r\n\r\n1 - passing `:excluded_ips` to the IPAM service.\r\n2 - stubbing `subnet.known_ips` to return whatever you want.\r\n\r\nIt'd look like this, you'd save creating an expensive object in db, and also it's much clearer. To understand the current test now one has to check the implementation.\r\n\r\n```ruby\r\ntest do\r\n  subnet = FactoryGirl.create(\r\n          :subnet_ipv4, :name => 'my_subnet',\r\n          :network => '192.168.2.0',\r\n          :ipam => IPAM::MODES[:db])\r\n  ipam = IPAM::Db.new(:subnet => subnet, :excluded_ips => ['192.168.2.1', '192.168.2.2'])\r\n  assert_equal '192.168.2.3', ipam.suggest_ip\r\nend \r\n```","created_at":"2016-04-29T09:05:47Z","updated_at":"2016-04-29T09:05:47Z","html_url":"https://github.com/theforeman/foreman/pull/3442#discussion_r61550858","pull_request_url":"https://api.github.com/repos/theforeman/foreman/pulls/3442","_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/comments/61550858"},"html":{"href":"https://github.com/theforeman/foreman/pull/3442#discussion_r61550858"},"pull_request":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/3442"}}},"pull_request":{"url":"https://api.github.com/repos/theforeman/foreman/pulls/3442","id":67026973,"html_url":"https://github.com/theforeman/foreman/pull/3442","diff_url":"https://github.com/theforeman/foreman/pull/3442.diff","patch_url":"https://github.com/theforeman/foreman/pull/3442.patch","issue_url":"https://api.github.com/repos/theforeman/foreman/issues/3442","number":3442,"state":"open","locked":false,"title":"fixes #14661 - support IPv6 subnets","user":{"login":"timogoebel","id":4107560,"avatar_url":"https://avatars.githubusercontent.com/u/4107560?v=3","gravatar_id":"","url":"https://api.github.com/users/timogoebel","html_url":"https://github.com/timogoebel","followers_url":"https://api.github.com/users/timogoebel/followers","following_url":"https://api.github.com/users/timogoebel/following{/other_user}","gists_url":"https://api.github.com/users/timogoebel/gists{/gist_id}","starred_url":"https://api.github.com/users/timogoebel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timogoebel/subscriptions","organizations_url":"https://api.github.com/users/timogoebel/orgs","repos_url":"https://api.github.com/users/timogoebel/repos","events_url":"https://api.github.com/users/timogoebel/events{/privacy}","received_events_url":"https://api.github.com/users/timogoebel/received_events","type":"User","site_admin":false},"body":"This adds another Subnet type: IPv6!\r\n\r\nThe IPv6 class is based on Dominic's IPv6 Branch: https://github.com/theforeman/foreman/compare/develop...domcleal:2315-ipv6","created_at":"2016-04-19T14:21:31Z","updated_at":"2016-04-29T09:05:47Z","closed_at":null,"merged_at":null,"merge_commit_sha":"59961bf77545fa6b387e68fe10d1c288263829c3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/theforeman/foreman/pulls/3442/commits","review_comments_url":"https://api.github.com/repos/theforeman/foreman/pulls/3442/comments","review_comment_url":"https://api.github.com/repos/theforeman/foreman/pulls/comments{/number}","comments_url":"https://api.github.com/repos/theforeman/foreman/issues/3442/comments","statuses_url":"https://api.github.com/repos/theforeman/foreman/statuses/da066ffa75b7d4241480882d689119b50a9cb00b","head":{"label":"timogoebel:14661-ipv6-subnets","ref":"14661-ipv6-subnets","sha":"da066ffa75b7d4241480882d689119b50a9cb00b","user":{"login":"timogoebel","id":4107560,"avatar_url":"https://avatars.githubusercontent.com/u/4107560?v=3","gravatar_id":"","url":"https://api.github.com/users/timogoebel","html_url":"https://github.com/timogoebel","followers_url":"https://api.github.com/users/timogoebel/followers","following_url":"https://api.github.com/users/timogoebel/following{/other_user}","gists_url":"https://api.github.com/users/timogoebel/gists{/gist_id}","starred_url":"https://api.github.com/users/timogoebel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timogoebel/subscriptions","organizations_url":"https://api.github.com/users/timogoebel/orgs","repos_url":"https://api.github.com/users/timogoebel/repos","events_url":"https://api.github.com/users/timogoebel/events{/privacy}","received_events_url":"https://api.github.com/users/timogoebel/received_events","type":"User","site_admin":false},"repo":{"id":39135770,"name":"foreman","full_name":"timogoebel/foreman","owner":{"login":"timogoebel","id":4107560,"avatar_url":"https://avatars.githubusercontent.com/u/4107560?v=3","gravatar_id":"","url":"https://api.github.com/users/timogoebel","html_url":"https://github.com/timogoebel","followers_url":"https://api.github.com/users/timogoebel/followers","following_url":"https://api.github.com/users/timogoebel/following{/other_user}","gists_url":"https://api.github.com/users/timogoebel/gists{/gist_id}","starred_url":"https://api.github.com/users/timogoebel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timogoebel/subscriptions","organizations_url":"https://api.github.com/users/timogoebel/orgs","repos_url":"https://api.github.com/users/timogoebel/repos","events_url":"https://api.github.com/users/timogoebel/events{/privacy}","received_events_url":"https://api.github.com/users/timogoebel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/timogoebel/foreman","description":"an application that automates the lifecycle of servers ","fork":true,"url":"https://api.github.com/repos/timogoebel/foreman","forks_url":"https://api.github.com/repos/timogoebel/foreman/forks","keys_url":"https://api.github.com/repos/timogoebel/foreman/keys{/key_id}","collaborators_url":"https://api.github.com/repos/timogoebel/foreman/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/timogoebel/foreman/teams","hooks_url":"https://api.github.com/repos/timogoebel/foreman/hooks","issue_events_url":"https://api.github.com/repos/timogoebel/foreman/issues/events{/number}","events_url":"https://api.github.com/repos/timogoebel/foreman/events","assignees_url":"https://api.github.com/repos/timogoebel/foreman/assignees{/user}","branches_url":"https://api.github.com/repos/timogoebel/foreman/branches{/branch}","tags_url":"https://api.github.com/repos/timogoebel/foreman/tags","blobs_url":"https://api.github.com/repos/timogoebel/foreman/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/timogoebel/foreman/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/timogoebel/foreman/git/refs{/sha}","trees_url":"https://api.github.com/repos/timogoebel/foreman/git/trees{/sha}","statuses_url":"https://api.github.com/repos/timogoebel/foreman/statuses/{sha}","languages_url":"https://api.github.com/repos/timogoebel/foreman/languages","stargazers_url":"https://api.github.com/repos/timogoebel/foreman/stargazers","contributors_url":"https://api.github.com/repos/timogoebel/foreman/contributors","subscribers_url":"https://api.github.com/repos/timogoebel/foreman/subscribers","subscription_url":"https://api.github.com/repos/timogoebel/foreman/subscription","commits_url":"https://api.github.com/repos/timogoebel/foreman/commits{/sha}","git_commits_url":"https://api.github.com/repos/timogoebel/foreman/git/commits{/sha}","comments_url":"https://api.github.com/repos/timogoebel/foreman/comments{/number}","issue_comment_url":"https://api.github.com/repos/timogoebel/foreman/issues/comments{/number}","contents_url":"https://api.github.com/repos/timogoebel/foreman/contents/{+path}","compare_url":"https://api.github.com/repos/timogoebel/foreman/compare/{base}...{head}","merges_url":"https://api.github.com/repos/timogoebel/foreman/merges","archive_url":"https://api.github.com/repos/timogoebel/foreman/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/timogoebel/foreman/downloads","issues_url":"https://api.github.com/repos/timogoebel/foreman/issues{/number}","pulls_url":"https://api.github.com/repos/timogoebel/foreman/pulls{/number}","milestones_url":"https://api.github.com/repos/timogoebel/foreman/milestones{/number}","notifications_url":"https://api.github.com/repos/timogoebel/foreman/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/timogoebel/foreman/labels{/name}","releases_url":"https://api.github.com/repos/timogoebel/foreman/releases{/id}","deployments_url":"https://api.github.com/repos/timogoebel/foreman/deployments","created_at":"2015-07-15T12:33:09Z","updated_at":"2015-07-15T12:33:14Z","pushed_at":"2016-04-29T06:22:09Z","git_url":"git://github.com/timogoebel/foreman.git","ssh_url":"git@github.com:timogoebel/foreman.git","clone_url":"https://github.com/timogoebel/foreman.git","svn_url":"https://github.com/timogoebel/foreman","homepage":"http://theforeman.org","size":42523,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"theforeman:develop","ref":"develop","sha":"0abad5795c55f84f2ffc4e744725cce72fc7b241","user":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"repo":{"id":258750,"name":"foreman","full_name":"theforeman/foreman","owner":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/theforeman/foreman","description":"an application that automates the lifecycle of servers ","fork":false,"url":"https://api.github.com/repos/theforeman/foreman","forks_url":"https://api.github.com/repos/theforeman/foreman/forks","keys_url":"https://api.github.com/repos/theforeman/foreman/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theforeman/foreman/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theforeman/foreman/teams","hooks_url":"https://api.github.com/repos/theforeman/foreman/hooks","issue_events_url":"https://api.github.com/repos/theforeman/foreman/issues/events{/number}","events_url":"https://api.github.com/repos/theforeman/foreman/events","assignees_url":"https://api.github.com/repos/theforeman/foreman/assignees{/user}","branches_url":"https://api.github.com/repos/theforeman/foreman/branches{/branch}","tags_url":"https://api.github.com/repos/theforeman/foreman/tags","blobs_url":"https://api.github.com/repos/theforeman/foreman/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theforeman/foreman/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theforeman/foreman/git/refs{/sha}","trees_url":"https://api.github.com/repos/theforeman/foreman/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theforeman/foreman/statuses/{sha}","languages_url":"https://api.github.com/repos/theforeman/foreman/languages","stargazers_url":"https://api.github.com/repos/theforeman/foreman/stargazers","contributors_url":"https://api.github.com/repos/theforeman/foreman/contributors","subscribers_url":"https://api.github.com/repos/theforeman/foreman/subscribers","subscription_url":"https://api.github.com/repos/theforeman/foreman/subscription","commits_url":"https://api.github.com/repos/theforeman/foreman/commits{/sha}","git_commits_url":"https://api.github.com/repos/theforeman/foreman/git/commits{/sha}","comments_url":"https://api.github.com/repos/theforeman/foreman/comments{/number}","issue_comment_url":"https://api.github.com/repos/theforeman/foreman/issues/comments{/number}","contents_url":"https://api.github.com/repos/theforeman/foreman/contents/{+path}","compare_url":"https://api.github.com/repos/theforeman/foreman/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theforeman/foreman/merges","archive_url":"https://api.github.com/repos/theforeman/foreman/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theforeman/foreman/downloads","issues_url":"https://api.github.com/repos/theforeman/foreman/issues{/number}","pulls_url":"https://api.github.com/repos/theforeman/foreman/pulls{/number}","milestones_url":"https://api.github.com/repos/theforeman/foreman/milestones{/number}","notifications_url":"https://api.github.com/repos/theforeman/foreman/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theforeman/foreman/labels{/name}","releases_url":"https://api.github.com/repos/theforeman/foreman/releases{/id}","deployments_url":"https://api.github.com/repos/theforeman/foreman/deployments","created_at":"2009-07-23T15:07:00Z","updated_at":"2016-04-26T17:45:11Z","pushed_at":"2016-04-29T08:42:13Z","git_url":"git://github.com/theforeman/foreman.git","ssh_url":"git@github.com:theforeman/foreman.git","clone_url":"https://github.com/theforeman/foreman.git","svn_url":"https://github.com/theforeman/foreman","homepage":"http://theforeman.org","size":65331,"stargazers_count":1004,"watchers_count":1004,"language":"Ruby","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":511,"mirror_url":null,"open_issues_count":74,"forks":511,"open_issues":74,"watchers":1004,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/3442"},"html":{"href":"https://github.com/theforeman/foreman/pull/3442"},"issue":{"href":"https://api.github.com/repos/theforeman/foreman/issues/3442"},"comments":{"href":"https://api.github.com/repos/theforeman/foreman/issues/3442/comments"},"review_comments":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/3442/comments"},"review_comment":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/theforeman/foreman/pulls/3442/commits"},"statuses":{"href":"https://api.github.com/repos/theforeman/foreman/statuses/da066ffa75b7d4241480882d689119b50a9cb00b"}}}}