53 Commits

Author SHA1 Message Date
Chris Punches
865c81b36a new docs 2021-04-04 22:34:15 -04:00
Chris Punches
63c4e542ea release-ready 2021-04-04 22:19:42 -04:00
Chris Punches
04f9e63756 pre-release licensing cleanup - AGPL 2021-04-04 21:32:00 -04:00
Chris Punches
89f734de84 pre-release 2021-04-04 21:21:05 -04:00
Chris Punches
4b3a9170bf cleaning up 2021-04-03 22:39:25 -04:00
Chris Punches
3d421b1ca0 stdout/stderr routing is now 'virtually' async 2021-04-03 20:24:22 -04:00
Chris Punches
199d93a2b2 clean push 2021-03-25 02:13:48 -04:00
Chris Punches
dce543a15d early rex, finally 2021-03-25 02:11:23 -04:00
Chris Punches
31ed2feb7f i/o for parent child good, but some fd is staying open 2021-03-07 23:29:47 -05:00
Chris Punches
d4a228f351 logging improvements 2021-02-13 19:41:08 -05:00
Chris Punches
a5a729054a updated readme for reviewers 2020-12-28 22:20:25 -05:00
Master
6db624ef93 typo; squash previous 2020-08-01 16:15:41 -04:00
Master
c16d69429a sproc::execute changed sete[u|g]id() to set[u|g]id() 2020-08-01 15:44:20 -04:00
Master
a5317bfeda units now can choose their environment. consider moving to plan. 2020-07-03 00:24:01 -04:00
Master
8b35a88643 added shell attribute to unit object definition to allow more flexibility; defaults to sh 2020-07-01 23:01:13 -04:00
Master
3b467e2c0a added shell attribute to unit object definition to allow more flexibility; defaults to sh 2020-07-01 22:57:32 -04:00
Master
c4828d506b added shell attribute to unit object definition to allow more flexibility; defaults to sh 2020-07-01 22:30:51 -04:00
Master
c9567f20e4 fix uid/gid set order 2020-06-29 23:54:53 -04:00
Master
4cb2449f24 improved error reporting on setegid failure 2020-06-29 23:51:18 -04:00
Master
58f4684449 improved error reporting on setegid failure 2020-06-29 23:47:00 -04:00
Master
3bb3b5f47e reworked exceptions for message value 2020-06-29 22:00:01 -04:00
Master
52734d2f2c reworked exceptions for message value 2020-06-29 21:52:39 -04:00
Master
af18419eda cleanup after changes 2020-06-29 21:06:18 -04:00
Master
f4a38de0c0 added group and user set[uid|gid] capability at unit definition level 2020-06-29 02:22:11 -04:00
Master
3517b9cc11 repair target string 2020-06-20 23:14:04 -04:00
Master
137c82ebaa repair target string 2020-06-20 23:07:14 -04:00
Master
e49cc335f3 fixing execution context for targets 2020-06-20 23:05:51 -04:00
Master
4ea05b842a minor repair of usage of env vars file 2020-06-20 23:00:55 -04:00
Master
3bc60f56de minor repair of usage of env vars file 2020-06-20 22:57:30 -04:00
Master
88eaea7bfa fixed context issue with conf file loading re: env vars file 2020-06-20 21:10:42 -04:00
Master
d636ece26a dtype repair to logger 2020-06-20 20:25:45 -04:00
Master
839c3d398a logging reflow 2020-06-20 20:09:32 -04:00
Chris Punches
11829aca39 fixed missing vars load on post-rectification execution 2018-06-01 23:23:38 -04:00
Chris Punches
8f6f7761c4 fixed missing vars load on post-rectification execution 2018-06-01 23:19:30 -04:00
Chris Punches
722688ebf3 new environment variable file feature 2018-02-25 01:24:59 -05:00
Chris Punches
3591bd344d now shows where it looked for missing config file during initialisation 2018-02-24 20:18:31 -05:00
Phanes
1c354b4401 updated readme to be more clear 2017-12-08 00:34:29 -05:00
Phanes
0db575a075 Merge remote-tracking branch 'origin/master' 2017-12-07 22:38:05 -05:00
Phanes
46e56b8d6f implemented execution context. needs thoroughly tested. 2017-12-07 22:37:42 -05:00
Chris Punches
93c22887e8 Update README.md 2017-12-07 10:07:04 +00:00
Phanes
9d89f5ad6a minor punctuation fixes 2017-12-07 02:39:27 -05:00
Phanes
6fca4f2d91 added markdown extention 2017-12-07 02:32:56 -05:00
Phanes
c75fa9d2c8 updated readme 2017-12-07 02:24:17 -05:00
Phanes
49b4e77ca8 updated readme 2017-12-07 02:05:03 -05:00
Phanes
8a95bbf219 not sure why but ok 2017-12-07 01:32:00 -05:00
Chris Punches
4d66a0f059 Merge branch 'master' into 'master'
Honor long options as well.

See merge request !1
2017-12-07 06:22:55 +00:00
DJ Lucas
221edee07c Forgot print_usage() on invalid option. 2017-12-05 22:40:57 -06:00
DJ Lucas
0c70f7ee36 Honor long options as well. 2017-12-05 22:09:33 -06:00
Phanes
2b2225f3e4 fixed cmakelists 2017-12-05 21:36:00 -05:00
Phanes
6af1082852 branding, legal notices, and improved usage statement 2017-12-05 19:42:53 -05:00
Phanes
9d5af160c5 Merge remote-tracking branch 'origin/master' 2017-12-05 19:26:06 -05:00
Phanes
da50f152f2 fixed merge issue that broke 1.3a release, implemented commandline switches 2017-12-05 19:25:51 -05:00
Chris Punches
7404f07dc5 Update examplar.cpp 2017-12-05 21:39:10 +00:00
49 changed files with 2347 additions and 731 deletions

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.5)
project(ftests) project(rex)
set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++1z -O0 -DDEBUG=1") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++1z -O0 -DDEBUG=1")
set(SOURCE_FILES examplar.cpp src/loaders/loaders.cpp src/loaders/loaders.h src/json/jsoncpp.cpp src/loaders/JSON_Loader.cpp src/loaders/JSON_Loader.h src/loaders/helpers.cpp src/loaders/helpers.h src/loaders/Suite.cpp src/loaders/Suite.h src/loaders/Plan.cpp src/loaders/Plan.h src/loaders/Conf.cpp src/loaders/Conf.h src/loaders/Unit.cpp src/loaders/Unit.h src/loaders/Task.cpp src/loaders/Task.h src/sproc/Sproc.cpp src/sproc/Sproc.h) set(SOURCE_FILES Rex.cpp src/loaders/abstract/loaders.cpp src/loaders/abstract/loaders.h src/json/jsoncpp.cpp src/loaders/low_level/JSON_Loader.cpp src/loaders/low_level/JSON_Loader.h src/loaders/misc/helpers.cpp src/loaders/misc/helpers.h src/loaders/abstract/Suite.cpp src/loaders/abstract/Suite.h src/loaders/abstract/Plan.cpp src/loaders/abstract/Plan.h src/loaders/abstract/Conf.cpp src/loaders/abstract/Conf.h src/loaders/abstract/Unit.cpp src/loaders/abstract/Unit.h src/loaders/abstract/Task.cpp src/loaders/abstract/Task.h src/Sproc/Sproc.cpp src/Sproc/Sproc.h src/Logger/Logger.cpp src/Logger/Logger.h)
add_executable(ftests ${SOURCE_FILES}) add_executable(rex ${SOURCE_FILES})

170
README.md Normal file
View File

@@ -0,0 +1,170 @@
# Rex
The Meta-Automation system you didn't know you were missing. It's elegant, yet crude, it's advanced, yet simple.
## What is Rex?
Rex is a project-based, json-driven execution flow/workflow tool designed to place rails around very complex automations in a controlled way that
is easy to troubleshoot.
While designed for the generation of SURRO Linux, the design was kept broad for many other use cases and extensions.
At a high level, it is a very simple thing: It executes scripts and other executables in a predetermined order, logs
their output, and has basic error handling using exit codes of the executables it is running.
Rex relies on a library of `Units` which are files that define, in json format, the executables it will execute.
Rex uses a `Plan` to define which of those units it will actually execute -- once selected they are called `Tasks`.
This allows you to have many things defined by multiple teams, and, with sufficient abstraction, use the same library of
automations for multiple purposes throughout your environment -- bring shared library patterns in software development
to your infrastructure operations efforts if you so desire, and more.
# Instructions
These are instructions for some primitive ways of using Rex.
## Build
Compiling Rex is easy. There are zero external dependencies. Build does require *cmake*.
~~~~
$ cmake .
$ make
~~~~
Then place the binary where you'd like. I'd recommend packaging it for your favorite Linux distribution.
## High Level Usage
### Self-Healing Workflows
Rex introduces self-healing workflows.
#### Model A
1. Write a script that does a thing.
2. Write a script that checks if that thing is done.
3. Set up your check script as a `target` in a `unit`.
4. Set up your script that does the thing as that unit's `rectifier`.
5. Turn on the `rectify` pattern in the `unit definition`.
#### Model B
Or, if you want a flow that's more simple:
1. Write a script that does a thing.
2. Write a script that fixes any environmental conditions that prevent that thing from being done.
3. Set up your `target` script to be the script that does the thing.
4. Set up your `rectifier` script to be the script that fixes the bad condition.
5. Turn on the `rectify pattern` in the unit definition.
### Traditional Workflows
In fact, you don't need a dual mode of automation (though it is highly recommended):
1. Write a script that does a thing.
2. Set the `user`, `group` to run as, well as the `shell` that should be used to execute within.
3. Set the `environment file` to a file to be sourced for that shell containing all of your environment definitions for
your automation.
4. Turn off the `rectify` pattern.
5. Repeat for every step.
As you can see, for small automations, it's often going to be more desirable to just write a shell script, but for
very large efforts spanning many subsystems or components, you may want more control -- that's really where Rex comes
in.
## Definitions
So you've got Rex compiled and you're ready to start automating the world.
If you're thinking "how do I configure this thing", this README is for you.
### Units
A Unit is an automation definition, written in JSON in a UNIT FILE. Deeper into Rex’s internals, Units and Tasks have slightly different functions, but for the purposes of users, the terms can be used interchangeably. A Task is a task to be performed in a Plan, and a Unit is its definition. A Unit is a JSON object that has:
* A `name`, which is an identifier for the Unit used by people.
* A `target`, which is the path to the automation script performing the work. This provides a clean linear path for huge chains of scripts to be executed in order and tracked on return for additional logic in chaining.
* A `rectifier`, which is the path to the automation script to be executed if the target call fails.
* An `active` attribute,which tells Rex whether or not the Unit can be used in a Plan. This gives Unit developers a way to tell Plan developers not to use the Unit.
* A `required` attribute which tells Rex whether or not the Plan can continue if the Unit fails. If the rectify attribute is set to true, this attribute is checked after a rectifier failure. If not, this is checked after target failure. In either case, if the rectifier or target do not return successfully, Rex will halt the execution of the Plan if this is turned on for the unit being executed. Otherwise it simply moves to the next Unit being executed.
* A `log` attribute which tells Rex whether or not to log the stdout of the task. STDERR will always be logged regardless.
* A `user` attribute, along with its accompanying `group` attribute, which together set the identity context to execute the script as that user.
* A `rectify` attribute, which tells Rex whether or not to execute the rectifier in the case of failure when executing the target.
* An `environment` attribute, which points to the path of an environment file -- usually a shell script to be sourced to populate the environment executing the `target`.
### Tasks
A `Task` is an action item in a `Plan`, just like in real life. In the context of Rex, a `Task` is a `Unit` that has been loaded and incorporated into a `Plan` in an actionable state. Inactive `Units` can not be loaded into a `Plan` and thus can never be a `Task`. The primary difference between a Task and a Unit is that a Unit is not actionable — it’s just a definition — while a Task is a consumable, actionable automation definition that is scheduled to execute.
### Suite
A `Suite` is not visible to the user and this is only for informational purposes. A Suite is a collection of all available Unit definitions loaded from one or more UNIT FILES. Just as a Unit is the definition for a Task, a Suite is a collection of Units that define the Task components of a Plan.
A Suite is consumed by a Plan during the conversion of Units to Tasks, though this is not visible to the user — it just simply helps to understand the kind of abstraction taking place in the conceptual model of Rex.
Plan
A Plan is the glue of all the components of Rex and is deceptively simple. A Plan loads a Suite for its Task definitions (Units), but the Tasks to actually execute are specified in the PLAN FILE. The Tasks are executed in the order specified in the PLAN FILE.
### FILES
There are several types of files used by a Rex project.
#### CONFIG FILE and Attributes
This is the one config file that Rex uses. The default path it looks is /etc/Rex/config.json.
A config file at the time of writing this specifies a single JSON object with 5 attributes:
* `units_path`: The `UNIT FILE` path or a path to a directory containing unit files.
* `config_version`: The configuration VERSION.
* `execution_context`: The current working directory to use when loading unit files, plan files, or executing Tasks.
* `execution_context_override`: A boolean indicating whether or not the execution context should be set, or left alone. It is highly recommended to set this to `true`.
* `logs_path`: The path relative to the execution context to store logs. This directory will be created if it does not exist.
#### Configuration VERSION
The configuration version is checked to ensure that the configuration is consumable by that version of Rex. This will pave the way for reverse compatibility if the project moves in that direction.
#### UNIT FILE
The UNIT FILE is a specification of where the Units are defined. All UNIT FILES in that directory will be amalgamated to generate the Suite. These types of files must end in `*.units` for their filename.
#### PLAN FILE
The PLAN FILE is a specification of the order that Tasks are executed, and their dependencies upon each other. Dependency implementation is a touchy matter that is pending implementation, so, mileage may vary until release.
## I still don't see how this works.
That's ok. It's in its infancy so we're always looking for ways to make it simpler. Here's a 'hello world' example.
### 1. Write your tests.
First, we want to know all the things we need to be able to print "hello world" to the screen. In this case we just need to make we have the "echo" binary.
Write a bash script that checks if the "echo" binary is on the system.
#!/usr/bin/bash
stat /usr/bin/echo
exit $?
Save it as ~/check-echo.bash.
This script will be your "target" attribute for your "hello world" unit definition.
### 2. Write your automation.
Write a "hello world" script.
#!/usr/bin/bash
echo "hello world"
exit $?
Save it as ~/hello.bash
This script will be your "rectify" attribute for your "hello world" unit definition.
### 3. Set up the Unit file.
At this point you've got both the script that checks if hello world can run and you've got your hello world script. Time to set up the unit.
### 4. Add the Unit definition to the Plan.
Next, add the unit to the plan by name.
### 5. Set up your config file.
Point your config file at your plan file and your units directory.
### 6. Run Rex pointing at that config file.
Execute rex:
```
rex --config path/to/your/config/file.json --plan path/to/your/plan/file.json
```
And you should see your 'hello world' script. Check out the `test/` directory in this repo for an example project for
more details.

228
Rex.cpp Normal file
View File

