@Test public void testDeleteSubnet() { try { setUpDriver(successScript, DnsmasqDriverTest.class.getResource("/dnsmasq.leases").getPath()); dnsmasqDriver.deleteSubnet("subnet1"); File file = new File(DnsmasqDriverTest.class.getResource("/options").getPath() + "/subnet1"); if (file.exists() && !file.isDirectory()) { fail("Option file not deleted"); } FileReader configFileReader = new FileReader( DnsmasqDriverTest.class.getResource("/config/dnsmasq.conf").getPath()); BufferedReader configFileBufferedReader = new BufferedReader(configFileReader); String configFileLine; boolean hasConfigFileLine = false; while ((configFileLine = configFileBufferedReader.readLine()) != null) { if (!configFileLine.contains("subnet1")) { continue; } hasConfigFileLine = true; break; } if (hasConfigFileLine) { fail("Dhcp range for the subnet was not removed from config file"); } dnsmasqDriver.createSubnet("subnet1", "192.168.1.1", "192.168.1.0/8", "192.168.1.0", "192.168.1.16"); configFileBufferedReader.close(); } catch (Throwable e) { fail("Failed with exception: " + e.getMessage()); } }
@Override public Response deleteSubnet( String subnetId) throws Exception { logger.info(String.format( "Deleting subnet configuration files for [%s]", subnetId)); String optionFilePath = dhcpOptionFileDir + "/" + subnetId; File optionFile = new File(optionFilePath); Files.deleteIfExists(optionFile.toPath()); removeLinesFromFile( dhcpConfigFilePath, Arrays.asList(subnetId)); String hostFilePath = dhcpHostFileDir + "/" + subnetId; File hostFile = new File(hostFilePath); if (hostFile.exists()) { hostFile.delete(); } Response response = new Response(); response.exitCode = 0; return response; }
DnsmasqDriver implements DHCPDriver { @Override public Response deleteSubnet( String subnetId) throws Exception { logger.info(String.format( "Deleting subnet configuration files for [%s]", subnetId)); String optionFilePath = dhcpOptionFileDir + "/" + subnetId; File optionFile = new File(optionFilePath); Files.deleteIfExists(optionFile.toPath()); removeLinesFromFile( dhcpConfigFilePath, Arrays.asList(subnetId)); String hostFilePath = dhcpHostFileDir + "/" + subnetId; File hostFile = new File(hostFilePath); if (hostFile.exists()) { hostFile.delete(); } Response response = new Response(); response.exitCode = 0; return response; } }
DnsmasqDriver implements DHCPDriver { @Override public Response deleteSubnet( String subnetId) throws Exception { logger.info(String.format( "Deleting subnet configuration files for [%s]", subnetId)); String optionFilePath = dhcpOptionFileDir + "/" + subnetId; File optionFile = new File(optionFilePath); Files.deleteIfExists(optionFile.toPath()); removeLinesFromFile( dhcpConfigFilePath, Arrays.asList(subnetId)); String hostFilePath = dhcpHostFileDir + "/" + subnetId; File hostFile = new File(hostFilePath); if (hostFile.exists()) { hostFile.delete(); } Response response = new Response(); response.exitCode = 0; return response; } DnsmasqDriver(
      String dhcpLeaseFilePath,
      String dhcpHostFileDir,
      String dhcpOptionFileDir,
      String dhcpConfigFilePath); }
DnsmasqDriver implements DHCPDriver { @Override public Response deleteSubnet( String subnetId) throws Exception { logger.info(String.format( "Deleting subnet configuration files for [%s]", subnetId)); String optionFilePath = dhcpOptionFileDir + "/" + subnetId; File optionFile = new File(optionFilePath); Files.deleteIfExists(optionFile.toPath()); removeLinesFromFile( dhcpConfigFilePath, Arrays.asList(subnetId)); String hostFilePath = dhcpHostFileDir + "/" + subnetId; File hostFile = new File(hostFilePath); if (hostFile.exists()) { hostFile.delete(); } Response response = new Response(); response.exitCode = 0; return response; } DnsmasqDriver(
      String dhcpLeaseFilePath,
      String dhcpHostFileDir,
      String dhcpOptionFileDir,
      String dhcpConfigFilePath); @Override boolean reload(); @Override boolean isRunning(); @Override Response createSubnet(
      String subnetId,
      String gateway,
      String cidr,
      String lowIp,
      String highIp); @Override Response deleteSubnet(
      String subnetId); @Override Response updateSubnet(
      String subnetId,
      Map<String, String> ipAddressToMACAddressMap,
      Long version); }
DnsmasqDriver implements DHCPDriver { @Override public Response deleteSubnet( String subnetId) throws Exception { logger.info(String.format( "Deleting subnet configuration files for [%s]", subnetId)); String optionFilePath = dhcpOptionFileDir + "/" + subnetId; File optionFile = new File(optionFilePath); Files.deleteIfExists(optionFile.toPath()); removeLinesFromFile( dhcpConfigFilePath, Arrays.asList(subnetId)); String hostFilePath = dhcpHostFileDir + "/" + subnetId; File hostFile = new File(hostFilePath); if (hostFile.exists()) { hostFile.delete(); } Response response = new Response(); response.exitCode = 0; return response; } DnsmasqDriver(
      String dhcpLeaseFilePath,
      String dhcpHostFileDir,
      String dhcpOptionFileDir,
      String dhcpConfigFilePath); @Override boolean reload(); @Override boolean isRunning(); @Override Response createSubnet(
      String subnetId,
      String gateway,
      String cidr,
      String lowIp,
      String highIp); @Override Response deleteSubnet(
      String subnetId); @Override Response updateSubnet(
      String subnetId,
      Map<String, String> ipAddressToMACAddressMap,
      Long version);  }