diff options
author | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-06 00:57:00 -0600 |
---|---|---|
committer | A. Wilcox <AWilcox@Wilcox-Tech.com> | 2019-11-06 00:57:00 -0600 |
commit | ada546b6002360169570a72c83fadc574b936c18 (patch) | |
tree | 85305bc68600abdfbbc743eea8622537b5379bad | |
parent | ed351160f94bfff12fadbceb44a2f85604dfb957 (diff) | |
download | horizon-ada546b6002360169570a72c83fadc574b936c18.tar.gz horizon-ada546b6002360169570a72c83fadc574b936c18.tar.bz2 horizon-ada546b6002360169570a72c83fadc574b936c18.tar.xz horizon-ada546b6002360169570a72c83fadc574b936c18.zip |
hscript: Implement Runner.Execute.netaddress.OpenRC
-rw-r--r-- | hscript/script_e.cc | 36 | ||||
-rw-r--r-- | tests/fixtures/0200-netaddress-openrc.installfile | 6 | ||||
-rw-r--r-- | tests/spec/simulator_spec.rb | 10 |
3 files changed, 52 insertions, 0 deletions
diff --git a/hscript/script_e.cc b/hscript/script_e.cc index 27d5fbf..b494698 100644 --- a/hscript/script_e.cc +++ b/hscript/script_e.cc @@ -12,6 +12,8 @@ #include <algorithm> #include <fstream> +#include <set> +#include <string> #ifdef HAS_INSTALL_ENV # include <parted/parted.h> #endif /* HAS_INSTALL_ENV */ @@ -26,6 +28,7 @@ namespace Horizon { bool Script::execute() const { bool success; error_code ec; + std::set<std::string> ifaces; /* assume create_directory will give us the error if removal fails */ if(fs::exists("/tmp/horizon", ec)) { @@ -250,6 +253,8 @@ bool Script::execute() const { if(!addr->execute(opts)) { EXECUTE_FAILURE("netaddress"); /* "Soft" error. Not fatal. */ + } else { + ifaces.insert(addr->iface()); } if(addr->type() == NetAddress::DHCP) dhcp = true; } @@ -460,6 +465,37 @@ bool Script::execute() const { /**************** POST PACKAGE METADATA ****************/ output_step_start("post-metadata"); + if(internal->packages.find("netifrc") != internal->packages.end() && + !internal->addresses.empty()) { + /* REQ: Runner.Execute.netaddress.OpenRC */ + if(opts.test(Simulate)) { + for(auto &iface : ifaces) { + std::cout << "ln -s /etc/init.d/net.lo /target/etc/init.d/net." + << iface << std::endl; + std::cout << "ln -s /etc/init.d/net." << iface + << " /target/etc/runlevels/default/net." << iface + << std::endl; + } + } else { + for(auto &iface : ifaces) { + fs::create_symlink("/etc/init.d/net.lo", + "/target/etc/init.d/net." + iface, ec); + if(ec) { + output_error("internal", "could not set up networking on " + + iface, ec.message()); + } else { + fs::create_symlink("/etc/init.d/net." + iface, + "/target/etc/runlevels/default/net." + + iface, ec); + if(ec) { + output_error("internal", "could not auto-start " + "networking on" + iface, ec.message()); + } + } + } + } + } + if(!internal->rootpw->execute(opts)) { EXECUTE_FAILURE("rootpw"); return false; diff --git a/tests/fixtures/0200-netaddress-openrc.installfile b/tests/fixtures/0200-netaddress-openrc.installfile new file mode 100644 index 0000000..5d3aee4 --- /dev/null +++ b/tests/fixtures/0200-netaddress-openrc.installfile @@ -0,0 +1,6 @@ +network true +netaddress eth0 static 2600:1702:2a80:1b9f:5bbc:af4c:5dd1:a183 64 +hostname test.machine.internal +pkginstall adelie-base openrc s6-linux-init netifrc +rootpw $6$gumtLGmHwOVIRpQR$2M9PUO24hy5mofzWWf9a.YLbzOgOlUby1g0hDj.wG67E2wrrvys59fq02PPdxBdbgkLZFtjfEx6MHZwMBamwu/ +mount /dev/sda1 / diff --git a/tests/spec/simulator_spec.rb b/tests/spec/simulator_spec.rb index d46c87c..be684a1 100644 --- a/tests/spec/simulator_spec.rb +++ b/tests/spec/simulator_spec.rb @@ -174,6 +174,16 @@ printf '%s\\t%s\\t%s\\t%s\\t0\\t0\\n' /dev/gwyn/source /usr/src auto noatime >> # The end quote is missing deliberately. expect(last_command_started.stdout).to include('routes_eth0="default via 172.16.1.1') end + it "doesn't perform OpenRC configuration when netifrc isn't installed" do + use_fixture '0042-netaddress-valid-static6.installfile' + run_simulate + expect(last_command_started.stdout).to_not include ("/target/etc/init.d/net") + end + it "performs OpenRC configuration when netifrc is installed" do + use_fixture '0200-netaddress-openrc.installfile' + run_simulate + expect(last_command_started.stdout).to include("ln -s /etc/init.d/net.lo /target/etc/init.d/net.eth0") + end end context "simulating 'nameserver' execution" do it "configures nameservers correctly" do |