@@ -0,0 +1,228 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <iostream>
#include <unistd.h>
#include <getopt.h>
#include "src/loaders/abstract/loaders.h"
#include "src/Logger/Logger.h"
void version_info()
{
std::cout << "pre-release alpha" << std::endl;
}
void print_usage()
{
// commandline switches:
// -h help OPTIONAL
// -v verbose OPTIONAL
// -c CONFIG_FILE REQUIRED
// -p PLAN_FILE REQUIRED
fprintf( stderr, "\nUsage:\n\trex [ -h | --help ] [ -v | --verbose ] ( ( ( -c | --config ) CONFIG_PATH ) ( -p | plan ) PLAN_PATH ) )\n" );
fprintf( stderr, "\nOptional Arguments:\n");
fprintf( stderr, "\t-h | --help\n\t\tThis usage screen. Mutually exclusive to all other options.\n");
fprintf( stderr, "\t-v | --verbose\n\t\tSets verbose output. Generally more than you want to see.\n");
fprintf( stderr, "\nRequired Arguments:\n");
fprintf( stderr, "\t-c | --config\n\t\tSupply the directory path for the configuration file.\n");
fprintf( stderr, "\t-p | --plan\n\t\tSupply the directory path for the plan file to execute.\n\n");
}
int main( int argc, char * argv[] )
{
// default verbosity setting
int verbose_flag = false;
// whether to show usage screen
int help_flag = false;
// did the user supply an argument to config
int config_flag = false;
// did the user supply an argument to plan
int plan_flag = false;
// did the user ask for the version info
int version_flag = false;
// default config path
std::string config_path;
// default plan path
std::string plan_path;
// initialise for commandline argument processing
int c;
int digit_optind = 0;
if ( argc <= 1 )
{
help_flag = true;
}
// process commandline arguments
while ( 1 )
{
int this_option_optind = optind ? optind : 1;
int option_index = 0;
// commandline argument structure
static struct option long_options[] = {
{"verbose_flag", no_argument, 0, 'v' },
{"version_info", no_argument, 0, 'i' },
{"help", no_argument, 0, 'h' },
{"config", required_argument, 0, 'c' },
{"plan", required_argument, 0, 'p' },
{0,0,0,0}
};
c = getopt_long(argc, argv, "vihc:p:", long_options, &option_index );
if ( c == -1 )
{
break;
}
switch ( c )
{
case 'i':
version_flag = true;
case 'h':
help_flag = true;
break;
case 'v':
verbose_flag = true;
break;
case 'c':
config_flag = true;
config_path = std::string( optarg );
break;
case 'p':
plan_flag = true;
plan_path = std::string( optarg );
break;
case '?':
help_flag = true;
break;
default:
break;
} // end switch
} // end opts while
if ( version_flag ) {
version_info();
exit(0);
}
// if the user supplied no config file, there's nothing to do but teach the user how to use this tool
if (! config_flag ) {
std::cerr << "NOT SUPPLIED: CONFIG_PATH" << std::endl;
help_flag = true;
}
// if the user supplied no plan file, there's nothing to do but teach the user how to use this tool
if (! plan_flag ) {
std::cerr << "NOT SUPPLIED: PLAN_PATH" << std::endl;
help_flag = true;
}
// if the user wants the help screen, just show it and leave
if ( (help_flag) | (! config_flag) | (! plan_flag) )
{
print_usage();
exit( 0 );
}
// default logging level
int L_LEVEL = E_INFO;
// if set to verbose_flag mode, output with DEBUG level verbosity
if ( verbose_flag )
{
std::cout << "Setting verbosity level to 'DBUG'..." << std::endl;
L_LEVEL = E_DEBUG;
}
// the main scope logger
Logger slog = Logger( L_LEVEL, "_main_" );
slog.log( E_INFO, "* Initialising Logging...");
// configuration object that reads from config_path
Conf configuration = Conf( config_path, L_LEVEL );
// check if context override is set in the config file
if ( configuration.has_context_override() )
{
// if so, set the CWD.
chdir( configuration.get_execution_context().c_str() );
slog.log( E_DEBUG, "* Setting execution context: " + get_working_path() );
}
// The Rex Paradigm:
// - A Suite is made up of Units.
// - A Unit is a definition of an executable along with various options surrounding its context and behaviour.
// - A Plan is made up of Tasks.
// - A Unit becomes a Task when it is added to a Plan.
// A Plan contains what units are executed and a Suite contains the definitions of those units.
std::string plan_file = plan_path;
// load the filepaths to definitions of a plan and definitions of units.
std::string definitions_file = configuration.get_units_path();
// initialise an empty suite (unit definitions library)
slog.log( E_DEBUG, "* Initialising Suite...");
Suite available_definitions = Suite( L_LEVEL );
// load units into suite
slog.log( E_INFO, "* Loading all actionable Units into Suite..." );
available_definitions.load_units_file( definitions_file );
// initialise an empty plan
slog.log( E_DEBUG, "* Initialising Plan..." );
Plan plan = Plan( &configuration, L_LEVEL );
// load the plan the user supplied
slog.log( E_INFO, "* Loading Plan...");
plan.load_plan_file( plan_file );
// ingest the suitable Tasks from the Suite into the Plan
slog.log( E_INFO, "* Loading planned Tasks from Suite to Plan." );
plan.load_definitions( available_definitions );
slog.log( E_INFO, "* Ready to execute all actionable Tasks in Plan." );
try
{
plan.execute();
}
catch ( std::exception& e)
{
slog.log( E_FATAL, "Caught exception.");
slog.log( E_FATAL, e.what() );
return 1;
}
return 0;
}

View File

@@ -1,5 +0,0 @@
{
"units_path": "/home/phanes/development/internal/Examplar/conf/units/all_test.units",
"plan_path": "/home/phanes/development/internal/Examplar/conf/plans/test.plan",
"config_version": "1"
}

View File

@@ -1,36 +0,0 @@
{
"units": [
{
"name": "independent test 1",
"target": "/usr/bin/true",
"rectifier": "/usr/bin/true",
"active": true,
"required": true,
"rectify": true
},
{
"name": "independent test 2",
"target": "/usr/bin/true",
"rectifier": "/usr/bin/true",
"active": true,
"required": false,
"rectify": false
},
{
"name": "A DEFINITION THAT IS NOT USED",
"target": "/usr/bin/dialog --yesno test 50 50",
"rectifier": "/usr/bin/false",
"active": true,
"required": true,
"rectify": true
},
{
"name": "dependent test",
"target": "/usr/bin/false",
"rectifier": "/usr/bin/true",
"active": true,
"required": true,
"rectify": true
}
]
}

170
docs/README.md Normal file
View File

@@ -0,0 +1,170 @@
# Rex
The Meta-Automation system you didn't know you were missing. It's elegant, yet crude, it's advanced, yet simple.
## What is Rex?
Rex is a project-based, json-driven execution flow/workflow tool designed to place rails around very complex automations in a controlled way that
is easy to troubleshoot.
While designed for the generation of SURRO Linux, the design was kept broad for many other use cases and extensions.
At a high level, it is a very simple thing: It executes scripts and other executables in a predetermined order, logs
their output, and has basic error handling using exit codes of the executables it is running.
Rex relies on a library of `Units` which are files that define, in json format, the executables it will execute.
Rex uses a `Plan` to define which of those units it will actually execute -- once selected they are called `Tasks`.
This allows you to have many things defined by multiple teams, and, with sufficient abstraction, use the same library of
automations for multiple purposes throughout your environment -- bring shared library patterns in software development
to your infrastructure operations efforts if you so desire, and more.
# Instructions
These are instructions for some primitive ways of using Rex.
## Build
Compiling Rex is easy. There are zero external dependencies. Build does require *cmake*.
~~~~
$ cmake .
$ make
~~~~
Then place the binary where you'd like. I'd recommend packaging it for your favorite Linux distribution.
## High Level Usage
### Self-Healing Workflows
Rex introduces self-healing workflows.
#### Model A
1. Write a script that does a thing.
2. Write a script that checks if that thing is done.
3. Set up your check script as a `target` in a `unit`.
4. Set up your script that does the thing as that unit's `rectifier`.
5. Turn on the `rectify` pattern in the `unit definition`.
#### Model B
Or, if you want a flow that's more simple:
1. Write a script that does a thing.
2. Write a script that fixes any environmental conditions that prevent that thing from being done.
3. Set up your `target` script to be the script that does the thing.
4. Set up your `rectifier` script to be the script that fixes the bad condition.
5. Turn on the `rectify pattern` in the unit definition.
### Traditional Workflows
In fact, you don't need a dual mode of automation (though it is highly recommended):
1. Write a script that does a thing.
2. Set the `user`, `group` to run as, well as the `shell` that should be used to execute within.
3. Set the `environment file` to a file to be sourced for that shell containing all of your environment definitions for
your automation.
4. Turn off the `rectify` pattern.
5. Repeat for every step.
As you can see, for small automations, it's often going to be more desirable to just write a shell script, but for
very large efforts spanning many subsystems or components, you may want more control -- that's really where Rex comes
in.
## Definitions
So you've got Rex compiled and you're ready to start automating the world.
If you're thinking "how do I configure this thing", this README is for you.
### Units
A Unit is an automation definition, written in JSON in a UNIT FILE. Deeper into Rex’s internals, Units and Tasks have slightly different functions, but for the purposes of users, the terms can be used interchangeably. A Task is a task to be performed in a Plan, and a Unit is its definition. A Unit is a JSON object that has:
* A `name`, which is an identifier for the Unit used by people.
* A `target`, which is the path to the automation script performing the work. This provides a clean linear path for huge chains of scripts to be executed in order and tracked on return for additional logic in chaining.
* A `rectifier`, which is the path to the automation script to be executed if the target call fails.
* An `active` attribute,which tells Rex whether or not the Unit can be used in a Plan. This gives Unit developers a way to tell Plan developers not to use the Unit.
* A `required` attribute which tells Rex whether or not the Plan can continue if the Unit fails. If the rectify attribute is set to true, this attribute is checked after a rectifier failure. If not, this is checked after target failure. In either case, if the rectifier or target do not return successfully, Rex will halt the execution of the Plan if this is turned on for the unit being executed. Otherwise it simply moves to the next Unit being executed.
* A `log` attribute which tells Rex whether or not to log the stdout of the task. STDERR will always be logged regardless.
* A `user` attribute, along with its accompanying `group` attribute, which together set the identity context to execute the script as that user.
* A `rectify` attribute, which tells Rex whether or not to execute the rectifier in the case of failure when executing the target.
* An `environment` attribute, which points to the path of an environment file -- usually a shell script to be sourced to populate the environment executing the `target`.
### Tasks
A `Task` is an action item in a `Plan`, just like in real life. In the context of Rex, a `Task` is a `Unit` that has been loaded and incorporated into a `Plan` in an actionable state. Inactive `Units` can not be loaded into a `Plan` and thus can never be a `Task`. The primary difference between a Task and a Unit is that a Unit is not actionable — it’s just a definition — while a Task is a consumable, actionable automation definition that is scheduled to execute.
### Suite
A `Suite` is not visible to the user and this is only for informational purposes. A Suite is a collection of all available Unit definitions loaded from one or more UNIT FILES. Just as a Unit is the definition for a Task, a Suite is a collection of Units that define the Task components of a Plan.
A Suite is consumed by a Plan during the conversion of Units to Tasks, though this is not visible to the user — it just simply helps to understand the kind of abstraction taking place in the conceptual model of Rex.
Plan
A Plan is the glue of all the components of Rex and is deceptively simple. A Plan loads a Suite for its Task definitions (Units), but the Tasks to actually execute are specified in the PLAN FILE. The Tasks are executed in the order specified in the PLAN FILE.
### FILES
There are several types of files used by a Rex project.
#### CONFIG FILE and Attributes
This is the one config file that Rex uses. The default path it looks is /etc/Rex/config.json.
A config file at the time of writing this specifies a single JSON object with 5 attributes:
* `units_path`: The `UNIT FILE` path or a path to a directory containing unit files.
* `config_version`: The configuration VERSION.
* `execution_context`: The current working directory to use when loading unit files, plan files, or executing Tasks.
* `execution_context_override`: A boolean indicating whether or not the execution context should be set, or left alone. It is highly recommended to set this to `true`.
* `logs_path`: The path relative to the execution context to store logs. This directory will be created if it does not exist.
#### Configuration VERSION
The configuration version is checked to ensure that the configuration is consumable by that version of Rex. This will pave the way for reverse compatibility if the project moves in that direction.
#### UNIT FILE
The UNIT FILE is a specification of where the Units are defined. All UNIT FILES in that directory will be amalgamated to generate the Suite. These types of files must end in `*.units` for their filename.
#### PLAN FILE
The PLAN FILE is a specification of the order that Tasks are executed, and their dependencies upon each other. Dependency implementation is a touchy matter that is pending implementation, so, mileage may vary until release.
## I still don't see how this works.
That's ok. It's in its infancy so we're always looking for ways to make it simpler. Here's a 'hello world' example.
### 1. Write your tests.
First, we want to know all the things we need to be able to print "hello world" to the screen. In this case we just need to make we have the "echo" binary.
Write a bash script that checks if the "echo" binary is on the system.
#!/usr/bin/bash
stat /usr/bin/echo
exit $?
Save it as ~/check-echo.bash.
This script will be your "target" attribute for your "hello world" unit definition.
### 2. Write your automation.
Write a "hello world" script.
#!/usr/bin/bash
echo "hello world"
exit $?
Save it as ~/hello.bash
This script will be your "rectify" attribute for your "hello world" unit definition.
### 3. Set up the Unit file.
At this point you've got both the script that checks if hello world can run and you've got your hello world script. Time to set up the unit.
### 4. Add the Unit definition to the Plan.
Next, add the unit to the plan by name.
### 5. Set up your config file.
Point your config file at your plan file and your units directory.
### 6. Run Rex pointing at that config file.
Execute rex:
```
rex --config path/to/your/config/file.json --plan path/to/your/plan/file.json
```
And you should see your 'hello world' script. Check out the `test/` directory in this repo for an example project for
more details.

View File

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

View File

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View File

@@ -1,8 +1,9 @@
# Logic Tree for Examplar Task Execution # Logic Tree for Rex Task Execution
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation system that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as

View File

