shill: DHCPConfig: Get new lease with RenewIP If a DHCP process is not running when RenewIP is called, acquire a new lease instead of returning. This allows callers external to shill to avoid having to keep track of whether the IPConfig object has a lease or not. BUG=chromium:318290 TEST=Unit test + manual: Reproduce the issue in crbug.com/318290. In specific, change the IP address to a static IP first and close the configuration panel, then separately switch to custom name servers. Originally-Reviewed-on: https://chromium-review.googlesource.com/177350 (cherry picked from commit abb99ef706a8d6895c5137a5b42a0703fe3fec12) Change-Id: I07bc86b893a502a7fceb86972b04e87928644cd1 Reviewed-on: https://chromium-review.googlesource.com/177762 Reviewed-by: Paul Stewart <pstew@chromium.org> Commit-Queue: Paul Stewart <pstew@chromium.org> Tested-by: Paul Stewart <pstew@chromium.org>
diff --git a/dhcp_config.cc b/dhcp_config.cc index 0c11115..05ffd33 100644 --- a/dhcp_config.cc +++ b/dhcp_config.cc
@@ -114,7 +114,7 @@ bool DHCPConfig::RenewIP() { SLOG(DHCP, 2) << __func__ << ": " << device_name(); if (!pid_) { - return false; + return Start(); } if (!proxy_.get()) { LOG(ERROR) << "Unable to renew IP before acquiring destination.";
diff --git a/dhcp_config_unittest.cc b/dhcp_config_unittest.cc index 312530d..88adfd2 100644 --- a/dhcp_config_unittest.cc +++ b/dhcp_config_unittest.cc
@@ -31,6 +31,7 @@ using testing::_; using testing::AnyNumber; using testing::ContainsRegex; +using testing::Mock; using testing::Return; using testing::SetArgumentPointee; using testing::Test; @@ -604,6 +605,11 @@ } TEST_F(DHCPConfigTest, RenewIP) { + EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).WillOnce(Return(false)); + config_->pid_ = 0; + EXPECT_FALSE(config_->RenewIP()); // Expect a call to Start() if pid_ is 0. + Mock::VerifyAndClearExpectations(minijail_.get()); + EXPECT_CALL(*minijail_, RunAndDestroy(_, _, _)).Times(0); EXPECT_TRUE(config_->lease_acquisition_timeout_callback_.IsCancelled()); config_->pid_ = 456; EXPECT_FALSE(config_->RenewIP()); // Expect no crash with NULL proxy.
diff --git a/mock_dhcp_config.h b/mock_dhcp_config.h index c7de64c..1ce2820 100644 --- a/mock_dhcp_config.h +++ b/mock_dhcp_config.h
@@ -22,6 +22,7 @@ MOCK_METHOD0(RequestIP, bool()); MOCK_METHOD1(ReleaseIP, bool(ReleaseReason)); + MOCK_METHOD0(RenewIP, bool()); private: DISALLOW_COPY_AND_ASSIGN(MockDHCPConfig);