This repository contains a set of Bash scripts that make up a data pipeline, designed to automate the process of interacting with an SEL-735 meter. The pipeline is divided into two main executable scripts:
data_pipeline.sh
: Handles the first four steps:
archive_pipeline.sh
: Handles the final step:
Ensure you have the following before running the pipeline:
lftp
yq
zip
rsync
jq
Clone the repository:
git clone git@github.com:acep-uaf/camio-meter-streams.git
cd camio-meter-streams/cli_meter
Note: You can check your SSH connection with ssh -T git@github.com
Navigate to the config
directory and copy the example configuration files to a new file:
cd config
cp config.yml.example config.yml
cp archive_config.yml.example archive_config.yml
Update the configuration files with the target details:
config.yml
: Add the FTP server credentials and meter configuration data.archive_config.yml
: Add the source and destination directories and other relevant details.Secure the configuration files so that only the owner can read and write:
chmod 600 config.yml
chmod 600 archive_config.yml
To run the data pipeline and then transfer data to the target server:
Run the Data Pipeline
Execute the data_pipeline
script from the cli_meter
directory. The script requires a configuration file specified via the -c/--config
flag. If this is your first time running the pipeline, the initial download may take a few hours. To pause the download safely, see: How to Stop the Pipeline
./data_pipeline.sh -c config/config.yml
Run the Archive Pipeline
After the data_pipeline
script completes, execute the archive_pipeline
script from the cli_meter
directory. The script requires a configuration file specified via the -c/--config
flag.
./archive_pipeline.sh -c config/archive_config.yml
The rsync uses the --exclude
flag to exclude the working
directory to ensure only complete files are transfered.
Run the Cleanup Process (Conditional)
If the archive_pipeline
script completes successfully and the enable_cleanup
flag is set to true in the archive configuration file, the cleanup.sh
script will be executed automatically. This script removes outdated event files based on the retention period specified in the configuration file.
If the enable_cleanup
flag is not enabled, you can run the cleanup manually by passing in the archive configuration file.
./cleanup.sh -c config/archive_config.yml
Ensure that the archive_config.yml
file is properly configured with the retention periods for each directory in the cleanup process.
When you need to stop the pipeline:
Ctrl+C
to interrupt the process. Ctrl+\
to quit.data_pipeline
command.The download will resume from where it left off, provided the same config file (-c
)is used.Ctrl+Z
:
Ctrl+Z
to suspend the process, as it may cause the pipeline to end without properly closing the FTP connection.This repository includes automated tests for the scripts using Bats (Bash Automated Testing System) along with helper libraries: bats-assert
, bats-mock
, and bats-support
. The tests are located in the test
directory and are automatically run on all pull requests using Github Actions to ensure code quality and functionality.
Ensure you have cloned the repository with its required submodules, they should be located under the test
and test/test_helper
directories:
bats-core
bats-assert
bats-mock
bats-support
Clone the repository with submodules:
git clone --recurse-submodules git@github.com:acep-uaf/camio-meter-streams.git
If you have already cloned the repository without submodules, you can initialize and update them with:
git submodule update --init --recursive
Navigate to the project directory:
cd /path/to/camio-meter-streams/cli_meter
Run all the tests:
bats test
When making changes to the pipeline, it is essential to add or update tests to cover the new or modified functionality. Follow these steps to add tests:
Locate the appropriate test file:
Navigate to the test
directory and identify the test file that corresponds to the functionality you're modifying. If no such file exists, create a new test file using the .bats
extension (e.g., my_script_test.bats
).
Write your tests:
Use bats-assert
, bats-mock
, and bats-support
helper libraries to write comprehensive tests. Refer to the bats-core documentation.
If your tests require shared variables or helper functions, define them in test/test-helper/commons.bash
to ensure consistency and reusability across multiple test files. For example:
# commons.bash
MY_VARIABLE="common value"
function my_helper_function {
echo "This is a helper function"
}
Example test structure:
@test "description of the test case" {
# Arrange
# Set up any necessary environment or input data.
# Act
result=$(command-to-test)
# Assert
assert_success
assert_output "expected output"
}
Run your tests locally:
Ensure your new tests pass locally by running bats test
.
Commit and push your changes:
Include your test updates in the same pull request as the code changes.
All tests in the repository are automatically executed through GitHub Actions on every pull request. This ensures that all contributions meet quality and functionality standards before merging. Ensure your pull request passes all tests to avoid delays in the review process.