Skip to content

Commit

Permalink
Merge pull request #143 from DMTF/interop-dirpath
Browse files Browse the repository at this point in the history
Interop directory path
  • Loading branch information
mraineri authored Mar 25, 2022
2 parents 7c92584 + 52414d2 commit a604946
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 29 deletions.
7 changes: 5 additions & 2 deletions RedfishInteropValidator.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ def main(argslist=None, configfile=None):
from common.profile import getProfiles, checkProfileAgainstSchema, hashProfile

my_profiles = []
my_paths = []
success = True
for filename in args.profile:
with open(filename) as f:
my_profiles.append((filename, json.loads(f.read())))
my_paths.append(os.path.split(filename)[0])
if args.schema is not None:
with open(args.schema) as f:
schema = json.loads(f.read())
Expand All @@ -154,12 +156,13 @@ def main(argslist=None, configfile=None):
# Combine profiles
all_profiles = []
for name, profile in my_profiles:
all_profiles.extend(getProfiles(profile, './', online=args.online_profiles))
all_profiles.extend(getProfiles(profile, [os.getcwd()] + my_paths, online=args.online_profiles))

my_logger.info('\nProfile Hashes: ')
for profile in all_profiles:
profileName = profile.get('ProfileName')
my_logger.info('profile: {}, dict md5 hash: {}'.format(profileName, hashProfile(profile)))
profileVersion = profile.get('ProfileVersion')
my_logger.info('profile: {} {}, dict md5 hash: {}'.format(profileName, profileVersion, hashProfile(profile)))

# Start main
status_code = 1
Expand Down
51 changes: 26 additions & 25 deletions common/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

import os
import re
import glob
import json
import logging

from common.redfish import splitVersionString, versionpattern

my_logger = logging.getLogger()
my_logger.setLevel(logging.DEBUG)

Expand Down Expand Up @@ -38,16 +41,16 @@ def checkProfileAgainstSchema(profile, schema):
# consider @odata.type, with regex
return True

extension = 'json'
versionpattern = 'v[0-9]_[0-9]_[0-9]'

defaultrepository = 'http://redfish.dmtf.org/profiles'

def getListingVersions(filename, dirname):
pattern = '\.' + versionpattern + '\.'
filepattern = re.compile(pattern.join(filename.split('.')))
for item in os.listdir(dirname):
if filepattern.match(item):
yield item
def getProfilesMatchingName(name, directories):
pattern = r'\.{}\.'.format(versionpattern)
filepattern = re.compile(pattern.join(name.split('.')) + "|{}".format(name.replace('.', '\.')))
for dirname in directories:
for file in glob.glob(os.path.join(dirname, '*.json')):
if filepattern.match(os.path.basename(file)):
yield file

def dict_merge(dct, merge_dct):
"""
Expand Down Expand Up @@ -102,7 +105,7 @@ def getProfileFromRepo(profilename, repo=None):
return None


def getProfiles(profile, dirname, chain=None, online=False):
def getProfiles(profile, directories, chain=None, online=False):
alldata = [profile]
if 'RequiredProfiles' not in profile:
my_logger.debug('No such item RequiredProfiles')
Expand All @@ -119,35 +122,33 @@ def getProfiles(profile, dirname, chain=None, online=False):
for item in requiredProfiles:
targetName = item
rp = requiredProfiles[targetName]
targetVersionUnformatted = rp.get('MinVersion', '1.0.0')
targetVersion = 'v{}_{}_{}'.format(*tuple(targetVersionUnformatted.split('.')))
targetFileBlank = '{}.{}'.format(targetName, extension)
targetFile = None
min_version = splitVersionString(rp.get('MinVersion', '1.0.0'))
targetVersion = 'v{}_{}_{}'.format(*min_version)
targetFile = '{}.{}'.format(targetName, 'json')

# get max filename
repo = rp.get('Repository')
if online:
data = getProfileFromRepo(targetFileBlank, repo)
data = getProfileFromRepo(targetFile, repo)
else:
data = None

if data is None:
targetList = sorted(list(getListingVersions(targetFileBlank, dirname)))
targetList = list(getProfilesMatchingName(targetFile, directories))
if len(targetList) > 0:
max_version = (1,0,0)
for item in targetList:
if targetFile is None:
targetFile = item
targetFile = max(targetFile, item)
fileVersion = re.search(versionpattern, targetFile).group()
filehandle = open(dirname + '/' + targetFile, "r")
data = filehandle.read()
filehandle.close()
data = json.loads(data)
if targetVersion > fileVersion:
with open(item) as f:
my_profile = json.load(f)
my_version = splitVersionString(my_profile.get('ProfileVersion', '1.0.0'))
max_version = max(max_version, my_version)
if my_version == max_version or data == None:
data = my_profile
if min_version > max_version:
my_logger.warning('File version smaller than target MinVersion')
else:
my_logger.error('Could not acquire this profile {} {}'.format(targetName, repo))
continue

alldata.extend(getProfiles(data, dirname, chain))
alldata.extend(getProfiles(data, directories, chain))
return alldata
4 changes: 2 additions & 2 deletions common/redfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def splitVersionString(version):
else:
payload_split = v_payload.split('.')
if len(payload_split) != 3:
return [0, 0, 0]
return [int(v) for v in payload_split]
return (0, 0, 0)
return tuple([int(v) for v in payload_split])


def compareMinVersion(version, min_version):
Expand Down

0 comments on commit a604946

Please sign in to comment.