@@ -1,65 +0,0 @@
/*
Examplar - An automation and testing framework.
© SURRO INDUSTRIES and Chris Punches, 2017.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <iostream>
#include "src/json/json.h"
#include "src/loaders/loaders.h"
/*
* TODO Logging -- Pump to syslog with clone to STDOUT
* TODO Unit Files Directory instead of a single Unit File (optional to user)
* TODO Commandline switches
*/
int main( )
{
bool verbose = true;
// A Plan is made up of Tasks, and a Suite is made up of Units.
// A Plan declares what units are executed and a Suite declares the definitions of those units.
Conf configuration = Conf("/home/phanes/development/internal/Examplar/conf/config.json", verbose );
// load the configuration file which contains filepaths to definitions of a plan and definitions of units.
std::string definitions_file = configuration.get_units_path();
std::string plan_file = configuration.get_plan_path();
Suite available_definitions;
available_definitions.load_units_file( definitions_file, verbose );
Plan plan;
plan.load_plan_file( plan_file, verbose );
plan.load_definitions( available_definitions, verbose );
std::cout << "Ready to execute all tasks in Plan." << std::endl;
try
{
plan.execute( verbose );
}
catch ( std::exception& e)
{
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}

58
src/Logger/Logger.cpp Normal file
View File

@@ -0,0 +1,58 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Logger.h"
Logger::Logger( int LOG_LEVEL, std::string mask )
{
this->LOG_LEVEL = LOG_LEVEL;
this->mask = mask;
setlogmask( LOG_UPTO( this->LOG_LEVEL ) );
openlog( "rex", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_PERROR | LOG_LOCAL1 );
}
void Logger::log( int LOG_LEVEL, std::string msg )
{
std::string ERR = "XXXX";
if ( LOG_LEVEL <= this->LOG_LEVEL )
{
switch ( LOG_LEVEL )
{
case E_DEBUG: ERR = "DBUG"; break;
case E_FATAL: ERR = "FATL"; break;
case E_INFO: ERR = "INFO"; break;
case E_WARN: ERR = "WARN"; break;
}
std::string s_msg = "[" + ERR + "] " + msg;
syslog( this->LOG_LEVEL, s_msg.c_str() );
if ( LOG_LEVEL == E_FATAL | LOG_LEVEL == E_WARN )
{
std::cerr << "[" << get_8601() << "] [" << ERR << "] " << "[" << this->mask << "] " << msg.c_str() << std::endl;
} else {
std::cout << "[" << get_8601() << "] [" << ERR << "] " << "[" << this->mask << "] " << msg.c_str() << std::endl;
}
}
}

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -18,18 +19,33 @@
*/ */
#ifndef FTESTS_SPROC_H #ifndef REX_LOGGER_H
#define FTESTS_SPROC_H #define REX_LOGGER_H
#include <syslog.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <iomanip>
#include <sstream>
#include "../loaders/misc/helpers.h"
// executes a subprocess and captures STDOUT, STDERR, and return code. enum L_LVL {
// should be able to recieve path of binary to be executed as well as any parameters E_FATAL,
class Sproc { E_WARN,
public: E_INFO,
// call the object. returnvalue is enum representing external execution attempt not binary exit code E_DEBUG
static int execute( std::string input );
}; };
#endif //FTESTS_SPROC_H class Logger {
public:
Logger( int LOG_LEVEL, std::string mask );
void log( int LOG_LEVEL, std::string msg );
private:
int LOG_LEVEL;
std::string mask;
};
#endif //REX_LOGGER_H

414
src/Sproc/Sproc.cpp Normal file
View File

@@ -0,0 +1,414 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Sproc.h"
#include "../loaders/misc/helpers.h"
#include "sys/stat.h"
#define PARENT default
enum PIPE_FILE_DESCRIPTORS {
READ_END = 0,
WRITE_END = 1
};
enum READ_RESULTS {
READ_EOF = 0,
READ_PIPEOPEN_O_NONBLOCK = -1
};
enum FORK_STATES {
FORK_FAILURE = -1,
CHILD = 0
};
/* ------------------
* HELPERS
* ------------------ */
// converts username to UID
// returns false on failure
int username_to_uid( std::string username, int & uid )
{
// assume failure unless proven otherwise
int r_code = false;
struct passwd * pw;
if ( ( pw = getpwnam( username.c_str() ) ) != NULL )
{
// successful user lookup
r_code = true;
uid = pw->pw_uid;
} else {
// failed lookup, do nothing, assumed failure
}
return r_code;
};
// converts group name to GID
// returns false on failure
int groupname_to_gid( std::string groupname, int & gid )
{
int r_code = false;
struct group * gp;
if ( ( gp = getgrnam( groupname.c_str() ) ) != NULL )
{
r_code = true;
gid = gp->gr_gid;
} else {
// failed lookup, do nothing, assumed failure
}
return r_code;
}
// teebuf constructor
teebuf::teebuf(std::streambuf *sb1, std::streambuf *sb2): sb1(sb1), sb2(sb2)
{}
// teebuf overflow method
int teebuf::overflow( int c )
{
if (c == EOF)
{
return !EOF;
}
else
{
int const r1 = sb1->sputc(c);
int const r2 = sb2->sputc(c);
return r1 == EOF || r2 == EOF ? EOF : c;
}
}
// teebuf sync method
int teebuf::sync()
{
int const r1 = sb1->pubsync();
int const r2 = sb2->pubsync();
return r1 == 0 && r2 == 0 ? 0 : -1;
}
// teestream impl constructor
teestream::teestream(std::ostream &o1, std::ostream &o2) : std::ostream( &tbuf), tbuf( o1.rdbuf(), o2.rdbuf() )
{}
// SET PROCESS TO A CERTAIN IDENTITY CONTEXT
int set_identity_context( std::string task_name, std::string user_name, std::string group_name, Logger slog ) {
// the UID and GID for the username and groupname provided for context setting
int context_user_id;
int context_group_id;
// show the user something usable in debug mode
slog.log( E_DEBUG, "[ '" + task_name + "' ] Attempt: Running as user '" + user_name + "'.");
slog.log( E_DEBUG, "[ '" + task_name + "' ] Attempt: Running as group_name '" + group_name + "'.");
// convert username to UID
if ( username_to_uid(user_name, context_user_id ) )
{
slog.log( E_DEBUG, "[ '" + task_name + "' ] UID of '" + user_name + "' is '" + std::to_string(context_user_id ) + "'." );
} else {
slog.log( E_FATAL, "[ '" + task_name + "' ] Failed to look up UID for '" + user_name + "'.");
return SPROC_RETURN_CODES::UID_NOT_FOUND;
}
// convert group name to GID
if ( groupname_to_gid(group_name, context_group_id ) )
{
slog.log( E_DEBUG, "[ '" + task_name + "' ] GID of '" + group_name + "' is '" + std::to_string(context_group_id ) + "'." );
} else {
slog.log( E_FATAL, "[ '" + task_name + "' ] Failed to look up GID for '" + group_name + "'.");
return SPROC_RETURN_CODES::GID_NOT_FOUND;
}
if (setgid(context_group_id) == 0) {
slog.log(E_DEBUG,
"[ '" + task_name + "' ] Successfully set GID to '" + std::to_string(context_group_id) + "' (" +
group_name + ").");
} else {
slog.log(E_FATAL, "[ '" + task_name + "' ] Failed to set GID. Panicking.");
return SPROC_RETURN_CODES::SET_GID_FAILED;
}
if (setuid(context_user_id) == 0) {
slog.log(E_DEBUG,
"[ '" + task_name + "' ] Successfully set UID to '" + std::to_string(context_user_id) + "' (" +
user_name + ").");
} else {
slog.log(E_FATAL, "[ '" + task_name + "' ] Failed to set UID. Panicking.");
return SPROC_RETURN_CODES::SET_UID_FAILED;
}
return SPROC_RETURN_CODES::SUCCESS;
}
/// Sproc::execute
///
/// \param input - The commandline input to execute.
/// \return - The return code of the execution of input in the calling shell.
int Sproc::execute(std::string shell, std::string environment_file, std::string user_name, std::string group_name, std::string command, int LOG_LEVEL, std::string task_name, bool log_to_file, std::string logs_dir )
{
// the logger
Logger slog = Logger( LOG_LEVEL, "_sproc" );
// if you get this return value, it's an issue with this method and not your
// called executable.
int exit_code_raw = SPROC_RETURN_CODES::EXEC_FAILURE_GENERAL;
// An explanation is due here:
// We want to log the STDOUT and STDERR of the child process, while still displaying them in the parent, in a way
// that does not interfere with, for example libcurses compatibility.
// To simplify the handling of I/O, we will "tee" STDOUT and STDERR of the parent to respective log files.
// Then fork(), and exec() the command to execute in the child, and link its STDOUT/STDERR to the parents' in
// realtime.
// Since the parent has a Tee between STDOUT/STDOUT_LOG and another between STDERR/STDERR_LOG, simply piping the
// child STDOUT/STDERR to the parent STDOUT/STDERR should simplify I/O redirection happening here without
// potentially corrupting user interaction with TUIs in the processes. This should give us our log and our output
// in as hands off a way as possible with as few assumptions as possible, while still doing this in a somewhat C++-y
// way.
if (! is_dir( logs_dir ) ) {
int check = mkdir( logs_dir.c_str(), 0777 );
if (! check ) {
slog.log( E_FATAL, "Sprocket couldn't create the logs parent directory." );
}
}
std::string timestamp = get_8601();
std::string contained_dir = logs_dir + "/" + task_name;
if (! is_dir( contained_dir ) ) {
int check = mkdir( contained_dir.c_str(), 0777 );
if (! check ) {
slog.log( E_FATAL, "Sprocket couldn't create the instance log directory.");
}
}
// set up the "Tee" with the parent
std::string child_stdout_log_path = contained_dir + "/" + timestamp + ".stdout.log";
std::string child_stderr_log_path = contained_dir + "/" + timestamp + ".stderr.log";
std::ofstream stdout_log;
std::ofstream stderr_log;
stdout_log.open( child_stdout_log_path.c_str(), std::ofstream::out | std::ofstream::app );
stderr_log.open( child_stderr_log_path.c_str(), std::ofstream::out | std::ofstream::app );
// avoid cyclic dependencies between stdout and tee_out
std::ostream tmp_stdout( std::cout.rdbuf() );
std::ostream tmp_stderr( std::cerr.rdbuf() );
// writing to this ostream derivative will write to stdout log file and std::cout
teestream tee_out(tmp_stdout, stdout_log);
teestream tee_err(tmp_stderr, stderr_log);
// pop the cout/cerr buffers to the appropriate Tees' buffers
// These cause a segfault when used with the I/O redirection happening around fork, pipe, dup2, execl...
//std::cout.rdbuf( tee_out.rdbuf() );
//std::cerr.rdbuf( tee_err.rdbuf() );
// ....and I don't know why.
// build the command to execute in the shell
std::string sourcer = ". " + environment_file + " && " + command;
// Show the user a debug print of what is going to be executed in the shell.
slog.log(E_DEBUG, "[ '" + task_name + "' ] Shell call for loading: ``" + sourcer + "``.");
// file descriptors for parent/child i/o
int child_stdout_pipe[2];
int child_stderr_pipe[2];
slog.log( E_DEBUG, "[ '" + task_name + "' ] STDIN/STDOUT/STDERR file descriptors created." );
// man 3 pipe
if (pipe(child_stdout_pipe) == -1 ) {
slog.log(E_FATAL, "[ '" + task_name + "' ] STDOUT PIPE FAILED");
return SPROC_RETURN_CODES::PIPE_FAILED;
} else {
slog.log(E_DEBUG, "[ '" + task_name + "' ] file descriptors piped.");
}
// man 3 pipe
if (pipe(child_stderr_pipe) == -1 ) {
slog.log(E_FATAL, "[ '" + task_name + "' ] STDERR PIPE FAILED");
return SPROC_RETURN_CODES::PIPE_FAILED;
} else {
slog.log(E_DEBUG, "[ '" + task_name + "' ] file descriptors piped.");
}
// fork a process
pid_t pid = fork();
slog.log( E_DEBUG, "[ '" + task_name + "' ] Process forked. Reporting. (PID: " + std::to_string(pid) + ")" );
switch ( pid ) {
case FORK_STATES::FORK_FAILURE:
{
// fork failed
slog.log(E_FATAL, "[ '" + task_name + "' ] Fork Failed.");
exit( FORK_FAILED );
break;
}
case FORK_STATES::CHILD:
{
// enter child process
slog.log(E_DEBUG, "[ '" + task_name + "' ] Entering child process.");
while ((dup2(child_stdout_pipe[WRITE_END], STDOUT_FILENO) == -1) && (errno == EINTR)) {}
while ((dup2(child_stderr_pipe[WRITE_END], STDERR_FILENO) == -1) && (errno == EINTR)) {}
close( child_stdout_pipe[WRITE_END] );
close( child_stdout_pipe[READ_END] );
close( child_stderr_pipe[WRITE_END] );
close( child_stderr_pipe[READ_END] );
slog.log(E_INFO, "[ '" + task_name + "' ] TEE Logging enabled.");
slog.log(E_DEBUG, "[ '" + task_name + "' ] DUP2: child_*_pipe[1]->STD*_FILENO");
// set identity context
// set gid and uid
int context_status = set_identity_context(task_name, user_name, group_name, slog);
if (!(context_status)) {
slog.log(E_FATAL, "[ '" + task_name + "' ] Identity context set failed.");
return context_status;
} else {
slog.log( E_INFO, "[ '" + task_name + "' ] Identity context set as user '" + user_name + "' and group '" + group_name + "'." );
}
// execute our big nasty thing
int ret = execl("/bin/sh", "/bin/sh", "-c", sourcer.c_str(), (char *) NULL);
// print something useful to debug with if execl fails
slog.log(E_FATAL, "ret code: " + std::to_string(ret) + "; errno: " + strerror(errno));
// exit child -- if this is executing, you've had a failure
exit(exit_code_raw);
}
PARENT:
{
// enter the parent process
close(child_stdout_pipe[WRITE_END]);
close(child_stderr_pipe[WRITE_END]);
// buffers for reading from child fd's
char stdout_buf[1000] = {0};
char stderr_buf[1000] = {0};
// will contain a set of file descriptors to monitor representing stdout and stderr of the child process
fd_set readfds;
// loop completion flags
bool set_stdout_break = false;
bool set_stderr_break = false;
// read from fd until child completes -- signaled by stdout_break and stderr_break flags
while ((! set_stderr_break ) or (! set_stdout_break)) {
// clear it out to make sure it's clean
FD_ZERO( & readfds );
// add child stdout and stderr pipes (read end)
FD_SET( child_stdout_pipe[READ_END], & readfds );
FD_SET( child_stderr_pipe[READ_END], & readfds );
// for some reason select needs the highest number of the fd +1 of its own input
int highest_fd = child_stderr_pipe[READ_END] > child_stdout_pipe[READ_END] ? child_stderr_pipe[READ_END] : child_stdout_pipe[READ_END];
// wait for one of the fd's to become readable
if ( select( highest_fd + 1, &readfds, NULL, NULL, NULL ) >= 0 )
{ // can read any
if ( FD_ISSET( child_stdout_pipe[READ_END], &readfds ) )
{ // can read child stdout pipe
// read and return the byte size of what was read
int stdout_count = read(child_stdout_pipe[READ_END], stdout_buf, sizeof(stdout_buf) - 1);
switch(stdout_count) { // switch on the count size to allow for error return handling
case READ_PIPEOPEN_O_NONBLOCK:
if ( errno == EINTR ) {
continue;
} else {
slog.log(E_FATAL, "Pipe reading issue with child STDOUT.");
exit( PIPE_FAILED2 );
}
case READ_EOF:
// signal that STDOUT is complete
set_stdout_break = true;
break;
default:
if ( log_to_file ) {
tee_out.write( stdout_buf, stdout_count );
tee_out.flush();
} else {
std::cout.write( stdout_buf, stdout_count );
std::cout.flush();
}
// clear the buffer to prevent artifacts from previous loop
memset( &stdout_buf[0], 0, sizeof( stdout_buf ) -1 );
}
}
if ( FD_ISSET( child_stderr_pipe[READ_END], & readfds ) ) {
// can read child stderr pipe
// so do so
// read and return the byte size of what was read
int stderr_count = read( child_stderr_pipe[READ_END], stderr_buf, sizeof( stderr_buf ) -1 );
// switch on the count size to allow for error return handling
switch( stderr_count ) {
case READ_RESULTS::READ_PIPEOPEN_O_NONBLOCK:
if ( errno == EINTR ) {
continue;
} else {
perror( "read stderr" );
slog.log( E_FATAL, "Pipe reading issue with child STDERR." );
exit( PIPE_FAILED3 );
}
case READ_RESULTS::READ_EOF:
// let the loop know the STDERR criteria has been met
set_stderr_break = true;
// continue the loop
continue;
default:
// write the buffer contents to the STDERR Tee
tee_err.write( stderr_buf, stderr_count );
// flush the TEE
tee_err.flush();
// clear the buffer to prevent artifacts from previous loop
memset( &stderr_buf[0], 0, sizeof( stderr_buf ) -1 );
}
}
} else {
// select error, fatal, throw
slog.log( E_FATAL, "Fatal error, Unknown.");
} // end select/if
}
// wait for the child to exit
while ( ( pid = waitpid(pid, &exit_code_raw, 0 ) ) == -1 ) {}
// clean up Tee
stdout_log.close();
stderr_log.close();
}
}
return WEXITSTATUS( exit_code_raw );
}

