Fix files actions run() method

New run() method receives a context, which wasn't accounted for
in the initial submission.

Change-Id: I8a166a54e7f715437cec15c076377500b9f138f9
This commit is contained in:
Giulio Fidente 2017-06-29 13:56:05 +02:00
parent e62c095324
commit 6dce323726
2 changed files with 6 additions and 6 deletions

View File

@ -28,7 +28,7 @@ class FileExists(base.Action):
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
def run(self): def run(self, context):
if (isinstance(self.path, six.string_types) and if (isinstance(self.path, six.string_types) and
os.path.exists(self.path)): os.path.exists(self.path)):
msg = "Found file %s" % self.path msg = "Found file %s" % self.path
@ -48,7 +48,7 @@ class MakeTempDir(base.Action):
def __init__(self): def __init__(self):
pass pass
def run(self): def run(self, context):
try: try:
_path = tempfile.mkdtemp(dir='/tmp/', _path = tempfile.mkdtemp(dir='/tmp/',
prefix='file-mistral-action') prefix='file-mistral-action')
@ -67,7 +67,7 @@ class RemoveTempDir(base.Action):
def __init__(self, path): def __init__(self, path):
self.path = path self.path = path
def run(self): def run(self, context):
# regex from tempfile's _RandomNameSequence characters # regex from tempfile's _RandomNameSequence characters
_regex = '^/tmp/file-mistral-action[A-Za-z0-9_]{6}$' _regex = '^/tmp/file-mistral-action[A-Za-z0-9_]{6}$'
if (not isinstance(self.path, six.string_types) or if (not isinstance(self.path, six.string_types) or

View File

@ -28,7 +28,7 @@ class FileExistsTest(base.TestCase):
def test_file_exists(self, mock_exists): def test_file_exists(self, mock_exists):
mock_exists.return_value = True mock_exists.return_value = True
action = files.FileExists(self.path) action = files.FileExists(self.path)
action_result = action.run() action_result = action.run(context={})
self.assertFalse(action_result.cancel) self.assertFalse(action_result.cancel)
self.assertIsNone(action_result.error) self.assertIsNone(action_result.error)
self.assertEqual('Found file /etc/issue', self.assertEqual('Found file /etc/issue',
@ -44,7 +44,7 @@ class MakeTempDirTest(base.TestCase):
def test_make_temp_dir(self, mock_mkdtemp): def test_make_temp_dir(self, mock_mkdtemp):
mock_mkdtemp.return_value = "/tmp/file-mistral-actionxFLfYz" mock_mkdtemp.return_value = "/tmp/file-mistral-actionxFLfYz"
action = files.MakeTempDir() action = files.MakeTempDir()
action_result = action.run() action_result = action.run(context={})
self.assertFalse(action_result.cancel) self.assertFalse(action_result.cancel)
self.assertIsNone(action_result.error) self.assertIsNone(action_result.error)
self.assertEqual('/tmp/file-mistral-actionxFLfYz', self.assertEqual('/tmp/file-mistral-actionxFLfYz',
@ -61,7 +61,7 @@ class RemoveTempDirTest(base.TestCase):
def test_sucess_remove_temp_dir(self, mock_rmtree): def test_sucess_remove_temp_dir(self, mock_rmtree):
mock_rmtree.return_value = None # rmtree has no return value mock_rmtree.return_value = None # rmtree has no return value
action = files.RemoveTempDir(self.path) action = files.RemoveTempDir(self.path)
action_result = action.run() action_result = action.run(context={})
self.assertFalse(action_result.cancel) self.assertFalse(action_result.cancel)
self.assertIsNone(action_result.error) self.assertIsNone(action_result.error)
self.assertEqual('Deleted directory /tmp/file-mistral-actionxFLfYz', self.assertEqual('Deleted directory /tmp/file-mistral-actionxFLfYz',