except HTTPError as e:
log.error(str(e))
sys.exit(1)
+ except OSError as e:
+ deploy_sys._log_error_and_exit(str(e))
log.info('Archives upload complete.')
log.debug('archives_dir = {}'.format(archives_dir))
if os.path.exists(archives_dir):
- log.debug('Archives file/dir {} does exist.'.format(archives_dir))
- for file_or_dir in os.listdir(archives_dir):
- f = os.path.join(archives_dir, file_or_dir)
- try:
- log.debug('Moving {}'.format(f))
- shutil.move(f, dest_dir)
- except shutil.Error as e:
- log.warn(e)
+ if os.path.isfile(archives_dir):
+ log.error('Archives {} is a file, not a directory.'.format(archives_dir))
+ raise OSError(errno.ENOENT, 'Not a directory', archives_dir)
+ else:
+ log.debug('Archives dir {} does exist.'.format(archives_dir))
+ for file_or_dir in os.listdir(archives_dir):
+ f = os.path.join(archives_dir, file_or_dir)
+ try:
+ log.debug('Moving {}'.format(f))
+ shutil.move(f, dest_dir)
+ except shutil.Error as e:
+ log.error(e)
+ raise OSError(errno.EPERM, 'Could not move to', archives_dir)
else:
- log.debug('Archives file/dir {} does not exist.'.format(archives_dir))
+ log.error('Archives dir {} does not exist.'.format(archives_dir))
+ raise OSError(errno.ENOENT, 'Missing directory', archives_dir)
if pattern is None:
return
--- /dev/null
+---
+fixes:
+ - |
+ There is a possibility that there exists a file called Archives, and if so, there will be an OSError crash
+ 02:15:01 File "/home/jenkins/.local/lib/python2.7/site-packages/lftools/deploy.py", line 236, in deploy_archives
+ 02:15:01 copy_archives(workspace, pattern)
+ 02:15:01 File "/home/jenkins/.local/lib/python2.7/site-packages/lftools/deploy.py", line 170, in copy_archives
+ 02:15:01 for file_or_dir in os.listdir(archives_dir):
+ 02:15:01 OSError: [Errno 20] Not a directory: '/w/workspace/autorelease-update-validate-jobs-fluorine/archives'
+
+ This fix raises an Exception, and exists lftools with (1), if there is any issues with the Archive directory
+ (missing, a file instead of directory, or something else)
--- /dev/null
+abcdefghijklmnopqrstuvwxyz
--- /dev/null
+aaa:controller,infrautils,mdsal,odlparent,yangtools
+bgpcep:controller,infrautils,mdsal,netconf,odlparent,yangtools
+controller:mdsal,odlparent,yangtools
+coe:controller,mdsal,netconf,odlparent
+daexim:controller,infrautils,mdsal,netconf,odlparent,yangtools
+genius:controller,daexim,infrautils,mdsal,netconf,odlparent,openflowplugin,ovsdb,serviceutils,yangtools
+infrautils:odlparent
+integration/distribution:aaa,integration,odlparent
+lispflowmapping:controller,mdsal,netconf,neutron,odlparent
+mdsal:odlparent,yangtools
+netconf:aaa,controller,mdsal,odlparent,yangtools
+netvirt:aaa,coe,controller,genius,infrautils,mdsal,netconf,neutron,odlparent,openflowplugin,ovsdb,serviceutils,sfc,yangtools
+neutron:aaa,controller,infrautils,mdsal,netconf,odlparent,ovsdb,yangtools
+openflowplugin:controller,infrautils,mdsal,netconf,odlparent,serviceutils,yangtools
+ovsdb:aaa,controller,infrautils,mdsal,netconf,odlparent,yangtools
+serviceutils:controller,infrautils,mdsal,odlparent,yangtools
+sfc:aaa,controller,genius,infrautils,lispflowmapping,mdsal,netconf,odlparent,openflowplugin,ovsdb,serviceutils
--- /dev/null
+abcdefghijklmnopqrstuvwxyz
--- /dev/null
+aaa:controller,infrautils,mdsal,odlparent,yangtools
+bgpcep:controller,infrautils,mdsal,netconf,odlparent,yangtools
+controller:mdsal,odlparent,yangtools
+coe:controller,mdsal,netconf,odlparent
+daexim:controller,infrautils,mdsal,netconf,odlparent,yangtools
+genius:controller,daexim,infrautils,mdsal,netconf,odlparent,openflowplugin,ovsdb,serviceutils,yangtools
+infrautils:odlparent
+integration/distribution:aaa,integration,odlparent
+lispflowmapping:controller,mdsal,netconf,neutron,odlparent
+mdsal:odlparent,yangtools
+netconf:aaa,controller,mdsal,odlparent,yangtools
+netvirt:aaa,coe,controller,genius,infrautils,mdsal,netconf,neutron,odlparent,openflowplugin,ovsdb,serviceutils,sfc,yangtools
+neutron:aaa,controller,infrautils,mdsal,netconf,odlparent,ovsdb,yangtools
+openflowplugin:controller,infrautils,mdsal,netconf,odlparent,serviceutils,yangtools
+ovsdb:aaa,controller,infrautils,mdsal,netconf,odlparent,yangtools
+serviceutils:controller,infrautils,mdsal,odlparent,yangtools
+sfc:aaa,controller,genius,infrautils,lispflowmapping,mdsal,netconf,odlparent,openflowplugin,ovsdb,serviceutils
@pytest.mark.datafiles(
os.path.join(FIXTURE_DIR, 'deploy'),
)
-def test_deploy_archive2(cli_runner, datafiles, responses):
- """Test deploy_archives() command for expected upload cases."""
+def test_deploy_archive2(datafiles):
+ """Test deploy_archives() command when archives dir is missing."""
os.chdir(str(datafiles))
workspace_dir = os.path.join(str(datafiles), 'workspace-noarchives')
- # Test successful upload
- url = 'https://nexus.example.org/service/local/repositories/logs/content-compressed'
- responses.add(responses.POST, '{}/test/path/abc'.format(url),
- json=None, status=201)
- result = cli_runner.invoke(
- cli.cli,
- ['--debug', 'deploy', 'archives', 'https://nexus.example.org', 'test/path/abc', workspace_dir],
- obj={})
- assert result.exit_code == 0
+ with pytest.raises(OSError) as excinfo:
+ deploy_sys.copy_archives(workspace_dir)
+ assert workspace_dir in str(excinfo.value)
+
+
+@pytest.mark.datafiles(
+ os.path.join(FIXTURE_DIR, 'deploy'),
+ )
+def test_deploy_archive3(datafiles):
+ """Test deploy_archives() command when archives dir is a file instead of a dir."""
+ os.chdir(str(datafiles))
+ workspace_dir = os.path.join(str(datafiles), 'workspace-archivesfile')
+
+ with pytest.raises(OSError) as excinfo:
+ deploy_sys.copy_archives(workspace_dir)
+ assert workspace_dir in str(excinfo.value)
@pytest.mark.datafiles(