95
src/Sproc/Sproc.h Normal file
View File

@@ -0,0 +1,95 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef REX_SPROCKET_H
#define REX_SPROCKET_H
#include "../Logger/Logger.h"
#include <iostream>
#include <stdio.h>
#include "errno.h"
#include <string>
#include <cstring>
#include <streambuf>
#include "unistd.h"
#include <sys/wait.h>
#include <pwd.h>
#include <grp.h>
#include <fstream>
#include "fcntl.h"
// exit codes for Rex
enum SPROC_RETURN_CODES {
SUCCESS = true,
UID_NOT_FOUND = -404,
GID_NOT_FOUND = -405,
SET_GID_FAILED = -401,
SET_UID_FAILED = -404,
EXEC_FAILURE_GENERAL = -666,
PIPE_FAILED3 = -996,
PIPE_FAILED2 = -997,
PIPE_FAILED = -998,
DUP2_FAILED = -999,
FORK_FAILED = -1000
};
// executes a subprocess and captures STDOUT, STDERR, and return code.
// should be able to receive path of binary to be executed as well as any parameters
class Sproc {
public:
// call the object. return value is enum representing external execution attempt not binary exit code
static int execute(
std::string shell,
std::string environment_file,
std::string user_name,
std::string group_name,
std::string command,
int LOG_LEVEL,
std::string task_name,
bool log_to_file,
std::string logs_dir
);
};
// a teebuff implementation
class teebuf: public std::streambuf
{
public:
// Construct a streambuf which tees output to both input
// streambufs.
teebuf(std::streambuf * sb1, std::streambuf * sb2);
private:
virtual int overflow(int c);
virtual int sync();
std::streambuf * sb1;
std::streambuf * sb2;
};
// a simple helper class to create a tee stream from two input streams
class teestream : public std::ostream
{
public:
// Construct an ostream which tees output to the supplied ostreams.
teestream( std::ostream & o1, std::ostream & o2);
teebuf tbuf;
};
#endif //REX_SPROCKET_H

View File

@@ -1,54 +0,0 @@
/*
Examplar - An automation and testing framework.
© SURRO INDUSTRIES and Chris Punches, 2017.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Conf.h"
/// CONF_PLANPATH_INVALID - Exception thrown when the Conf type can not load the supplied path for the Plan definition
/// file.
class CONF_PLANPATH_INVALID: public std::runtime_error { public:
CONF_PLANPATH_INVALID(): std::runtime_error("conf: The supplied path for the plan definition file is invalid.") {}
};
/// CONF_UNITSPATH_INVALID - Exception thrown when the Conf type can not load the supplied path for the Unit definition
/// files.
class CONF_UNITSPATH_INVALID: public std::runtime_error { public:
CONF_UNITSPATH_INVALID(): std::runtime_error("conf: The supplied path for the unit definition file is invalid.") {}
};
/// Conf::Conf - Constructor for Conf type. Loads the configuration for the application.
/// TODO Expand to detect when a directory path is supplied for units_path or plan_path and import all Tasks and Units.
///
/// \param filename - The filename to load the configuration from.
Conf::Conf( std::string filename, bool verbose ): JSON_Loader()
{
// load the conf file.
this->load_json_file( filename, verbose );
// find the path to the plan file
if (this->get_serialized(this->plan_path, "plan_path", true) != 0 ) { throw CONF_PLANPATH_INVALID(); }
// find the path to the unit definitions file
if (this->get_serialized(this->units_path, "units_path", true) != 0 ) { throw CONF_UNITSPATH_INVALID(); }
};
/// Conf::get_plan_path - Retrieves the path to the Plan definition file from the application configuration file.
std::string Conf::get_plan_path() { return this->plan_path.asString(); }
/// Conf::get_units_path - Retrieves the path to the Unit definition file from the application configuration file.
std::string Conf::get_units_path() { return this->units_path.asString(); }

View File

@@ -1,37 +0,0 @@
/*
Examplar - An automation and testing framework.
© SURRO INDUSTRIES and Chris Punches, 2017.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FTESTS_CONF_H
#define FTESTS_CONF_H
#include "JSON_Loader.h"
class Conf: public JSON_Loader
{
private:
Json::Value plan_path;
Json::Value units_path;
public:
Conf( std::string filename, bool verbose );
std::string get_plan_path();
std::string get_units_path();
};
#endif //FTESTS_CONF_H

View File

@@ -1,164 +0,0 @@
/*
Examplar - An automation and testing framework.
© SURRO INDUSTRIES and Chris Punches, 2017.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Unit.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdexcept>
/// Unit_NotPopulated - Meant to be thrown when a Unit type is not populated before being used.
/// Signaled by use of the 'populated' boolean member of the Unit class.
class Unit_NotPopulated: public std::runtime_error { public:
Unit_NotPopulated(): std::runtime_error("Unit: Attempted to access a member before loading values.") {}
};
/// Unit_DataStructureException - Meant to be thrown when a Unit type is accessing a member that does not exist.
class Unit_DataStructureException: public std::runtime_error { public:
// TODO rework this to accept the key name being fetched
Unit_DataStructureException(): std::runtime_error("Unit: Attempted to access a member not present in defined Unit.") {}
};
/// Unit::Unit - Constructor for Unit type. The Unit is a definition of an automation task. Each Unit has:
/// name, used for identification and retrieval.
/// target, which is the filepath of an executable to trigger.
/// output, which is the desired output of the execution of target to STDOUT in determinations of of success or failure
/// (in addition to 0|non-0 exit code). If the output is set to look for "0" then it uses the exit code.
///
/// There is also:
/// rectifier, which is the path to an executable in the event of a non-0 exit code or a failure to get the desired
/// output.
/// required, which is used as a flag to halt or continue if rectifier does not heal the system in such a way that
/// target can run successfully.
/// rectify, which is used as a flag to determine in the rectifier runs.
Unit::Unit() {}
/// Unit::load_root - Takes a JSON::Value and assigns the members to the Unit being populated.
///
/// \param loader_root - The JSON::Value object to use to populate unit from. Usually supplied as the Suite's buffer
/// member.
/// \return - Boolean representation of success or failure.
int Unit::load_root(Json::Value loader_root)
{
// TODO this needs reworked to have errmsg actually end up as a null return from json::value.get()
std::string errmsg = "SOMETHING WENT TERRIBLY WRONG IN PARSING";
// TODO this pattern is 'working but broken'. need to use a datastructure for required members and iterate
// do NOT replace this with a switch case pattern
if ( loader_root.isMember("name") )
{ this->name = loader_root.get("name", errmsg).asString(); } else throw Unit_DataStructureException();
if ( loader_root.isMember("target") )
{ this->target = loader_root.get("target", errmsg).asString(); } else throw Unit_DataStructureException();
if ( loader_root.isMember("rectifier") )
{ this->rectifier = loader_root.get("rectifier", errmsg).asString(); } else throw Unit_DataStructureException();
if ( loader_root.isMember("active") )
{ this->active = loader_root.get("active", errmsg).asBool(); } else throw Unit_DataStructureException();
if ( loader_root.isMember("required") )
{ this->required = loader_root.get("required", errmsg).asBool(); } else throw Unit_DataStructureException();
if ( loader_root.isMember("rectify") )
{ this->rectify = loader_root.get("rectify", errmsg).asBool(); } else throw Unit_DataStructureException();
this->populated = true;
return 0;
}
/// Unit::load_string - populates a Unit object from a supplies JSON-formatted string. It's stellar.
///
/// \param json_val - JSON-formatted string to populate from. See Unit::load_root() for details on required structure.
/// \return - The bool representation of success or failure.
int Unit::load_string(std::string json_val)
{
// serialize
this->load_json_string( json_val, true );
// deserialize
this->load_root( this->json_root );
return 0;
}
/// Unit::get_name - retrieves the name of the unit.
///
/// \return the name of the unit.
std::string Unit::get_name()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->name;
}
/// Unit::get_target - retrieves the target of the unit.
///
/// \return the target of the unit.
std::string Unit::get_target()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->target;
}
/// Unit::get_output - retrieves the output of the unit.
///
/// \return the output of the unit.
std::string Unit::get_output()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->output;
}
/// Unit::get_rectifier - retrieves the rectifier of the unit.
///
/// \return the rectifier of the unit.
std::string Unit::get_rectifier()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->rectifier;
}
/// Unit::get_active - retrieves the armed status of the unit.
///
/// \return the armed status of the unit.
bool Unit::get_active()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->active;
}
/// Unit::get_required - retrieves the requirement status of the unit.
///
/// \return the requirement status of the unit.
bool Unit::get_required()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->required;
}
/// Unit::get_rectify - retrieves the rectification status of the unit.
///
/// \return the rectification status of the unit.
bool Unit::get_rectify()
{
if ( ! this->populated ) { throw Unit_NotPopulated(); }
return this->rectify;
}

View File

@@ -0,0 +1,147 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Conf.h"
/// ConfigLoadException - General exception handler for the Conf class.
class ConfigLoadException: public std::exception
{
public:
/** Constructor (C strings).
* @param message C-style string error message.
* The string contents are copied upon construction.
* Hence, responsibility for deleting the char* lies
* with the caller.
*/
explicit ConfigLoadException(const char* message):
msg_(message)
{
}
/** Constructor (C++ STL strings).
* @param message The error message.
*/
explicit ConfigLoadException(const std::string& message):
msg_(message)
{}
/** Destructor.
* Virtual to allow for subclassing.
*/
virtual ~ConfigLoadException() throw (){}
/** Returns a pointer to the (constant) error description.
* @return A pointer to a const char*. The underlying memory
* is in posession of the Exception object. Callers must
* not attempt to free the memory.
*/
virtual const char* what() const throw (){
return msg_.c_str();
}
protected:
/** Error message.
*/
std::string msg_;
};
/// Conf::Conf - Constructor for Conf type. Loads the configuration for the application.
/// TODO Expand to detect when a directory path is supplied for units_path or plan_path and import all Tasks and Units.
///
/// \param filename - The filename to load the configuration from.
Conf::Conf(std::string filename, int LOG_LEVEL ): JSON_Loader(LOG_LEVEL ), slog(LOG_LEVEL, "_conf_" )
{
this->LOG_LEVEL = LOG_LEVEL;
// prepare context spaghetti
this->override_context = false;
try {
// load the test file.
this->load_json_file( filename );
}
catch (std::exception) {
this->slog.log( E_FATAL, "Unable to locate configuration file: '" + filename + "'." );
throw ConfigLoadException("Config file not found.");
}
if (this->get_serialized(this->config_version, "config_version" ) != 0)
{
throw ConfigLoadException("config_version string is not set in the config file supplied: " + filename);
}
if ( this->config_version.asString() != VERSION_STRING )
{
throw ConfigLoadException("config_version string expected was " + std::string(VERSION_STRING) + " in: " + filename);
}
// find the path to the unit definitions file
if (this->get_serialized(this->units_path, "units_path" ) != 0 )
{
throw ConfigLoadException("units_path string is not set in the config file supplied: " + filename);
}
// find the path to logs directory
if (this->get_serialized(this->logs_path, "logs_path" ) != 0 )
{
throw ConfigLoadException("logs_path string is not set in the config file supplied: " + filename);
}
if ( this->get_serialized(this->override_execution_context, "execution_context_override" ) != 0 )
{
throw ConfigLoadException("execution_context_override boolean is not set in the config file supplied: " + filename);
} else {
this->override_context = true;
}
if ( this->get_serialized(this->execution_context, "execution_context" ) != 0 )
{
throw ConfigLoadException("execution_context string is not set in the config file supplied: " + filename);
} else {
if ( is_dir( this->execution_context.asString() ) ) {
this->execution_context_literal = this->execution_context.asString();
} else {
throw ConfigLoadException( "The execution context supplied is an invalid directory.");
}
}
};
/// Conf::has_context_override - Specifies whether or not the override context function is enabled in the Conf file.
bool Conf::has_context_override() {
return this->override_execution_context.asBool();
}
/// Conf::get_execution_context - Specifies the path to the current working directory to set for all unit executions.
std::string Conf::get_execution_context() {
return this->execution_context_literal;
}
/// Conf::get_units_path - Retrieves the path to the Unit definition file from the application configuration file.
std::string Conf::get_units_path() { return this->units_path.asString(); }
/// Conf::get_units_path - Retrieves the path to the Unit definition file from the application configuration file.
std::string Conf::get_logs_path() { return this->logs_path.asString(); }
/// Conf::set_execution_context- Sets the execution context.
void Conf::set_execution_context(std::string execution_context )
{
this->execution_context_literal = execution_context;
}

View File

