summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-06 20:40:22 -0600
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2019-11-06 20:40:22 -0600
commit87b0a43d850e3fba110d0b2bdeb0f02bb0c5f46b (patch)
tree058f2919ce97c9a8a61372fbe2131e936e353e4e
parent5682d368343ccd8440178ea21ee4e29f4bb5201e (diff)
downloadhorizon-87b0a43d850e3fba110d0b2bdeb0f02bb0c5f46b.tar.gz
horizon-87b0a43d850e3fba110d0b2bdeb0f02bb0c5f46b.tar.bz2
horizon-87b0a43d850e3fba110d0b2bdeb0f02bb0c5f46b.tar.xz
horizon-87b0a43d850e3fba110d0b2bdeb0f02bb0c5f46b.zip
hscript: Drastically simplify validation too
-rw-r--r--hscript/script_v.cc53
1 files changed, 17 insertions, 36 deletions
diff --git a/hscript/script_v.cc b/hscript/script_v.cc
index 0052ad2..995b8ea 100644
--- a/hscript/script_v.cc
+++ b/hscript/script_v.cc
@@ -330,12 +330,15 @@ bool Horizon::Script::validate() const {
failures += validate_one_account(acct.first, detail, opts);
}
+#define VALIDATE_OR_SKIP(obj) \
+ if(!obj->validate(opts)) {\
+ failures++;\
+ continue;\
+ }
+
/* REQ: Runner.Validate.diskid */
for(auto &diskid : internal->diskids) {
- if(!diskid->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(diskid)
/* REQ: Runner.Validate.diskid.Unique */
if(seen_diskids.find(diskid->device()) != seen_diskids.end()) {
@@ -349,10 +352,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.disklabel */
for(auto &label : internal->disklabels) {
- if(!label->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(label)
/* REQ: Runner.Validate.disklabel.Unique */
if(seen_labels.find(label->device()) != seen_labels.end()) {
@@ -367,10 +367,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.partition */
for(auto &part : internal->partitions) {
- if(!part->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(part)
/* REQ: Runner.Validate.partition.Unique */
const std::string &dev = part->device();
@@ -388,10 +385,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.lvm_pv */
for(auto &pv : internal->lvm_pvs) {
- if(!pv->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(pv)
/* We don't actually have a requirement, but... */
if(seen_pvs.find(pv->value()) != seen_pvs.end()) {
@@ -419,10 +413,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.lvm_vg */
for(auto &vg : internal->lvm_vgs) {
- if(!vg->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(vg)
if(seen_vg_names.find(vg->name()) != seen_vg_names.end()) {
failures++;
@@ -467,10 +458,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.lvm_lv */
for(auto &lv : internal->lvm_lvs) {
const std::string lvpath(lv->vg() + "/" + lv->name());
- if(!lv->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(lv)
/* REQ: Runner.Validate.lvm_lv.Name */
if(seen_lvs.find(lvpath) != seen_lvs.end()) {
@@ -510,10 +498,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.encrypt */
for(auto &crypt : internal->luks) {
- if(!crypt->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(crypt)
/* REQ: Runner.Validate.encrypt.Unique */
if(seen_luks.find(crypt->device()) != seen_luks.end()) {
@@ -535,10 +520,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.fs */
for(auto &fs : internal->fses) {
- if(!fs->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(fs)
/* REQ: Runner.Validate.fs.Unique */
if(seen_fses.find(fs->device()) != seen_fses.end()) {
@@ -559,10 +541,7 @@ bool Horizon::Script::validate() const {
/* REQ: Runner.Validate.mount */
for(auto &mount : internal->mounts) {
- if(!mount->validate(opts)) {
- failures++;
- continue;
- }
+ VALIDATE_OR_SKIP(mount)
/* REQ: Runner.Validate.mount.Unique */
if(seen_mounts.find(mount->mountpoint()) != seen_mounts.end()) {
@@ -591,6 +570,8 @@ bool Horizon::Script::validate() const {
output_error("installfile:0", "mount: no root mount specified");
}
+#undef VALIDATE_OR_SKIP
+
output_log("validator", "0", "installfile",
to_string(failures) + " failure(s).", "");
return (failures == 0);