From cd2ab0ea31fd4dc9305c1d5e08100eafaff19f7e Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sat, 26 Oct 2019 01:09:57 -0500 Subject: hscript: Implement lvm_pv, add tests --- hscript/disk.cc | 23 +++++++++++++++++++++++ hscript/disk.hh | 7 ++++++- hscript/script.cc | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 2 deletions(-) (limited to 'hscript') diff --git a/hscript/disk.cc b/hscript/disk.cc index c41e6d0..3423928 100644 --- a/hscript/disk.cc +++ b/hscript/disk.cc @@ -381,6 +381,29 @@ bool Partition::execute(ScriptOptions) const { } +Key *LVMPhysical::parseFromData(const std::string &data, int lineno, + int *errors, int *warnings) { + if(data.size() < 6 || data.substr(0, 5) != "/dev/") { + if(errors) *errors += 1; + output_error("installfile:" + std::to_string(lineno), + "lvm_pv: expected an absolute path to a block device"); + return nullptr; + } + + /*if(access(data.c_str(), F_OK) != 0) { + if(warnings) *warnings += 1; + output_warning("installfile:" + std::to_string(lineno), + "lvm_pv: device may not exist"); + }*/ + + return new LVMPhysical(lineno, data); +} + +bool LVMPhysical::execute(ScriptOptions) const { + return false; +} + + Key *Mount::parseFromData(const std::string &data, int lineno, int *errors, int *warnings) { std::string dev, where, opt; diff --git a/hscript/disk.hh b/hscript/disk.hh index 90deca4..53527f3 100644 --- a/hscript/disk.hh +++ b/hscript/disk.hh @@ -116,7 +116,12 @@ public: class Encrypt : public Key { }; -class LVMPhysical : public Key { +class LVMPhysical : public StringKey { +private: + LVMPhysical(int _line, const std::string &_d) : StringKey(_line, _d) {} +public: + static Key *parseFromData(const std::string &, int, int*, int*); + bool execute(ScriptOptions) const override; }; class LVMGroup : public Key { diff --git a/hscript/script.cc b/hscript/script.cc index afb1870..cd15089 100644 --- a/hscript/script.cc +++ b/hscript/script.cc @@ -110,6 +110,12 @@ struct Script::ScriptPrivate { std::vector< std::unique_ptr > disklabels; /*! Partition creation keys */ std::vector< std::unique_ptr > partitions; + /*! LVM physical volume keys */ + std::vector< std::unique_ptr > lvm_pvs; + /*! LVM volume group keys */ + std::vector< std::unique_ptr > lvm_vgs; + /*! LVM logical volume keys */ + std::vector< std::unique_ptr > lvm_lvs; /*! Target system's mountpoints. */ std::vector< std::unique_ptr > mounts; @@ -174,6 +180,18 @@ struct Script::ScriptPrivate { std::unique_ptr p(dynamic_cast(obj)); this->partitions.push_back(std::move(p)); return true; + } else if(key_name == "lvm_pv") { + std::unique_ptr pv(dynamic_cast(obj)); + this->lvm_pvs.push_back(std::move(pv)); + return true; + } else if(key_name == "lvm_vg") { + std::unique_ptr vg(dynamic_cast(obj)); + this->lvm_vgs.push_back(std::move(vg)); + return true; + } else if(key_name == "lvm_lv") { + std::unique_ptr lv(dynamic_cast(obj)); + this->lvm_lvs.push_back(std::move(lv)); + return true; } else if(key_name == "mount") { std::unique_ptr mount(dynamic_cast(obj)); this->mounts.push_back(std::move(mount)); @@ -526,7 +544,8 @@ const Script *Script::load(std::istream &sstream, bool Script::validate() const { int failures = 0; - std::set seen_diskids, seen_labels, seen_parts, seen_mounts; + std::set seen_diskids, seen_labels, seen_parts, seen_pvs, + seen_mounts; std::map seen_iface; /* REQ: Runner.Validate.network */ @@ -779,6 +798,23 @@ bool Script::validate() const { seen_parts.insert(name); } + /* REQ: Runner.Validate.lvm_pv */ + for(auto &pv : this->internal->lvm_pvs) { + if(!pv->validate(this->opts)) { + failures++; + continue; + } + + /* We don't actually have a requirement, but... */ + if(seen_pvs.find(pv->value()) != seen_pvs.end()) { + failures++; + output_error("installfile:" + std::to_string(pv->lineno()), + "lvm_pv: a physical volume already exists on device " + + pv->value()); + } + seen_pvs.insert(pv->value()); + } + /* REQ: Runner.Validate.mount */ for(auto &mount : this->internal->mounts) { if(!mount->validate(this->opts)) { -- cgit v1.2.3-60-g2f50