@@ -0,0 +1,68 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef REX_CONF_H
#define REX_CONF_H
#include "../low_level/JSON_Loader.h"
#include <exception>
#include "../../Logger/Logger.h"
#include "../misc/helpers.h"
#define STRINGIZE2(s) #s
#define STRINGIZE(s) STRINGIZE2(s)
# define IMPL_CONFIG_VERSION 4
# define VERSION_STRING STRINGIZE(IMPL_CONFIG_VERSION)
class Conf: public JSON_Loader
{
private:
Json::Value plan_path;
Json::Value units_path;
Json::Value execution_context;
Json::Value config_version;
Json::Value logs_path;
// flag to indicate if execution context should be overriden in config file
// if set to true rex should use whats in the config file for current working directory
// if set to false, rex should use the current working directory at time of execution
Json::Value override_execution_context;
bool override_context;
std::string execution_context_literal;
public:
Conf(std::string filename, int LOG_LEVEL );
bool has_context_override();
std::string get_units_path();
std::string get_execution_context();
std::string get_logs_path();
void set_execution_context( std::string );
private:
int LOG_LEVEL;
Logger slog;
};
#endif //REX_CONF_H

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -120,37 +121,39 @@ protected:
/// Plan::Plan() - Constructor for Plan class. A Plan is a managed container for a Task vector. These tasks reference /// Plan::Plan() - Constructor for Plan class. A Plan is a managed container for a Task vector. These tasks reference
/// Units that are defined in the Units files (Suite). If Units are definitions, Tasks are selections of those /// Units that are defined in the Units files (Suite). If Units are definitions, Tasks are selections of those
/// definitions to execute, and if Units together form a Suite, Tasks together form a Plan. /// definitions to execute, and if Units together form a Suite, Tasks together form a Plan.
Plan::Plan(): JSON_Loader() {}; Plan::Plan(Conf * configuration, int LOG_LEVEL ): JSON_Loader(LOG_LEVEL ), slog(LOG_LEVEL, "_plan_" )
{
this->configuration = configuration;
this->LOG_LEVEL = LOG_LEVEL;
}
/// Plan::load_plan_file - Uses the json_root buffer on each run to append intact Units as they're deserialized from /// Plan::load_plan_file - Uses the json_root buffer on each run to append intact Units as they're deserialized from
/// the provided file. /// the provided file.
/// ///
/// \param filename - The filename to load the plan from. /// \param filename - The filename to load the plan from.
/// \param verbose - Whether to print verbose output to STDOUT. /// \param verbose - Whether to print verbose output to STDOUT.
void Plan::load_plan_file(std::string filename, bool verbose) void Plan::load_plan_file( std::string filename )
{ {
// plan always loads from file // plan always loads from file
this->load_json_file( filename, verbose ); this->load_json_file( filename );
// staging buffer // staging buffer
Json::Value jbuff; Json::Value jbuff;
// fill the jbuff staging buffer wih a json::value object in the supplied filename // fill the jbuff staging buffer wih a json::value object in the supplied filename
if ( this->get_serialized( jbuff, "plan", verbose ) == 0 ) if ( this->get_serialized( jbuff, "plan" ) == 0 )
{ {
this->json_root = jbuff; this->json_root = jbuff;
} }
// iterate through the json::value members that have been loaded. append to this->tasks vector // iterate through the json::value members that have been loaded. append to this->tasks vector
// buffer for tasks to append: // buffer for tasks to append:
Task tmp_T; Task tmp_T = Task( this->LOG_LEVEL );
for ( int index = 0; index < this->json_root.size(); index++ ) for ( int index = 0; index < this->json_root.size(); index++ )
{ {
tmp_T.load_root( this->json_root[ index ], verbose ); tmp_T.load_root( this->json_root[ index ] );
this->tasks.push_back( tmp_T ); this->tasks.push_back( tmp_T );
if ( verbose ) { this->slog.log( LOG_INFO, "Added task \"" + tmp_T.get_name() + "\" to Plan." );
std::cout << "Added task \"" << tmp_T.get_name() << "\" to Plan." << std::endl;
}
} }
} }
@@ -174,10 +177,10 @@ void Plan::get_task(Task & result, int index )
/// ///
/// \param unit_definitions - The Suite to load definitions from. /// \param unit_definitions - The Suite to load definitions from.
/// \param verbose - Whether to print verbose information to STDOUT. /// \param verbose - Whether to print verbose information to STDOUT.
void Plan::load_definitions( Suite unit_definitions, bool verbose ) void Plan::load_definitions( Suite unit_definitions )
{ {
// placeholder Unit // placeholder Unit
Unit tmp_U; Unit tmp_U = Unit( this->LOG_LEVEL );
// for every task in the plan: // for every task in the plan:
for (int i = 0; i < this->tasks.size(); i++ ) for (int i = 0; i < this->tasks.size(); i++ )
@@ -186,7 +189,7 @@ void Plan::load_definitions( Suite unit_definitions, bool verbose )
unit_definitions.get_unit( tmp_U, this->tasks[i].get_name() ); unit_definitions.get_unit( tmp_U, this->tasks[i].get_name() );
// then have that task attach a copy of tmp_U // then have that task attach a copy of tmp_U
this->tasks[i].load_definition( tmp_U, verbose ); this->tasks[i].load_definition( tmp_U );
} }
} }
@@ -210,7 +213,7 @@ void Plan::get_task(Task & result, std::string provided_name )
} }
if (! foundMatch ) if (! foundMatch )
{ {
std::cerr << "Task name \"" << provided_name << "\" was referenced but not defined!" << std::endl; this->slog.log( E_FATAL, "Task name \"" + provided_name + "\" was referenced but not defined!" );
throw Plan_InvalidTaskName(); throw Plan_InvalidTaskName();
} }
} }
@@ -223,14 +226,14 @@ void Plan::get_task(Task & result, std::string provided_name )
bool Plan::all_dependencies_complete(std::string name) bool Plan::all_dependencies_complete(std::string name)
{ {
// get the task by name // get the task by name
Task named_task; Task named_task = Task( this->LOG_LEVEL );
this->get_task( named_task, name ); this->get_task( named_task, name );
// get the dependencies of that task // get the dependencies of that task
std::vector<std::string> deps = named_task.get_dependencies(); std::vector<std::string> deps = named_task.get_dependencies();
// create an empty task to assign values to during iteration // create an empty task to assign values to during iteration
Task tmpTask; Task tmpTask = Task( this->LOG_LEVEL );
// iterate through its dependencies // iterate through its dependencies
for ( int i = 0; i < deps.size(); i++ ) for ( int i = 0; i < deps.size(); i++ )
{ {
@@ -247,26 +250,26 @@ bool Plan::all_dependencies_complete(std::string name)
/// Plan::execute() - Iterates through all tasks in a plan and executes them. /// Plan::execute() - Iterates through all tasks in a plan and executes them.
/// ///
/// \param verbose /// \param verbose
void Plan::execute( bool verbose ) void Plan::execute()
{ {
// for each task in this plan // for each task in this plan
for ( int i = 0; i < this->tasks.size(); i++ ) for ( int i = 0; i < this->tasks.size(); i++ )
{ {
if (this->all_dependencies_complete(this->tasks[i].get_name()) ) if (this->all_dependencies_complete(this->tasks[i].get_name()) )
{ {
if ( verbose )
{ this->slog.log( E_INFO, "[ '" + this->tasks[i].get_name() + "' ] Executing..." );
std::cout << "Executing task \"" << this->tasks[i].get_name() << "\"." << std::endl;
}
try { try {
this->tasks[i].execute( verbose ); this->tasks[i].execute( this->configuration );
} }
catch (std::exception& e) { catch (std::exception& e) {
throw Plan_Task_GeneralExecutionException( "Plan Task: \"" + this->tasks[i].get_name() + "\" reported: " + e.what() ); this->slog.log( E_FATAL, "[ '" + this->tasks[i].get_name() + "' ] Report: " + e.what() );
throw Plan_Task_GeneralExecutionException("Could not execute task.");
} }
} else { } else {
// not all deps met for this task // not all deps met for this task
throw Plan_Task_Missing_Dependency( "Plan Task \"" + this->tasks[i].get_name() + "\" was specified in the Plan but not executed due to missing dependencies. Please revise your plan." ); this->slog.log( E_FATAL, "[ '" + this->tasks[i].get_name() + "' ] This task was specified in the Plan but not executed due to missing dependencies. Please revise your plan." );
throw Plan_Task_Missing_Dependency( "Unmet dependency for task." );
} }
} }
} }

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -18,25 +19,28 @@
*/ */
#ifndef FTESTS_PLAN_H #ifndef REX_PLAN_H
#define FTESTS_PLAN_H #define REX_PLAN_H
#include <string> #include <string>
#include "../json/json.h" #include "../../json/json.h"
#include "JSON_Loader.h" #include "../low_level/JSON_Loader.h"
#include "Task.h" #include "Task.h"
#include "Conf.h"
#include "../../Logger/Logger.h"
class Plan: public JSON_Loader class Plan: public JSON_Loader
{ {
private: private:
// storage for the tasks that make up the plan // storage for the tasks that make up the plan
std::vector<Task> tasks; std::vector<Task> tasks;
Conf * configuration;
public: public:
Plan(); Plan(Conf * configuration, int LOG_LEVEL );
// append this->tasks from JSON file // append this->tasks from JSON file
void load_plan_file( std::string filename, bool verbose ); void load_plan_file( std::string filename );
// fetch a task from this->tasks // fetch a task from this->tasks
void get_task( Task & result, std::string provided_name ); void get_task( Task & result, std::string provided_name );
@@ -45,15 +49,19 @@ class Plan: public JSON_Loader
void get_task( Task & result, int index ); void get_task( Task & result, int index );
// load unit definitions from a provided suite and import them into individual tasks // load unit definitions from a provided suite and import them into individual tasks
void load_definitions( Suite unit_definitions, bool verbose ); void load_definitions( Suite unit_definitions );
// fetch a corresponding Unit to a Task // fetch a corresponding Unit to a Task
// void get_definition_from_task(Unit & result, Task input, bool verbose ); // void get_definition_from_task(Unit & result, Task input, bool verbose );
// execute all tasks in this plan // execute all tasks in this plan
void execute( bool verbose ); void execute();
bool all_dependencies_complete(std::string name); bool all_dependencies_complete(std::string name);
private:
int LOG_LEVEL;
Logger slog;
}; };
#endif //FTESTS_PLAN_H #endif //REX_PLAN_H

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -79,24 +80,13 @@ protected:
/// human processes to allow modularly developed profiles of test suites. As inferred, Unit is expected to be one of /// human processes to allow modularly developed profiles of test suites. As inferred, Unit is expected to be one of
/// the two types that are only instantiated once per application run, though it is designed to be used more than once /// the two types that are only instantiated once per application run, though it is designed to be used more than once
/// if the implementor so desires. /// if the implementor so desires.
Suite::Suite(): JSON_Loader() {}; Suite::Suite( int LOG_LEVEL ): JSON_Loader( LOG_LEVEL ), slog( LOG_LEVEL, "_suite" )
bool is_file( std::string path)
{ {
struct stat buf; this->LOG_LEVEL;
stat( path.c_str(), &buf );
return S_ISREG(buf.st_mode);
} }
bool is_dir( std::string path )
{
struct stat buf;
stat( path.c_str(), &buf );
return S_ISDIR(buf.st_mode);
}
void get_units_from_dir( std::vector<std::string> * files, std::string path ) void Suite::get_units_from_dir( std::vector<std::string> * files, std::string path )
{ {
DIR* dirFile = opendir( path.c_str() ); DIR* dirFile = opendir( path.c_str() );
if ( dirFile ) if ( dirFile )
@@ -107,11 +97,20 @@ void get_units_from_dir( std::vector<std::string> * files, std::string path )
errno = 0; errno = 0;
while (( hFile = readdir( dirFile )) != NULL ) while (( hFile = readdir( dirFile )) != NULL )
{ {
if ( !strcmp( hFile->d_name, "." )) continue; if ( !strcmp( hFile->d_name, "." ))
if ( !strcmp( hFile->d_name, ".." )) continue; {
continue;
}
if ( !strcmp( hFile->d_name, ".." ))
{
continue;
}
// hidden files // hidden files
if ( hFile->d_name[0] == '.' ) continue; if ( hFile->d_name[0] == '.' )
{
continue;
}
// dirFile.name is the name of the file. Do whatever string comparison // dirFile.name is the name of the file. Do whatever string comparison
// you want here. Something like: // you want here. Something like:
@@ -123,18 +122,17 @@ void get_units_from_dir( std::vector<std::string> * files, std::string path )
} }
closedir( dirFile ); closedir( dirFile );
} else { } else {
std::cout << "file not found" << std::endl; this->slog.log( E_DEBUG, "File not found: " + path );
} }
} }
/// Suite::load_units_file - Uses the json_root buffer on each run to append intact Units as they're /// Suite::load_units_file - Uses the json_root buffer on each run to append intact Units as they're
/// deserialized from the provided file. /// deserialized from the provided file.
/// ///
/// \param units_path - The file to pull the JSON-formatted units from. /// \param units_path - The file to pull the JSON-formatted units from.
/// \param verbose - Whether to print verbose output to STDOUT. /// \param verbose - Whether to print verbose output to STDOUT.
void Suite::load_units_file( std::string units_path, bool verbose ) void Suite::load_units_file( std::string units_path )
{ {
std::vector<std::string> unit_files; std::vector<std::string> unit_files;
@@ -149,28 +147,26 @@ void Suite::load_units_file( std::string units_path, bool verbose )
unit_files.push_back( units_path ); unit_files.push_back( units_path );
} }
std::ostringstream infostring; this->slog.log( E_INFO, "Unit files found: " + std::to_string( unit_files.size() ) );
infostring << "Unit files found: " << unit_files.size() << std::endl;
syslog(LOG_INFO, infostring.str().c_str() );
std::cerr << infostring.str();
for ( int i = 0; i < unit_files.size(); i++ ) for ( int i = 0; i < unit_files.size(); i++ )
{ {
// will use json_root buffer on each run to append to this->units vector as valid units are found. // will use json_root buffer on each run to append to this->units vector as valid units are found.
this->load_json_file( unit_files[i], verbose ); this->load_json_file( unit_files[i] );
// staging buffer // staging buffer
Json::Value jbuff; Json::Value jbuff;
// fill the jbuff staging buffer with a json::value object in the supplied units_path // fill the jbuff staging buffer with a json::value object in the supplied units_path
if ( this->get_serialized( jbuff, "units", verbose ) == 0) if ( this->get_serialized( jbuff, "units" ) == 0)
{ {
this->json_root = jbuff; this->json_root = jbuff;
} }
// iterate through the json::value members that have been loaded. append to this->units vector // iterate through the json::value members that have been loaded. append to this->units vector
// buffer for units to append: // buffer for units to append:
Unit tmp_U; Unit tmp_U = Unit( this->LOG_LEVEL );
for ( int index = 0; index < this->json_root.size(); index++ ) for ( int index = 0; index < this->json_root.size(); index++ )
{ {
// assemble the unit from json_root using the built-in value operator // assemble the unit from json_root using the built-in value operator
@@ -178,20 +174,13 @@ void Suite::load_units_file( std::string units_path, bool verbose )
if ( tmp_U.get_active() ) { if ( tmp_U.get_active() ) {
// append to this->units // append to this->units
this->units.push_back( tmp_U ); this->units.push_back( tmp_U );
if ( verbose ) { this->slog.log( E_INFO, "Added unit \"" + tmp_U.get_name() + "\" to Suite.");
std::ostringstream infostring;
infostring << "Added unit \"" << tmp_U.get_name() << "\" to Suite." << std::endl;
syslog(LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
}
} }
} }
} }
} }
/// Suite::get_unit - returns a contained Unit identified by name attribute. /// Suite::get_unit - returns a contained Unit identified by name attribute.
/// ///
/// \param result - the unit type receiving the unit's value /// \param result - the unit type receiving the unit's value
@@ -213,11 +202,8 @@ void Suite::get_unit(Unit & result, std::string provided_name)
if (! foundMatch ) if (! foundMatch )
{ {
std::ostringstream infostring; this->slog.log( E_FATAL, "Unit name \"" + provided_name + "\" was referenced but not defined!" );
infostring << "Unit name \"" << provided_name << "\" was referenced but not defined!" << std::endl; throw SuiteException( "Undefined unit in use." );
syslog(LOG_ERR, infostring.str().c_str() );
std::cerr << infostring.str();
throw SuiteException( infostring.str() );
} }
} }

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -18,13 +19,15 @@
*/ */
#ifndef FTESTS_UNITS_H #ifndef REX_UNITS_H
#define FTESTS_UNITS_H #define REX_UNITS_H
#include <vector> #include <vector>
#include "../json/json.h" #include "../../json/json.h"
#include "JSON_Loader.h" #include "../low_level/JSON_Loader.h"
#include "Unit.h" #include "Unit.h"
#include "../../Logger/Logger.h"
#include "../misc/helpers.h"
class Suite: public JSON_Loader class Suite: public JSON_Loader
@@ -34,14 +37,22 @@ class Suite: public JSON_Loader
std::vector<Unit> units; std::vector<Unit> units;
public: public:
// constructor, empty // constructor
Suite(); Suite( int LOG_LEVEL );
// load a unit definitions file and add valid unit definitions to this->units // load a unit definitions file and add valid unit definitions to this->units
void load_units_file( std::string filename, bool verbose ); void load_units_file( std::string filename );
// returns the unit identified by name // returns the unit identified by name
void get_unit(Unit & result, std::string provided_name); void get_unit(Unit & result, std::string provided_name);
private:
void get_units_from_dir( std::vector<std::string> * files, std::string path );
private:
int LOG_LEVEL;
Logger slog;
}; };
#endif //FTESTS_UNITS_H #endif //REX_UNITS_H

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -19,10 +20,7 @@
*/ */
#include "Task.h" #include "Task.h"
#include <unistd.h>
#include <stdio.h>
#include <syslog.h>
#include "../sproc/Sproc.h"
/// Task_InvalidDataStructure - Exception thrown when a Task is defined with invalid JSON. /// Task_InvalidDataStructure - Exception thrown when a Task is defined with invalid JSON.
class Task_InvalidDataStructure: public std::runtime_error { class Task_InvalidDataStructure: public std::runtime_error {
@@ -33,7 +31,7 @@ public:
/// Task_InvalidDataStructure - Exception thrown when a Task is defined with invalid JSON. /// Task_InvalidDataStructure - Exception thrown when a Task is defined with invalid JSON.
class Task_NotReady: public std::runtime_error { class Task_NotReady: public std::runtime_error {
public: public:
Task_NotReady(): std::runtime_error("Task: Attempted to access a unit of a Task that is not defined.") {} Task_NotReady(): std::runtime_error("Task: Attempted to execute a Task whose Unit is not well defined.") {}
}; };
@@ -82,20 +80,24 @@ protected:
/// Task::Task() - Constructor for the Task class. The Task is the building block of a Plan indicating of which Unit to /// Task::Task() - Constructor for the Task class. The Task is the building block of a Plan indicating of which Unit to
/// execute, and its dependencies on other units to have already been completed successfully. /// execute, and its dependencies on other units to have already been completed successfully.
Task::Task() Task::Task( int LOG_LEVEL ):
slog( LOG_LEVEL, "_task_" ),
definition( LOG_LEVEL )
{ {
// it hasn't executed yet. // it hasn't executed yet.
this->complete = false; this->complete = false;
// it hasn't been matched with a definition yet. // it hasn't been matched with a definition yet.
this->defined = false; this->defined = false;
this->LOG_LEVEL = LOG_LEVEL;
} }
/// Task::load_root() - loads json values to private members /// Task::load_root() - loads json values to private members
/// ///
/// \param loader_root - the Json::Value to populate from. /// \param loader_root - the Json::Value to populate from.
/// \param verbose - Whether to print verbose information to STDOUT. /// \param verbose - Whether to print verbose information to STDOUT.
void Task::load_root(Json::Value loader_root, bool verbose ) void Task::load_root(Json::Value loader_root )
{ {
if ( loader_root.isMember("name") ) { if ( loader_root.isMember("name") ) {
this->name = loader_root.get("name", "?").asString(); this->name = loader_root.get("name", "?").asString();
@@ -110,16 +112,10 @@ void Task::load_root(Json::Value loader_root, bool verbose )
// iterate through each member of that obj // iterate through each member of that obj
for ( int i = 0; i < des_dep_root.size(); i++ ) { for ( int i = 0; i < des_dep_root.size(); i++ ) {
// add each string to dependencies // add each string to dependencies
if ( des_dep_root[i].asString() != "" ) { if ( des_dep_root[i].asString() != "" )
{
this->dependencies.push_back( des_dep_root[i].asString() ); this->dependencies.push_back( des_dep_root[i].asString() );
if ( verbose ) { this->slog.log( E_INFO, "Added dependency \"" + des_dep_root[i].asString() + "\" to task \"" + this->get_name() + "\"." );
std::ostringstream infostring;
infostring << "Added dependency \"" << des_dep_root[i].asString() << "\" to task \""
<< this->get_name() << "\"." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
}
} }
} }
} }
@@ -134,17 +130,10 @@ std::string Task::get_name()
/// ///
/// \param selected_unit - The unit to attach. /// \param selected_unit - The unit to attach.
/// \param verbose - Whether to print to STDOUT. /// \param verbose - Whether to print to STDOUT.
void Task::load_definition( Unit selected_unit, bool verbose ) void Task::load_definition( Unit selected_unit )
{ {
this->definition = selected_unit; this->definition = selected_unit;
if ( verbose ) { this->slog.log( E_INFO, "Loaded definition \"" + selected_unit.get_name() + "\" as task in configured plan.");
std::ostringstream infostring;
infostring << "Loaded definition \"" << selected_unit.get_name() << "\" for task \""
<< this->get_name() << "\"." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
}
this->defined = true; this->defined = true;
} }
@@ -174,17 +163,12 @@ bool Task::has_definition()
return this->defined; return this->defined;
} }
/// Task::execute - execute a task's unit definition. /// Task::execute - execute a task's unit definition.
/// See the design document for what flow control needs to look like here. /// See the design document for what flow control needs to look like here.
/// \param verbose - Verbosity level - not implemented yet. /// \param verbose - Verbosity level - not implemented yet.
void Task::execute( bool verbose ) void Task::execute(Conf * configuration )
{ {
// DUFFING - If Examplar is broken it's probably going to be in this block. // DUFFING - If rex is broken it's probably going to be in this block.
// Somebody come clean this up, eh? // Somebody come clean this up, eh?
// PREWORK // PREWORK
@@ -197,29 +181,49 @@ void Task::execute( bool verbose )
// get the name // get the name
std::string task_name = this->definition.get_name(); std::string task_name = this->definition.get_name();
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Using unit definition: \"" + task_name + "\"." );
// END PREWORK // END PREWORK
// get the target execution command // get the target execution command
std::string target_command = this->definition.get_target(); std::string target_command = this->definition.get_target();
// if we're in verbose mode, do some verbose things // check if context override
if ( verbose ) if ( configuration->has_context_override() )
{ {
infostring = std::ostringstream(); // if so, set the CWD.
infostring << "\tUsing unit \"" << task_name << "\"." << std::endl; chdir( configuration->get_execution_context().c_str() );
syslog( LOG_INFO, infostring.str().c_str() ); this->slog.log( E_INFO, "[ '" + task_name + "' ] Setting execution context: " + get_working_path() );
std::cout << infostring.str();
infostring = std::ostringstream();
infostring << "\tExecuting target \"" << target_command << "\"." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
} }
// a[0] execute target // a[0] execute target
int return_code = Sproc::execute( target_command ); // TODO revise variable sourcing strategy
// ....sourcing on the shell for variables and environment population doesn't have a good smell.
this->slog.log( E_INFO, "[ '" + task_name + "' ] Executing target: \"" + target_command + "\"." );
if ( exists( target_command ) )
{
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Target executable found.");
} else {
this->slog.log( E_FATAL, "[ '" + task_name + "' ] Target executable does not exist." );
throw Task_NotReady();
}
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Vars file: " + this->definition.get_env_vars_file() );
this->slog.log( E_DEBUG, "[ '" + task_name + "' ] Shell: " + this->definition.get_shell() );
std::string static_env_file = configuration->get_execution_context() + "/" + this->definition.get_env_vars_file();
int return_code = Sproc::execute(
this->definition.get_shell(),
static_env_file,
this->definition.get_user(),
this->definition.get_group(),
target_command,
this->LOG_LEVEL,
task_name,
this->definition.get_stdout_log_flag(),
configuration->get_logs_path()
);
// ********************************************** // **********************************************
// d[0] Error Code Check // d[0] Error Code Check
@@ -227,13 +231,8 @@ void Task::execute( bool verbose )
if ( return_code == 0 ) if ( return_code == 0 )
{ {
// d[0].0 ZERO // d[0].0 ZERO
this->slog.log( E_INFO, "[ '" + task_name + "' ] Target succeeded. Marking as complete." );
if ( verbose ) {
infostring = std::ostringstream();
infostring << "\tTarget " << task_name << " succeeded. Marking as complete." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
}
this->mark_complete(); this->mark_complete();
// a[1] NEXT // a[1] NEXT
@@ -243,12 +242,7 @@ void Task::execute( bool verbose )
if ( return_code != 0 ) if ( return_code != 0 )
{ {
// d[0].1 NON-ZERO // d[0].1 NON-ZERO
this->slog.log( E_WARN, "[ '" + task_name + "' ] Target failed with exit code " + std::to_string( return_code ) + "." );
infostring = std::ostringstream();
infostring << "\tTarget \"" << task_name << "\" failed with exit code " << return_code << "." << std::endl;
syslog(LOG_ERR, infostring.str().c_str() );
std::cerr << infostring.str();
// ********************************************** // **********************************************
// d[1] Rectify Check // d[1] Rectify Check
@@ -264,18 +258,13 @@ void Task::execute( bool verbose )
{ {
// d[2].0 FALSE // d[2].0 FALSE
// a[2] NEXT // a[2] NEXT
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ '" + task_name + "' ] This task is not required to continue the plan. Moving on." );
infostring << "\tThis task is not required to continue the plan. Moving on." << std::endl;
syslog(LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
return; return;
} } else {
if ( this->definition.get_required() )
{
// d[2].1 TRUE // d[2].1 TRUE
// a[3] EXCEPTION // a[3] EXCEPTION
throw TaskException("Task \"" + task_name + "\" is required, and failed, and rectification is not enabled."); this->slog.log( E_FATAL, "[ '" + task_name + "' ] Task is required, and failed, and rectification is not enabled." );
throw TaskException( "Task failed: " + task_name );
} }
// ********************************************** // **********************************************
// end - d[2] Required Check // end - d[2] Required Check
@@ -286,20 +275,24 @@ void Task::execute( bool verbose )
if ( this->definition.get_rectify() ) if ( this->definition.get_rectify() )
{ {
// d[1].1 TRUE (Rectify Check) // d[1].1 TRUE (Rectify Check)
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ " + task_name + " ] Rectification pattern is enabled." );
infostring << "\tRectification pattern is enabled for \"" << task_name << "\"." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
// a[4] Execute RECTIFIER // a[4] Execute RECTIFIER
std::string rectifier_command = this->definition.get_rectifier(); std::string rectifier_command = this->definition.get_rectifier();
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ '" + task_name + "' ] Executing rectification: " + rectifier_command + "." );
infostring << "\tExecuting rectification: " << rectifier_command << "." << std::endl;
syslog(LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
int rectifier_error = Sproc::execute( rectifier_command ); int rectifier_error = Sproc::execute(
this->definition.get_shell(),
static_env_file,
this->definition.get_user(),
this->definition.get_group(),
rectifier_command,
this->LOG_LEVEL,
task_name,
this->definition.get_stdout_log_flag(),
configuration->get_logs_path()
);
// ********************************************** // **********************************************
// d[3] Error Code Check for Rectifier // d[3] Error Code Check for Rectifier
@@ -307,12 +300,7 @@ void Task::execute( bool verbose )
if ( rectifier_error != 0 ) if ( rectifier_error != 0 )
{ {
// d[3].1 Non-Zero // d[3].1 Non-Zero
infostring = std::ostringstream(); this->slog.log( E_WARN, "[ '" + task_name + "' ] Rectification failed with exit code " + std::to_string( rectifier_error ) + "." );
infostring << "\tRectification of \"" << task_name << "\" failed with exit code "
<< rectifier_error << "." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
// ********************************************** // **********************************************
// d[4] Required Check // d[4] Required Check
@@ -320,10 +308,7 @@ void Task::execute( bool verbose )
if ( ! this->definition.get_required() ) { if ( ! this->definition.get_required() ) {
// d[4].0 FALSE // d[4].0 FALSE
// a[5] NEXT // a[5] NEXT
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ '" + task_name + "' ] This task is not required to continue the plan. Moving on." );
infostring << "\tThis task is not required to continue the plan. Moving on." << std::endl;
syslog(LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
return; return;
} }
@@ -331,7 +316,8 @@ void Task::execute( bool verbose )
{ {
// d[4].1 TRUE // d[4].1 TRUE
// a[6] EXCEPTION // a[6] EXCEPTION
throw TaskException("Task \"" + task_name + "\" is required, and failed, then rectified but rectification failed."); this->slog.log( E_FATAL, "[ '" + task_name + "' ] Task is required, but failed, and rectification failed. Lost cause." );
throw TaskException( "Lost cause, task failure." );
} }
// ********************************************** // **********************************************
// end - d[4] Required Check // end - d[4] Required Check
@@ -342,18 +328,22 @@ void Task::execute( bool verbose )
if ( rectifier_error == 0 ) if ( rectifier_error == 0 )
{ {
// d[3].0 Zero // d[3].0 Zero
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ '" + task_name + "' ] Rectification returned successfully." );
infostring << "\tRectification returned successfully." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
// a[7] Re-execute Target // a[7] Re-execute Target
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ '" + task_name + "' ] Re-Executing target \"" + this->definition.get_target() + "\"." );
infostring << "\tRe-Executing target \"" << this->definition.get_target() << "\"." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
int retry_code = Sproc::execute( target_command ); int retry_code = Sproc::execute(
this->definition.get_shell(),
static_env_file,
this->definition.get_user(),
this->definition.get_group(),
target_command,
this->LOG_LEVEL,
task_name,
this->definition.get_stdout_log_flag(),
configuration->get_logs_path()
);
// ********************************************** // **********************************************
// d[5] Error Code Check // d[5] Error Code Check
@@ -362,20 +352,11 @@ void Task::execute( bool verbose )
{ {
// d[5].0 ZERO // d[5].0 ZERO
// a[8] NEXT // a[8] NEXT
infostring = std::ostringstream(); this->slog.log( E_INFO, "[ '" + task_name + "' ] Re-execution was successful." );
infostring << "\tRe-execution was successful." << std::endl;
syslog( LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
return; return;
} } else {
if ( retry_code != 0 )
{
// d[5].1 NON-ZERO // d[5].1 NON-ZERO
infostring = std::ostringstream(); this->slog.log( E_WARN, "[ '" + task_name + "' ] Re-execution failed with exit code " + std::to_string( retry_code ) + "." );
infostring << "\tRe-execution failed with exit code " << retry_code << "." << std::endl;
syslog(LOG_ERR, infostring.str().c_str() );
std::cerr << infostring.str();
// ********************************************** // **********************************************
// d[6] Required Check // d[6] Required Check
@@ -384,11 +365,7 @@ void Task::execute( bool verbose )
{ {
// d[6].0 FALSE // d[6].0 FALSE
// a[9] NEXT // a[9] NEXT
infostring = std::ostringstream(); this->slog.log( E_INFO, "This task is not required to continue the plan. Moving on." );
infostring << "\tThis task is not required to continue the plan. Moving on." << std::endl;
syslog(LOG_INFO, infostring.str().c_str() );
std::cout << infostring.str();
return; return;
} }
@@ -396,7 +373,8 @@ void Task::execute( bool verbose )
{ {
// d[6].1 TRUE // d[6].1 TRUE
// a[10] EXCEPTION // a[10] EXCEPTION
throw TaskException("Task \"" + task_name + "\" is required, and failed, then rectified but rectifier did not heal the condition causing the target to fail. Cannot proceed with Plan."); this->slog.log( E_FATAL, "[ '" + task_name + "' ] Task is required, and failed, then rectified but rectifier did not heal the condition causing the target to fail. Cannot proceed with Plan." );
throw TaskException( "Lost cause, task failure." );
} }
// ********************************************** // **********************************************
// end - d[6] Required Check // end - d[6] Required Check
@@ -409,4 +387,4 @@ void Task::execute( bool verbose )
// end d[1] Rectify Check // end d[1] Rectify Check
// ********************************************** // **********************************************
} }
} }

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -18,12 +19,17 @@
*/ */
#ifndef FTESTS_TASK_H #ifndef REX_TASK_H
#define FTESTS_TASK_H #define REX_TASK_H
#include <string> #include <string>
#include "../json/json.h" #include <unistd.h>
#include "../../json/json.h"
#include "Unit.h" #include "Unit.h"
#include "Suite.h" #include "Suite.h"
#include "Conf.h"
#include <stdio.h>
#include "../../Sproc/Sproc.h"
#include "../misc/helpers.h"
class Task class Task
{ {
@@ -47,13 +53,13 @@ class Task
public: public:
// constructor // constructor
Task(); Task( int LOG_LEVEL );
// load a json::value into task members (second stage deserialization) // load a json::value into task members (second stage deserialization)
void load_root( Json::Value loader_root, bool verbose ); void load_root( Json::Value loader_root );
// appends definition unit as child member // appends definition unit as child member
void load_definition( Unit definition, bool verbose ); void load_definition( Unit definition );
bool is_complete(); bool is_complete();
bool has_definition(); bool has_definition();
@@ -62,12 +68,16 @@ class Task
std::string get_name(); std::string get_name();
// execute this task's definition // execute this task's definition
void execute( bool verbose ); void execute(Conf * configuration );
void mark_complete(); void mark_complete();
// returns a pointer to the dependencies vector // returns a pointer to the dependencies vector
std::vector<std::string> get_dependencies(); std::vector<std::string> get_dependencies();
private:
Logger slog;
int LOG_LEVEL;
}; };
#endif //FTESTS_TASK_H #endif //REX_TASK_H

View File

@@ -0,0 +1,302 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Unit.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <stdexcept>
#include <pwd.h>
#include <grp.h>
/// UnitException -
class UnitException: public std::exception
{
public:
/** Constructor (C strings).
* @param message C-style string error message.
* The string contents are copied upon construction.
* Hence, responsibility for deleting the char* lies
* with the caller.
*/
explicit UnitException(const char* message):
msg_(message)
{
}
/** Constructor (C++ STL strings).
* @param message The error message.
*/
explicit UnitException(const std::string& message):
msg_(message)
{}
/** Destructor.
* Virtual to allow for subclassing.
*/
virtual ~UnitException() throw (){}
/** Returns a pointer to the (constant) error description.
* @return A pointer to a const char*. The underlying memory
* is in posession of the Exception object. Callers must
* not attempt to free the memory.
*/
virtual const char* what() const throw (){
return msg_.c_str();
}
protected:
/** Error message.
*/
std::string msg_;
};
/// Unit::Unit - Constructor for Unit type. The Unit is a definition of an automation task. Each Unit has:
/// name, used for identification and retrieval.
/// target, which is the filepath of an executable to trigger.
/// output, which is the desired output of the execution of target to STDOUT in determinations of of success or failure
/// (in addition to 0|non-0 exit code). If the output is set to look for "0" then it uses the exit code.
///
/// There is also:
/// rectifier, which is the path to an executable in the event of a non-0 exit code or a failure to get the desired
/// output.
/// required, which is used as a flag to halt or continue if rectifier does not heal the system in such a way that
/// target can run successfully.
/// rectify, which is used as a flag to determine in the rectifier runs.
Unit::Unit( int LOG_LEVEL ): JSON_Loader( LOG_LEVEL ), slog( LOG_LEVEL, "_unit_" )
{
this->LOG_LEVEL;
}
/// Unit::load_root - Takes a JSON::Value and assigns the members to the Unit being populated.
///
/// \param loader_root - The JSON::Value object to use to populate unit from. Usually supplied as the Suite's buffer
/// member.
/// \return - Boolean representation of success or failure.
int Unit::load_root(Json::Value loader_root)
{
// TODO this needs reworked to have errmsg actually end up as a null return from json::value.get()
std::string errmsg = "SOMETHING WENT TERRIBLY WRONG IN PARSING";
// TODO this pattern is 'working but broken'. need to use a datastructure for required members and iterate
// do NOT replace this with a switch case pattern
if ( loader_root.isMember("name") )
{ this->name = loader_root.get("name", errmsg).asString(); } else
throw UnitException("No name attribute specified when loading a unit.");
if ( loader_root.isMember("target") )
{ this->target = loader_root.get("target", errmsg).asString(); } else
throw UnitException("No target attribute specified when loading a unit.");
if ( loader_root.isMember("rectifier") )
{ this->rectifier = loader_root.get("rectifier", errmsg).asString(); } else
throw UnitException("No rectifier executable attribute specified when loading a unit.");
if ( loader_root.isMember("active") )
{ this->active = loader_root.get("active", errmsg).asBool(); } else
throw UnitException("No activation attribute specified when loading a unit.");
if ( loader_root.isMember("required") )
{ this->required = loader_root.get("required", errmsg).asBool(); } else
throw UnitException("No required attribute specified when loading a unit.");
if ( loader_root.isMember("log") )
{ this->stdout_log_flag = loader_root.get("log", errmsg).asBool(); } else
throw UnitException("No log attribute specified when loading a unit.");
if ( loader_root.isMember("rectify") )
{ this->rectify = loader_root.get("rectify", errmsg).asBool(); } else
throw UnitException("No rectify boolean attribute specified when loading a unit.");
// TODO functionize this
int uid = getuid();
struct passwd * upw;
std::string errmsg_user;
// if no user field is specified then default to the currently executing user
if ( ( upw = getpwuid(uid) ) == NULL )
{
throw UnitException( "Could not retrieve current user." );
} else {
errmsg_user = upw->pw_name;
}
// -TODO
if ( loader_root.isMember( "user" ) )
{ this->user = loader_root.get( "user", errmsg_user ).asString(); } else this->user = errmsg_user;
// TODO functionalize this
// get the current context gid as a backup value
int gid = getgid();
// declare the grp object to pull the name from once populated
struct group * grp;
// storage for backup value once retrieved
std::string errmsg_group;
// get the backup value and store it to errmsg_group
if ( ( grp = getgrgid( gid ) ) == NULL )
{
throw UnitException("Could not retrieve current group");
} else {
errmsg_group = grp->gr_name;
}
if ( loader_root.isMember( "group" ) )
{ this->group = loader_root.get( "group", errmsg_group ).asString(); } else this->group = grp->gr_name;
if ( loader_root.isMember( "shell" ) )
{ this->shell = loader_root.get( "shell", errmsg ).asString(); } else this->shell = "/usr/bin/env sh";
if ( loader_root.isMember( "environment") )
{ this->env_vars_file = loader_root.get( "environment", errmsg ).asString(); } else {
throw UnitException("No environment file specified for a unit, and environment files are required for unit definitions.");
}
this->populated = true;
return 0;
}
/// Unit::load_string - populates a Unit object from a supplies JSON-formatted string. It's stellar.
///
/// \param json_val - JSON-formatted string to populate from. See Unit::load_root() for details on required structure.
/// \return - The bool representation of success or failure.
int Unit::load_string(std::string json_val)
{
// serialize
this->load_json_string( json_val );
// deserialize
this->load_root( this->json_root );
return 0;
}
/// Unit::get_name - retrieves the name of the unit.
///
/// \return the name of the unit.
std::string Unit::get_name()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->name;
}
/// Unit::get_target - retrieves the target of the unit.
///
/// \return the target of the unit.
std::string Unit::get_target()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->target;
}
/// Unit::get_output - retrieves the output of the unit.
///
/// \return the output of the unit.
std::string Unit::get_output()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->output;
}
/// Unit::get_rectifier - retrieves the rectifier of the unit.
///
/// \return the rectifier of the unit.
std::string Unit::get_rectifier()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->rectifier;
}
/// Unit::get_active - retrieves the armed status of the unit.
///
/// \return the armed status of the unit.
bool Unit::get_active()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->active;
}
/// Unit::get_required - retrieves the requirement status of the unit.
///
/// \return the requirement status of the unit.
bool Unit::get_required()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->required;
}
/// Unit::get_rectify - retrieves the rectification status of the unit.
///
/// \return the rectification status of the unit.
bool Unit::get_rectify()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->rectify;
}
/// Unit::get_user - retrieves the user context for the unit.
///
/// \return the string value of the user name.
std::string Unit::get_user()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->user;
}
/// Unit::get_group - retrieves the group context for the unit.
///
/// \return the string value of the group name.
std::string Unit::get_group()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->group;
}
/// Unit::get_shell - retrieves the shell path to use for the unit execution.
///
/// \return the string value of the shell path.
std::string Unit::get_shell()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->shell;
}
/// Unit::get_env_vars_file - retrieves the file path to use for the unit environment file. This is a file that is
/// sourced by the chosen shell to populate any environment variables.
/// \return the string value of the shell path.
std::string Unit::get_env_vars_file()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->env_vars_file;
}
/// Unit::get_stdout_log_flag() - retrieves the file path to use for the unit environment file. This is a file that is
/// sourced by the chosen shell to populate any environment variables.
/// \return the string value of the shell path.
bool Unit::get_stdout_log_flag()
{
if ( ! this->populated ) { throw UnitException("Attempted to access an unpopulated unit."); }
return this->stdout_log_flag;
}

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -19,15 +20,16 @@
*/ */
/* Unit.h /* Unit.h
* Unit is a type that represents a safely deserialized JSON object which defines what actions are taken as Examplar * Unit is a type that represents a safely deserialized JSON object which defines what actions are taken as rex
* iterates through it's Tasks in it's given Plan. They only define the behaviour on execution, while the tasks define * iterates through it's Tasks in it's given Plan. They only define the behaviour on execution, while the tasks define
* which Units are executed and in what order (and which Units a given Task depends on. * which Units are executed and in what order (and which Units a given Task depends on.
*/ */
#ifndef FTESTS_UNIT_H #ifndef FTEST_UNIT_H
#define FTESTS_UNIT_H #define FTEST_UNIT_H
#include <string> #include <string>
#include "../json/json.h" #include "../../json/json.h"
#include "JSON_Loader.h" #include "../low_level/JSON_Loader.h"
#include "../../Logger/Logger.h"
class Unit: JSON_Loader class Unit: JSON_Loader
{ {
@@ -58,8 +60,24 @@ private:
// if rectifier exits on non-zero return code, it should be trigger the behaviour indicated by required // if rectifier exits on non-zero return code, it should be trigger the behaviour indicated by required
bool rectify; bool rectify;
//indicator of whether stdout should log to file. used mainly to handle glitchy TUI systems when logs are being tailed.
bool stdout_log_flag;
// user to run process as.
// not intended for protected accounts, handle your own security
std::string user;
// group to run process as.
// not intended for protected accounts, handle your own security
std::string group;
// shell to use for env
std::string shell;
std::string env_vars_file;
public: public:
Unit(); Unit( int LOG_LEVEL );
// loads a serialized jason::value object as a unit // loads a serialized jason::value object as a unit
int load_root( Json::Value loader_root ); int load_root( Json::Value loader_root );
@@ -72,9 +90,19 @@ public:
std::string get_target(); std::string get_target();
std::string get_output(); std::string get_output();
std::string get_rectifier(); std::string get_rectifier();
std::string get_env_vars_file();
bool get_active(); bool get_active();
bool get_required(); bool get_required();
bool get_rectify(); bool get_rectify();
bool get_stdout_log_flag();
std::string get_user();
std::string get_group();
std::string get_shell();
private:
int LOG_LEVEL;
Logger slog;
}; };
#endif //FTESTS_UNIT_H #endif //FTEST_UNIT_H

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -17,12 +18,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef FTESTS_LOADERS_H #ifndef REX_LOADERS_H
#define FTESTS_LOADERS_H #define REX_LOADERS_H
#include "JSON_Loader.h" #include "../low_level/JSON_Loader.h"
#include "Suite.h" #include "Suite.h"
#include "Plan.h" #include "Plan.h"
#include "Conf.h" #include "Conf.h"
#endif //FTESTS_LOADERS_H #endif //REX_LOADERS_H

