Merge "Use unix pattern when syncing deployment tasks"
This commit is contained in:
@@ -38,6 +38,7 @@ class ReleaseAction(Action):
|
||||
Args.get_network_arg("Release network configuration."),
|
||||
Args.get_deployment_tasks_arg("Release tasks configuration."),
|
||||
Args.get_sync_deployment_tasks_arg(),
|
||||
Args.get_file_pattern_arg(),
|
||||
Args.get_dir_arg(
|
||||
"Select directory to which download release attributes"),
|
||||
group(
|
||||
@@ -133,6 +134,7 @@ class ReleaseAction(Action):
|
||||
/etc/puppet/2014.2-6.0/
|
||||
|
||||
fuel rel --sync-deployment-tasks --dir /etc/puppet/2014.2-6.0/
|
||||
fuel rel --sync-deployment-tasks --fp '*tasks.yaml'
|
||||
|
||||
In case no directory will be provided:
|
||||
|
||||
@@ -142,11 +144,10 @@ class ReleaseAction(Action):
|
||||
"""
|
||||
all_rels = Release.get_all_data()
|
||||
real_path = os.path.realpath(params.dir)
|
||||
files = list(utils.iterfiles(real_path, ('tasks.yaml',)))
|
||||
serialized_tasks = defaultdict(list)
|
||||
versions = set([r['version'] for r in all_rels])
|
||||
|
||||
for file_name in files:
|
||||
for file_name in utils.iterfiles(real_path, params.filepattern):
|
||||
for version in versions:
|
||||
if version in file_name:
|
||||
serialized_tasks[version].extend(
|
||||
|
||||
@@ -237,6 +237,14 @@ def get_sync_deployment_tasks_arg():
|
||||
help="Update tasks for each release.")
|
||||
|
||||
|
||||
def get_file_pattern_arg():
|
||||
return get_str_arg(
|
||||
"filepattern",
|
||||
flags=("--fp", "--file-pattern"),
|
||||
default="*tasks.yaml",
|
||||
help="Provide unix file pattern to filter tasks with files.")
|
||||
|
||||
|
||||
def get_network_arg(help_msg):
|
||||
return get_boolean_arg("network", flags=("--net",), help=help_msg)
|
||||
|
||||
|
||||
@@ -12,17 +12,18 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from fnmatch import fnmatch
|
||||
import os
|
||||
|
||||
|
||||
def iterfiles(dir_path, file_patterns):
|
||||
def iterfiles(dir_path, file_pattern):
|
||||
"""Returns generator where each item is a path to file, that satisfies
|
||||
file_patterns condtion
|
||||
|
||||
:param dir_path: path to directory, e.g /etc/puppet/
|
||||
:param file_patterns: iterable with file name, e.g (tasks.yaml,)
|
||||
:param file_pattern: unix filepattern to match files
|
||||
"""
|
||||
for root, dirs, file_names in os.walk(dir_path):
|
||||
for file_name in file_names:
|
||||
if file_name in file_patterns:
|
||||
if fnmatch(file_name, file_pattern):
|
||||
yield os.path.join(root, file_name)
|
||||
|
||||
@@ -86,12 +86,12 @@ class TestSyncDeploymentTasks(base.UnitTestCase):
|
||||
mrequests.get().json.return_value = RELEASE_OUTPUT
|
||||
mfiles.return_value = ['/etc/puppet/2014.2-6.0/tasks.yaml']
|
||||
mopen().__enter__().read.return_value = API_OUTPUT
|
||||
|
||||
file_pattern = '*tests*'
|
||||
self.execute_wo_auth(
|
||||
['fuel', 'rel', '--sync-deployment-tasks'])
|
||||
['fuel', 'rel', '--sync-deployment-tasks', '--fp', file_pattern])
|
||||
|
||||
mfiles.assert_called_once_with(
|
||||
os.path.realpath(os.curdir), ('tasks.yaml',))
|
||||
os.path.realpath(os.curdir), file_pattern)
|
||||
|
||||
call_args = mrequests.put.call_args_list[0]
|
||||
url = call_args[0][0]
|
||||
@@ -107,7 +107,7 @@ class TestSyncDeploymentTasks(base.UnitTestCase):
|
||||
real_path = '/etc/puppet'
|
||||
self.execute_wo_auth(
|
||||
['fuel', 'rel', '--sync-deployment-tasks', '--dir', real_path])
|
||||
mfiles.assert_called_once_with(real_path, ('tasks.yaml',))
|
||||
mfiles.assert_called_once_with(real_path, '*tasks.yaml')
|
||||
|
||||
def test_multiple_tasks_but_one_release(self, mfiles, mopen, mrequests):
|
||||
mrequests.get().json.return_value = RELEASE_OUTPUT
|
||||
|
||||
@@ -27,9 +27,9 @@ class TestUtils(base.UnitTestCase):
|
||||
@mock.patch('fuelclient.cli.utils.os.walk')
|
||||
def test_iterfiles(self, mwalk):
|
||||
mwalk.return_value = [
|
||||
('/some_directory/', [], ['valid.yaml', 'invalid.yaml'])]
|
||||
('/some_directory/', [], ['valid.yaml', 'invalid.yml'])]
|
||||
|
||||
pattern = ('valid.yaml',)
|
||||
pattern = '*.yaml'
|
||||
directory = '/some_directory'
|
||||
|
||||
expected_result = [os.path.join(directory, 'valid.yaml')]
|
||||
|
||||
Reference in New Issue
Block a user