Browse Source

add support for hostid..

main
John-Mark Gurney 2 years ago
parent
commit
c2f3364647
2 changed files with 49 additions and 6 deletions
  1. +30
    -0
      ui/fixtures/cmd.basic.json
  2. +19
    -6
      ui/medashare/cli.py

+ 30
- 0
ui/fixtures/cmd.basic.json View File

@@ -130,6 +130,36 @@
"cmd": [ "list", "test.txt" ],
"stdout_re": "foo:\tbar=baz\nhashes:\tsha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\nsig:\t.*\ntag:\t\n"
},
{
"special": "verify store object cnt",
"comment": "should have two file and one metadata",
"count": 3
},
{
"title": "test.txt in subdir t has same metadata",
"cmd": [ "list", "t/newfile.txt" ],
"stdout_re": "foo:\tbar=baz\nhashes:\tsha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\nsig:\t.*\ntag:\t\n"
},
{
"special": "verify store object cnt",
"comment": "and a obj was created for subdir",
"count": 4
},
{
"special": "set hostid",
"comment": "and that a modified hostid",
"hostid": "ceaa4862-dd00-41ba-9787-7480ec1b2679"
},
{
"title": "test.txt in subdir t has same metadata",
"cmd": [ "list", "t/newfile.txt" ],
"stdout_re": "foo:\tbar=baz\nhashes:\tsha512:90f8342520f0ac57fb5a779f5d331c2fa87aa40f8799940257f9ba619940951e67143a8d746535ed0284924b2b7bc1478f095198800ba96d01847d7b56ca465c\nsig:\t.*\ntag:\t\n"
},
{
"special": "verify store object cnt",
"comment": "and a obj was created for the new host",
"count": 5
},
{
"title": "a common tag is disallowed",
"cmd": [ "modify", "+modified=foo", "test.txt" ],


+ 19
- 6
ui/medashare/cli.py View File

@@ -9,6 +9,8 @@ from cryptography.hazmat.primitives.serialization import Encoding, \

from unittest import mock

from .hostid import hostuuid

import base58
import copy
import datetime
@@ -542,15 +544,16 @@ class FileObject(MDBase):

fname = os.path.realpath(fname)
return uuid.uuid5(_NAMESPACE_MEDASHARE_PATH,
'/'.join(os.path.split(fname)))
str(hostuuid()) + '/'.join(os.path.split(fname)))

@classmethod
def from_file(cls, filename, created_by_ref):
s = os.stat(filename)
# XXX - add host uuid?
obj = {
'dir': os.path.dirname(filename),
'created_by_ref': created_by_ref,
'hostid': hostuuid(),
'dir': os.path.dirname(filename),
'filename': os.path.basename(filename),
'id': cls.make_id(filename),
'mtime': datetime.datetime.fromtimestamp(s.st_mtime,
@@ -582,7 +585,8 @@ def enumeratedir(_dir, created_by_ref):
Returned is a list of FileObjects.'''

return [FileObject.from_file(os.path.join(_dir, x),
created_by_ref) for x in os.listdir(_dir)]
created_by_ref) for x in os.listdir(_dir) if not
os.path.isdir(os.path.join(_dir, x)) ]

def get_objstore(options):
persona = get_persona(options)
@@ -723,7 +727,7 @@ def cmd_list(options):
objstr.loadobj(fobj)

objs = objstr.by_file(i)
except (FileNotFoundError, KeyError):
except (FileNotFoundError, KeyError) as e:
print('ERROR: file not found: %s' % repr(i), file=sys.stderr)
sys.exit(1)

@@ -734,7 +738,6 @@ def cmd_list(options):
sys.exit(1)

for j in objstr.by_file(i):
#print >>sys.stderr, `j._obj`
for k, v in _iterdictlist(j):
print('%s:\t%s' % (k, v))

@@ -933,7 +936,7 @@ class _TestCases(unittest.TestCase):
self.assertEqual(ftest.dir, str(self.tempdir))
# XXX - do we add host information?
self.assertEqual(ftest.id, uuid.uuid5(_NAMESPACE_MEDASHARE_PATH,
'/'.join(os.path.split(self.tempdir) +
str(hostuuid()) + '/'.join(os.path.split(self.tempdir) +
( fname, ))))
self.assertEqual(ftest.mtime, datetime.datetime(2019, 5, 20,
21, 47, 36, tzinfo=datetime.timezone.utc))
@@ -1171,6 +1174,8 @@ class _TestCases(unittest.TestCase):
testfname = os.path.join(self.tempdir, 'test.txt')
newtestfname = os.path.join(self.tempdir, 'newfile.txt')

patches = []

for cmd in cmds:
try:
special = cmd['special']
@@ -1187,6 +1192,10 @@ class _TestCases(unittest.TestCase):
pasn1obj = pasn1.loads(fp.read())
objcnt = len(pasn1obj['objects'])
self.assertEqual(objcnt, cmd['count'])
elif special == 'set hostid':
hostidpatch = mock.patch(__name__ + '.hostuuid')
hostidpatch.start().return_value = uuid.uuid4()
patches.append(hostidpatch)
else: # pragma: no cover
raise ValueError('unhandled special: %s' % repr(special))

@@ -1216,6 +1225,10 @@ class _TestCases(unittest.TestCase):

self.assertEqual(cm.exception.code, cmd.get('exit', 0))

patches.reverse()
for i in patches:
i.stop()

def test_cmds(self):
cmds = self.fixtures.glob('cmd.*.json')



Loading…
Cancel
Save