View File

@@ -1,27 +0,0 @@
/*
Examplar - An automation and testing framework.
© SURRO INDUSTRIES and Chris Punches, 2017.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "helpers.h"
bool exists(const std::string& name)
{
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -19,8 +20,6 @@
*/ */
#include "JSON_Loader.h" #include "JSON_Loader.h"
#include "helpers.h"
#include <stdexcept>
/// JSON_Loader_NotReady - Exception thrown when a member function is called before data is populated. /// JSON_Loader_NotReady - Exception thrown when a member function is called before data is populated.
class JSON_Loader_NotReady: public std::runtime_error { public: class JSON_Loader_NotReady: public std::runtime_error { public:
@@ -40,51 +39,10 @@ class JSON_Loader_InvalidJSON: public std::runtime_error { public:
/// JSON_Loader::JSON_Loader - Constructor for JSON_Loader base class. Simply inits to an unpopulated state. /// JSON_Loader::JSON_Loader - Constructor for JSON_Loader base class. Simply inits to an unpopulated state.
/// ///
/// The JSON_Loader type is a base type. It is meant to provide the functionalities shared between Suite and Plan. /// The JSON_Loader type is a base type. It is meant to provide the functionalities shared between Suite and Plan.
JSON_Loader::JSON_Loader() JSON_Loader::JSON_Loader( int LOG_LEVEL ): slog( LOG_LEVEL, "_json_" )
{ {
this->populated = false; this->populated = false;
} this->LOG_LEVEL = LOG_LEVEL;
/// JSON_Loader::load_json_file - Loads JSON from a filepath into a serialized representation assigned as a local member
/// intended to be used as a buffer for further operations by base methods and derived class methods.
///
/// \param filename -
/// \param verbose
void JSON_Loader::load_json_file( std::string filename, bool verbose )
{
// reads from a file into a Json::Value type.
Json::Reader json_reader;
// the a deserialized json type to contain what's read by the reader
Json::Value json_root;
// first, check if the file exists
if (! exists( filename ) )
{
std::cerr << "File '" << filename << "' does not exist." << std::endl;
throw JSON_Loader_FileNotFound();
}
// create the ifstream file handle
std::ifstream json_file_ifstream( filename, std::ifstream::binary );
// use the reader to parse the ifstream to the local property
bool parsingSuccessful = json_reader.parse( json_file_ifstream, this->json_root );
if (! parsingSuccessful )
{
std::cerr << "Failed to parse '" << filename << "':\n\t" << json_reader.getFormattedErrorMessages();
throw JSON_Loader_InvalidJSON();
} else {
// if in verbose mode, give the user an "it worked" message
if (verbose)
{
std::cout << "Parsed '" << filename << "' with " << this->json_root.size() << " element(s)." << std::endl;
}
}
// Flag as ready for consumption.
this->populated = true;
} }
/// JSON_Loader::load_json_string - loads json from std::string into a json::value type and sets to protected member /// JSON_Loader::load_json_string - loads json from std::string into a json::value type and sets to protected member
@@ -92,7 +50,7 @@ void JSON_Loader::load_json_file( std::string filename, bool verbose )
/// ///
/// \param input - The JSON-formatted string to serialize /// \param input - The JSON-formatted string to serialize
/// \param verbose - Whether or not to print verbose information to STDOUT. /// \param verbose - Whether or not to print verbose information to STDOUT.
void JSON_Loader::load_json_string( std::string input, bool verbose ) void JSON_Loader::load_json_string( std::string input )
{ {
// reads from a string into a Json::Value type. // reads from a string into a Json::Value type.
Json::Reader json_reader; Json::Reader json_reader;
@@ -108,18 +66,52 @@ void JSON_Loader::load_json_string( std::string input, bool verbose )
if (! parsingSuccessful ) if (! parsingSuccessful )
{ {
std::cerr << "Failed to parse adhoc JSON value." << std::endl << input << std::endl << std::endl << json_reader.getFormattedErrorMessages(); this->slog.log( E_FATAL, "Failed to parse adhoc JSON value: " + json_reader.getFormattedErrorMessages() );
throw JSON_Loader_InvalidJSON();
} else {
this->slog.log( E_DEBUG, "Successfully parsed JSON string with " + std::to_string( this->json_root.size() ) + "elements. Value: '" + input + "'." );
}
// flag as ready for consumption
this->populated = true;
}
/// JSON_Loader::load_json_file - Loads JSON from a filepath into a serialized representation assigned as a local member
/// intended to be used as a buffer for further operations by base methods and derived class methods.
///
/// \param filename -
/// \param verbose
void JSON_Loader::load_json_file( std::string filename )
{
// reads from a file into a Json::Value type.
Json::Reader json_reader;
// the a deserialized json type to contain what's read by the reader
Json::Value json_root;
// first, check if the file exists
if (! exists( filename ) )
{
this->slog.log( E_DEBUG, "File '" + filename + "' does not exist." );
throw JSON_Loader_FileNotFound();
}
// create the ifstream file handle
std::ifstream json_file_ifstream( filename, std::ifstream::binary );
// use the reader to parse the ifstream to the local property
bool parsingSuccessful = json_reader.parse( json_file_ifstream, this->json_root );
if (! parsingSuccessful )
{
this->slog.log( E_FATAL, "Failed to parse file '" + filename + "': " + json_reader.getFormattedErrorMessages() );
throw JSON_Loader_InvalidJSON(); throw JSON_Loader_InvalidJSON();
} else { } else {
// if in verbose mode, give the user an "it worked" message // if in verbose mode, give the user an "it worked" message
if ( verbose ) this->slog.log( E_DEBUG, "Parsed '" + filename + "' with " + std::to_string( this->json_root.size() ) + " element(s)." );
{
std::cout << "Successfully parsed JSON string with " << this->json_root.size() << " elements. Value:" << std::endl;
std::cout << input << std::endl << std::endl;
}
} }
// flag as ready for consumption // Flag as ready for consumption.
this->populated = true; this->populated = true;
} }
@@ -138,7 +130,7 @@ std::string JSON_Loader::as_string()
/// \param key - The JSON key name to assign the value to (the root of the json::value object by name) /// \param key - The JSON key name to assign the value to (the root of the json::value object by name)
/// \param verbose - Whether or not to print verbose output to STDOUT. /// \param verbose - Whether or not to print verbose output to STDOUT.
/// \return - Boolean indicator of success or failure (0|1) /// \return - Boolean indicator of success or failure (0|1)
int JSON_Loader::get_serialized(Json::Value &input, std::string key, bool verbose) int JSON_Loader::get_serialized(Json::Value &input, std::string key )
{ {
// throw if the class is not ready to be used. // throw if the class is not ready to be used.
if ( ! this->populated ) { throw JSON_Loader_NotReady(); } if ( ! this->populated ) { throw JSON_Loader_NotReady(); }
@@ -151,11 +143,10 @@ int JSON_Loader::get_serialized(Json::Value &input, std::string key, bool verbos
} }
// key was not found // key was not found
if ( verbose )
{ // verbose mode tells the user what key we were looking for.
// verbose mode tells the user what key we were looking for. this->slog.log( E_FATAL, "Failed to find key '" + key + "'." );
std::cerr << "Failed to find key '" << key << "'." << std::endl;
}
// exit code for failure // exit code for failure
return 1; return 1;
} }

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -17,13 +18,15 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
#ifndef FTESTS_JLOADER_H #ifndef REX_JLOADER_H
#define FTESTS_JLOADER_H #define REX_JLOADER_H
#include "../json/json.h" #include "../../json/json.h"
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <cstdlib> #include <cstdlib>
#include <stdexcept>
#include "../misc/helpers.h"
#include "../../Logger/Logger.h"
class JSON_Loader class JSON_Loader
{ {
@@ -33,13 +36,13 @@ class JSON_Loader
public: public:
// constructor // constructor
JSON_Loader(); JSON_Loader( int LOG_LEVEL );
// load from json file // load from json file
void load_json_file( std::string filename, bool verbose ); void load_json_file( std::string filename );
// load from std::string json // load from std::string json
void load_json_string( std::string input, bool verbose ); void load_json_string( std::string input );
// return as a JSONCPP serialized object // return as a JSONCPP serialized object
// deprecated -- these aren't really used. // deprecated -- these aren't really used.
@@ -47,6 +50,10 @@ class JSON_Loader
std::string as_string(); std::string as_string();
// safely handle deserialized type retrieval (if we want it to be safe) // safely handle deserialized type retrieval (if we want it to be safe)
int get_serialized(Json::Value &input, std::string key, bool verbose); int get_serialized(Json::Value &input, std::string key );
private:
Logger slog;
int LOG_LEVEL;
}; };
#endif //FTESTS_JLOADER_H #endif //REX_JLOADER_H

View File

@@ -0,0 +1,58 @@
/*
Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "helpers.h"
bool exists(const std::string& name)
{
struct stat buffer;
return (stat (name.c_str(), &buffer) == 0);
}
std::string get_working_path()
{
char temp[MAXPATHLEN];
return ( getcwd(temp, MAXPATHLEN) ? std::string( temp ) : std::string("") );
}
bool is_file( std::string path)
{
struct stat buf;
stat( path.c_str(), &buf );
return S_ISREG(buf.st_mode);
}
bool is_dir( std::string path )
{
struct stat buf;
stat( path.c_str(), &buf );
return S_ISDIR(buf.st_mode);
}
std::string get_8601()
{
auto now = std::chrono::system_clock::now();
auto itt = std::chrono::system_clock::to_time_t(now);
std::ostringstream ss;
// ss << std::put_time(gmtime(&itt), "%FT%TZ");
ss << std::put_time(localtime(&itt), "%Y-%m-%d_%H:%M:%S");
return ss.str();
}

View File

@@ -1,7 +1,8 @@
/* /*
Examplar - An automation and testing framework. Rex - A configuration management and workflow automation tool that
compiles and runs in minimal environments.
© SURRO INDUSTRIES and Chris Punches, 2017. © SILO GROUP and Chris Punches, 2020.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as it under the terms of the GNU Affero General Public License as
@@ -18,13 +19,26 @@
*/ */
#ifndef FTESTS_HELPERS_H #ifndef REX_HELPERS_H
#define FTESTS_HELPERS_H #define REX_HELPERS_H
#include <string> #include <string>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/param.h>
#include <unistd.h>
#include <chrono>
#include <sstream>
#include <syslog.h>
#include <iostream>
#include <iomanip>
#include <sstream>
bool exists (const std::string& name); bool exists (const std::string& name);
std::string get_working_path();
bool is_file( std::string );
bool is_dir( std::string );
std::string get_8601();
#endif //FTESTS_HELPERS_H #endif //REX_HELPERS_JH

View File

@@ -1,15 +0,0 @@
#include "Sproc.h"
#include <unistd.h>
#include <cstring>
#include <wait.h>
/// Sproc::execute
///
/// \param input - The commandline input to execute.
/// \return - The return code of the execution of input in the calling shell.
int Sproc::execute(std::string input) {
int child_exit_code = -666;
child_exit_code = system( input.c_str() );
child_exit_code = WEXITSTATUS( child_exit_code );
return child_exit_code;
}

View File

@@ -0,0 +1,7 @@
#!/usr/bin/env bash
echo CURSES DIALOG TEST
echo "This is a test of how curses dialogs are handled. Expect freaky behaviour."
dialog --title "Dialog title" --inputbox "Enter your name:" 0 0
exit $?

View File

@@ -0,0 +1,6 @@
#!/bin/bash
echo "dependent test"
echo This test depends on another test having succeeded in order to execute.
echo This tests dependencies.
exit $?

6
test/components/fail.bash Executable file
View File

@@ -0,0 +1,6 @@
#!/usr/bin/env bash
echo "Failure handling test."
echo "This test will fail on purpose."
>&2 echo "This test is printing to stderr."
exit 1

View File

@@ -0,0 +1,5 @@
#!/bin/bash
echo "This is an independent test. It does not depend on other tests."
echo "Environment file check: TEST_VAR from environment file is set to: $TEST_VAR"
exit $?

View File

@@ -0,0 +1,3 @@
echo "independent test 2 output"
echo "independent test says TEST_VAR is ${TEST_VAR}"
exit $?

7
test/config.json Normal file
View File

@@ -0,0 +1,7 @@
{
"execution_context_override": true,
"execution_context": "/home/bagira/development/internal/rex/test",
"units_path": "units/",
"logs_path": "logs/",
"config_version": "4"
}

View File

@@ -0,0 +1,11 @@
#!/usr/bin/bash
set -a
echo "variables file says hello and set a variable named TEST_VAR"
TEST_VAR="999"

5
test/plans/atomic.plan Normal file
View File

@@ -0,0 +1,5 @@
{
"plan": [
{ "name": "independent test 1", "dependencies": [ null ] }
]
}

View File

@@ -2,6 +2,8 @@
"plan": [ "plan": [
{ "name": "independent test 1", "dependencies": [ null ] }, { "name": "independent test 1", "dependencies": [ null ] },
{ "name": "independent test 2", "dependencies": [ null ] }, { "name": "independent test 2", "dependencies": [ null ] },
{ "name": "dependent test", "dependencies": [ "independent test 1" ] } { "name": "dependent test", "dependencies": [ "independent test 1" ] },
{ "name": "curses dialog", "dependencies": [ "independent test 1" ] },
{ "name": "fail", "dependencies": [ null ] }
] ]
} }

