Add files verification for 'fuel2 graph upload' command
Now Nailgun reports about successful upload of deployment graph
from directory that can even not contain any 'tasks.yaml' files.
This patch fixes:
* check if at least one 'tasks.yaml' file exists in specified
directory path
* check if at least one 'tasks.yaml' file in specified
directory path is not empty
Change-Id: I5de2474b8fbb46780450ee3873af6189a6cf17cc
Closes-Bug: 1619586
(cherry picked from commit 9dfb28e33c)
This commit is contained in:
@@ -80,10 +80,18 @@ class GraphUpload(base.BaseCommand, FileMethodsMixin):
|
||||
|
||||
tasks = []
|
||||
for file_name in iterfiles(dir_path, 'tasks.yaml'):
|
||||
tasks.extend(serializer.read_from_full_path(file_name))
|
||||
task_data = serializer.read_from_full_path(file_name)
|
||||
if task_data:
|
||||
tasks.extend(task_data)
|
||||
|
||||
if tasks:
|
||||
data['tasks'] = tasks
|
||||
|
||||
if not data:
|
||||
msg = ("Nothing to upload. Check if at least one 'tasks.yaml' "
|
||||
"file is not empty and exists in '{path}' directory "
|
||||
"path".format(path=dir_path))
|
||||
raise error.ActionException(msg)
|
||||
return data
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
||||
@@ -18,6 +18,7 @@ import mock
|
||||
import six
|
||||
import yaml
|
||||
|
||||
from fuelclient.cli import error
|
||||
from fuelclient.tests.unit.v2.cli import test_engine
|
||||
|
||||
|
||||
@@ -148,6 +149,18 @@ class TestGraphActions(test_engine.BaseCLITest):
|
||||
graph_type='provision'
|
||||
)
|
||||
|
||||
@mock.patch('fuelclient.commands.graph.os')
|
||||
@mock.patch('fuelclient.commands.graph.iterfiles')
|
||||
def test_graph_upload_from_dir_fail(self, iterfiles_m, os_m):
|
||||
os_m.path.isdir.return_value = True
|
||||
os_m.path.exists.side_effect = [True, False]
|
||||
iterfiles_m.return_value = []
|
||||
args = 'graph upload --release 1 --dir /graph/provision -t provision'
|
||||
|
||||
self.assertRaisesRegexp(error.ActionException,
|
||||
"Nothing to upload",
|
||||
self.exec_command, args)
|
||||
|
||||
@mock.patch('sys.stderr')
|
||||
def test_upload_fail(self, mocked_stderr):
|
||||
cmd = 'graph upload --file new_graph.yaml -t test'
|
||||
|
||||
Reference in New Issue
Block a user