Skip to content

Commit

Permalink
Merge pull request #86 from stfc/ensure-output-directory-exists
Browse files Browse the repository at this point in the history
Ensure output directory exists
  • Loading branch information
DavidFair authored Jul 13, 2023
2 parents 3bd96de + d1197b4 commit 3787bb5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
20 changes: 15 additions & 5 deletions aq_zombie_finder/aq_zombie_finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from re import compile as re_compile
from pathlib import Path
import argparse
import os
import sys
Expand Down Expand Up @@ -128,30 +129,39 @@ def parse_args(inp_args):
"--output",
metavar="OUTPUT",
help="Directory to create the output files in",
default="output",
)
args = parser.parse_args(inp_args)
return args


def aq_zombie_finder():
"""
Main Function to query aquilon to get a list of IPs of
VMs with Aquilon images, check if VMs that no longer
exist are still being managed by Aquilon or if VMs that
should be managed by Aquilon aren't, then output the IPs
into 2 files.
"""
# Define the variables with the script arguments
args = parse_args(sys.argv[1:])
user = args.user
password = args.password
openstack_ip = args.ip
output = args.output
output_location = args.output

# Create a paramiko SSH client to the VM running Openstack and to Aquilon
openstack_client = create_client(openstack_ip, user, password)
aquilon_client = create_client("aquilon.gridpp.rl.ac.uk", user, password)

# Ensure output directory exists
Path(output_location).mkdir(exist_ok=True)

# Define the filepath for the output to be saved to
openstack_zombie_filepath = os.path.join(
output or "output", "openstack_zombie_list.txt"
)
aquilon_zombie_filepath = os.path.join(
output or "output", "aquilon_zombie_list.txt"
output_location, "openstack_zombie_list.txt"
)
aquilon_zombie_filepath = os.path.join(output_location, "aquilon_zombie_list.txt")

# Check if output files already exist
for filepath in [
Expand Down
21 changes: 16 additions & 5 deletions dns_entry_checker/dns_entry_checker.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections import defaultdict
from re import compile as re_compile
from pathlib import Path
import argparse
import os
import sys
Expand Down Expand Up @@ -137,18 +138,25 @@ def parse_args(inp_args):
"--output",
metavar="OUTPUT",
help="Directory to create the output files in",
default="output",
)
args = parser.parse_args(inp_args)
return args


def dns_entry_checker():
"""
Main Function to get a list of IP's and matching DNS'
and check whether there are mismatches, missing values
or gaps in the list, then output those IPs and DNS' into
4 files.
"""
# Define the variables with the script arguments
args = parse_args(sys.argv[1:])
user = args.user
password = args.password
ip = args.ip
output = args.output
output_location = args.output

# Create an SSH client with the credentials given
client = create_client(ip, user, password)
Expand All @@ -162,17 +170,20 @@ def dns_entry_checker():
"grep '172.16.'",
)

# Ensure output directory exists
Path(output_location).mkdir(exist_ok=True)

# Define the filepath for the output to be saved to
forward_mismatch_filepath = os.path.join(
output or "output", "forward_mismatch_list.txt"
output_location, "forward_mismatch_list.txt"
)
backward_mismatch_filepath = os.path.join(
output or "output", "backward_mismatch_list.txt"
output_location, "backward_mismatch_list.txt"
)
backward_missing_filepath = os.path.join(
output or "output", "backward_missing_list.txt"
output_location, "backward_missing_list.txt"
)
gap_missing_filepath = os.path.join(output or "output", "gap_missing_list.txt")
gap_missing_filepath = os.path.join(output_location, "gap_missing_list.txt")

# Check if output files already exist
for filepath in [
Expand Down
2 changes: 1 addition & 1 deletion dns_entry_checker/test/test_dns_entry_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def test_parse_args(self):
self.assertEqual(
args,
Namespace(
user="test_user", password="test_pass", ip="test_ip", output=None
user="test_user", password="test_pass", ip="test_ip", output="output"
),
)

Expand Down

0 comments on commit 3787bb5

Please sign in to comment.