5
test/stderr.log Normal file
View File

@@ -0,0 +1,5 @@
This test is printing to stderr.
This test is printing to stderr.
This test is printing to stderr.
This test is printing to stderr.

128
test/stdout.log Normal file
View File

@@ -0,0 +1,128 @@
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'independent test 1' ] TEE Logging enabled.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] UID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] GID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 1' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'independent test 1' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
TEST OUTPUT: Test var is: 999
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'independent test 2' ] TEE Logging enabled.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] UID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] GID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'independent test 2' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'independent test 2' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
independent test 2 output
independent test says TEST_VAR is 999
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'dependent test' ] TEE Logging enabled.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] UID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] GID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'dependent test' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'dependent test' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
dependent test
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'fail' ] TEE Logging enabled.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] UID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] GID of 'bagira' is '1000'.
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:08:56] [DBUG] [_sproc] [ 'fail' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:08:56] [INFO] [_sproc] [ 'fail' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
This test will fail on purpose.
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'independent test 1' ] TEE Logging enabled.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] UID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] GID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'independent test 1' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
TEST OUTPUT: Test var is: 999
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'independent test 1' ] TEE Logging enabled.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] UID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] GID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'independent test 1' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'independent test 1' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
TEST OUTPUT: Test var is: 999
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'dependent test' ] TEE Logging enabled.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] UID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] GID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'dependent test' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'dependent test' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
dependent test
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'fail' ] TEE Logging enabled.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] DUP2: child_*_pipe[1]->STD*_FILENO
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] Attempt: Running as user 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] Attempt: Running as group_name 'bagira'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] UID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] GID of 'bagira' is '1000'.
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] Successfully set GID to '1000' (bagira).
[2021-04-04_19:15:50] [DBUG] [_sproc] [ 'fail' ] Successfully set UID to '1000' (bagira).
[2021-04-04_19:15:50] [INFO] [_sproc] [ 'fail' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
This test will fail on purpose.
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'independent test 1' ] TEE Logging enabled.
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'independent test 1' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
TEST OUTPUT: Test var is: 999
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'independent test 2' ] TEE Logging enabled.
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'independent test 2' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
independent test 2 output
independent test says TEST_VAR is 999
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'dependent test' ] TEE Logging enabled.
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'dependent test' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
dependent test
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'fail' ] TEE Logging enabled.
[2021-04-04_19:23:08] [INFO] [_sproc] [ 'fail' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
This test will fail on purpose.
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'independent test 1' ] TEE Logging enabled.
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'independent test 1' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
This is an independent test. It does not depend on other tests.
Environment file check: TEST_VAR from environment file is set to: 999
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'independent test 2' ] TEE Logging enabled.
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'independent test 2' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
independent test 2 output
independent test says TEST_VAR is 999
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'dependent test' ] TEE Logging enabled.
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'dependent test' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
dependent test
This test depends on another test having succeeded in order to execute.
This tests dependencies.
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'fail' ] TEE Logging enabled.
[2021-04-04_19:45:01] [INFO] [_sproc] [ 'fail' ] Identity context set as user 'bagira' and group 'bagira'.
variables file says hello and set a variable named TEST_VAR
Failure handling test.
This test will fail on purpose.

69
test/units/all_test.units Normal file
View File

@@ -0,0 +1,69 @@
{
"units": [
{
"name": "independent test 1",
"target": "components/independent_test_1.bash",
"rectifier": "",
"active": true,
"required": true,
"log": true,
"user": "bagira",
"group": "bagira",
"rectify": false,
"shell": "/usr/bin/env bash",
"environment": "environments/rex.variables"
},
{
"name": "independent test 2",
"target": "components/independent_test_2.bash",
"rectifier": "",
"active": true,
"required": true,
"log": true,
"user": "bagira",
"group": "bagira",
"rectify": false,
"shell": "/usr/bin/env bash",
"environment": "environments/rex.variables"
},
{
"name": "dependent test",
"target": "components/dependent_test.bash",
"rectifier": "",
"active": true,
"required": true,
"log": true,
"user": "bagira",
"group": "bagira",
"rectify": false,
"shell": "/usr/bin/env bash",
"environment": "environments/rex.variables"
},
{
"name": "curses dialog",
"target": "components/curses_dialog.bash",
"rectifier": "",
"active": true,
"required": true,
"log": false,
"user": "bagira",
"group": "bagira",
"rectify": false,
"shell": "/usr/bin/env bash",
"environment": "environments/rex.variables"
},
{
"name": "fail",
"target": "components/fail.bash",
"rectifier": "",
"active": true,
"required": false,
"log": true,
"user": "bagira",
"group": "bagira",
"rectify": false,
"shell": "/usr/bin/env bash",
"environment": "environments/rex.variables"
}
]
}